📄 template.c
字号:
return( stat );
}
#endif /* !DEVICE_LOCK_PROTECTION */
#if !DEVICE_PAGE_MODE /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_PageMode
*
* Description:
*
* This procedure is called to enable or disable page mode read to
* the device.
*
* Parameters:
*
* IN enable - flag "1" to indicate the page mode is anable and
* flag "0" to indicate the page mode is disable to
* the device.
*
* 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_PageMode ( UINT16 enable )
{
TMPL_Status stat;
stat.Result = StatUnsupported;
return( stat );
}
#endif /* !DEVICE_PAGE_MODE */
#if !DEVICE_PROGRAM_FLASH /* if there is no device.c implementation */
#if X_16
/****************************************************************************
*
* TMPL_ProgramFlash
*
* Description:
*
* This procedure is called to program the flash device at the specified
* address with the single specified data value. See the flash device
* datasheet for specific details on this command.
*
* Parameters:
*
* IN address - the flash address to be programmed.
*
* IN item - the data value to be programmed.
*
* 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_ProgramFlash ( UINT32 address,
UINT8 item,
UINT8 returnSR )
{
TMPL_Status stat;
TMPL_FDATA_PTR fptr;
TMPL_FDATA writedata;
if ( address >= TMPL_TOTAL_SIZE )
{
stat.Result = StatBadAddress;
return( stat );
}
if ( returnSR )
{
TMPL_ClearStatus();
}
writedata = (TMPL_FDATA)( item );
if ( ( address & 0x1 ) != 0 )
{
address--;
#if (BIG_ENDIAN_ARCHITECTURE)
writedata |= 0xFF00;
#else /* little endian */
writedata = ( writedata << 8 ) | 0x00ff;
#endif
}
else
{
#if BIG_ENDIAN_ARCHITECTURE
writedata |= 0x00ff;
#else /* little endian */
writedata |= 0xff00;
#endif /* BIG_ENDIAN_ARCHITECTURE */
}
TMPL_WriteF(address, TMPL_PROGRAM_SETUP );
fptr = TMPL_GetFptr(address);
*fptr = writedata;
if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
{
stat.Result = StatTimeout;
}
else
{
stat.Result = StatCompleted;
}
if ( returnSR )
{
stat.SR = TMPL_ReadStatus();
}
/* return device to read array mode */
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );
return( stat );
}
#endif /* X_16 */
#endif /* !DEVICE_PROGRAM_FLASH */
#if !DEVICE_PROGRAM_FLASH_BUFFERED /* if there is no device.c implementation */
#if X_16
/****************************************************************************
*
* TMPL_ProgramFlashBuffered
*
* Description:
*
* This procedure is called to program the flash device at the specified
* starting address contiguously with the specified buffer data. See
* the flash device datasheet for specific details on the program
* command.
*
* Parameters:
*
* IN address - the flash address to be programmed.
*
* IN buffer - the buffer containing data to be programmed.
*
* IN numitems - the number of data items contained in the buffer.
*
* 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_ProgramFlashBuffered ( UINT32 address,
UINT8_PTR buffer,
UINT32 numbytes,
UINT8 returnSR )
{
UINT32 count;
TMPL_Status stat;
TMPL_FDATA_PTR fptr;
TMPL_FDATA writedata;
if ( ( address + numbytes ) > TMPL_TOTAL_SIZE )
{
stat.Result = StatBadAddress;
return( stat );
}
if ( returnSR )
{
TMPL_ClearStatus();
}
if ( numbytes > 0 ) /* while more data to write */
{
while ( numbytes > 0 ) /* if 2 or more bytes still to write */
{
if ( ( address & 0x1 ) != 0 ) /* if destination address is odd */
{
address--;
#if (BIG_ENDIAN_ARCHITECTURE)
writedata = (FDATA) *buffer;
writedata |= 0xff00;
#else /* little endian */
writedata = *((TMPL_FDATA_PTR)buffer);
writedata = ( writedata << 8 ) | 0x00ff;
#endif
numbytes--;
buffer++;
}
else /* destination address is even */
{
#if BIG_ENDIAN_ARCHITECTURE
/* grab first byte */
writedata = (TMPL_FDATA)( *buffer );
writedata = ( ( writedata << 8 ) & 0xFF00 );
/* grab second byte */
writedata = writedata | ( (TMPL_FDATA) *(buffer+1) );
#else /* little endian architecture */
/* grab 2 bytes */
writedata = *( (TMPL_FDATA_PTR)buffer );
#endif /* BIG_ENDIAN_ARCHITECTURE */
if ( numbytes == 1 )
{
#if BIG_ENDIAN_ARCHITECTURE
writedata |= 0x00ff;
#else
writedata |= 0xff00;
#endif
numbytes--;
}
else
{
numbytes -= sizeof(TMPL_FDATA);
}
buffer += sizeof(TMPL_FDATA);
}
TMPL_WriteF(address, TMPL_PROGRAM_SETUP );
fptr = TMPL_GetFptr(address);
*fptr = writedata;
if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
{
stat.Result = StatTimeout;
if ( returnSR )
{
stat.SR = TMPL_ReadStatus();
}
return( stat );
}
address += sizeof(TMPL_FDATA);
}
}
stat.Result = StatCompleted;
if ( returnSR )
{
stat.SR = TMPL_ReadStatus();
}
/* return device to read array mode */
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );
return( stat );
}
#endif /* X_16 */
#endif /* !DEVICE_PROGRAM_FLASH_BUFFERED */
#if !DEVICE_PROGRAM_PROTECTION /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_ProgramProtection
*
* Description:
*
* This procedure is called to program the protection register on
* the flash device at the specified location with the specified data
* value. See the flash device datasheet for specific details on this
* command.
*
* Parameters:
*
* IN location - the protection register location on the flash
* device to be programmed.
*
* IN value - the data item to be programmed.
*
* 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_ProgramProtection ( UINT32 location,
TMPL_FDATA value,
UINT8 returnSR )
{
TMPL_Status stat;
stat.Result = StatUnsupported;
return( stat );
}
#endif /* !DEVICE_PROGRAM_PROTECTION */
#if !DEVICE_PROGRAM_SUSPEND /* if there is no device.c implementation */
/****************************************************************************
*
* TMPL_ProgramSuspend
*
* Description:
*
* This procedure is called to issue the program suspend command to
* the flash device. See the flash device datasheet for specific details
* on this command.
*
* Parameters:
*
* IN blocknum - the block number on the device.
*
* 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:
*
* When this function is called the device is currently in the program
* mode for the block identified.
*
***************************************************************************/
TMPL_Status TMPL_ProgramSuspend ( UINT16 blocknum,
UINT8 returnSR )
{
TMPL_Status stat;
stat.Result = StatUnsupported;
return( stat );
}
#endif /* !DEVICE_PROGRAM_SUSPEND */
#if !DEVICE_QUERY /* if there is no device.c implementation */
#if X_16
/****************************************************************************
*
* TMPL_Query
*
* Description:
*
* This procedure is called to issue the query command to
* the flash device. See the flash device datasheet for specific details
* on this command.
*
* Parameters:
*
* OUT *query - pointer to query structure
*
* Returns:
*
* TMPL_Status - includes function return status defined by enum
* TMPL_CommandStat.
*
* Assumptions:
*
* NONE
*
***************************************************************************/
TMPL_Status TMPL_Query ( struct TMPL_QueryData *query )
{
TMPL_Status stat;
UINT32 add;
UINT32 offset;
TMPL_FDATA item;
UINT32 longitem;
UINT32 i;
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_QUERY );
offset = TMPL_QUERY_START_OFFSET;
/* read query string */
for ( i=0; i < 3; i++ )
{
stat = TMPL_GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_ReadF( add, &item );
item &= 0xff;
query->QueryStr[i] = (char)item;
offset++;
}
query->QueryStr[3] = '\0'; /* null terminate string */
/* read vendor id */
query->VendorId = 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->VendorId = (UINT16)( query->VendorId | item );
offset++;
}
/* read extended table ptr */
query->ExtTablePtr = 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -