register UCHAR uc;
g_dwSaveAddr = RecvDword(); /* buffer address */
g_dwSaveCount = dwCharCounter = RecvDword(); /* count */
dwCheckSum = dwBlockCounter = 0;
while (1)
{
pucBuf = (UCHAR*)(g_dwDramBase[dwBlockCounter++]);
for (dwInBlockCounter=0;
dwInBlockCounter<(DWORD)DRAM_BLOCK_SIZE;
dwInBlockCounter++)
{
uc = ReceiveChar();
*pucBuf = uc;
if (uc != *pucBuf)
{
PrintMsg((UCHAR*)g_szDramError);
while(1);
}
pucBuf++;
dwCheckSum += uc;
--dwCharCounter;
if ((dwCharCounter == 0)
|| (dwCharCounter & 0x80000000)) /*(int)dwCharCounter <= 0 */
{
g_dwCheckSum = dwCheckSum;
return;
}
}
}
}
DWORD RecvDword(void)
{
register DWORD i;
register DWORD dw;
for (i=dw=0; i<4; i++)
{
dw |= ReceiveChar()<<(8*i);
}
return dw;
}
/**************************************************************************
;
; UART driver
;
;**************************************************************************/
void SendChar(register UCHAR ch)
{
register DWORD dwReg;
dwReg = HW1base;
while (*((DWORD*)(dwReg+HW1_SYSFLG1)) & (UART1_TX_FIFO_FULL));
while (*((DWORD*)(dwReg+HW1_SYSFLG1)) & (UART1_TX_BUSY));
*((UCHAR*)(dwReg + HW1_UARTDR1)) = ch;
}
UCHAR ReceiveChar(void)
{
register DWORD dwReg;
dwReg = HW1base;
while (*((DWORD*)(dwReg + HW1_SYSFLG1)) & (UART1_RX_FIFO_EMPTY));
return *((UCHAR*)(dwReg + HW1_UARTDR1));
}
void Beep(void)
{
register DWORD i;
register DWORD dwReg;
dwReg = (DWORD)(HW1base + 0x1000 + HW2_SYSCON2);
*((DWORD*)dwReg) = SYSCON2_VALUE_BEEP_ON;
for (i=0; i<0x30000; i++);
*((DWORD*)dwReg) = SYSCON2_VALUE_BEEP_OFF;
/*
dwReg = (DWORD)(HW1base + HW1_SYSCON1);
for (j=0x600; j!=0; j--)
{
*pdwReg |= BUZZER_TOGGLE;
for (i=0x100; i!=0; i--);
*pdwReg &= ~BUZZER_TOGGLE;
for (i=0x100; i!=0; i--);
}
*/
}
/*-------------------------------------------------------------------------*/
void FlashChipUnlock(void)
{
register DWORD dw;
register UCHAR* pucFlashAddr;
register UCHAR ucCmdSetup = FLASH_COMMAND_CONFIG_SETUP ;
register UCHAR ucCmdUnlock = FLASH_COMMAND_UNLOCK_BLOCK;
pucFlashAddr = (UCHAR*)FLASH_START_ADDRESS;
for (dw=0; dw<FLASH_ERASE_8K_BLOCKS; dw++)
{
*pucFlashAddr = ucCmdSetup;
*pucFlashAddr = ucCmdUnlock;
pucFlashAddr += 0x2000;
}
for (dw=0; dw<FLASH_ERASE_64K_BLOCKS; dw++)
{
*pucFlashAddr = ucCmdSetup;
*pucFlashAddr = ucCmdUnlock;
pucFlashAddr += 0x10000;
}
*((UCHAR*)FLASH_START_ADDRESS) =
(UCHAR)FLASH_COMMAND_READ;
}
UCHAR* FlashBlockErase(UCHAR * pucBlockAddr, DWORD dwBlocks, DWORD dwBlockSize)
{
register UCHAR ucStatus;
register DWORD dw;
for (dw=0; dw<dwBlocks; dw++)
{
*((DWORD*)pucBlockAddr) = (FLASH_COMMAND_CONFIRM<<16) |FLASH_COMMAND_ERASE;
*pucBlockAddr = FLASH_COMMAND_STATUS;
do {
ucStatus = *pucBlockAddr;
} while (!(ucStatus & FLASH_STATUS_READY));
if (ucStatus & FLASH_STATUS_ERROR)
FlashErrorHandler((UCHAR*)&g_szEraseFlashError, pucBlockAddr);
pucBlockAddr += dwBlockSize;
}
return pucBlockAddr;
}
void FlashChipErase(void)
{
FlashBlockErase(FlashBlockErase((UCHAR*)FLASH_START_ADDRESS,
FLASH_ERASE_8K_BLOCKS, 0x2000),
FLASH_ERASE_64K_BLOCKS,
0x10000);
*((UCHAR*)FLASH_START_ADDRESS) =(UCHAR)FLASH_COMMAND_READ;
}
void FlashCheckEmpty()
{
register DWORD dwStartAddr;
dwStartAddr = (DWORD)FLASH_START_ADDRESS;
do
{
if (*((DWORD*)dwStartAddr) != (DWORD)(0xFFFFFFFF))
FlashErrorHandler((UCHAR*)&g_szFlashNotEmpty, (UCHAR *)dwStartAddr);
dwStartAddr += 4;
}while (dwStartAddr < (DWORD)FLASH_CHECK_EMPTY_END_ADDRESS);
}
void FlashWrite()
{
register DWORD dwValue;
register DWORD dwBlockCounter, dwInBlockCounter;
register DWORD dwCheckSum;
DWORD * pdwFlashAddr;
DWORD * pdwBufAddr;
1 2 3 4 5 6