📄 hal_nor.c
字号:
* bytes : number of bytes to write *
* *
* Returns : *
* NONE *
* *
******************************************************************************/
void blk_read_using_data_reg ( volatile FLByte * base,
FLByte * buf,
FLSNative bytes )
{
register FLWord * buf16 ;
register FLSNative max;
buf16 = (FLWord *) buf;
max = (FLSNative)buf + bytes;
/* retrieve data */
for (; (FLSNative)buf16 < max; buf16+=8)
{
buf16[0] = DOCHREAD_IO_WORD(base);
buf16[1] = DOCHREAD_IO_WORD(base);
buf16[2] = DOCHREAD_IO_WORD(base);
buf16[3] = DOCHREAD_IO_WORD(base);
buf16[4] = DOCHREAD_IO_WORD(base);
buf16[5] = DOCHREAD_IO_WORD(base);
buf16[6] = DOCHREAD_IO_WORD(base);
buf16[7] = DOCHREAD_IO_WORD(base);
}
}
/******************************************************************************
* *
* h a l _ b l k _ r e a d _ n o r *
* *
* Read 'sectors' sectors from DOCH *
* *
* Parameters : *
* base : pointer to the base of DOCH register set *
* dest : buffer to read to *
* sectors : number of sectors to read *
* *
* Returns : *
* always zero (success) *
* *
******************************************************************************/
FLSNative hal_blk_read_nor ( volatile FLByte * base,
FLByte * dest,
FLSNative sectors )
{
volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)(addToFarPointer(base, DOCH_DATA_PORT_AREA));
FLSNative count = sectors<<DOCH_SECTOR_SIZE_BITS;
register int i;
register FLWord tmp;
#ifndef DOCH_NO_INIT_MMU_PAGES
if (count == 0)
return 0;
dest[0] = 0;
*((FLByte FAR1*)addToFarPointer(dest, (count - 1)) ) = (FLByte)0;
#endif /* DOCH_NO_INIT_MMU_PAGES */
if( (FLDword)dest & 0x1 )
{
/* rare case: unaligned target buffer */
for (i = 0; i < (int)count; )
{
tmp = DOCHREAD_IO_WORD(swin);
#ifdef DOCH_BIG_ENDIAN
dest[i++] = (FLByte)(tmp>>8);
dest[i++] = (FLByte)tmp;
#else
dest[i++] = (FLByte)tmp;
dest[i++] = (FLByte)(tmp>>8);
#endif /* DOCH_BIG_ENDIAN */
}
}
else
{ /* mainstream case */
/* Some memcpy implementations from none 4 bytes aligned destination
* buffer may use a for loop of single byte calls to the first 2
* bytes. This implementation may be good for RAM, but will be
* problematic to 16bit DiskOnChip that does not have a BHE signal.
* so if the buffer is not dword aligned we would not perform memcpy */
if (((FLDword)dest&0x3)==0)
{
DOCHCPY_FROM_IO_16_BITS( (volatile byte *)swin, dest, count );
}
else
{ /* read in short words */
for (i = 0, count = count >> 1; i < (int)count; i++)
((FLWord FAR1 *)dest)[i] = DOCHREAD_IO_WORD(swin);
}
}
return 0;
}
/******************************************************************************
* *
* b l k _ w r i t e _ u s i n g _ d a t a _ r e g *
* *
* Write specified # of bytes through the ATA data register *
* *
* Parameters : *
* base : pointer to the base of DOCH register set *
* buf : buffer to write from *
* bytes : number of bytes to write *
* *
* Returns : *
* NONE *
* *
******************************************************************************/
void blk_write_using_data_reg ( volatile FLByte * base,
FLByte * buf,
FLSNative bytes )
{
volatile FLWord * reg16 = (FLWord*)base;
register FLWord * buf16 ;
register FLSNative max;
buf16 = (FLWord *) buf;
max = (FLSNative)buf + bytes;
/* write data */
for (; (FLSNative)buf16 < max; buf16+=8)
{
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[0],reg16);
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[1],reg16);
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[2],reg16);
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[3],reg16);
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[4],reg16);
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[5],reg16);
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[6],reg16);
DOCHWRITE_IO_WORD(((FLWord FAR1 *)buf16)[7],reg16);
}
}
/******************************************************************************
* *
* h a l _ b l k _ w r i t e _ n o r *
* *
* write 'sectors' sectors to DOCH *
* *
* Parameters : *
* base : pointer to the base of DOCH register set *
* src : buffer to write from *
* sectors : number of sectors to write *
* *
* Returns : *
* always zero (success) *
* *
******************************************************************************/
FLSNative hal_blk_write_nor ( volatile FLByte * base,
FLByte * src,
FLSNative sectors )
{
volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)addToFarPointer(base, DOCH_DATA_PORT_AREA);
FLSNative count = sectors<<DOCH_SECTOR_SIZE_BITS;
register int i;
register FLWord tmp;
if( (FLDword)src & 0x1 ) /* rare case: unaligned source buffer */
{
for (i = 0; i < (int)count; i+=2)
{
/* tmp variable is just a precaution from compiler optimizations */
#ifdef DOCH_BIG_ENDIAN
tmp = ((FLWord)src[i]<<8) + (FLWord)src[i+1];
#else
tmp = (FLWord)src[i] + ((FLWord)src[i+1]<<8);
#endif /* DOCH_BIG_ENDIAN */
DOCHWRITE_IO_WORD(tmp,swin);
}
}
else /* mainstream case */
{
/* Some memcpy implementations from none 4 bytes aligned destination
* buffer may use a for loop of single byte calls to the first 2
* bytes. This implementation may be good for RAM, but will be
* problematic to 16bit DiskOnChip that does not have a BHE signal.
* so if the buffer is not dword aligned we would not perform memcpy */
if (((FLDword)src&0x3)==0)
{
DOCHCPY_TO_IO_16_BITS((volatile FLByte *)swin,src,count);
}
else
{
/* write in short words */
for (i = 0, count = count >> 1; i < (int)count; i++)
/* while incrementing buffer offset */
/* but do not increament DiskOnChip offset */
DOCHWRITE_IO_WORD(((FLWord FAR1 *)src)[i],swin);
}
}
return 0;
}
#ifdef __cplusplus
}
#endif
#else /*DOCH_USE_FUNC*/
DOCH_Error hal_init_nor_noFunc ( FLSNative socketNo)
{
gAccessLayerType = DOCH_AL_NOR;
return DOCH_OK;
}
#endif /*DOCH_USE_FUNC*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -