📄 my_640j3.c
字号:
/* read maximum voltage */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->VccMax = (BYTE)item;
offset++;
/* read supply voltage */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->VppMin = (BYTE)item;
offset++;
/* read supply max voltage */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->VppMax = (BYTE)item;
offset++;
/* read typical program timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->TypicalProgTimeout = (BYTE)item;
offset++;
/* read typical buffer timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->TypicalBufferTimeout = (BYTE)item;
offset++;
/* read block erase timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->BlockEraseTimeout = (BYTE)item;
offset++;
/* read chip erase timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->ChipEraseTimeout = (BYTE)item;
offset++;
/* read max single timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->MaxSingleTimeout = (BYTE)item;
offset++;
/* read max buffer timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->MaxBufferTimeout = (BYTE)item;
offset++;
/* read max block erase timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->MaxBlockEraseTimeout = (BYTE)item;
offset++;
/* read max chip erase timeout */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->MaxChipEraseTimeout = (BYTE)item;
offset++;
/* read device size */
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->DeviceSize = (BYTE)item;
offset++;
/* read device interface */
query->DeviceInterface = 0;
for ( i=0; i < 2; i++ )
{
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( 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 = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( 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 = GetQueryAddress(offset, &add);
if ( stat.Result !=StatCompleted )
{
return( stat );
}
// ReadFlash( add, &item );
#if BIG_ENDIAN_ARCHITECTURE
{
item &= 0x00ff;
}
#else
{
item &= 0xff;
}
#endif
query->NumEraseBlocks = (BYTE)item;
offset++;
/* read erase block information */
query->EraseBlockInformation = 0;
for ( i=0; i < 4; i++ )
{
stat = GetQueryAddress(offset, &add);
if ( stat.Result != StatCompleted )
{
return( stat );
}
// ReadFlash( 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;
WriteFlash(BASE_FLASH_ADDRESS, READ_ARRAY );
return( stat );
}
/********************Read Block Status ******************/
Flash_Status ReadBlockStatus( UINT16 blocknum, UINT32 *blockstat )
{
UINT32 stataddress;
Flash_Status stat;
UINT32 blockaddr;
stat = GetBlockAddress( blocknum, &blockaddr );
if ( stat.Result != StatCompleted )
{
return( stat );
}
stataddress = ( blockaddr + ( 2 * sizeof( UINT16 ) ) );
WriteFlash( BASE_FLASH_ADDRESS, READ_ID_CODES );
// ReadFlash( stataddress, blockstat );
/* return device to read array mode */
WriteFlash( BASE_FLASH_ADDRESS, READ_ARRAY );
stat.Result = StatCompleted;
return( stat );
}
/******************Read Protection ************************/
Flash_Status ReadProtection( UINT32 location, UINT32_PTR value )
{
UINT32 baseaddr;
UINT32 address;
Flash_Status stat;
if ( location > OTP_NUMWORDS )
{
stat.Result = StatBadOtp;
return( stat );
}
baseaddr = BASE_FLASH_ADDRESS;
address = OTP_BASE + BASE_FLASH_ADDRESS;
address += ( location * sizeof(UINT16) );
WriteFlash( baseaddr, OTP_READ );
// ReadFlash( address, value );
/* return device to read array mode */
WriteFlash( BASE_FLASH_ADDRESS, READ_ARRAY );
stat.Result = StatCompleted;
return( stat );
}
/******************** Resume ************************/
Flash_Status Resume( UINT16 blocknum )
{
Flash_Status stat;
UINT32 blockaddr;
// UINT16 status;
stat = GetBlockAddress( blocknum, &blockaddr );
if ( stat.Result != StatCompleted )
{
return( stat );
}
WriteFlash( BASE_FLASH_ADDRESS, CLEAR_STATUS_REGISTER ); /* Clear status register */
WriteFlash( blockaddr, BLOCK_RESUME );
if ( !WaitUntilReady( PROGRAM_TIMEOUT ) )
{
stat.Result = StatTimeout;
}
else
{
stat.Result = StatCompleted;
}
stat.SR = ReadStatus();
return( stat );
}
/*********************** Unlock All Blocks ******************************/
Flash_Status UnlockAllBlocks( void )
{
Flash_Status stat;
WriteFlash( BASE_FLASH_ADDRESS, CLEAR_STATUS_REGISTER ); /* Clear status register */
WriteFlash( BASE_FLASH_ADDRESS, CONFIG_SETUP );
WriteFlash( BASE_FLASH_ADDRESS, LOCK_BIT_CLEAR );
if ( !WaitUntilReady( PROGRAM_TIMEOUT ) )
{
stat.Result = StatTimeout;
}
else
{
stat.Result = StatCompleted;
}
stat.SR = ReadStatus();
/* return device to read array mode */
WriteFlash(BASE_FLASH_ADDRESS, READ_ARRAY );
return( stat );
}
/****************************************************************************
* Function:
* This procedure is called to return a flash ptr given a
* specified device address.
*
* Parameters: address ---- The flash address
*
* Returns: UINT32_PTR ---- address returned in ptr form
***************************************************************************/
/****************** GetFptr *************************/
/*UINT32_PTR GetFptr( UINT32 address )
{
return( (UINT32_PTR)address );
}*/
void Flash_init (void)
{
#define EMIFS_GlB_Config_REG 0xfffecc0c /* TC EMIFS Configuration Register */
//#define CS0_CHIP_SELECT_REG 0xfffecc10 /* TC EMIFS CS0 Configuration Register */
//#define CS3_CHIP_SELECT_REG 0xfffecc1c /* TC EMIFS CS3 Configuration Register */
UINT32 regval;
regval = GetIo32(EMIFS_GlB_Config_REG);
regval = regval | 0x0001; /* Turn off write protection for flash devices. WP = 1 */
SetIo32(regval, EMIFS_GlB_Config_REG); //*((volatile UINT32 *) EMIFS_GlB_Config_REG) = regval;
/* If, instead, you want to reference flash at 0x0c000000, then it seemed the following were necessary. */
/* *((volatile unsigned int *)CS0_CHIP_SELECT_REG) = 0x202090; / * Overrides head.S setting of 0x212090 */
// *((volatile unsigned int *)CS3_CHIP_SELECT_REG) = 0x202053; /* Let's flash chips be fully functional. */
}
//flash write protected turn off
void Flash_wpoff(void)
{
#define EMIFS_GlB_Config_REG 0xfffecc0c /* TC EMIFS Configuration Register */
//#define CS0_CHIP_SELECT_REG 0xfffecc10 /* TC EMIFS CS0 Configuration Register */
//#define CS3_CHIP_SELECT_REG 0xfffecc1c /* TC EMIFS CS3 Configuration Register */
UINT32 regval;
regval = GetIo32(EMIFS_GlB_Config_REG);
regval |= 0x0001; /* Turn off write protection for flash devices. WP = 1 */
SetIo32(regval, EMIFS_GlB_Config_REG); //*((volatile UINT32 *) EMIFS_GlB_Config_REG) = regval;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -