void TM_taskHandler(packet_t *pkt) { switch(pkt->task) { case task_dummy: break; case task_LED: led_task(pkt); break; case task_alarm: if((alarm_subTaskHandler(pkt)) == retain_task) { return; } break; case task_zigbee: if((zigbee_SubtaskHandler(pkt)) == retain_task) { return; } break; default: alarm("TASK MASTER REACHED AN UNKNOWN TASK"); break; } TM_freePacket(pkt); }
int main( void) { struct itimer Blink_Timer; /*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 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); led_init(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE); timer_init(); lse_init(); led_init(); rs485_init(); bacnet_init(); timer_interval_start(&Blink_Timer, 125); for (;;) { if (timer_interval_expired(&Blink_Timer)) { timer_interval_reset(&Blink_Timer); led_ld3_toggle(); } led_task(); bacnet_task(); } }
/** * \brief Main function. * * Initializes the board, and runs the application in an infinite loop. */ int main(void) { /* hardware initialization */ sysclk_init(); board_init(); pmic_init(); timer_init(); rs485_init(); led_init(); adc_init(); #ifdef CONF_BOARD_ENABLE_RS485_XPLAINED // Enable display backlight gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT); #endif // Workaround for known issue: Enable RTC32 sysclk sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC); while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm) { // Wait for RTC32 sysclk to become stable } cpu_irq_enable(); /* application initialization */ rs485_baud_rate_set(38400); bacnet_init(); /* run forever - timed tasks */ timer_callback(bacnet_task_timed, 5); for (;;) { bacnet_task(); led_task(); } }
void bootloader_main() { SystemInit(); spiflash_reinit(); CGU_Init(); hw_digital_output(LED1); hw_digital_output(LED2); hw_digital_output(CC3K_CONN_LED); hw_digital_output(CC3K_ERR_LED); hw_digital_write(CC3K_CONN_LED, 0); hw_digital_write(CC3K_ERR_LED, 0); init_systick(); __enable_irq(); usb_init(); usb_set_speed(USB_SPEED_FULL); usb_attach(); while(!exit_and_jump) { led_task(); __WFI(); /* conserve power */ } delay_ms(25); usb_detach(); delay_ms(100); if (dfu_target == TARGET_RAM) { jump_to_flash(DFU_DEST_BASE, 0); } }
/* \brief Main entry point * This is an example of how to use watchdog. */ int main(void) { // Switch main clock to external oscillator 0 (crystal). pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); // Call Watchdog scheduler wdt_scheduler(); while(1) { // Launch led task led_task(); } }
/** * Implementación de la funcionalidad principal del programa */ void main() { //OSCCON = 0x6C; // Para usar el oscilador interno PIC16F88 4 Mhz OSCCON = 0x7C; // Para usar el oscilador interno PIC16F88 8 Mhz ANSEL = 0x00; // Configuracion de pines analogicos y digitales TRISA = 0xE0; TRISB = 0xFF; // Preparamos las librerías para su uso lcd_init(0, 16, 2); // Iniciar el controlador de pantalla tick_init(); // Iniciar el contador / temporizador del sistema dhtlib_init(); // Preparar la comunicación con el sensor DHT11 // Encendemos la pantalla LCD y escribimos titulo lcd_on(); lcd_puts(" PRUEBA DHT11 "); // Ciclo principal de nuestra aplicación for (;;) { led_task(); dht11_task(); } }
int main(void) { AppMode_T AppMode; APP_STATE_E state=UPDATE_TEMPERATURE; char LCDString[30], temp_char[2]; uint16_t temp; float ftemp; HardwareSetup(); /************************initializa LCD module********************************/ SPI2_Init(); InitialiseLCD(); led_init(); MSTimerInit(); /* Default app mode */ AppMode = GAINSPAN_DEMO; /* If the CIK is exist, auto into the Exosite mode */ NVSettingsLoad(&GNV_Setting); /* Determine if SW1 & SW3 is pressed at power up to enter programming mode */ if (Switch1IsPressed() && Switch3IsPressed()) { AppMode = PROGRAM_MODE; } else if(Switch3IsPressed() && Switch2IsPressed()) { AppMode = EXOSITE_ERASE; } else if(Switch1IsPressed()) { AppMode = RUN_EXOSITE; } else if(Switch2IsPressed()) { AppMode = RUN_PROVISIONING; } else if(Switch3IsPressed()) { AppMode = RUN_OVER_AIR_DOWNLOAD; } if(AppMode == GAINSPAN_DEMO) { LCDDisplayLogo(); LCDSelectFont(FONT_SMALL); DisplayLCD(LCD_LINE3, "RL78G14 RDK V2.0"); DisplayLCD(LCD_LINE4, " Wi-Fi & Cloud "); DisplayLCD(LCD_LINE5, " demos by: "); DisplayLCD(LCD_LINE6, "Gainspan "); DisplayLCD(LCD_LINE7, "Exosite "); DisplayLCD(LCD_LINE8, "Future Designs, Inc"); MSTimerDelay(3500); ClearLCD(); DisplayLCD(LCD_LINE1, "Demo Modes: "); DisplayLCD(LCD_LINE2, "-RST no key: "); DisplayLCD(LCD_LINE3, " GS Web Server "); DisplayLCD(LCD_LINE4, "-RST + SW1: "); DisplayLCD(LCD_LINE5, " Exosite Cloud "); DisplayLCD(LCD_LINE6, "-RST + SW2: "); DisplayLCD(LCD_LINE7, " AP Provisioning "); DisplayLCD(LCD_LINE8, "-RST + SW3: OTA "); MSTimerDelay(3000); ClearLCD(); LCDSelectFont(FONT_LARGE); if(Exosite_GetCIK(NULL)) { AppMode = RUN_EXOSITE; } } DisplayLCD(LCD_LINE1, "Starting..."); /*****************************************************************************/ SPI_Init(GAINSPAN_SPI_RATE); /* Setup LCD SPI channel for Chip Select P10, active low, active per byte */ SPI_ChannelSetup(GAINSPAN_SPI_CHANNEL, false, true); GainSpan_SPI_Start(); PM15 &= ~(1 << 2); P15 &= ~(1 << 2); if(AppMode == PROGRAM_MODE) { App_ProgramMode(); } else if (AppMode == RUN_EXOSITE) { DisplayLCD(LCD_LINE1, " CLOUD DEMO "); Temperature_Init(); Potentiometer_Init(); App_Exosite(); } else if(AppMode == RUN_PROVISIONING) { App_WebProvisioning(); } else if(AppMode == RUN_OVER_AIR_DOWNLOAD) { App_OverTheAirProgrammingPushMetheod(); } else if (AppMode == EXOSITE_ERASE) { ClearLCD(); LCDSelectFont(FONT_SMALL); DisplayLCD(LCD_LINE3, "EEPROM ERASING ... "); MSTimerDelay(2000); Exosite_Init("renesas", "rl78g14", IF_WIFI, 1); DisplayLCD(LCD_LINE3, " "); DisplayLCD(LCD_LINE4, "Please reset device"); while(1); } else{ UART0_Start(GAINSPAN_CONSOLE_BAUD); // UART2_Start(GAINSPAN_UART_BAUD); Temperature_Init(); Potentiometer_Init(); // sprintf(LCDString, "RDK Demo %s", VERSION_TEXT); // DisplayLCD(LCD_LINE1, (const uint8_t *)LCDString); /* Before doing any tests or apps, startup the module */ /* and nonvolatile stettings */ App_Startup(); // Now connect to the system //App_Connect(&G_nvsettings.webprov); // App_PassThroughSPI(); /******************Start Processing Sensor data******************/ uint32_t start = MSTimerGet(); uint8_t c; Accelerometer_Init(); while(1) { // if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, &c)) if(App_Read(&c, 1, 0)) AtLibGs_ReceiveDataProcess(c); /* Timeout? */ if (MSTimerDelta(start) >= 100) // every 100 ms, read sensor data { led_task(); switch(state) { case UPDATE_TEMPERATURE: // Temperature sensor reading temp = Temperature_Get(); #if 0 // Get the temperature and show it on the LCD temp_char[0] = (int16_t)temp / 16; temp_char[1] = (int16_t)((temp & 0x000F) * 10) / 16; #endif temp_char[1] = (temp & 0xFF00)>>8; temp_char[0] = temp & 0xFF; ftemp = *(uint16_t *)temp_char; gTemp_F = ((ftemp/5)*9)/128 + 22; // Display the contents of lcd_buffer onto the debug LCD //sprintf((char *)LCDString, "TEMP: %d.%d C", temp_char[0], temp_char[1]); sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F); DisplayLCD(LCD_LINE6, (const uint8_t *)LCDString); state = UPDATE_LIGHT; break; case UPDATE_LIGHT: // Light sensor reading gAmbientLight = LightSensor_Get(); // Display the contents of lcd_buffer onto the debug LCD sprintf((char *)LCDString, "Light: %d ", gAmbientLight); DisplayLCD(LCD_LINE7, (const uint8_t *)LCDString); state = UPDATE_ACCELEROMETER; break; case UPDATE_ACCELEROMETER: // 3-axis accelerometer reading Accelerometer_Get(); sprintf((char *)LCDString, "x%2d y%2d z%2d", gAccData[0], gAccData[1], gAccData[2]); DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString); state = UPDATE_TEMPERATURE; break; } start = MSTimerGet(); } } }