📄 strata.c
字号:
ulBufDatumSize = bIsPaired? (ulWriteBufferSize / sizeof(ULONG)) :
(ulWriteBufferSize / sizeof(USHORT));
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("ulBufDatumSize 0x%08x\r\n"), ulBufDatumSize));
for(i = 0; i < dwNumPages; i++)
{
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("Page: %d ulProgramAddress 0x%08x\r\n"), i, ulProgramAddress));
if(bIgnore0to1)
{
for(j = 0; j < ulBufDatumSize; j++)
ulIgnoreBuffer[j] = bIsPaired? *((volatile ULONG *)ulProgramAddress + j): *((volatile USHORT *)ulProgramAddress + j);
}
WR_FLASH_REG_16(bIsPaired, ulProgramAddress, BUFFER_WRITE_CMD);
if(!CheckStatus(bIsPaired, ulProgramAddress, FALSE))
{
ERRORMSG(ZONE_HAL_ERROR, (TEXT("Page: %d ulProgramAddress 0x%08x failed\r\n"), i, ulProgramAddress));
bSuccess = FALSE;
break;
}
WR_FLASH_REG_16(bIsPaired, ulProgramAddress, (ulBufDatumSize - 1)) ;
WR_FLASH_16(bIsPaired, ulProgramAddress, *(ULONG *)pulData);
for(j = 0; j < (ulBufDatumSize - 1); j++)
{
ulProgramAddress += dwBusWidth;
pulData = (ULONG *)((ULONG)pulData + dwBusWidth);
ulDataToWrite = bIsPaired? *(ULONG *)pulData : *(USHORT *)pulData;
if(bIgnore0to1)
ulDataToWrite &= ulIgnoreBuffer[j];
WR_FLASH_16(bIsPaired, ulProgramAddress, ulDataToWrite);
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("[0x%08x] expect 0x%08x\r\n"),
ulProgramAddress, *(ULONG *)pulData));
}
// Now program the buffer into flash...
//
WR_FLASH_REG_16(bIsPaired, ulProgramAddress, BLOCK_PROCEED_CMD);
if(!CheckStatus(bIsPaired, ulProgramAddress, FALSE))
{
bSuccess = FALSE;
break;
}
// Incrememnt programmed bytes count and print progress
ulProgramAddress += dwBusWidth;
pulData = (ULONG *)((ULONG)pulData + dwBusWidth);
}
}
// Put the Flash into a known state (READ_ARRAY mode with WRITE-ENABLE disabled).
// ******************************************************************************
WR_FLASH_REG_16(bIsPaired, ulFlashBase, READ_ARRAY_CMD);
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("StrataX16_Program-\r\n")));
return bSuccess;
}
//-----------------------------------------------------------------------------
//
// Function: StrataX16_EraseSector
//
// Erases a sector of flash.
// Note: Input address must be sector aligned (to be ensured by caller)
//
// Parameters:
// pFlashDesc
// [in] pointer to NOR flash descriptor
//
// ulSectorAddress
// [in] start address of block to start erase
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL StrataX16_EraseSector(NOR_FLASH_DESC *pFlashDesc, ULONG ulSectorAddress)
{
ULONG ulFlashBase;
BOOL bIsPaired;
BOOL bSuccess;
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("StrataX16_EraseSector+ 0x%08x 0x%08x\r\n"),
pFlashDesc, ulSectorAddress));
if(!pFlashDesc)
{
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("StrataX16_EraseSector: null param\r\n")));
return FALSE;
}
bIsPaired = pFlashDesc->PairedFlash;
ulFlashBase = pFlashDesc->FlashBase;
// Issue erase and confirm command.
// Note: eventually this should be changed to issue mass block erases, then loop to
// verify each completes.
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, BLOCK_ERASE_CMD);
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, BLOCK_PROCEED_CMD);
bSuccess = CheckStatus(bIsPaired, ulSectorAddress, FALSE);
// Put the Flash into a known state (READ_ARRAY mode with WRITE-ENABLE disabled).
// ******************************************************************************
WR_FLASH_REG_16(bIsPaired, ulFlashBase, READ_ARRAY_CMD);
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("StrataX16_EraseSector-\r\n")));
return bSuccess;
}
//-----------------------------------------------------------------------------
//
// Function: CheckStatus
//
// Function checks status of the operation. For 16bit mode flash devices.
// Notes:
// This needs to be relocated since the program/erase functions call it.
//
// Parameters:
// bIsPaired
// [in] TRUE if flash is paired.
//
// ulSectorAddress
// [in] address of sector to check status for
//
// fLockCmd
// [in] TRUE if this is a Set/Clear Lock-Bit command
//
// Returns:
// TRUE if device ready
//
//-----------------------------------------------------------------------------
BOOL CheckStatus(BOOL bIsPaired, ULONG ulSectorAddress, BOOL fLockCmd)
{
ULONG ulStatus;
ULONG ulCount = 0;
while(!CHECK_FLASH_STATUS_16(bIsPaired, ulSectorAddress, STATUS_READY_MASK))
{
if( ulCount++ == CHECK_STATUS_TIMEOUT)
{
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Timed out checking status\r\n")));
break;
}
}
ulStatus = RD_FLASH_16(bIsPaired, ulSectorAddress);
if(ulStatus == (ULONG)CREATE_MASK_16(bIsPaired, STATUS_READY_MASK))
{
// Success
return TRUE;
}
#ifdef DEBUG
//
// Print appropriate error...
//
if((ulStatus & STATUS_ERROR_VOLTAGE) == STATUS_ERROR_VOLTAGE)
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Voltage Range Error ... Lower flash.\r\n")));
else if((ulStatus & STATUS_ERROR_COMMAND) == STATUS_ERROR_COMMAND)
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Command Sequence Error ... Lower flash.\r\n")));
else if((ulStatus & STATUS_ERROR_LOCKED) == STATUS_ERROR_LOCKED)
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Block locked ... Lower flash.\r\n")));
else if((ulStatus & STATUS_ERROR_SR5) == STATUS_ERROR_SR5)
{
if(fLockCmd)
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Clear Lock Bits Error for Block... Lower flash.\r\n")));
else
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Erase Error for Block... Lower flash.\r\n")));
}
else if((ulStatus & STATUS_ERROR_SR4) == STATUS_ERROR_SR4)
{
if(fLockCmd)
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Set Lock Bits Error for Block... Lower flash.\r\n")));
else
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Programming Error for Block... Lower flash.\r\n")));
}
if(bIsPaired)
{
if((ulStatus & UPPER_16(STATUS_ERROR_VOLTAGE)) == UPPER_16(STATUS_ERROR_VOLTAGE))
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Voltage Range Error ... Upper flash.\r\n")));
else if((ulStatus & UPPER_16(STATUS_ERROR_COMMAND)) == UPPER_16(STATUS_ERROR_COMMAND))
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Command Sequence Error ... Upper flash.\r\n")));
else if((ulStatus & UPPER_16(STATUS_ERROR_LOCKED)) == UPPER_16(STATUS_ERROR_LOCKED))
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Block locked ... Upper flash.\r\n")));
else if((ulStatus & UPPER_16(STATUS_ERROR_SR5)) == UPPER_16(STATUS_ERROR_SR5))
{
if(fLockCmd)
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Clear Lock Bits Error for Block ... Upper flash.\r\n")));
else
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Erase Error for Block ... Upper flash.\r\n")));
}
else if((ulStatus & UPPER_16(STATUS_ERROR_SR4)) == UPPER_16(STATUS_ERROR_SR4))
{
if(fLockCmd)
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Set Lock Bits Error for Block... Upper flash.\r\n")));
else
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("STRATA Error: Programming Error for Block... Upper flash.\r\n")));
}
}
#endif
// Clear the status register
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, CLEAR_STATUS_CMD);
return FALSE;
}
// WARNING: for relocation purpose. Do not move!
void StrataX16_RelocateEnd(void)
{
}
//-----------------------------------------------------------------------------
//
// Function: StrataX16_LockSector
//
// Function locks a block. For 16bit mode flash devices.
// Note: Input address must be sector aligned (to be ensured by caller)
//
// Parameters:
// pFlashDesc
// [in] pointer to NOR flash descriptor
//
// ulSectorAddress
// [in] sector address to lock
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL StrataX16_LockSector(NOR_FLASH_DESC *pFlashDesc, ULONG ulSectorAddress)
{
ULONG ulFlashBase;
BOOL bIsPaired;
BOOL bSuccess;
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("StrataX16_LockSector+ 0x%08x 0x%08x\r\n"),
pFlashDesc, ulSectorAddress));
if(!pFlashDesc)
{
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("StrataX16_LockSector: null param\r\n")));
return FALSE;
}
bIsPaired = pFlashDesc->PairedFlash;
ulFlashBase = pFlashDesc->FlashBase;
// Clear the status register.
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, CLEAR_STATUS_CMD);
// Set the block lock bit and confirm.
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, BLOCK_LOCK_CMD);
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, BLOCK_SETLOCK_CMD);
bSuccess = CheckStatus(bIsPaired, ulSectorAddress, TRUE);
// Put the Flash into a known state (READ_ARRAY mode with WRITE-ENABLE disabled).
// ******************************************************************************
WR_FLASH_REG_16(bIsPaired, ulFlashBase, READ_ARRAY_CMD);
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("StrataX16_LockSector-\r\n")));
return bSuccess;
}
//-----------------------------------------------------------------------------
//
// Function: StrataX16_UnlockSector
//
// Function unlocks a block. For 16bit mode flash devices.
// Note: Input address must be sector aligned (to be ensured by caller)
//
// Parameters:
// pFlashDesc
// [in] pointer to NOR flash descriptor
//
// ulSectorAddress
// [in] sector address to unlock
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL StrataX16_UnlockSector(NOR_FLASH_DESC *pFlashDesc, ULONG ulSectorAddress)
{
ULONG ulFlashBase;
BOOL bIsPaired;
BOOL bSuccess;
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("StrataX16_UnlockSector+ 0x%08x 0x%08x\r\n"),
pFlashDesc, ulSectorAddress));
if(!pFlashDesc)
{
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("StrataX16_UnlockSector: null param\r\n")));
return FALSE;
}
bIsPaired = pFlashDesc->PairedFlash;
ulFlashBase = pFlashDesc->FlashBase;
// Clear the status register.
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, CLEAR_STATUS_CMD);
// Set the block lock bit and confirm.
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, BLOCK_LOCK_CMD);
WR_FLASH_REG_16(bIsPaired, ulSectorAddress, BLOCK_PROCEED_CMD);
bSuccess = CheckStatus(bIsPaired, ulSectorAddress, TRUE);
// Put the Flash into a known state (READ_ARRAY mode with WRITE-ENABLE disabled).
// ******************************************************************************
WR_FLASH_REG_16(bIsPaired, ulFlashBase, READ_ARRAY_CMD);
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("StrataX16_LockSector-\r\n")));
return bSuccess;
}
//-----------------------------------------------------------------------------
// PRIVATE FUNCTIONS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// END OF FILE
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -