//tmr.start(id,interval,function) //id:0~15 static int ltmr_start( lua_State* L ) { unsigned id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( tmr, id); unsigned interval = luaL_checkinteger( L, 2 ); if ( interval <= 0 ) return luaL_error( L, "wrong arg range" ); if (lua_type(L, 3) == LUA_TFUNCTION || lua_type(L, 3) == LUA_TLIGHTFUNCTION) { lua_pushvalue(L, 3); // copy argument (func) to the top of stack if(tmr_cb_ref[id] != LUA_NOREF) { luaL_unref(L, LUA_REGISTRYINDEX, tmr_cb_ref[id]); } gL = L; tmr_cb_ref[id] = luaL_ref(L, LUA_REGISTRYINDEX); mico_stop_timer(&_timer[id]); mico_deinit_timer( &_timer[id] ); mico_init_timer(&_timer[id], interval, _tmr_handler, (void*)id); mico_start_timer(&_timer[id]); tmr_is_started[id] = true; } else return luaL_error( L, "callback function needed" ); return 0; }
OSStatus HealthInit(app_context_t *app_context) { u8 idx; OSStatus err; for(idx = 0; idx < MAX_DEPTH_PUTDOWN; idx++) { putdown_timer[idx].index = idx; } // check if schedule remind timneout every 1 minute for(idx = 0; idx < MAX_DEPTH_SCHEDULE; idx++) { schedule_timer[idx].index = idx; err = mico_init_timer(&schedule_timer[idx].timer, 60*UpTicksPerSecond(), ScheduleTimeout, &schedule_timer[idx]); if(kNoErr != err) { user_log("[ERR]HealthInit: create schedule_timer[%d] failed", idx); } else { user_log("[DBG]HealthInit: create schedule_timer[%d] success", idx); } err = mico_start_timer(&schedule_timer[idx].timer); if(kNoErr != err) { user_log("[ERR]HealthInit: start schedule_timer[%d] failed", idx); } else { user_log("[DBG]HealthInit: start schedule_timer[%d] success", idx); } } #if 0 // initialize if outTrigger is implement by semaphore err = mico_rtos_init_semaphore(&semaphore_getup, 1); require_noerr_action(err, exit, user_log("[ERR]HealthInit: create semaphore_getup failed")); user_log("[DBG]HealthInit: create semaphore_getup success"); err = mico_rtos_init_semaphore(&semaphore_putdown, 1); require_noerr_action(err, exit, user_log("[ERR]HealthInit: create semaphore_putdown failed")); user_log("[DBG]HealthInit: create semaphore_putdown success"); #endif /* err = mico_init_timer(&timer_health_notify, 2*UpTicksPerSecond(), MOChangedNotification, app_context); require_noerr_action(err, exit, user_log("[ERR]HealthInit: create timer_health_notify failed")); user_log("[DBG]HealthInit: create timer_health_notify success"); err = mico_start_timer(&timer_health_notify); require_noerr_action(err, exit, user_log("[ERR]HealthInit: start timer_health_notify failed")); user_log("[DBG]HealthInit: start timer_health_notify success"); */ // start the health monitor thread err = mico_rtos_create_thread(&health_monitor_thread_handle, MICO_APPLICATION_PRIORITY, "health_monitor", health_thread, STACK_SIZE_HEALTH_THREAD, app_context); require_noerr_action( err, exit, user_log("[ERR]HealthInit: create health thread failed!")); user_log("[DBG]HealthInit: create health thread success!"); exit: return err; }
static void startPutDownTimerGroup() { u8 idx; for(idx = 0; idx < MAX_DEPTH_PUTDOWN; idx++) { if(!GetPutDownEnable(idx)) { continue; } if(GetPutDownRemindDelay(idx) == 0) { u8 type = GetPutDownTrackType(idx); u16 track_id = GetPutDownSelTrack(idx); AaSysLogPrint(LOGLEVEL_DBG, "track type %d index %d will be played", type, track_id); SendQuitReq(); SendPlayReq(type, track_id); } else { // if another putdown action trigger, reset last timers if(mico_is_timer_running(&putdown_timer[idx].timer)) { mico_stop_timer(&putdown_timer[idx].timer); mico_deinit_timer(&putdown_timer[idx].timer); } mico_init_timer(&putdown_timer[idx].timer, GetPutDownRemindDelay(idx)*60*UpTicksPerSecond(), PutdownTimeout, &putdown_timer[idx]); mico_start_timer(&putdown_timer[idx].timer); } } }
void ConfigEasyLinkIsSuccess( mico_Context_t * const inContext ) { (void)(inContext); config_delegate_log_trace(); #ifdef USE_MiCOKit_EXT char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; #endif mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); #ifdef USE_MiCOKit_EXT memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", (uint8_t*)"EasyLink got "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, (uint8_t*)oled_show_line); memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%16s", inContext->flashContentInRam.micoSystemConfig.ssid); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, (uint8_t*)oled_show_line); memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%16s", inContext->flashContentInRam.micoSystemConfig.user_key); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, (uint8_t*)oled_show_line); #endif return; }
int application_start( void ) { //start // lua_printf( "\r\n\r\nMiCO starting...(Free memory %d bytes)\r\n",MicoGetMemoryInfo()->free_memory); MicoInit(); //watch dog MicoWdgInitialize( DEFAULT_WATCHDOG_TIMEOUT); mico_init_timer(&_watchdog_reload_timer,DEFAULT_WATCHDOG_TIMEOUT/2, _watchdog_reload_timer_handler, NULL); mico_start_timer(&_watchdog_reload_timer); //usrinterface //MicoCliInit(); #if 1 // lua_printf("Free memory %d bytes\r\n", MicoGetMemoryInfo()->free_memory); lua_rx_data = (uint8_t*)malloc(INBUF_SIZE); ring_buffer_init ( (ring_buffer_t*)&lua_rx_buffer, (uint8_t*)lua_rx_data, INBUF_SIZE ); MicoUartInitialize( LUA_UART, &lua_uart_config, (ring_buffer_t*)&lua_rx_buffer ); mico_rtos_create_thread(NULL, MICO_DEFAULT_WORKER_PRIORITY, "lua_main_thread", lua_main_thread, 20*1024, 0); #endif // while(1) {;} mico_rtos_delete_thread(NULL); lua_printf("application_start exit\r\n"); return 0; }
void ConfigSoftApWillStart(mico_Context_t * const inContext ) { mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); }
void ConfigSoftApWillStart(mico_Context_t * const inContext ) { //OSStatus err; //mico_uart_config_t uart_config; mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); // sppProtocolInit(inContext); // // /*UART receive thread*/ // uart_config.baud_rate = inContext->flashContentInRam.appConfig.USART_BaudRate; // uart_config.data_width = DATA_WIDTH_8BIT; // uart_config.parity = NO_PARITY; // uart_config.stop_bits = STOP_BITS_1; // uart_config.flow_control = FLOW_CONTROL_DISABLED; // ring_buffer_init ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH ); // MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer ); // err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_UART_RECV_THREAD, (void*)inContext ); // require_noerr_action( err, exit, config_delegate_log("ERROR: Unable to start the uart recv thread.") ); // // if(inContext->flashContentInRam.appConfig.localServerEnable == true){ // err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, STACK_SIZE_LOCAL_TCP_SERVER_THREAD, (void*)inContext ); // require_noerr_action( err, exit, config_delegate_log("ERROR: Unable to start the local server thread.") ); // } //exit: return; }
//启动喝水定时 static void TIMER_start(void) { //获取配置 mico_reload_timer(&cupTimeObj.cup_timer); cupTimeObj.unitTimes = 0; mico_start_timer(&cupTimeObj.cup_timer); }
WEAK void mico_system_delegate_config_will_start( void ) { /*Led trigger*/ mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); return; }
void ConfigWillStart( mico_Context_t * const inContext ) { config_delegate_log_trace(); (void)(inContext); /*Led trigger*/ mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); return; }
WEAK void mico_system_delegate_config_recv_ssid ( char *ssid, char *key ) { UNUSED_PARAMETER(ssid); UNUSED_PARAMETER(key); mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); return; }
void ConfigAirkissIsSuccess( mico_Context_t * const inContext ) { (void)(inContext); config_delegate_log_trace(); mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); return; }
/************************************************* * Function: MX_TimerInit * Description: * Author: cxy * Returns: * Parameter: * History: *************************************************/ void MX_TimerInit() { u8 i = 0; for(i=0;i<ZC_TIMER_MAX_NUM;i++) { g_struMxTimer[i].u8ValidFlag = 0; } mico_init_timer(&g_struMicoTimer,100,MX_timer_callback,NULL); mico_start_timer(&g_struMicoTimer); }
static void _button_EL_irq_handler( void* arg ) { (void)(arg); int interval = -1; mico_start_timer(&_button_EL_timer); if ( MicoGpioInputGet( (mico_gpio_t)EasyLink_BUTTON ) == 0 ) { _default_start_time = mico_get_time()+1; mico_start_timer(&_button_EL_timer); MicoGpioEnableIRQ( (mico_gpio_t)EasyLink_BUTTON, IRQ_TRIGGER_RISING_EDGE, _button_EL_irq_handler, NULL ); } else { interval = mico_get_time() + 1 - _default_start_time; if ( (_default_start_time != 0) && interval > 50 && interval < RestoreDefault_TimeOut){ /* EasyLink button clicked once */ PlatformEasyLinkButtonClickedCallback(); //platform_log("PlatformEasyLinkButtonClickedCallback!"); MicoGpioOutputLow( (mico_gpio_t)MICO_RF_LED ); MicoGpioEnableIRQ( (mico_gpio_t)EasyLink_BUTTON, IRQ_TRIGGER_FALLING_EDGE, _button_EL_irq_handler, NULL ); } mico_stop_timer(&_button_EL_timer); _default_start_time = 0; } }
OSStatus mico_system_monitor_daemen_start( void ) { OSStatus err = kNoErr; /*Start system monotor thread*/ err = MICOStartSystemMonitor( ); require_noerr_string( err, exit, "ERROR: Unable to start the system monitor." ); /* Register first monitor */ err = mico_system_monitor_register(&mico_monitor, APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000); require_noerr( err, exit ); mico_init_timer(&_watchdog_reload_timer,APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000/2, _watchdog_reload_timer_handler, NULL); mico_start_timer(&_watchdog_reload_timer); exit: return err; }
static void _button_EL_irq_handler( void* arg ) { (void)(arg); if (GPIO_ReadInputDataBit(Button_EL_PORT, Button_EL_PIN) == 0) { _default_start_time = mico_get_time()+1; mico_start_timer(&_button_EL_timer); } else { if ( (_default_start_time != 0) && (mico_get_time() - _default_start_time) > 50){ /* EasyLink button clicked once */ PlatformEasyLinkButtonClickedCallback(); } mico_stop_timer(&_button_EL_timer); _default_start_time = 0; } }
static void _button_EL_irq_handler( void* arg ) { (void)(arg); int interval = -1; if ( MicoGpioInputGet( (mico_gpio_t)EasyLink_BUTTON ) == 0 ) { _default_start_time = mico_get_time()+1; mico_start_timer(&_button_EL_timer); } else { interval = mico_get_time() + 1 - _default_start_time; if ( (_default_start_time != 0) && interval > 50 && interval < RestoreDefault_TimeOut){ /* EasyLink button clicked once */ PlatformEasyLinkButtonClickedCallback(); } mico_stop_timer(&_button_EL_timer); _default_start_time = 0; } }
static void _user_key2_irq_handler( void* arg ) { (void)(arg); int interval = -1; if ( MicoGpioInputGet( (mico_gpio_t)USER_KEY2 ) == 0 ) { _default_key2_start_time = mico_get_time()+1; mico_start_timer(&_user_key2_timer); } else { interval = mico_get_time() + 1 - _default_key2_start_time; if ( (_default_key2_start_time != 0) && interval > 50 && interval < user_key2_long_press_timeout){ /* button clicked once */ user_key2_clicked_callback(); } mico_stop_timer(&_user_key2_timer); _default_key2_start_time = 0; } }
static void _button_EL_irq_handler( void* arg ) { (void)(arg); int interval = -1; if (GPIO_ReadInputDataBit(Button_EL_PORT, Button_EL_PIN) == 0) { _default_start_time = mico_get_time()+1; mico_start_timer(&_button_EL_timer); } else { interval = mico_get_time() + 1 - _default_start_time; if ( (_default_start_time != 0) && interval > 50 && interval < RestoreDefault_TimeOut){ /* EasyLink button clicked once */ PlatformEasyLinkButtonClickedCallback(); } mico_stop_timer(&_button_EL_timer); _default_start_time = 0; } }
static void _user_key1_irq_handler( void* arg ) { (void)(arg); int interval = -1; if ( MicoGpioInputGet( (mico_gpio_t)USER_KEY1 ) == 0 ) { MicoGpioEnableIRQ( (mico_gpio_t)USER_KEY1, IRQ_TRIGGER_RISING_EDGE, _user_key1_irq_handler, NULL ); _default_key1_start_time = mico_get_time()+1; mico_start_timer(&_user_key1_timer); } else { interval = mico_get_time() + 1 - _default_key1_start_time; if ( (_default_key1_start_time != 0) && interval > 50 && interval < user_key1_long_press_timeout){ /* button clicked once */ user_key1_clicked_callback(); } MicoGpioEnableIRQ( (mico_gpio_t)USER_KEY1, IRQ_TRIGGER_FALLING_EDGE, _user_key1_irq_handler, NULL ); mico_stop_timer(&_user_key1_timer); _default_key1_start_time = 0; } }
int application_start( void ) { //start // lua_printf( "\r\n\r\nMiCO starting...(Free memory %d bytes)\r\n",MicoGetMemoryInfo()->free_memory); MicoInit(); //watch dog MicoWdgInitialize( DEFAULT_WATCHDOG_TIMEOUT); mico_init_timer(&_watchdog_reload_timer,DEFAULT_WATCHDOG_TIMEOUT/2, _watchdog_reload_timer_handler, NULL); mico_start_timer(&_watchdog_reload_timer); #if 0 #include "tm_stm32f4_usb_vcp.h" lua_printf("\r\n\r\n TM_USB_VCP_Init:%d",TM_USB_VCP_Init()); uint8_t c; //NVIC_SetVectorTable(NVIC_VectTab_FLASH, new_addr); while(1) { if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) { if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) { TM_USB_VCP_Putc(c);/* Return data back */ } } } #endif //usrinterface //MicoCliInit(); #if 1 // lua_printf("Free memory %d bytes\r\n", MicoGetMemoryInfo()->free_memory); lua_rx_data = (uint8_t*)malloc(INBUF_SIZE); ring_buffer_init( (ring_buffer_t*)&lua_rx_buffer, (uint8_t*)lua_rx_data, INBUF_SIZE ); MicoUartInitialize( LUA_UART, &lua_uart_config, (ring_buffer_t*)&lua_rx_buffer ); mico_rtos_create_thread(NULL, MICO_DEFAULT_WORKER_PRIORITY, "lua_main_thread", lua_main_thread, 20*1024, 0); #endif // while(1) {;} mico_rtos_delete_thread(NULL); lua_printf("application_start exit\r\n"); return 0; }
int application_start( void ) { OSStatus err = kNoErr; os_timer_log("timer demo"); int arg = 0; err = mico_init_timer(&timer_handle, 1000, alarm, &arg); require_noerr(err, exit); err = mico_start_timer(&timer_handle); require_noerr(err, exit); mico_thread_sleep( MICO_NEVER_TIMEOUT ); exit: if( err != kNoErr ) os_timer_log( "Thread exit with err: %d", err ); mico_rtos_delete_thread( NULL ); return err; }
void OTAWillStart( mico_Context_t * const inContext ) { //config_delegate_log_trace(); (void)(inContext); #ifdef USE_MiCOKit_EXT char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; #endif /*Led trigger*/ mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_OTA_INTERVAL, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); #ifdef USE_MiCOKit_EXT memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", (uint8_t*)"Firmware update "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, (uint8_t*)oled_show_line); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, " Donwloading..."); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " will reboot..."); #endif return; }
static void button_irq_handler( void* arg ) { button_context_t *_context = arg; int interval = -1; if ( MicoGpioInputGet( _context->gpio ) == 0 ) { MicoGpioEnableIRQ( _context->gpio, IRQ_TRIGGER_RISING_EDGE, button_irq_handler, _context ); _context->start_time = mico_get_time()+1; mico_start_timer(&_context->_user_button_timer); } else { interval = mico_get_time() + 1 - _context->start_time ; if ( (_context->start_time != 0) && interval > 50 && interval < _context->timeout){ /* button clicked once */ if( _context->pressed_func != NULL ) (_context->pressed_func)(); } MicoGpioEnableIRQ( _context->gpio, IRQ_TRIGGER_FALLING_EDGE, button_irq_handler, _context ); mico_stop_timer(&_context->_user_button_timer); _context->start_time = 0; } }
void ConfigWillStart( mico_Context_t * const inContext ) { config_delegate_log_trace(); (void)(inContext); #ifdef USE_MiCOKit_EXT char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; #endif /*Led trigger*/ mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); #ifdef USE_MiCOKit_EXT memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", (uint8_t*)"Config... "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, (uint8_t*)oled_show_line); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, " Awaiting "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " ssid/key "); #endif inContext->appStatus.noOTACheckOnSystemStart = true; return; }
OSStatus startEasyLink( mico_Context_t * const inContext) { easylink_log_trace(); OSStatus err = kUnknownErr; require_action(inContext->micoStatus.easylink_thread_handler==NULL, exit, err = kParamErr); require_action(inContext->micoStatus.easylink_sem==NULL, exit, err = kParamErr); inContext->micoStatus.easylinkClient_fd = -1; //ps_enable(); mico_mcu_powersave_config(true); mico_rtos_init_mutex(&_mutex); err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)EasyLinkNotify_WifiStatusHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_WiFI_PARA_CHANGED, (void *)EasyLinkNotify_WiFIParaChangedHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_EASYLINK_COMPLETED, (void *)EasyLinkNotify_EasyLinkCompleteHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_EASYLINK_GET_EXTRA_DATA, (void *)EasyLinkNotify_EasyLinkGetExtraDataHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_DHCP_COMPLETED, (void *)EasyLinkNotify_DHCPCompleteHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_SYS_WILL_POWER_OFF, (void *)EasyLinkNotify_SYSWillPoerOffHandler ); require_noerr( err, exit ); /*Led trigger*/ mico_init_timer(&_Led_EL_timer, LED_EL_TRIGGER_INTERVAL, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); // Start the EasyLink thread ConfigWillStart(inContext); mico_rtos_init_semaphore(&inContext->micoStatus.easylink_sem, 1); err = mico_rtos_create_thread(&inContext->micoStatus.easylink_thread_handler, MICO_APPLICATION_PRIORITY, "EASYLINK", easylink_thread, 0x1000, (void*)inContext ); require_noerr_action( err, exit, easylink_log("ERROR: Unable to start the EasyLink thread.") ); exit: return err; }
void ConfigSoftApWillStart(mico_Context_t * const inContext ) { #ifdef USE_MiCOKit_EXT char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; #endif mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); #ifdef USE_MiCOKit_EXT snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", "SoftAP... "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, (uint8_t*)oled_show_line); memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, " EasyLink_%c%c%c%c%c%c", inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, (uint8_t*)oled_show_line); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " "); #endif return; }
void mico_system_delegate_config_recv_ssid ( char *ssid, char *key ) { config_delegate_log_trace(); #ifdef USE_MiCOKit_EXT char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; #endif mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); #ifdef USE_MiCOKit_EXT memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", (uint8_t*)"Got ssid/key "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, (uint8_t*)oled_show_line); memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%16s", ssid); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, (uint8_t*)oled_show_line); memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1); snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%16s", key); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, (uint8_t*)oled_show_line); #endif }
int application_start(void) { OSStatus err = kNoErr; net_para_st para; Platform_Init(); /*Read current configurations*/ context = ( mico_Context_t *)malloc(sizeof(mico_Context_t) ); require_action( context, exit, err = kNoMemoryErr ); memset(context, 0x0, sizeof(mico_Context_t)); mico_rtos_init_mutex(&context->flashContentInRam_mutex); mico_rtos_init_semaphore(&context->micoStatus.sys_state_change_sem, 1); MICOReadConfiguration( context ); err = MICOInitNotificationCenter ( context ); err = MICOAddNotification( mico_notify_READ_APP_INFO, (void *)micoNotify_ReadAppInfoHandler ); require_noerr( err, exit ); /*wlan driver and tcpip init*/ mxchipInit(); getNetPara(¶, Station); formatMACAddr(context->micoStatus.mac, (char *)¶.mac); mico_log_trace(); mico_log("%s mxchipWNet library version: %s", APP_INFO, system_lib_version()); /*Start system monotor thread*/ err = MICOStartSystemMonitor(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the system monitor.") ); err = MICORegisterSystemMonitor(&mico_monitor, APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000); require_noerr( err, exit ); mico_init_timer(&_watchdog_reload_timer,APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000-100, _watchdog_reload_timer_handler, NULL); mico_start_timer(&_watchdog_reload_timer); if(context->flashContentInRam.micoSystemConfig.configured != allConfigured){ mico_log("Empty configuration. Starting configuration mode..."); #ifdef CONFIG_MODE_EASYLINK err = startEasyLink( context ); require_noerr( err, exit ); #endif #ifdef CONFIG_MODE_WAC WACPlatformParameters_t* WAC_Params = NULL; WAC_Params = calloc(1, sizeof(WACPlatformParameters_t)); require(WAC_Params, exit); str2hex((unsigned char *)para.mac, WAC_Params->macAddress, 6); WAC_Params->isUnconfigured = 1; WAC_Params->supportsAirPlay = 0; WAC_Params->supportsAirPrint = 0; WAC_Params->supports2_4GHzWiFi = 1; WAC_Params->supports5GHzWiFi = 0; WAC_Params->supportsWakeOnWireless = 0; WAC_Params->firmwareRevision = FIRMWARE_REVISION; WAC_Params->hardwareRevision = HARDWARE_REVISION; WAC_Params->serialNumber = SERIAL_NUMBER; WAC_Params->name = context->flashContentInRam.micoSystemConfig.name; WAC_Params->model = MODEL; WAC_Params->manufacturer = MANUFACTURER; WAC_Params->numEAProtocols = 1; WAC_Params->eaBundleSeedID = BUNDLE_SEED_ID; WAC_Params->eaProtocols = (char **)eaProtocols;; err = startMFiWAC( context, WAC_Params, 1200); free(WAC_Params); require_noerr( err, exit ); #endif } else{ mico_log("Available configuration. Starting Wi-Fi connection..."); /* Regisist notifications */ err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WiFI_PARA_CHANGED, (void *)micoNotify_WiFIParaChangedHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_DHCP_COMPLETED, (void *)micoNotify_DHCPCompleteHandler ); require_noerr( err, exit ); if(context->flashContentInRam.micoSystemConfig.rfPowerSaveEnable == true){ ps_enable(); } if(context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true){ mico_mcu_powersave_config(true); } /*Bonjour service for searching*/ // if(context->flashContentInRam.micoSystemConfig.bonjourEnable == true){ // err = MICOStartBonjourService( Station, context ); // require_noerr( err, exit ); // } err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mDNSResponder", mDNSResponder_thread, 0x1000, (void*)context ); require_noerr_action( err, exit, mico_log("ERROR: Unable to start mDNSResponder thread.") ); /*Local configuration server*/ if(context->flashContentInRam.micoSystemConfig.configServerEnable == true){ err = MICOStartConfigServer(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the local server thread.") ); } /*Start mico application*/ err = MICOStartApplication( context ); require_noerr( err, exit ); _ConnectToAP( context ); } /*System status changed*/ while(mico_rtos_get_semaphore(&context->micoStatus.sys_state_change_sem, MICO_WAIT_FOREVER)==kNoErr){ switch(context->micoStatus.sys_state){ case eState_Normal: break; case eState_Software_Reset: sendNotifySYSWillPowerOff(); mico_thread_msleep(500); PlatformSoftReboot(); break; case eState_Wlan_Powerdown: sendNotifySYSWillPowerOff(); mico_thread_msleep(500); wifi_power_down(); break; case eState_Standby: mico_log("Enter standby mode"); sendNotifySYSWillPowerOff(); mico_thread_msleep(200); wifi_power_down(); Platform_Enter_STANDBY(); break; default: break; } } require_noerr_action( err, exit, mico_log("Closing main thread with err num: %d.", err) ); exit: mico_rtos_delete_thread(NULL); return kNoErr; }
int application_start(void) { OSStatus err = kNoErr; net_para_st para; Platform_Init(); /*Read current configurations*/ context = ( mico_Context_t *)malloc(sizeof(mico_Context_t) ); require_action( context, exit, err = kNoMemoryErr ); memset(context, 0x0, sizeof(mico_Context_t)); mico_rtos_init_mutex(&context->flashContentInRam_mutex); mico_rtos_init_semaphore(&context->micoStatus.sys_state_change_sem, 1); MICOReadConfiguration( context ); err = MICOInitNotificationCenter ( context ); err = MICOAddNotification( mico_notify_READ_APP_INFO, (void *)micoNotify_ReadAppInfoHandler ); require_noerr( err, exit ); /*wlan driver and tcpip init*/ mxchipInit(); getNetPara(¶, Station); formatMACAddr(context->micoStatus.mac, (char *)¶.mac); mico_log_trace(); mico_log("%s mxchipWNet library version: %s", APP_INFO, system_lib_version()); /*Start system monotor thread*/ err = MICOStartSystemMonitor(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the system monitor.") ); err = MICORegisterSystemMonitor(&mico_monitor, APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000); require_noerr( err, exit ); mico_init_timer(&_watchdog_reload_timer,APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000-100, _watchdog_reload_timer_handler, NULL); mico_start_timer(&_watchdog_reload_timer); if(context->flashContentInRam.micoSystemConfig.configured != allConfigured){ mico_log("Empty configuration. Starting configuration mode..."); #ifdef CONFIG_MODE_EASYLINK err = startEasyLink( context ); require_noerr( err, exit ); #endif #ifdef CONFIG_MODE_WAC err = startMfiWac( context ); require_noerr( err, exit ); #endif } else{ mico_log("Available configuration. Starting Wi-Fi connection..."); /* Regisist notifications */ err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WiFI_PARA_CHANGED, (void *)micoNotify_WiFIParaChangedHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_DHCP_COMPLETED, (void *)micoNotify_DHCPCompleteHandler ); require_noerr( err, exit ); if(context->flashContentInRam.micoSystemConfig.rfPowerSaveEnable == true){ ps_enable(); } if(context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true){ mico_mcu_powersave_config(true); } /*Bonjour service for searching*/ if(context->flashContentInRam.micoSystemConfig.bonjourEnable == true){ err = MICOStartBonjourService( Station, context ); require_noerr( err, exit ); } /*Local configuration server*/ if(context->flashContentInRam.micoSystemConfig.configServerEnable == true){ err = MICOStartConfigServer(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the local server thread.") ); } /*Start mico application*/ err = MICOStartApplication( context ); require_noerr( err, exit ); _ConnectToAP( context ); } /*System status changed*/ while(mico_rtos_get_semaphore(&context->micoStatus.sys_state_change_sem, MICO_WAIT_FOREVER)==kNoErr){ switch(context->micoStatus.sys_state){ case eState_Normal: break; case eState_Software_Reset: sendNotifySYSWillPowerOff(); mico_thread_msleep(500); PlatformSoftReboot(); break; case eState_Wlan_Powerdown: sendNotifySYSWillPowerOff(); mico_thread_msleep(500); wifi_power_down(); break; case eState_Standby: mico_log("Enter standby mode"); sendNotifySYSWillPowerOff(); mico_thread_msleep(100); wifi_power_down(); Platform_Enter_STANDBY(); break; default: break; } } require_noerr_action( err, exit, mico_log("Closing main thread with err num: %d.", err) ); exit: mico_rtos_delete_thread(NULL); return kNoErr; }