int main(void) { debug_init(SOFTWARE_NAME); PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST); char_display_init(); LED_Configure(0); LED_Configure(1); if (! BCAN_Init(1000, 0, NULL)) { printf("INIT FAIL"); LED_Set(1); return 1; } printf("INIT OK\n\r"); LED_Set(0); BCAN_InitMailboxRegisters( 0, 2, AT91C_CAN_MIDvA, (0x5AC << 18), AT91C_CAN_MOT_RX, 0x0); char_display_number(6); while(1) { CAN_Packet packet = BCAN_ReadAndClear(0,2); if (packet.valid) { char_display_number(packet.data_low); } char_display_tick(); for (unsigned volatile int i = 0xFF; i > 0; i--) ; } return 0; }
static void gp_dog_icon_commInfo(void) { void *fb = gp_dogDispBuf; int battayLeve=dv_set.battery_state; extern UINT8 flip_flag; if(battayLeve > 3) battayLeve = 3; else if(battayLeve<0) battayLeve =0; gp_Icon_draw_Index(DOG_ICON_R_BAT_0+battayLeve); if(1 == dv_set.dv_ctrl)// Recorder ing { if(0== flip_flag) { gp_Icon_draw(fb, RECORDER_X,RECORDER_Y-3,lcd_size.width, lcd_size.height,ICON_REDLIGHT,RGB888_TO_RGB565(0xc0c0c0)); LED_Set(NORMAL_LED,1); } else { fill_rectangle(fb,RECORDER_X,RECORDER_Y,lcd_size.width,lcd_size.height,Icon_Manager[ICON_REDLIGHT].icon_width,Icon_Manager[ICON_REDLIGHT].icon_height-10,RGB888_TO_RGB565(0x444444)); LED_Set(NORMAL_LED,0); } } }
int main(void) { unsigned int switchPressed; debug_init(SOFTWARE_NAME); PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST); switches_init(); char_display_init(); LED_Configure(0); LED_Configure(1); if (! BCAN_Init(1000, 0, NULL)) { printf("INIT FAIL"); LED_Set(1); return 1; } printf("INIT OK\n\r"); LED_Set(0); BCAN_InitMailboxRegisters( 0, 1, 0x0, (0x5AC << 18), AT91C_CAN_MOT_TX, 0x0); while(1) { DisplayMenu(); switchPressed = -1; while (switchPressed == -1) { if (switches_pressed(0)) { TRACE_INFO("Switch 0 is pressed\n\r"); switchPressed = 0; } else if (switches_pressed(1)) { TRACE_INFO("Switch 1 is pressed\n\r"); switchPressed = 1; } else if (switches_pressed(2)) { TRACE_INFO("Switch 2 is pressed\n\r"); switchPressed = 2; } else if (switches_pressed(3)) { TRACE_INFO("Switch 3 is pressed\n\r"); switchPressed = 3; } else { //TRACE_INFO("No Switch is pressed\n\r"); } char_display_tick(); for (volatile unsigned int i = 0xFF; i > 0; i--) ; } unsigned int result = -1; while (result != CAN_STATUS_SUCCESS) { result = BCAN_Write(0, 1, 0, switchPressed, 0x1); } char_display_number(switchPressed); } return 0; }
void display_rgb(int iCt ){ for(int n=0;n< mLED_MAX;n++){ LED_Color_RGB(mColorMap[iCt][0], mColorMap[iCt][1], mColorMap[iCt][2] ); } LED_Set(); wait(2); //reset for(int n=0;n< mLED_MAX;n++){ LED_Color_RGB(0x00, 0x00, 0x00); } LED_Set(); }
int main(void) { RCC->APB2ENR = 0x3D; while (1&~GPIOA->IDR); LED_init(); while (1) { LED_Set(0xAA); for (u32 i = 0; i < 1000000; i++); LED_Set(0x55); for (u32 i = 0; i < 1000000; i++); } }
int main(void) { u32 t0; u32 i; RCC->APB2ENR = 0x3D; while (1 &~ GPIOA->IDR); SysTick_Config(72000); STM3210B_LCD_Init(); LED_init(); LCD_DrawPicture(pic); LCD_SetBackColor(White); LCD_SetTextColor(Red); LCD_DisplayStringLine(Line1, " Hello? "); while (1) { if (tick-t0 >= 10) { t0 = tick; LED_Set(~(1<<(++i/20%8))); sprintf(s, " times: %.2lf s.", t0/1000.0); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line3, (u8*)s); } } }
//------------------------------------------------------------------------------ /// Invoked when the USB device leaves the Suspended state. By default, /// configures the LEDs. //------------------------------------------------------------------------------ void USBDCallbacks_Resumed(void) { // Initialize LEDs //LED_Configure(USBD_LEDPOWER); //moved to USB_Init() //LED_Configure(USBD_LEDUSB); LED_Set(USBD_LEDPOWER); LED_Clear(USBD_LEDUSB); }
void assert_failed(uint8_t* file, uint32_t line) { printf("Wrong parameters value: file %s on line %ld\r\n", file, line); LED_Set(14); TIM_Delay_Init(); while (1) { } }
void USBDDriverCallbacks_InterfaceSettingChanged(unsigned char interface, unsigned char setting) { if ((interface == AUDDLoopRecDriverDescriptors_STREAMING) && (setting == 0)) LED_Clear(USBD_LEDOTHER); else LED_Set(USBD_LEDOTHER); }
//------------------------------------------------------------------------------ // Callbacks re-implementation //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ /// Invoked when the USB device leaves the Suspended state. By default, /// configures the LEDs. //------------------------------------------------------------------------------ void USBDCallbacks_Resumed(void) { // Initialize LEDs LED_Configure(USBD_LEDPOWER); LED_Set(USBD_LEDPOWER); LED_Configure(USBD_LEDUSB); LED_Clear(USBD_LEDUSB); USBState = STATE_RESUME; }
/** * Invoked when an audio streaming interface setting changed. Actually control * streaming rate. * \param mic 1 to indicate microphone mute changed. * \param newSetting New stream (interface) setting. */ void AUDDFunction_StreamSettingChanged(uint8_t mic, uint8_t newSetting) { mic = mic; /* dummy */ if (newSetting) { LED_Set(USBD_LEDOTHER); //XDMAD_StopTransfer(&dmad, sscDmaTxChannel); numBuffersToSend = 0; } else LED_Clear(USBD_LEDOTHER); }
void ui_usb_connection_event(USBH_device_t *dev, bool b_present) { UNUSED(dev); if (b_present) LED_Set(LED_YELLOW0); else { LED_Clear(LED_YELLOW0); ui_enum_status = UHC_ENUM_DISCONNECT; } }
void USBDDriverCallbacks_InterfaceSettingChanged(unsigned char interface, unsigned char setting) { printf("USB_IF_CHANGED(%u, %u)\n\r", interface, setting); if ((interface == AUDDLoopRecDriverDescriptors_STREAMINGIN) && (setting == 0)) LED_Clear(USBD_LEDOTHER); else LED_Set(USBD_LEDOTHER); }
void vParTestSetLED( UBaseType_t uxLED, BaseType_t xValue ) { if( xValue == pdTRUE ) { LED_Set( uxLED ); } else { LED_Clear( uxLED ); } }
//----------------------------------------------------------------------------- /// Invoked whenever the active setting of an interface is changed by the /// host. Changes the status of the third LED accordingly. /// \param interface Interface number. /// \param setting Newly active setting. //----------------------------------------------------------------------------- void AUDDFunctionCallbacks_InterfaceSettingChanged(unsigned char interface, unsigned char setting) { if ((interface == AUDD_Descriptors_STREAMING) && (setting == 0)) { LED_Clear(USBD_LEDOTHER); } else { LED_Set(USBD_LEDOTHER); } }
/*void PPP_IRQHandler(void) { }*/ void TIM3_IRQHandler() { static int led_value=0x80; if(TIM_GetITStatus(TIM3 , TIM_IT_Update) == SET) { LED_Set(~led_value); led_value=led_value>>1; if(led_value==0) { led_value = 0x80; } }
void panic_ir(unsigned char val) { filtered_ir[panic_sensor] = (val+filtered_ir[panic_sensor]*9)/10; if (filtered_ir[panic_sensor] < 100 && filtered_sonar < 1750000) { if (usemotors) Motor_Set(127,127); ADC_Background_Read(&avoid_ir); } else { ADC_Single_Background_Read(panic_sensor,&panic_ir); } LED_Set(LED_2,c++); if (c==0) UARTprintf("ir==>%d sonar==>%d sensor==>%d c=>%d\n",filtered_ir[panic_sensor],filtered_sonar,panic_sensor,c); }
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) { if( uxLED < partstNUM_LEDS ) { if( xValue == 0 ) { LED_Clear( uxLED ); } else { LED_Set( uxLED ); } } }
/** * Invoked when the status of the keyboard LEDs changes. Turns the num. lock * LED on or off. * \param numLockStatus Indicates the current status of the num. lock key. * \param capsLockStatus Indicates the current status of the caps lock key. * \param scrollLockStatus Indicates the current status of the scroll lock key */ void HIDDKeyboardCallbacks_LedsChanged( uint8_t numLockStatus, uint8_t capsLockStatus, uint8_t scrollLockStatus) { capsLockStatus = capsLockStatus; /* dummy */ scrollLockStatus = scrollLockStatus; /* dummy */ /* Num. lock */ if (numLockStatus) LED_Set(LED_NUMLOCK); else LED_Clear(LED_NUMLOCK); }
void avoid_ir(unsigned char * adc) { signed char offset; for(c=0; c<7; c++) filtered_ir[c] = (adc[c]+filtered_ir[c]*9)/10; offset = (filtered_ir[IR_FRONT_LEFT]- filtered_ir[IR_FRONT_RIGHT])/100 + (filtered_ir[IR_LONG_LEFT] - filtered_ir[IR_LONG_RIGHT] )/50; LED_Set(LED_0,offset+1); LED_Set(LED_1,1-offset); if (offset > 0) Motor_Set(127,127-offset); else Motor_Set(127+offset,127); if (filtered_ir[IR_FRONT] > 100 || Sonar_Value > 1750000) { if (usemotors) { if (filtered_ir[IR_FRONT_LEFT] > filtered_ir[IR_FRONT_RIGHT]) Motor_Set(-127,127); else Motor_Set(127,-127); } ADC_Single_Background_Read(panic_sensor=IR_FRONT,&panic_ir); } else if (filtered_ir[IR_FRONT_LEFT] > 100) { if (usemotors) Motor_Set(-127,127); ADC_Single_Background_Read(panic_sensor=IR_FRONT_LEFT,&panic_ir); } else if (filtered_ir[IR_FRONT_RIGHT] > 100) { if (usemotors) Motor_Set(127,-127); ADC_Single_Background_Read(panic_sensor=IR_FRONT_RIGHT,&panic_ir); } else { ADC_Background_Read(&avoid_ir); } LED_Set(LED_3,d++); if (d==0) UARTprintf("off-->%d sonar-->%d d->%d\n",offset,filtered_sonar,d); }
//----------------------------------------------------------------------------- /// Invoked when the status of the keyboard LEDs changes. Turns the num. lock /// LED on or off. /// \param numLockStatus Indicates the current status of the num. lock key. /// \param capsLockStatus Indicates the current status of the caps lock key. /// \param scrollLockStatus Indicates the current status of the scroll lock key //----------------------------------------------------------------------------- void HIDDKeyboardCallbacks_LedsChanged( unsigned char numLockStatus, unsigned char capsLockStatus, unsigned char scrollLockStatus) { // Num. lock if (numLockStatus) { LED_Set(LED_NUMLOCK); } else { LED_Clear(LED_NUMLOCK); } }
/*---------------------------------------------------------------------------*/ void leds_arch_set(unsigned char leds) { if( leds & LEDS_GREEN ) { LED_Set(0); } else { LED_Clear(0); } if( leds & LEDS_YELLOW ) { LED_Set(1); } else { LED_Clear(1); } if( leds & LEDS_RED ) { LED_Set(2); } else { LED_Clear(2); } }
/** * Invoked when the status of the keyboard LEDs changes. Turns the num. lock * LED on or off. * \param numLockStatus Indicates the current status of the num. lock key. * \param capsLockStatus Indicates the current status of the caps lock key. * \param scrollLockStatus Indicates the current status of the scroll lock key */ void HIDDKeyboardCallbacks_LedsChanged( uint8_t numLockStatus, uint8_t capsLockStatus, uint8_t scrollLockStatus) { /* Num. lock */ if (numLockStatus) { LED_Set(LED_NUMLOCK); } else { LED_Clear(LED_NUMLOCK); } }
int main(void) { //初始化系统时钟 使用外部50M晶振 PLL倍频到100M SystemClockSetup(ClockSource_EX50M,CoreClock_100M); DelayInit(); //初始化LED LED_Init(LED_PinLookup_CHK60EVB, kNumOfLED); //将LED1设置为高电平 LED_Set(kLED1); while(1) { //2LED闪烁 LED_Toggle(kLED1); LED_Toggle(kLED2); DelayMs(500); } }
void ui_usb_sof_event(void) { bool b_btn_state; static bool btn_suspend_and_remotewakeup = false; static uint16_t counter_sof = 0; if (ui_enum_status == UHC_ENUM_SUCCESS) { /* Display device enumerated and in active mode */ if (++counter_sof > ui_device_speed_blink) { counter_sof = 0; LED_Toggle(LED_YELLOW0); } /* Scan button to enter in suspend mode and remote wakeup */ /*b_btn_state = (!gpio_pin_is_high(GPIO_PUSH_BUTTON_1)) ? true : false;*/ b_btn_state = true; if (b_btn_state != btn_suspend_and_remotewakeup) { /* Button have changed */ btn_suspend_and_remotewakeup = b_btn_state; if (b_btn_state) { /* Button has been pressed */ ui_enable_asynchronous_interrupt(); USBH_suspend(true); return; } } /* Power on a LED when the mouse move */ if (!ui_x && !ui_y && !ui_scroll) { #if 2 == LED_NUM LED_Clear(LED_YELLOW1); #endif } else { ui_x = ui_y = ui_scroll = 0; #if 2 == LED_NUM LED_Set(LED_YELLOW1); #endif } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ LED_Configuration(); SysTick_Configuration(); USART_Configuration(); Buzzer_Configuration(); LED_Interrupt();//¿ªÆô¶¨Ê±Æ÷ÖÐ¶Ï PWM_Configuration(); LED_Set(0x00); /* Infinite loop */ while (1) { // Set_Speed(1,50,0); // Set_Speed(2,50,0); // Buzzer_ON(); // delay_ms(1000); // Set_Speed(1,50,1); // Set_Speed(2,50,1); // Buzzer_ON(); // delay_ms(1000); switch(instruction) { case 'a': Set_Speed(1,50,1); Set_Speed(2,50,1); break; case 'b': Set_Speed(1,50,1); Set_Speed(2,50,0); break; case 'c': Set_Speed(1,50,0); Set_Speed(2,50,1); break; case 'd': Set_Speed(1,50,0); Set_Speed(2,50,0); break; case 's': Set_Speed(1,0,0); Set_Speed(2,0,0); break; case 'z': Buzzer_ON(); break; case 'y': Buzzer_OFF(); break; default: break; } } }
//------------------------------------------------------------------------------ /// Main function //------------------------------------------------------------------------------ int main(void) { unsigned char key; unsigned char isValid; // Configure all pins PIO_Configure(pins, PIO_LISTSIZE(pins)); LED_Configure(0); LED_Set(0); LED_Configure(1); LED_Set(1); // Initialize the DBGU TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); // Switch to Main clock AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK; while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0); // Configure PLL to 98.285MHz *AT91C_CKGR_PLLR = ((1 << 29) | (171 << AT91C_CKGR_MUL_SHIFT) \ | (0x0 << AT91C_CKGR_OUT_SHIFT) |(0x3f << AT91C_CKGR_PLLCOUNT_SHIFT) \ | (21 << AT91C_CKGR_DIV_SHIFT)); while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) == 0); // Configure master clock in two operations AT91C_BASE_PMC->PMC_MCKR = (( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK) & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK; while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0); AT91C_BASE_PMC->PMC_MCKR = ( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK); while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0); // DBGU reconfiguration DBGU_Configure(DBGU_STANDARD, 115200, SSC_MCK); // Configure and enable the TWI (required for accessing the DAC) *AT91C_PMC_PCER = (1<< AT91C_ID_TWI0); TWI_ConfigureMaster(AT91C_BASE_TWI0, TWI_CLOCK, SSC_MCK); TWID_Initialize(&twid, AT91C_BASE_TWI0); printf("-- OsmoSDR firmware (" BOARD_NAME ") " GIT_REVISION " --\n\r"); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); req_ctx_init(); PIO_InitializeInterrupts(0); cmd_state.out = vprintf; uart_cmd_reset(&cmd_state); uart_cmds_register(cmds, sizeof(cmds)/sizeof(cmds[0])); fastsource_init(); VBus_Configure(); power_peripherals(1); si570_init(&si570, &twid, SI570_I2C_ADDR); set_si570_freq(30000000); sam3u_e4k_init(&e4k, &twid, E4K_I2C_ADDR); e4k.vco.fosc = 30000000; osdr_fpga_init(SSC_MCK); //osdr_fpga_reg_write(OSDR_FPGA_REG_ADC_TIMING, (1 << 8) | 255); //osdr_fpga_reg_write(OSDR_FPGA_REG_PWM1, (1 << 400) | 800); osdr_fpga_set_iq_swap(0); ssc_init(); e4k_init(&e4k); e4k_init(&e4k); // Enter menu loop while (1) { if (DBGU_IsRxReady()) { key = DBGU_GetChar(); // Process user input if (uart_cmd_char(&cmd_state, key) == 1) { //ssc_stats(); } } ssc_dma_start(); fastsource_start(); } }
void ui_com_tx_start(void) { #if 2 == LED_NUM LED_Set(LED_YELLOW1); #endif }
int flash_test( void ) { unsigned int i, j; unsigned char error; unsigned int pBuffer[AT91C_IFLASH_PAGE_SIZE / 4]; unsigned int lastPageAddress; volatile unsigned int *pLastPageData; //unsigned char pageLocked; // Initialize flash driver //FLASHD_Initialize( BOARD_MCK ); // Unlock whole flash //printf("-I- Unlocking the whole flash\n\r"); LED_Clear(LED_DS2); // The AT91SAM7A3 has 16 lock regions. Each lock region contains 16 pages of 256 bytes. // Each lock region has a size of 4 Kbytes, thus only the first 64 Kbytes can be locked. #if defined(at91sam7a3) error = FLASHD_Unlock(AT91C_IFLASH, AT91C_IFLASH + 64 * 1024, 0, 0); // 16* 16 * 256 = 64kB, Only the first 64KB can be locked in the SAM7A3 #else error = FLASHD_Unlock(AT91C_IFLASH, AT91C_IFLASH + AT91C_IFLASH_SIZE, 0, 0); #endif //ASSERT(!error, "-F- Error while trying to unlock the whole flash (0x%02X)\n\r", error); if(error !=0 ) { while(1); } //fill data to sectors : 512 ~ 1024. for(j = 1; j<= 512; j++) { LED_Toggle(LED_DS2); // Performs tests on last page (to avoid overriding existing program). lastPageAddress = AT91C_IFLASH + AT91C_IFLASH_SIZE - AT91C_IFLASH_PAGE_SIZE * j; pLastPageData = (volatile unsigned int *) lastPageAddress; // Write page with walking bit pattern (0x00000001, 0x00000002, ...) //printf("-I- Writing last page with walking bit pattern\n\r"); for (i=0; i < (AT91C_IFLASH_PAGE_SIZE / 4); i++) { pBuffer[i] = 0xee;//(i % 32); } error = FLASHD_Write(lastPageAddress, pBuffer, AT91C_IFLASH_PAGE_SIZE); //ASSERT(!error, "-F- Error when trying to write page (0x%02X)\n\r", error); // Check page contents //printf("-I- Checking page contents "); for (i=0; i < (AT91C_IFLASH_PAGE_SIZE / 4); i++) { //printf("."); //ASSERT(pLastPageData[i] == (1 << (i % 32)),\ "\n\r-F- Expected 0x%08X at address 0x%08X, found 0x%08X\n\r",\ (1 << (i % 32)), (unsigned int) &(pLastPageData[i]), pLastPageData[i]); if( pLastPageData[i] != (1 << (i % 32))) { LED_Set(LED_DS2); break; } } } /*****************************************************************************/ LED_Clear(LED_DS2); //while(1); //printf(" ok \n\r"); #if defined(at91sam7a3) // Only the first 64Kb can be locked in the SAM7A3 lastPageAddress = AT91C_IFLASH + (64*1024) - AT91C_IFLASH_PAGE_SIZE; #endif // Lock page //printf("-I- Locking last page\n\r"); //error = FLASHD_Lock(lastPageAddress, lastPageAddress + AT91C_IFLASH_PAGE_SIZE, 0, 0); //ASSERT(!error, "-F- Error when trying to lock page (0x%02X)\n\r", error); // Check that associated region is locked //printf("-I- Checking lock status ... "); //pageLocked = FLASHD_IsLocked(lastPageAddress, lastPageAddress + AT91C_IFLASH_PAGE_SIZE); //ASSERT(pageLocked, "\n\r-F- Page is not locked\n\r"); //printf("ok\n\r"); // Unlock page //printf("-I- Unlocking last page\n\r"); //error = FLASHD_Unlock(lastPageAddress, lastPageAddress + AT91C_IFLASH_PAGE_SIZE, 0, 0); //ASSERT(!error, "-F- Error when trying to unlock page (0x%02X)\n\r", error); // Check that associated region is unlocked //printf("-I- Checking lock status ... "); //pageLocked = FLASHD_IsLocked(lastPageAddress, lastPageAddress + AT91C_IFLASH_PAGE_SIZE); //ASSERT(!pageLocked, "\n\r-F- Page is locked\n\r"); //printf("ok\n\r"); #if (EFC_NUM_GPNVMS > 0) // Test GPNVM bit #1 (should be safe) if (FLASHD_IsGPNVMSet(1)) { //printf("-I- GPNVM #1 is set\n\r"); // Clear GPNVM //printf("-I- Clearing GPNVM #%d\n\r", 1); error = FLASHD_ClearGPNVM(1); //ASSERT(!error, "-F- Error while trying to clear GPNVM (0x%02X)\n\r", error); //ASSERT(!FLASHD_IsGPNVMSet(1), "-F- GPNVM is set\n\r"); // Set GPNVM //printf("-I- Setting GPNVM #%d\n\r", 1); error = FLASHD_SetGPNVM(1); //ASSERT(!error, "-F- Error while trying to set GPNVM (0x%02X)\n\r", error); //ASSERT(FLASHD_IsGPNVMSet(1), "-F- GPNVM is not set\n\r"); } else { //printf("-I- GPNVM #1 is cleared\n\r"); // Set GPNVM //printf("-I- Setting GPNVM #%d\n\r", 1); error = FLASHD_SetGPNVM(1); //ASSERT(!error, "-F- Error while trying to set GPNVM (0x%02X)\n\r", error); //ASSERT(FLASHD_IsGPNVMSet(1), "-F- GPNVM is not set\n\r"); // Clear GPNVM //printf("-I- Clearing GPNVM #%d\n\r", 1); error = FLASHD_ClearGPNVM(1); //ASSERT(!error, "-F- Error while trying to clear GPNVM (0x%02X)\n\r", error); //ASSERT(!FLASHD_IsGPNVMSet(1), "-F- GPNVM is set\n\r"); } #endif //printf("-I- All tests ok\n\r"); return 0; }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { int i = 0; uint16_t temp_humid_sensor; float rel_humidity, dew_point; char buffer_humid[10]; // char buffer_voltage[10]; // char light_level[10]; /* Chip errata */ CHIP_Init(); /* If first word of user data page is non-zero, enable eA Profiler trace */ TRACE_ProfilerSetup(); /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ; /* Disable usart0 clock, it is enabled by default in gecko series mcu's. */ CMU_ClockEnable(cmuClock_USART0, false); /* Infinite blink loop with main state machine */ state = RESET; while (1) { // state machine switch(state){ case RESET: // RESET state check for vital HW functions if(1){ // todo all checks i = 0; state = INIT; } else state = RESET; break; case INIT: // INIT state initialize all necessary peripherials if(1){ i = i + 1; /* Enable clocks. */ CMU_ClockEnable(cmuClock_GPIO, true); CMU_ClockEnable(cmuClock_I2C0, true); /* Configure PB9, PB10 pin interrupt on falling edge do not enable yet. */ GPIO_PinModeSet(gpioPortB, 9, gpioModeInput, 0); GPIO_PinModeSet(gpioPortB, 10, gpioModeInput, 0); GPIO_IntConfig(gpioPortB, 9, false, true, true); GPIO_IntConfig(gpioPortB, 10, false, true, true); HumiditySensorInit(); LED_Init(); /* Initialize LED driver */ LED_Set(0); /* Enable LCD without voltage boost */ SegmentLCD_Init(false); /* Init LCD driver */ SegmentLCD_Write("ST: INIT"); Delay(500); SegmentLCD_Number(i); Delay(500); state = IDLE; } else state = INIT; break; case IDLE: if(1){ i = i + 1; SegmentLCD_Write("ST: IDLE"); Delay(500); SegmentLCD_Number(i); Delay(500); // while idle check humidity and temp paramters rel_humidity = ReadHumiditySensor(); dew_point = getDewPoint(); /* Get temperature from humidity sensor, notice that both pressure sensor and */ /* humidity sensor has built in temperature sensors, since dewpoint and pressure */ /* is dependent on the temperature close to the sensor it gives the most accurate */ /* results to use the built in temperature sensor in each device. */ temp_humid_sensor = getTemperatureHumidSensor(); state = RX_STATE; } else state = IDLE; break; case RX_STATE : if(1){ i = i + 1; SegmentLCD_Write("ST: Rx"); Delay(500); SegmentLCD_Number(i); Delay(500); SegmentLCD_Symbol(LCD_SYMBOL_ANT, 1); state = TX_STATE; } else state = RX_STATE; break; case TX_STATE: if(1){ i = i + 1; SegmentLCD_Write("ST: TX"); Delay(500); SegmentLCD_Number(i); Delay(500); SegmentLCD_Symbol(LCD_SYMBOL_ANT, 1); state = ERROR; } else state = TX_STATE; break; case ERROR: if(1){ i = i + 1; SegmentLCD_Write("ST: ERR"); Delay(500); SegmentLCD_Number(i); Delay(500); state = IDLE; } else state = ERROR; break; } LED_Toggle(0); LED_Toggle(1); Delay(1000); } }