/*********************************************************************//** * @brief RTC interrupt handler sub-routine * @param[in] None * @return None **********************************************************************/ void RTC_IRQHandler(void) { uint32_t secval; /* This is increment counter interrupt*/ if (RTC_GetIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE)) { secval = RTC_GetTime (LPC_RTC, RTC_TIMETYPE_SECOND); /* Send debug information */ _DBG ("Second: "); _DBD(secval); _DBG_(""); // Clear pending interrupt RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE); } /* Continue to check the Alarm match*/ if (RTC_GetIntPending(LPC_RTC, RTC_INT_ALARM)) { /* Send debug information */ _DBG_ ("ALARM 10s matched!"); // Clear pending interrupt RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM); } }
/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { volatile uint32_t adc_value, tmp; uint8_t quit; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initialize ADC ----------------------------------------------------*/ /* * Init ADC pin that currently is being used on the board */ PINSEL_ConfigPin (BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO); PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE); /* Configuration for ADC : * ADC conversion rate = 400Khz */ ADC_Init(LPC_ADC, 400000); ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, DISABLE); ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE); while(1) { // Start conversion ADC_StartCmd(LPC_ADC, ADC_START_NOW); //Wait conversion complete while (!(ADC_ChannelGetStatus(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ADC_DATA_DONE))); adc_value = ADC_ChannelGetData(LPC_ADC, BRD_ADC_PREPARED_CHANNEL); //Display the result of conversion on the UART _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(" is: "); _DBD32(adc_value); _DBG_(""); //delay for(tmp = 0; tmp < 1000000; tmp++); if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } _DBG_("Demo termination!!!"); ADC_DeInit(LPC_ADC); }
int wallFound(int wallSide) { SensorPair leftSensors = calibratedValuesLeft(getLeftSensorValues()); SensorPair rightSensors = calibratedValuesRight(getRightSensorValues()); _DBG("LF: ");_DBD(leftSensors.FrontSensor);_DBG_(""); _DBG("LR: ");_DBD(leftSensors.RearSensor);_DBG_(""); _DBG("RF: ");_DBD(rightSensors.FrontSensor);_DBG_(""); _DBG("RR: ");_DBD(rightSensors.RearSensor);_DBG_(""); if(wallSide == 1) { if (leftSensors.FrontSensor <35 || leftSensors.RearSensor <35) { delay(200); if (leftSensors.FrontSensor <35 || leftSensors.RearSensor <35) { setSensorSide(1); return 1; } } } if(wallSide == 2) { if (rightSensors.FrontSensor <35 || rightSensors.RearSensor <35) { delay(200); if (rightSensors.FrontSensor <35 || rightSensors.RearSensor <35) { setSensorSide(2); return 1; } } } if(wallSide == 3) { if ((rightSensors.FrontSensor <35 || rightSensors.RearSensor <35) && (leftSensors.FrontSensor <35 || leftSensors.RearSensor <35)) { delay(200); if ((rightSensors.FrontSensor <35 || rightSensors.RearSensor <35) && (leftSensors.FrontSensor <35 || leftSensors.RearSensor <35)) { setSensorSide(3); return 1; } } } setSensorSide(-1); return 0; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry (void) { uint32_t pre_secval = 0, inc = 0, calib_cnt = 0; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* In this example: * Suppose that the RTC need periodically adjust after each 5 second. * And the time counter need by incrementing the counter by 2 instead of 1 * We will observe timer counter after calibration via serial display */ // Init RTC module RTC_Init(LPC_RTC); /* Enable rtc (starts increase the tick counter and second counter register) */ RTC_ResetClockTickCounter(LPC_RTC); RTC_Cmd(LPC_RTC, ENABLE); //Set current time = 0 RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0); /* Setting Timer calibration * Calibration value = 6s; * Direction = Forward calibration * So after each 6s, calibration logic can periodically adjust the time counter by * incrementing the counter by 2 instead of 1 */ RTC_CalibConfig(LPC_RTC, 6, RTC_CALIB_DIR_FORWARD); RTC_CalibCounterCmd(LPC_RTC, ENABLE); /* Set the CIIR for second counter interrupt*/ RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE); /* Enable RTC interrupt */ NVIC_EnableIRQ(RTC_IRQn); /* Loop forever */ while(1) { if(pre_secval != secval) { if(pre_secval > secval) inc = 60 + secval - pre_secval; else inc = secval - pre_secval; if(inc > 1) { _DBG ("Second: "); _DBD(secval); _DBG("--> Increase ");_DBD(inc); _DBG(" after ");_DBD(calib_cnt);_DBG(" seconds"); _DBG_(""); calib_cnt = 0; } else { _DBG ("Second: "); _DBD(secval); _DBG_(""); calib_cnt++; } pre_secval = secval; } } }
void RTC_print_time(void){ char buffer[100]; time_t rawtime; struct tm * timeinfo; // xprintf(INFO "%d/%d/%d %d:%d:%d" " (%s:%d)\n",GetDOM(),GetM(),GetY(),GetHH(),GetMM(),GetSS(),_F_,_L_); time( &rawtime ); timeinfo = localtime ( &rawtime ); strftime(buffer,90,"%d/%m/%Y %I:%M:%S%p WOY:%U DOY:%j",timeinfo); xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_); // xprintf(INFO "%d/%d/%d %d:%d:%d" " (%s:%d)\n",_F_,_L_); // xprintf(INFO "Unix: %d" " (%s:%d)\n",time2.unix,_F_,_L_); // xprintf(INFO "Sunrise: %d" " (%s:%d)\n",time2.sunrise_unix,_F_,_L_); timeinfo = localtime ( &time2.sunrise_unix ); strftime(buffer,80,"Sunrise: %I:%M:%S%p.",timeinfo); xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_); // xprintf(INFO "Sunset: %d" " (%s:%d)\n",time2.sunset_unix,_F_,_L_); timeinfo = localtime ( &time2.sunset_unix ); strftime(buffer,80,"Sunset: %I:%M:%S%p.",timeinfo); xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_); // xprintf(INFO "Noon: %d" " (%s:%d)\n",time2.noon_unix,_F_,_L_); timeinfo = localtime ( &time2.noon_unix ); strftime(buffer,80,"Noon: %I:%M:%S%p.",timeinfo); xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_); xprintf(INFO "It's %s" " (%s:%d)\n",time2.day_night ? "Night time" : "Day time" ,_F_,_L_); // xprintf(INFO "Day/Night: %d" " (%s:%d)\n",time2.day_night,_F_,_L_); xprintf(INFO "DST begin: %d end: %d" " (%s:%d)\n",time2.DST_begin_calculated,time2.DST_end_calculated,_F_,_L_); #if 0 _DBG("[INFO]-Date="); _DBD(GetDOM()); _DBG("/"); _DBD(GetM()); _DBG("/"); _DBD16(GetY()); _DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n"); _DBG("[INFO]-Time="); _DBD(GetHH()); _DBG(":"); _DBD(GetMM()); _DBG(":"); _DBD(GetSS()); _DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n"); _DBG("[INFO]-Unix: "); _DBD32(time2.unix); _DBG(" Sunrise: "); _DBD32(time2.sunrise_unix); _DBG(" Sunset: "); _DBD32(time2.sunset_unix); _DBG(" Noon: "); _DBD32(time2.noon_unix); _DBG(" Day/Night: "); _DBD(time2.day_night); _DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n"); _DBG("[INFO]-DST begin: "); _DBD32(time2.DST_begin_calculated); _DBG(" end: "); _DBD32(time2.DST_end_calculated); _DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n"); #endif }
/*********************************************************************//** * @brief c_entry: Main RTC program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { RTC_TIME_Type RTCFullTime; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* RTC Block section ------------------------------------------------------ */ // Init RTC module RTC_Init(LPC_RTC); /* Disable RTC interrupt */ NVIC_DisableIRQ(RTC_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(RTC_IRQn, ((0x01<<3)|0x01)); /* Enable rtc (starts increase the tick counter and second counter register) */ RTC_ResetClockTickCounter(LPC_RTC); RTC_Cmd(LPC_RTC, ENABLE); RTC_CalibCounterCmd(LPC_RTC, DISABLE); /* Set current time for RTC */ // Current time is 8:00:00PM, 2009-04-24 RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0); RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 0); RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 20); RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 4); RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2009); RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 24); /* Set ALARM time for second */ RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 10); // Get and print current time RTC_GetFullTime (LPC_RTC, &RTCFullTime); _DBG( "Current time set to: "); _DBD((RTCFullTime.HOUR)); _DBG (":"); _DBD ((RTCFullTime.MIN)); _DBG (":"); _DBD ((RTCFullTime.SEC)); _DBG(" "); _DBD ((RTCFullTime.DOM)); _DBG("/"); _DBD ((RTCFullTime.MONTH)); _DBG("/"); _DBD16 ((RTCFullTime.YEAR)); _DBG_(""); _DBG("Second ALARM set to "); _DBD (RTC_GetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND)); _DBG_("s"); /* Set the CIIR for second counter interrupt*/ RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE); /* Set the AMR for 10s match alarm interrupt */ RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE); /* Enable RTC interrupt */ NVIC_EnableIRQ(RTC_IRQn); /* Loop forever */ while(1); return 1; }
void doTheDemo() { cmdDoPlay(">cc"); _DBG_("State 0"); forwards(20); cmdDoPlay(">dd"); _DBG_("State 1"); while (sensorSide != 1) { //Forwards until we find a left wall checkForWall(); _DBD(sensorSide);_DBG_(" sens"); } cmdDoPlay(">ee"); _DBG_("State 2"); //Follow wall until it's ended int wallState = -1; while (wallState != 3 && wallState != 0) { wallState = checkForWall(); correctForwardMotion(); } if (courseType == 0) { cmdDoPlay(">aa"); _DBG_("State 5"); while(!checkForLine()) { } followLine(); while(!checkForNoLine()) { } brake(); } else { //Bear right to head for other wall cmdDoPlay(">ff"); _DBG_("State 3"); right(); delay(1000); _DBG_("State 3.1"); forwards(20); //Wait until right wall is trackable while (sensorSide != 2) { checkForWall(); _DBD(sensorSide);_DBG_(" sens"); } //Track right wall cmdDoPlay(">gg"); _DBG_("State 4"); wallState = -1; while (wallState != 4 && wallState != 0) { wallState = checkForWall(); correctForwardMotion(); } //Find the line cmdDoPlay(">aa"); _DBG_("State 5"); forwards(20); while(!checkForLine()) { } followLine(); while(!checkForNoLine()) { } brake(); } }
/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { volatile uint32_t tmp; #if !__DMA_USED__ uint32_t adc_value; #endif uint8_t quit; EXTI_InitTypeDef EXTICfg; #if __DMA_USED__ GPDMA_Channel_CFG_Type GPDMACfg; #endif GPIO_Init(); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Init ADC pin connect * AD0.2 on P0.25 */ PINSEL_ConfigPin(BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO); PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE); #ifdef LPC177x_8x_ADC_BURST_MULTI /* * Init ADC pin connect * AD0.3 on P0.26 */ PINSEL_ConfigPin(0, 26, 1); PINSEL_SetAnalogPinMode(0,26,ENABLE); #endif /* Configuration for ADC: * select: ADC channel 2 * ADC channel 3 * ADC conversion rate = 400KHz */ ADC_Init(LPC_ADC, 400000); ADC_ChannelCmd(LPC_ADC,BRD_ADC_PREPARED_CHANNEL,ENABLE); #ifdef LPC177x_8x_ADC_BURST_MULTI ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,ENABLE); #endif #ifdef LPC177x_8x_ADC_INJECT_TEST //Config P2.10 as EINT0 PINSEL_ConfigPin(2,10,1); EXTI_Init(); EXTICfg.EXTI_Line = EXTI_EINT0; /* edge sensitive */ EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE; EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE; EXTI_Config(&EXTICfg); GPIO_SetDir(LED_PORT,LED_PIN,1); GPIO_SetValue(LED_PORT,LED_PIN); NVIC_EnableIRQ(EINT0_IRQn); #endif #if __DMA_USED__ /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t)s_buf; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_ADC; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); while(1) { for(tmp = 0; tmp < 0x1000; tmp++); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; for(tmp = 0; tmp < DMA_SIZE; tmp++) { s_buf[tmp] = 0; } //Start burst conversion ADC_BurstCmd(LPC_ADC,ENABLE); GPDMA_Setup(&GPDMACfg); // Enable GPDMA channel 1 GPDMA_ChannelCmd(0, ENABLE); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0)); GPDMA_ChannelCmd(0, DISABLE); for(tmp = 0; tmp < DMA_SIZE; tmp++) { if(s_buf[tmp] & ADC_GDR_DONE_FLAG) { _DBG("ADC value on channel "); _DBD(ADC_GDR_CH(s_buf[tmp])); _DBG(": "); _DBD32(ADC_GDR_RESULT(s_buf[tmp]));_DBG_(""); } } if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } #else //Start burst conversion ADC_BurstCmd(LPC_ADC,ENABLE); while(1) { adc_value = ADC_ChannelGetData(LPC_ADC,BRD_ADC_PREPARED_CHANNEL); _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(": "); _DBD32(adc_value); _DBG_(""); #ifdef LPC177x_8x_ADC_BURST_MULTI adc_value = ADC_ChannelGetData(LPC_ADC,_ADC_CHANNEL_n); _DBG("ADC value on channel 3: "); _DBD32(adc_value); _DBG_(""); #endif // Wait for a while for(tmp = 0; tmp < 1500000; tmp++); if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } #endif /*__DMA_USED__*/ _DBG_("Demo termination!!!"); ADC_DeInit(LPC_ADC); GPIO_Deinit(); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel DMA_CHANNEL_NO GPDMACfg.ChannelNum = DMA_CHANNEL_NO; // Source memory GPDMACfg.SrcMemAddr = (uint32_t)DMASrc_Buffer; // Destination memory GPDMACfg.DstMemAddr = (uint32_t)DMADest_Buffer; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; _DBG("Start transfer on channel "); _DBD(DMA_CHANNEL_NO);_DBG_(""); // Enable GPDMA channel DMA_CHANNEL_NO GPDMA_ChannelCmd(DMA_CHANNEL_NO, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); /* Verify buffer */ Buffer_Verify(); _DBG_(compl_menu); _DBG("Demo terminated!"); /* Loop forever */ while(1); }
/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; volatile uint32_t adc_value, tmp; uint8_t quit; /* Initialize debug via UART0 * ?115200bps * ?8 data bit * ?No parity * ?1 stop bit * ?No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initialize ADC ----------------------------------------------------*/ /* Settings for AD input pin */ PINSEL_ConfigPin (BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO); PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE); /* Configuration for ADC : * ADC conversion rate = 400KHz */ ADC_Init(LPC_ADC, 400000); ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, ENABLE); ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE); /* GPDMA block section -------------------------------------------- */ /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t) &adc_value; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_ADC; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); while (1) { // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); ADC_StartCmd(LPC_ADC, ADC_START_NOW); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0)); // Disable GPDMA channel 0 GPDMA_ChannelCmd(0, DISABLE); //Display the result of conversion on the UART _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(" is: "); _DBD32(ADC_DR_RESULT(adc_value)); _DBG_(""); // Wait for a while for(tmp = 0; tmp < 1000000; tmp++); /* GPDMA Re-setup */ GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } _DBG_("Demo termination!!!"); ADC_DeInit(LPC_ADC); }
/*********************************************************************//** * @brief The entry of the program * * @param[in]None * * @return None. * **********************************************************************/ void c_entry (void) { uint32_t result[4]; uint8_t ver_major, ver_minor; uint32_t i; uint8_t *ptr; uint32_t flash_prog_area_sec_start; uint32_t flash_prog_area_sec_end; IAP_STATUS_CODE status; // Initialize debug_frmwrk_init(); for (i = 0;i < sizeof(buffer);i++) { buffer[i] = (uint8_t)i; } flash_prog_area_sec_start = GetSecNum(FLASH_PROG_AREA_START); flash_prog_area_sec_end = GetSecNum(FLASH_PROG_AREA_START + FLASH_PROG_AREA_SIZE); _DBG_(menu); status = ReadPartID(result); if(status != CMD_SUCCESS) { _DBG("Read Part ID failed with code is ");_DBD(status);_DBG_(""); while(1); } _DBG("PartID: ");_DBH32(result[0]);_DBG_(""); status = ReadBootCodeVer(&ver_major, &ver_minor); if(status != CMD_SUCCESS) { _DBG("Read Boot Code Version failed with code is ");_DBD(status);_DBG_(""); while(1); } _DBG("Boot Code Version: ");_DBD(ver_major);_DBG(".");_DBD(ver_minor);_DBG_(""); status = ReadDeviceSerialNum(result); if(status != CMD_SUCCESS) { _DBG("Read UID failed with code is ");_DBD(status);_DBG_(""); while(1); } _DBG("UID: "); for(i = 0; i < 4; i++) { _DBD32(result[i]); if(i<3) _DBG("-"); } _DBG_(""); status = EraseSector(flash_prog_area_sec_start, flash_prog_area_sec_end); if(status != CMD_SUCCESS) { _DBG("Erase chip failed with code is ");_DBD(status);_DBG_(""); while(1); } status = BlankCheckSector(flash_prog_area_sec_start, flash_prog_area_sec_end, &result[0], &result[1]); if(status != CMD_SUCCESS) { _DBG("Blank Check failed with code is ");_DBD(status);_DBG_(""); if(status == SECTOR_NOT_BLANK) { _DBG(">>>>The first non-blank sector is sector "); _DBD(flash_prog_area_sec_start + result[0]); _DBG_(""); } while(1); } _DBG_("Erase chip: Success"); /* Be aware that Program and ErasePage take long time to complete!!! If bigger RAM is present, allocate big buffer and reduce the number of Program blocks. */ /* Program flash block by block until the end of the flash. */ for ( i = 0; i < FLASH_PROG_AREA_SIZE/BUFF_SIZE; i++ ) { ptr = (uint8_t*)(FLASH_PROG_AREA_START + i*BUFF_SIZE); status = CopyRAM2Flash(ptr, buffer,IAP_WRITE_1024); if(status != CMD_SUCCESS) { _DBG("Program chip failed with code is ");_DBD(status);_DBG_(""); while(1); } } // Compare for ( i = 0; i < FLASH_PROG_AREA_SIZE/BUFF_SIZE; i++ ) { ptr = (uint8_t*)(FLASH_PROG_AREA_START + i*BUFF_SIZE); status = Compare(ptr, buffer,BUFF_SIZE); if(status != CMD_SUCCESS) { _DBG("Compare memory failed with code is ");_DBD(status);_DBG_(""); while(1); } } _DBG_("Program chip: Success"); _DBG_("Demo termination"); while (1); }