static void bootstrap() { const int moduleClock = 12000000; const int KHzInHz = 1000; const int baud = 115200; mcgInit(); sdramInit(); svcInit_SetSVCPriority(15); setSysTickPriority(14); setPendSVPriority(14); uartInit(UART2_BASE_PTR, moduleClock/KHzInHz, baud); lcdcInit(); lcdcConsoleInit(&console); adc_init(); vfs_init(); ledInitAll(); pushbuttonInitAll(); TSI_Init(); TSI_Calibrate(); init_memory(); //uinit(); intSerialIOInit(); flexTimerInit(); sysTickInit(); }
/************************************************************* * Main function ************************************************************/ int main(void) { int err; bootparam_t bootparam; //Initial initialisation pmClkInit(FCPU, FPBA); usartInit(USART0, &usart0_options, FPBA); //Init serial communication usartWriteLine(USART0, version); ledInit(); usartWriteLine(USART0, "Preinit done.\nGetting bootparm.txt...\n"); //Load boot parameters from SD-card bootparam = bootparamLoad("bootparm.txt"); done(); //Second init according to boot parameters //pmClkReInit(bootparam.fcpu, bootparam.fpba); usartWriteLine(USART0, "reinit USART"); usartSetBaudrate(USART0, bootparam.baudrate, bootparam.fpba); done(); usartWriteLine(USART0, "Init SDRAM..."); sdramInit(bootparam.fcpu); done(); spiReset(&AVR32_SPI1); //Optional loading a banner from SD-card and display on terminal. usartWriteLine(USART0, "Loading banner..."); banner(&bootparam); done(); //Boot file from SD-card, according to the bootparam.txt that should exist //on the SD-card. Otherwise default settings will be used. //If the boot is successful we (probably) never come back here. //If the boot is unsuccessful we come back here. usartWriteLine(USART0, "Loading bootfile, wait at least 15 sec..."); err = boot(&bootparam); if(err) { //TODO: Booting another file might NOT be the proper way to handle failure to load the user specified file. Reconsider! usartWriteLine(USART0, "\nCould not boot "); usartWriteLine(USART0, bootparam.bootfile); usartWriteLine(USART0, "\nWarning: Trying to boot "); usartWriteLine(USART0, DEFAULT_AUTORUN_FILE); strcpy(bootparam.bootfile, DEFAULT_AUTORUN_FILE); err = boot(&bootparam); } if(err) { /* Execution will only return to here on error */ usartWriteLine(USART0, "\nError booting, stopping here."); while(1); //TODO: Sleep } while(1); //TODO: Sleep }
/** * \brief Setup the microcontroller system. * Initialize the System and update the SystemFrequency variable. */ void SystemInit( void ) { #if (__FPU_USED == 1) // Keil /* enable FPU if available and used */ SCB->CPACR |= ((3UL << 10*2) | /* set CP10 Full Access */ (3UL << 11*2) ); /* set CP11 Full Access */ #endif /* Set FWS according to SYS_BOARD_MCKR configuration */ EFC->EEFC_FMR = EEFC_FMR_FWS(5) | EEFC_FMR_CLOE; /* Initialize main oscillator */ if ( !(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) ) { PMC->CKGR_MOR = CKGR_MOR_KEY_PASSWD | SYS_BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN; while ( !(PMC->PMC_SR & PMC_SR_MOSCXTS) ) { } } /* Switch to 3-20MHz Xtal oscillator */ PMC->CKGR_MOR = CKGR_MOR_KEY_PASSWD | SYS_BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL; while ( !(PMC->PMC_SR & PMC_SR_MOSCSELS) ) { } PMC->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS_Msk) | PMC_MCKR_CSS_MAIN_CLK; while ( !(PMC->PMC_SR & PMC_SR_MCKRDY) ) { } /* Initialize PLLA */ PMC->CKGR_PLLAR = SYS_BOARD_PLLAR; while ( !(PMC->PMC_SR & PMC_SR_LOCKA) ) { } /* Switch to main clock */ PMC->PMC_MCKR = (SYS_BOARD_MCKR & ~PMC_MCKR_CSS_Msk) | PMC_MCKR_CSS_MAIN_CLK; while ( !(PMC->PMC_SR & PMC_SR_MCKRDY) ) { } /* Switch to PLLA */ PMC->PMC_MCKR = SYS_BOARD_MCKR; while ( !(PMC->PMC_SR & PMC_SR_MCKRDY) ) { } SystemCoreClock = CHIP_FREQ_CPU_MAX; /* SDRAM initialization */ sdramInit(); }
/***************************************************************************** * * Description: * Sets up LCD. Required before using LCD. * * Params: * None ****************************************************************************/ void LCDSetup (void) { //Setup external SDRAM. Used for Frame Buffer sdramInit(); //Setup LPC2478 LCD Controller for our specific LCD //lcd_config is defined in lcd/lcd_cfg.h lcdInit(&lcd_config); //Turn the LCD on lcdTurnOn(); lcd_fillScreen(BLACK); }
static void bootstrap() { const int moduleClock = 60000000; const int KHzInHz = 1000; const int baud = 115200; mcgInit(); sdramInit(); svcInit_SetSVCPriority(7); uartInit(UART2_BASE_PTR, moduleClock/KHzInHz, baud); lcdcInit(); lcdcConsoleInit(&console); adc_init(); vfs_init(); ledInitAll(); pushbuttonInitAll(); TSI_Init(); TSI_Calibrate(); init_memory(); uinit(); privUnprivileged(); }