/** * @brief main routine for blinky example * @return Function should not exit. */ int main(void) { uint32_t current_systick = 0; ticksSet(0); SystemCoreClockUpdate(); promptInit(&CmdlineHistory); /* Enable and setup SysTick Timer at a periodic rate */ SysTick_Config(SystemCoreClock / SYSTICKS_PER_S); flashInit(); fsInit(); while (1) { // blink the led to show the device works if((current_systick + SYSTICKS_PER_S/4) < systick) { current_systick = systick; Chip_GPIO_SetPinToggle(LPC_GPIO, LED_PORT, LED_PIN); } promptProcess(cmdLineEntries); } return 0; }
int MSCenable(void){ USBD_API_INIT_PARAM_T usb_param; USB_CORE_DESCS_T desc; ErrorCode_t ret = LPC_OK; USB_CORE_CTRL_T *pCtrl; flashInit(); usb_clock_init(); usb_phy_enable(); /* Init USB API structure */ g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase; /* initialize call back structures */ memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T)); usb_param.usb_reg_base = LPC_USB_BASE; usb_param.mem_base = USB_STACK_MEM_BASE; usb_param.mem_size = USB_STACK_MEM_SIZE; usb_param.max_num_ep = 2; /* Set the USB descriptors */ desc.device_desc = (uint8_t *) USB_msc_DeviceDescriptor; desc.string_desc = (uint8_t *) USB_msc_StringDescriptor; desc.high_speed_desc = USB_msc_HsConfigDescriptor; desc.full_speed_desc = USB_msc_FsConfigDescriptor; desc.device_qualifier = (uint8_t *) USB_msc_DeviceQualifier; /* USB Initialization */ ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* WORKAROUND for artf45032 ROM driver BUG: Due to a race condition there is the chance that a second NAK event will occur before the default endpoint0 handler has completed its preparation of the DMA engine for the first NAK event. This can cause certain fields in the DMA descriptors to be in an invalid state when the USB controller reads them, thereby causing a hang. */ pCtrl = (USB_CORE_CTRL_T *) g_hUsb; /* convert the handle to control structure */ g_Ep0BaseHdlr = pCtrl->ep_event_hdlr[0];/* retrieve the default EP0_OUT handler */ pCtrl->ep_event_hdlr[0] = EP0_patch;/* set our patch routine as EP0_OUT handler */ ret = mscDisk_init(g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* enable USB interrrupts */ nvic_enable_irq(NVIC_USB0_IRQ); /* now connect */ USBD_API->hw->Connect(g_hUsb, 1); return 0; } } return 1; }
int main(uint32_t startloc) { cpu_clock_init(); ssp_clock_init(); systickInit(); // cpu_clock_set(204); SETUPgout(EN_VDD); SETUPgout(MIXER_EN); SETUPgout(MIC_AMP_DIS); SETUPgout(LED1); SETUPgout(LED2); SETUPgout(LED3); SETUPgout(LED4); inputInit(); flashInit(); lcdInit(); fsInit(); lcdFill(0xff); /* Display BL Image here */ sli=startloc; if (startloc != (uintptr_t)&_app_start){ /* not booted via DFU, do autoboot */ char filename[FLEN]; switch(getInputRaw()){ case BTN_LEFT: getInputWaitRelease(); doRealExec(1); break; case BTN_UP: doMSC(); default: case BTN_NONE: readTextFile(BOOTCFG, filename, FLEN); lcdPrintln("Booting:"); lcdPrintln(filename); bootFile(filename); break; }; }; static const struct MENU main={ "Bootloader", { { "Exec Firmware", &doExec}, { "MSC", &doMSC}, { "Flash Boot Ldr", &doFlash}, { "Info", &doInfo}, {NULL,NULL} }}; do { handleMenu(&main); }while(1); }
bool init() { rom = (u8 *)malloc(0x2000000); if (!rom) { systemMessage("Failed to allocate memory for %s", "ROM"); return false; } flashInit(); sramInit(); eepromInit(); return true; }
// *************************************************************** // ** flashWrite - Write the given data to the given address in // ** Flash memory. Erases the 256 byte page before // ** writing. // ** address must be DWORD-aligned. // ** data must not cross a 256-byte boundary. // ** Returns nonzero on successful write. // ** FASTRUN int flashWrite(unsigned address, const void *data, unsigned size) { unsigned i; unsigned page; unsigned *src = (unsigned *)data; unsigned *dest = (unsigned *)address; // Get base location of memory controller peripheral. volatile AT91PS_MC mc = AT91C_BASE_MC; // Calculate the number of DWORDs to be written. size = (size + 3) / 4; // Copy the data into the flash write buffer (this must be done 32 bits at a time). /* for(i = 0; i < size; i++) dest[i] = src[i]; */ for(i = 0; i < PAGE_SIZE; i++) { dest[i] = src[i]; } //disable interrupts unsigned int mask; mask = AT91C_BASE_AIC->AIC_IMR; AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF; flashInit(); // Write the page to Flash memory. page = ((char *)dest - AT91C_IFLASH) / AT91C_IFLASH_PAGE_SIZE; //mc->MC_FCR = AT91C_MC_WRITE_KEY | AT91C_MC_FCMD_START_PROG | (page << 8); mc->MC_FCR = AT91C_MC_CORRECT_KEY | AT91C_MC_FCMD_START_PROG | (AT91C_MC_PAGEN & (page << 8)) ; // Check for errors. if(0 != (mc->MC_FSR & AT91C_MC_PROGE)) return 0; // Wait for write cycle to complete. while(0 == (mc->MC_FSR & AT91C_MC_FRDY)); //enable interrupts AT91C_BASE_AIC->AIC_IECR = mask; return 1; }
int main(uint32_t startloc) { cpu_clock_init(); ssp_clock_init(); systick_set_reload(208000); systick_set_clocksource(0); systick_interrupt_enable(); systick_counter_enable(); // cpu_clock_pll1_max_speed(); SETUPgout(EN_VDD); SETUPgout(MIXER_EN); SETUPgout(LED1); SETUPgout(LED2); SETUPgout(LED3); SETUPgout(LED4); inputInit(); flashInit(); lcdInit(); fsInit(); lcdFill(0xff); /* Display BL Image here */ sli=startloc; if (startloc != (uintptr_t)&_app_start){ /* not booted via DFU, do autoboot */ if (getInputRaw()!=BTN_LEFT){ char filename[FLEN]; readTextFile(BOOTCFG, filename, FLEN); lcdPrintln("Fname"); lcdPrintln(filename); bootFile(filename,0); }; }; static const struct MENU main={ "Bootloader", { { "Info", &doInfo}, { "Exec", &doExec}, { "Flash", &doFlash}, {NULL,NULL} }}; handleMenu(&main); return 0; }
void main(void) { // Stop WDT WDTCTL = WDTPW + WDTHOLD; // Initialize the boards boardInit(); clockInit(); timerInit(); flashInit(); __bis_SR_register(GIE); // Set up the LCD LCDInit(); GrContextInit(&g_sContext, &g_sharp96x96LCD); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrClearDisplay(&g_sContext); GrFlush(&g_sContext); // Intro Screen GrStringDrawCentered(&g_sContext, "How to use", AUTO_STRING_LENGTH, 48, 15, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "the MSP430", AUTO_STRING_LENGTH, 48, 35, TRANSPARENT_TEXT); GrStringDraw(&g_sContext, "Graphics Library", AUTO_STRING_LENGTH, 1, 51, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "Primitives", AUTO_STRING_LENGTH, 48, 75, TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Draw pixels and lines on the display GrStringDrawCentered(&g_sContext, "Draw Pixels", AUTO_STRING_LENGTH, 48, 5, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "& Lines", AUTO_STRING_LENGTH, 48, 15, TRANSPARENT_TEXT); GrPixelDraw(&g_sContext, 30, 30); GrPixelDraw(&g_sContext, 30, 32); GrPixelDraw(&g_sContext, 32, 32); GrPixelDraw(&g_sContext, 32, 30); GrLineDraw(&g_sContext, 35, 35, 90, 90); GrLineDraw(&g_sContext, 5, 80, 80, 20); GrLineDraw(&g_sContext, 0, GrContextDpyHeightGet(&g_sContext) - 1, GrContextDpyWidthGet(&g_sContext) - 1, GrContextDpyHeightGet(&g_sContext) - 1); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Draw circles on the display GrStringDraw(&g_sContext, "Draw Circles", AUTO_STRING_LENGTH, 10, 5, TRANSPARENT_TEXT); GrCircleDraw(&g_sContext, 30, 70, 20); GrCircleFill(&g_sContext, 60, 50, 30); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Draw rectangles on the display GrStringDrawCentered(&g_sContext, "Draw Rectangles", AUTO_STRING_LENGTH, 48, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangle1); GrRectFill(&g_sContext, &myRectangle2); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Combining Primitive screen GrStringDrawCentered(&g_sContext, "Combining", AUTO_STRING_LENGTH, 48, 15, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "Primitives to", AUTO_STRING_LENGTH, 48, 35, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "create menus", AUTO_STRING_LENGTH, 48, 51, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "and animations", AUTO_STRING_LENGTH, 48, 75, TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Draw a Menu screen GrStringDrawCentered(&g_sContext, "Create a Menu", AUTO_STRING_LENGTH, 48, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption1); GrStringDraw(&g_sContext,"Option #1", 10,15,15,TRANSPARENT_TEXT); GrRectFill(&g_sContext, &myRectangleOption2); GrStringDraw(&g_sContext,"Option #2", 10,15,25,TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption3); GrStringDraw(&g_sContext,"Option #3", 10,15,35,TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption4); GrStringDraw(&g_sContext,"Option #4", 10,15,45,TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption5); GrStringDraw(&g_sContext,"Option #5", 10,15,55,TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Show progress bar screen // The following animation consist on displaying a progress bar and // updating the progress bar in increments of 25%. GrStringDrawCentered(&g_sContext, "Show progress", AUTO_STRING_LENGTH, 48, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleFrame); GrStringDrawCentered(&g_sContext, "Processing...", AUTO_STRING_LENGTH, 48, 75, TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_short(); // Update display with 25 %. Initial value of "myRectangleProgress" are set // to update bar with a 25 % increment. GrRectFill(&g_sContext, &myRectangleProgress); GrFlush(&g_sContext); Delay_short(); // Set myRectangleProgress values to update progress bar with 50 % myRectangleProgress.sXMin = 30; myRectangleProgress.sYMin = 40; myRectangleProgress.sXMax = 50; myRectangleProgress.sYMax = 60; GrRectFill(&g_sContext, &myRectangleProgress); GrFlush(&g_sContext); Delay_short(); // Set myRectangleProgress values to update progress bar with 75 % myRectangleProgress.sXMin = 50; myRectangleProgress.sYMin = 40; myRectangleProgress.sXMax = 70; myRectangleProgress.sYMax = 60; GrRectFill(&g_sContext, &myRectangleProgress); GrFlush(&g_sContext); Delay_short(); // Set myRectangleProgress values to update progress bar with 100 % myRectangleProgress.sXMin = 70; myRectangleProgress.sYMin = 40; myRectangleProgress.sXMax = 90; myRectangleProgress.sYMax = 60; GrRectFill(&g_sContext, &myRectangleProgress); GrStringDrawCentered(&g_sContext, "DONE!", AUTO_STRING_LENGTH, 48, 85, TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_long(); while(1); }
//*-------------------------------------------------------------------------------------- //* Function Name : Main //* Object : Software entry point //* Input Parameters : none. //* Output Parameters : none. //*-------------------------------------------------------------------------------------- int main(void) { char data[MSG_SIZE]; unsigned int length; int stepCnt = 0; unsigned char str[10]; /**** System init ****/ //InitFrec(); Init_CP_WP(); //chek for CP and WP //CP - card present while(((AT91C_BASE_PIOA->PIO_PDSR) & BIT15)) { /*put your card present event here*/ } //WP - write protect //while(((AT91C_BASE_PIOA->PIO_PDSR) & BIT16)) { /*put your write protect event here*/ } if (initMMC() == MMC_SUCCESS) { //card_state |= 1; memset(&mmc_buffer,0,512); mmcReadRegister (10, 16); mmc_buffer[7]=0; } flashInit(); Init_PWM(); // Enable User Reset and set its minimal assertion to 960 us AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24); // Led init // First, enable the clock of the PIOB AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ; //* to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only. AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); //* Clear the LED's. /* AT91F_PIO_SetOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); */ // Init USB device AT91F_USB_Open(); AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, OUTPUT_MASK ); // Init USB device // Wait for the end of enumeration setForce(40000); int pCDCEnablingCounter = 0; while (!pCDC.IsConfigured(&pCDC) && pCDCEnablingCounter < 2500000){ pCDCEnablingCounter++; }; if (pCDCEnablingCounter < 2500000) { CDC = 1; } setForce(0); // Set Usart in interrupt //Usart_init(); //Read and set settings memcpy(settings, OUR_FLASH_ADDR, 128); int i;memset(&mmc_buffer, 0x00, 512); int j; char *settingsBlocks[50]; char settingsDelim[] = "~"; char *settingsParts = strtok( settings, settingsDelim ); i = 0; while( settingsParts != NULL ) { settingsBlocks[i++] = settingsParts; settingsParts = strtok( NULL, settingsDelim ); } for (j = 0; j < i; j++) { parseSettings(settingsBlocks[j]); } InitADC(); Init_PWM(); AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SW1_MASK); AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SW2_MASK); AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_GREEN); AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_YELLOW); setForce(0); //startBlinking(250000); /**** MMC CARD ****/ init_extint(); while (1) { cnt++; if (cnt > 50000) { cnt = 0; printTrace("COUNTER RESET\n"); } } }
void doFlash(){ uint32_t addr=0x0; uint32_t sw=0x1; uint8_t data[256]; uint8_t x=0; flashInit(); lcdClear(0xff); lcdPrint("xxd @ "); lcdPrint(IntToStr(addr,8,F_HEX));lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(sw,8,F_HEX));lcdNl(); lcdDisplay(); while(1){ TOGGLE(LED1); switch(getInput()){ case BTN_UP: /* addr-=sw; lcdClear(0xff); lcdPrint("xxd @ "); lcdPrint(IntToStr((uint32_t)addr,8,F_HEX));lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(sw,8,F_HEX));lcdNl(); lcdDisplay(); */ flash_write_enable(); lcdPrint("WE done."); lcdDisplay(); break; case BTN_DOWN: addr+=sw; lcdClear(0xff); lcdPrint("xxd @ "); lcdPrint(IntToStr((uint32_t)addr,8,F_HEX));lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(sw,8,F_HEX));lcdNl(); lcdDisplay(); break; case BTN_LEFT: /*sw<<=1; lcdClear(0xff); lcdPrint("xxd @ "); lcdPrint(IntToStr((uint32_t)addr,8,F_HEX));lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(sw,8,F_HEX));lcdNl(); lcdDisplay(); */ lcdPrint(IntToStr(flash_status1(),2,F_HEX)); lcdPrint(" "); lcdPrint(IntToStr(flash_status2(),2,F_HEX)); lcdNl();lcdDisplay(); break; case BTN_RIGHT: /*sw>>=1; lcdClear(0xff); lcdPrint("xxd @ "); lcdPrint(IntToStr((uint32_t)addr,8,F_HEX));lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(sw,8,F_HEX));lcdNl(); lcdDisplay(); */ data[0]=0xfe; data[1]=0xf8; flash_program(addr,0x2,data); lcdPrint("done."); lcdNl(); lcdDisplay(); break; case BTN_ENTER: lcdClear(0xff); lcdPrint("xxd @ "); lcdPrint(IntToStr(addr,8,F_HEX));lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(sw,8,F_HEX));lcdNl(); flash_read(addr,0x100,data); int ctr; for (ctr=0x00;ctr<0x024;ctr++){ if (ctr%4==0){ lcdNl(); lcdPrint(IntToStr(ctr,2,F_HEX)); lcdPrint(":"); }; lcdPrint(" "); lcdPrint(IntToStr(data[ctr],2,F_HEX)); }; lcdNl(); lcdDisplay(); break; }; }; };