ARM仿真器-foxICE 设为首页   |   加入收藏夹   |   网站地图         
  站内搜索:
 
http://www.foxice.net
最新下载_foxICE
ARM7TDMI R3内核
ARM7EJS内核
ARM946E-S内核
ARM966E-S内核
ARM9TDMI内核
ARM940T内核
ARM指令集速查卡
ARM925T内核(TI925T)

更多 >> 

 技术专栏RSS订阅

   首页>技术专栏>Redboot >ARM Bootloader的实现 ---C和ASM混合编程

ARM Bootloader的实现 ---C和ASM混合编程

作者:Gavin Li ver 1  2  3  4  5  6

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

立即下载:
点击下载
相关文档
 
下载说明:
  1. 未经本站明确许可,任何网站不得非法盗链及抄袭本站资源!
 

首页 | 产品介绍 | 技术支持 | 下载中心 | 技术专栏 | 关于我们 | 联系我们
电话:86-755-82798083   82796301   传真:86-755-82799007    Email:sales@foxice.net   sales6@foxice.net
在线咨询:QQ:346466907   MSN:sales6@foxice.net   ini3000@msn.com

© 2006 Foxice.net 版权所有