📄 template.c
字号:
/* read typical buffer timeout */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->TypicalBufferTimeout = (UINT8)item;
offset++;
/* read block erase timeout */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->BlockEraseTimeout = (UINT8)item;
offset++;
/* read chip erase timeout */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->ChipEraseTimeout = (UINT8)item;
offset++;
/* read max single timeout */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->MaxSingleTimeout = (UINT8)item;
offset++;
/* read max buffer timeout */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->MaxBufferTimeout = (UINT8)item;
offset++;
/* read max block erase timeout */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->MaxBlockEraseTimeout = (UINT8)item;
offset++;
/* read max chip erase timeout */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->MaxChipEraseTimeout = (UINT8)item;
offset++;
/* read device size */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->DeviceSize = (UINT8)item;
offset++;
/* read device interface */
query->DeviceInterface = 0;
for ( i=0; i < 2; i++ )
{
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
item = item << (8*(1-i) );
#else
item &= 0xff;
item = item << (8*i);
#endif
query->DeviceInterface = (UINT16)
( query->DeviceInterface | item );
offset++;
}
/* read max write buffer bytes */
query->MaxWriteBufferBytes = 0;
for ( i=0; i < 2; i++ )
{
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
item = item << (8*(1-i) );
#else
item &= 0xff;
item = item << (8*i);
#endif
query->MaxWriteBufferBytes = (UINT16)
( query->MaxWriteBufferBytes | item );
offset++;
}
/* read num erase blocks */
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
#else
item &= 0xff;
#endif
query->NumEraseBlocks = (UINT8)item;
offset++;
/* read erase block information */
query->EraseBlockInformation = 0;
for ( i=0; i < 4; i++ )
{
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF(add, &item);
#if BIG_ENDIAN_ARCHITECTURE
item &= 0x00ff;
longitem = (UINT32)((UINT32)item << (8*(3-i) ));
#else
item &= 0xff;
longitem = (UINT32)((UINT32)item << (8*i));
#endif
query->EraseBlockInformation = (UINT32)
( query->EraseBlockInformation | longitem );
offset++;
}
stat.Result = StatCompleted;
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );
return( stat );
}
#endif /* X_16 */
#endif /* !DEVICE_QUERY */
#if !DEVICE_READ_BLOCK_STATUS /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_ReadBlockStatus
*
* Description:
*
* This procedure is called to read the status for the specified block
* from the flash device. See the flash device datasheet for specific
* details on this command.
*
* Parameters:
*
* IN blocknum - the block number on the device.
*
* OUT blockstat- the status of the block as: unlocked, locked,
* or locked down.
*
* Returns:
*
* TMPL_Status - includes function return status defined by enum
* TMPL_CommandStat.
*
* Assumptions:
*
* NONE
*
***************************************************************************/
TMPL_Status TMPL_ReadBlockStatus ( UINT16 blocknum,
TMPL_FDATA *blockstat );
{
TMPL_Status stat;
stat.Result = StatUnsupported;
return( stat );
}
#endif /* !DEVICE_READ_BLOCK_STATUS */
#if !DEVICE_READ_DEVICE_ID /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_ReadDeviceID
*
* Description:
*
* This procedure is called to read the status for the specified block
* from the flash device. See the flash device datasheet for specific
* details on this command.
*
* Parameters:
*
* OUT mcode - the manufacturer code.
*
* OUT deviceid - the device id.
*
* Returns:
*
* TMPL_Status - includes function return status defined by enum
* TMPL_CommandStat.
*
* Assumptions:
*
* NONE
*
***************************************************************************/
TMPL_Status TMPL_ReadDeviceID ( UINT16_PTR mcode,
UINT16_PTR deviceid )
{
TMPL_Status stat;
UINT32 idaddress;
#if X_8
idaddress = ( TMPL_BASE_FLASH_ADDRESS + 2 );
#endif
#if PX_16
idaddress = ( TMPL_BASE_FLASH_ADDRESS + sizeof( TMPL_FDATA ) );
#endif
#if X_16
idaddress = ( TMPL_BASE_FLASH_ADDRESS + sizeof( TMPL_FDATA ) );
#endif
#if X_32
idaddress = ( TMPL_BASE_FLASH_ADDRESS + sizeof( TMPL_FDATA ) );
#endif
#if ILX_32
idaddress = ( TMPL_BASE_FLASH_ADDRESS + ( sizeof( TMPL_FDATA ) * 2 ) );
#endif
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ID_CODES);
TMPL_ReadF(TMPL_BASE_FLASH_ADDRESS, mcode );
TMPL_ReadF(idaddress, deviceid);
stat.Result = StatCompleted;
return( stat );
}
#endif /* !DEVICE_READ_DEVICE_ID */
#if !DEVICE_READF /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_ReadF
*
* Description:
*
* This procedure is called to read a single data item directly from the
* specified device address. This function is used internally by the
* flash template api. Clients that need to read data from the flash
* device should use the TMPL_ReadFlash command. See the flash device
* datasheet for specific details on reading flash data.
*
* Parameters:
*
* IN address - the flash address to be read from.
*
* OUT value - the flash data read from the device.
*
* Returns:
*
* NONE
*
* Assumptions:
*
* The flash device is in the READ_ARRAY mode when this function is
* called.
*
***************************************************************************/
void TMPL_ReadF ( UINT32 address,
TMPL_FDATA_PTR value )
{
TMPL_FDATA_PTR fptr;
fptr = TMPL_GetFptr(address);
*value = *fptr;
}
#endif /* !TMPL_READF */
#if !DEVICE_READ_FLASH /* if there is no device.c implementation */
#if X_16
/****************************************************************************
*
* TMPL_ReadFlash
*
* Description:
*
* This procedure is called to read one or more data items from
* the flash device at the specified starting address. See the flash
* device datasheet for specific details on reading flash data.
*
* Parameters:
*
* IN address - the starting device address.
*
* OUT buffer - the buffer to contain the data items read.
*
* IN numbytes - the number of data items to read.
*
* IN returnSR - flag to indicate whether the device status register
* value should be returned by this function.
*
* Returns:
*
* TMPL_Status - includes function return status defined by enum
* TMPL_CommandStat and optionally the flash device
* status register value.
*
* Assumptions:
*
* NONE
*
***************************************************************************/
TMPL_Status TMPL_ReadFlash ( UINT32 address,
UINT16_PTR buffer,
UINT32 numbytes,
UINT8 returnSR )
{
TMPL_Status stat;
UINT32 curr_address, numwords, temp_words;
if ( ( address + numbytes ) > TMPL_TOTAL_SIZE )
{
stat.Result = StatBadAddress;
return( stat );
}
if ( returnSR )
{
TMPL_ClearStatus();
}
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );
curr_address = address;
if (temp_words = numbytes% 2)
{
numwords = (UINT32)(numbytes/2 + 1);
}
else
{
numwords = (UINT32)(numbytes/2) ;
}
while ( numwords > 0)
{
TMPL_ReadF(curr_address, buffer);
buffer ++;
numwords --;
curr_address += sizeof(UINT16);
}
stat.Result = StatCompleted;
if ( returnSR )
{
stat.SR = TMPL_ReadStatus();
}
return( stat );
}
#endif /* X_16 */
#endif /* !DEVICE_READ_FLASH */
#if !DEVICE_READ_STATUS /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_ReadStatus
*
* Description:
*
* This procedure is called to read the status register value from
* the flash device. See the flash device datasheet for specific details
* on this command.
*
* Parameters:
*
* NONE
*
* Returns:
*
* TMPL_FDATA - the status register value read from the device.
*
* Assumptions:
*
* NONE
*
***************************************************************************/
TMPL_FDATA TMPL_ReadStatus ( void )
{
TMPL_FDATA status;
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_STATUS_REGISTER );
TMPL_ReadF(TMPL_BASE_FLASH_ADDRESS, &status );
return( status );
}
#endif /* !DEVICE_READ_STATUS */
#if !DEVICE_WAIT_UNTIL_READY /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_WaitUntilReady
*
* Description:
*
* This procedure is called to wait until the flash device status
* indicates a ready state or times out. See the flash device datasheet
* for specific details on reading status data.
*
* Parameters:
*
* IN timeout - timeout value specified as number of times
* to read the status register before giving up.
*
* Returns:
*
* UINT8 - boolean flag indicating whether the ready state was
* reached before the timeout number of reads
* occured.
*
* Assumptions:
*
* NONE.
*
***************************************************************************/
UINT8 TMPL_WaitUntilReady ( UINT32 timeout )
{
while ( timeout )
{
if ( mIsStatusReady( TMPL_ReadStatus() ) )
{
return( TRUE );
}
timeout--;
}
return( FALSE );
}
#endif /* !DEVICE_WAIT_UNTIL_READY */
#if !DEVICE_WRITEF /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_WriteF
*
* Description:
*
* This procedure is called to write a single data item directly to the
* specified device address. This function is used internally by the
* flash template api. Clients that need to write data to the flash
* device should use the TMPL_ProgramFlash or TMPL_ProgramFlashBuffered
* command. See the flash device datasheet for specific details on
* writing flash data.
*
* Parameters:
*
* IN address - the flash address to be written to.
*
* IN value - the flash data to write to the device.
*
* Returns:
*
* NONE
*
* Assumptions:
*
* NONE
*
***************************************************************************/
void TMPL_WriteF ( UINT32 address,
TMPL_FDATA value )
{
TMPL_FDATA_PTR fptr;
fptr = TMPL_GetFptr(address);
*fptr = value;
}
#endif /* !DEVICE_WRITEF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -