📄 main.c
字号:
printf("Set PLLA to 180Mhz and Master clock to 60Mhz and start U-BOOT\n\r");
//* Added by liaizun 20051202
//* Enable Watchdog
//AT91S_SYS_ST = (AT91S_ST *)AT91C_BASE_ST;
//AT91S_SYS_ST->ST_WDMR = AT91C_ST_EXTEN | AT91C_ST_RSTEN | (((65536 * 1) >> 8) & AT91C_ST_WDV);
//AT91S_SYS_ST->ST_CR = AT91C_ST_WDRST;
//* Reset registers
//AT91F_ResetRegisters();
// Disabble Watchdog
AT91S_SYS_ST = (AT91S_ST *)AT91C_BASE_ST;
AT91S_SYS_ST->ST_WDMR =0;
AT91S_SYS_ST->ST_CR =0;
AT91F_ResetRegisters();
Jump(AT91C_BOOT_LOADER_ADDR);
while(1);
}
#endif
//*--------------------------------------------------------------------------------------
//* Function Name : AT91F_Start_Bootloader
//* Object : copy uboot.bin to sdram and run it
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void AT91F_Start_Bootloader(unsigned int dummy, void* pdummy)
{
printf("\r\nLoading boot loader from dataflash to SDRAM...");
//read bin from addr dataflash to sdram
if (0x01 ==
read_datum_from_flash(AT91C_BOOT_LOADER_DATAFLASH_ADDR, AT91C_BOOT_LOADER_SIZE, (char *)(AT91C_BOOT_LOADER_ADDR)))
{
printf("done.\r\n");
printf("Starting boot loader...\r\n");
AT91S_SYS_ST = (AT91S_ST *)AT91C_BASE_ST;
AT91S_SYS_ST->ST_WDMR =0;
AT91S_SYS_ST->ST_CR =0;
AT91F_ResetRegisters();
Jump(AT91C_BOOT_LOADER_ADDR);
}
else
{
printf("failed. \r\n");
printf("Please reset the target board.\r\n");
}
while(1);
}
//*----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main function
//* Input Parameters : none
//* Output Parameters : True
//*----------------------------------------------------------------------------
int main(void)
{
AT91PS_Buffer pXmBuffer;
AT91PS_SvcComm pSvcXmodem;
AT91S_SvcTempo boottempo;
unsigned int AddressToDownload = 0, SizeToDownload = 0, tempData = 0;
unsigned int DeviceAddress = 0xc0000000;
volatile int i = 0;
char command = 0;
unsigned int crc1 = 0, crc2 = 0;
#ifdef INCLUDE_DATAFLASH_SUPPORT
volatile int device = 0;
int NbPage = 0;
#endif
pAT91 = AT91C_ROM_BOOT_ADDRESS;
// Tempo Initialisation
pAT91->OpenCtlTempo(&ctlTempo, (void *) &(pAT91->SYSTIMER_DESC));
ctlTempo.CtlTempoStart((void *) &(pAT91->SYSTIMER_DESC));
ctlTempo.CtlTempoCreate(&ctlTempo, &boottempo);
// Xmodem Initialisation
pXmBuffer = pAT91->OpenSBuffer(&sXmBuffer);
pSvcXmodem = pAT91->OpenSvcXmodem(&svcXmodem, (AT91PS_USART)AT91C_BASE_DBGU, &ctlTempo);
pAT91->OpenPipe(&xmodemPipe, pSvcXmodem, pXmBuffer);
//* System Timer initialization
AT91F_AIC_ConfigureIt (
AT91C_BASE_AIC, // AIC base address
AT91C_ID_SYS, // System peripheral ID
AT91C_AIC_PRIOR_HIGHEST, // Max priority
AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, // Level sensitive
AT91F_ST_ASM_HANDLER );
//* Enable ST interrupt
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);
#ifdef INCLUDE_FIQ_SUPPORT
*AT91C_PIOA_PER = 0x00100000; /* Enables the PIO to control all the pins */
*AT91C_PIOA_OER = 0x00100000; /* Enables all the output pins */
*AT91C_PIOA_SODR = 0x00100000;
/* Enable PIOB clock */
AT91F_AIC_CfgPMC();
/* Internally pull up the PB28 */
AT91F_PIO_CfgPullup(AT91C_BASE_PIOB, AT91C_PIO_PB28);
/* Enable input filter */
AT91F_PIO_InputFilterEnable(AT91C_BASE_PIOB, AT91C_PIO_PB28);
AT91F_PIO_CfgPeriph(
AT91C_BASE_PIOB, /* PIO controller base address*/
((unsigned int) AT91C_PB28_FIQ), /* Peripheral A*/
0 /* Peripheral B*/);
//* System Timer initialization
AT91F_AIC_ConfigureIt (
AT91C_BASE_AIC, // AIC base address
AT91C_ID_FIQ, // System peripheral ID
AT91C_AIC_PRIOR_HIGHEST, // Max priority
AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED, // Level sensitive
AT91F_FiqHandler);
//* Enable ST interrupt
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_FIQ);
#endif //INCLUDE_FIQ_SUPPORT
#ifdef INCLUDE_IRQ0_SUPPORT
*AT91C_PIOA_PER = 0x00100000; /* Enables the PIO to control all the pins */
*AT91C_PIOA_OER = 0x00100000; /* Enables all the output pins */
*AT91C_PIOA_SODR = 0x00100000;
/* Enable PIOB clock */
AT91F_AIC_CfgPMC();
/* Internally pull up the PB29 */
AT91F_PIO_CfgPullup(AT91C_BASE_PIOB, AT91C_PIO_PB29);
/* Enable input filter */
AT91F_PIO_InputFilterEnable(AT91C_BASE_PIOB, AT91C_PIO_PB29);
AT91F_PIO_CfgPeriph(
AT91C_BASE_PIOB, /* PIO controller base address*/
((unsigned int) AT91C_PB29_IRQ0), /* Peripheral A*/
0 /* Peripheral B*/);
//* System Timer initialization
AT91F_AIC_ConfigureIt (
AT91C_BASE_AIC, // AIC base address
AT91C_ID_IRQ0, // System peripheral ID
AT91C_AIC_PRIOR_HIGHEST, // Max priority
AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED, // Level sensitive
AT91F_IRQ0_ASM_HANDLER);
//* Enable ST interrupt
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_IRQ0);
#endif //INCLUDE_IRQ0_SUPPORT
#ifdef INCLUDE_SRAM_SUPPORT
ncs2_init();
#endif
#ifdef INCLUDE_DATAFLASH_SUPPORT
// DataFlash on SPI Configuration
AT91F_DataflashInit ();
#endif
//start bootloaer after defined time default time :1000ms
boottempo.Start(&boottempo, 2000, 0, AT91F_Start_Bootloader, NULL);
#ifdef INCLUDE_LOGO_SHOW
GRENTECH_Show_Info();
#endif
printf ("\r\nPress <ENTER> in 2 seconds to stop loading OS loader...\r\n\r\n");
message[0] = 0;
AT91F_ReadLine (NULL,message);
boottempo.Stop(&boottempo);
#ifdef INCLUDE_DATAFLASH_SUPPORT
/*Get current used dataflash info*/
AT91F_DataflashPrintInfo ();
#endif
/* Pull up the PB14 for FPGA */
AT91F_PIO_CfgOutput(AT91C_BASE_PIOB, AT91C_PIO_PB14);
AT91F_PIO_SetOutput(AT91C_BASE_PIOB, AT91C_PIO_PB14);
while(1)
{
while(command == 0)
{
AddressToDownload = AT91C_DOWNLOAD_BASE_ADDRESS;
SizeToDownload = AT91C_DOWNLOAD_MAX_SIZE;
DeviceAddress = 0;
tempData = 0;
AT91F_DisplayMenu();
message[0] = 0;
AT91F_ReadLine ("Enter: ",message);
#if 0
boottempo.Stop(&boottempo);
#endif
command = message[0];
if(!AsciiToHex(&message[2], &DeviceAddress) )
command = 0;
switch(command)
{
case '1': /*Download Romboot*/
#ifdef INCLUDE_DATAFLASH_SUPPORT
//set the device address to save the romboot
DeviceAddress = CFG_DATAFLASH_LOGIC_ADDR_CS0;
switch(DeviceAddress & 0xFF000000)
{
case CFG_DATAFLASH_LOGIC_ADDR_CS0:
device = 0;
break;
case CFG_DATAFLASH_LOGIC_ADDR_CS3:
device = 1;
break;
default:
command = 0;
break;
}
#endif
#ifdef INCLUDE_NOR_FLASH_SUPPORT
DeviceAddress = NOR_FLASH_BASE_ADDRESS;
#endif
break;
case '2': /*Download OS loader*/
#ifdef INCLUDE_DATAFLASH_SUPPORT
//set the device address to save the romboot
DeviceAddress = AT91C_BOOT_LOADER_DATAFLASH_ADDR;
switch(DeviceAddress & 0xFF000000)
{
case CFG_DATAFLASH_LOGIC_ADDR_CS0:
device = 0;
break;
case CFG_DATAFLASH_LOGIC_ADDR_CS3:
device = 1;
break;
default:
command = 0;
break;
}
#endif
#ifdef INCLUDE_NOR_FLASH_SUPPORT
DeviceAddress = 0x10010000;
#endif
break;
case '3':
AT91F_Start_Bootloader(0,NULL);
command = 0;
break;
#ifdef INCLUDE_DEBUG_SUPPORT
case '4':
#ifdef INCLUDE_HW_DETECT
system_hw_check();
#else
AddressToDownload = AT91C_BOOT_LOADER_ADDR;
xmodemPipe.Read(&xmodemPipe, (char *)AddressToDownload, SizeToDownload, XmodemProtocol, 0);
while(XmodemComplete !=1);
SizeToDownload = (unsigned int)(svcXmodem.pData) - (unsigned int)AddressToDownload;
printf("\r\nDowand %d bytes to 0x%x.\r\n", SizeToDownload, AddressToDownload);
/* Disable watchdog's internal reset and external signal assertion */
AT91S_SYS_ST = (AT91S_ST *)AT91C_BASE_ST;
AT91S_SYS_ST->ST_WDMR =0;
AT91S_SYS_ST->ST_CR =1;
AT91F_ResetRegisters();
Jump(AddressToDownload);
while(1);
#endif
command = 0;
break;
case '5':
do
{
AT91F_MemoryDisplay(DeviceAddress, 4, 64);
AT91F_ReadLine (NULL, message);
DeviceAddress += 0x100;
}
while(message[0] == '\0');
command = 0;
break;
#if 0
case '6':
tempData = *((volatile unsigned int*) DeviceAddress);
printf("address = 0x%x, value = 0x%x\n", DeviceAddress, tempData);
command = 0;
break;
case '7':
if(!AsciiToHex(&message[11], &tempData))
command = 0;
if (command != 0)
{
/*write*/
*((volatile unsigned int*) DeviceAddress) = (unsigned int)tempData;
/*verify*/
tempData = *((volatile unsigned int*) DeviceAddress);
printf("address = 0x%x, value = 0x%x\r\n", DeviceAddress, tempData);
command = 0;
}
break;
#endif
#endif
default:
AT91F_ClrScr();
command = 0;
break;
}
}
xmodemPipe.Read(&xmodemPipe, (char *)AddressToDownload, SizeToDownload, XmodemProtocol, 0);
while(XmodemComplete !=1);
SizeToDownload = (unsigned int)(svcXmodem.pData) - (unsigned int)AddressToDownload;
#ifdef INCLUDE_DATAFLASH_SUPPORT
NbPage = 0;
i = dataflash_info[device].Device.pages_number;
while(i >>= 1)
NbPage++;
i = (SizeToDownload / 512) + 1 + (NbPage << 13) + (dataflash_info[device].Device.pages_size << 17);
#endif
#ifdef INCLUDE_NOR_FLASH_SUPPORT
i = (SizeToDownload / 512) + 1;
#endif
*(int *)(AddressToDownload + AT91C_OFFSET_VECT6) = i;
printf("\n\rWrite %d bytes in DataFlash [0x%x]\n\r",SizeToDownload, DeviceAddress);
crc1 = 0;
pAT91->CRC32((const unsigned char *)AddressToDownload, SizeToDownload , &crc1);
// write the dataflash
write_datum_to_flash(AddressToDownload, SizeToDownload, DeviceAddress);
// clear the buffer before read
for(i=0; i < SizeToDownload; i++)
*(unsigned char *)(AddressToDownload + i) = 0;
//* Read dataflash page in TestBuffer
read_datum_from_flash(DeviceAddress, SizeToDownload, (char *)(AddressToDownload));
printf("Verify Dataflash: ");
crc2 = 0;
pAT91->CRC32((const unsigned char *)AddressToDownload, SizeToDownload , &crc2);
if (crc1 != crc2)
printf("Failed\r\n");
else
printf("OK\r\n");
command = 0;
XmodemComplete = 0;
AT91F_WaitKeyPressed();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -