Exemple #1
0
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;
}
int application_start(void)
{
    app_log_trace();
    OSStatus err = kNoErr;
    mico_uart_config_t uart_config;
    app_context_t* app_context;
    mico_Context_t* mico_context;

    /* Create application context */
    app_context = ( app_context_t *)calloc(1, sizeof(app_context_t) );
    require_action( app_context, exit, err = kNoMemoryErr );

    /* Create mico system context and read application's config data from flash */
    mico_context = mico_system_context_init( sizeof( application_config_t) );
    app_context->appConfig = mico_system_context_get_user_data( mico_context );

    /* mico system initialize */
    err = mico_system_init( mico_context );
    require_noerr( err, exit );

    /* Bonjour for service searching */
    MICOStartBonjourService( Station, app_context );

    /* Protocol initialize */
    sppProtocolInit( app_context );

    /*UART receive thread*/
    uart_config.baud_rate    = app_context->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;
    if(mico_context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true)
        uart_config.flags = UART_WAKEUP_ENABLE;
    else
        uart_config.flags = UART_WAKEUP_DISABLE;
    
    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*)app_context );
    require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") );

    /* Local TCP server thread */
    if(app_context->appConfig->localServerEnable == true)
    {
        err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, STACK_SIZE_LOCAL_TCP_SERVER_THREAD, (void*)app_context );
        require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") );
    }

    /* Remote TCP client thread */
    if(app_context->appConfig->remoteServerEnable == true)
    {
        err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, STACK_SIZE_REMOTE_TCP_CLIENT_THREAD, (void*)app_context );
        require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") );
    }

exit:
    mico_rtos_delete_thread(NULL);
    return err;
}
OSStatus user_uartInit(void)
{
    OSStatus err = kUnknownErr;
    mico_uart_config_t uart_config;

    //USART init
    uart_config.baud_rate    = 115200;
    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;
    uart_config.flags = UART_WAKEUP_DISABLE;
    ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, USER_UART_BUFFER_LENGTH );

    MicoUartInitialize( USER_UART, &uart_config, (ring_buffer_t *)&rx_buffer );

    //USART receive thread		启动uart接收线程
    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv",
                                  uartRecv_thread, STACK_SIZE_USART_RECV_THREAD,
                                  NULL );
    require_noerr_action( err, exit, user_uart_log("ERROR: Unable to start the USART recv thread.") );


    //ZCB Msg Handle Thread		启动 ZCB Msg 处理线程
    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "ZCB Msg Handle",
                                  ZCB_MessageHandle_thread, STACK_SIZE_ZCBMSG_HANDLE_THREAD,
                                  NULL );
    require_noerr_action( err, exit, user_uart_log("ERROR: Unable to start the zcbMsg hdl thread.") );


    return kNoErr;

exit:
    return err;
}
Exemple #4
0
OSStatus MICOStartApplication( mico_Context_t * const inContext )
{
  app_log_trace();

  OSStatus err = kNoErr;
  require_action(inContext, exit, err = kParamErr);

  haProtocolInit(inContext);
  PlatformUartInitialize(inContext);

  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, 0x500, (void*)inContext );
  require_noerr_action( err, exit, app_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, 0x200, (void*)inContext );
   require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") );
 }

 if(inContext->flashContentInRam.appConfig.remoteServerEnable == true){
   err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, 0x500, (void*)inContext );
   require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") );
 }

exit:
  return err;
}
int application_start( void )
{
  OSStatus err = kNoErr;

  /* Create a mutex*/
  err = mico_rtos_init_mutex( &mutex);
  require_noerr(err, exit);

  /* Create threads */
  err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY+1, "t1", run, 0x800, p_name1 );
  require_noerr(err, exit);

  err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY+1, "t2", run, 0x800, p_name2 );
  require_noerr(err, exit);

  err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY+1, "t3", run, 0x800, p_name3 );
  require_noerr(err, exit);

  err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY+1, "t4", run, 0x800, p_name4 );
  require_noerr(err, exit);

exit:
  if( err != kNoErr )
    os_mutex_log( "Thread exit with err: %d", err );

  mico_rtos_delete_thread(NULL);
  return err;  
}
/* user main function, called by AppFramework.
 */
OSStatus user_main( app_context_t * const app_context )
{
  user_log_trace();
  OSStatus err = kUnknownErr;
  
  user_log("User main thread start...");
  
  // start prop get/set thread
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "prop_recv", property_recv, 
                                STACK_SIZE_PROP_RECV_THREAD, (void*)app_context);
  require_noerr_action( err, exit, user_log("ERROR: Unable to start the prop_recv thread.") );
  
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "prop_update", property_update, 
                                STACK_SIZE_PROP_UPDATE_THREAD, (void*)app_context);
  require_noerr_action( err, exit, user_log("ERROR: Unable to start the prop_update thread.") );

  /* main loop for user display */
  while(1){
    // system work state show on OLED
    system_state_display(app_context);
    mico_thread_sleep(1);
  }
  
exit:
  user_log("ERROR: user_main exit with err=%d", err);
  return err;
}
Exemple #7
0
int application_start( void )
{
  OSStatus err = kNoErr;
  mico_thread_t handle1;
  mico_thread_t handle2;
  /* Create new thread */
  err = mico_rtos_create_thread(&handle1, MICO_APPLICATION_PRIORITY, "t1", run1, 500, NULL);
  err = mico_rtos_create_thread(&handle2, MICO_APPLICATION_PRIORITY, "t2", run2, 500, NULL);
  mico_rtos_thread_join(&handle1);
  mico_rtos_thread_join(&handle2);
  os_thread_log( "t1 t2 exit now" );
  return kNoErr;  
}
/* user main function, called by AppFramework after system init done && wifi
 * station on in user_main thread.
 */
OSStatus user_main( app_context_t * const app_context )
{
    OSStatus err = kNoErr;
    int time_sencond = 50*1000;  /* 60s */


    require(app_context, exit);
    net_init(app_context);

    /* Create a new thread */

    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "RGB_LED", LED_handleThread, 1024, NULL );
    require_noerr_string( err, exit, "ERROR: Unable to start the RGB LED thread ." );

    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "MP3_PLAY", MP3_handleThread, 1024, NULL );
    require_noerr_string( err, exit, "ERROR: Unable to start the MP3 PLAY thread" );

    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "BAT_DETECT", BAT_handleThread, 500, NULL );
    require_noerr_string( err, exit, "ERROR: Unable to start the BAT DETECT thread ." );

    KEY_Init(KEY_irq_handler); //按键初始化

    mico_rtos_init_semaphore(&cupTimeObj.playMp3_sem, 1);  //信号量初始化
    mico_rtos_init_semaphore(&cupTimeObj.playLed_sem, 1);
    mico_rtos_init_semaphore(&cupTimeObj.stopLed_sem, 1);

    err = mico_init_timer(&cupTimeObj.cup_timer, time_sencond, cup_timer_timeout_handler, (void *)&cupTimeObj);
    cupTimeObj.drinkTime = 1;
    cupTimeObj.playMode = PLAY_MP3_LED;
    if (KEY_getValue() == KEY_DOWN)
    {
        TIMER_start(); //启动定时喝水
    }

    while(1)
    {
        // printf("this is main thread.\r\n");
        //net_test(app_context);
        mico_thread_sleep(10);
    }

exit:
    if(kNoErr != err) {
        printf("ERROR: user_main thread exit with err=%d", err);
    }
    mico_rtos_delete_thread(NULL);
    return kNoErr;
}
OSStatus MVDDevInterfaceInit(mico_Context_t* const inContext)
{
  OSStatus err = kUnknownErr;
  mico_uart_config_t uart_config;
  
  //USART init
  uart_config.baud_rate    = inContext->flashContentInRam.appConfig.virtualDevConfig.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;
  if(inContext->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true)
    uart_config.flags = UART_WAKEUP_ENABLE;
  else
    uart_config.flags = UART_WAKEUP_DISABLE;
  ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH );
  
  MicoUartInitialize( UART_FOR_MCU, &uart_config, (ring_buffer_t *)&rx_buffer );
  
  //USART receive thread
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", 
                                uartRecv_thread, STACK_SIZE_USART_RECV_THREAD, 
                                (void*)inContext );
  require_noerr_action( err, exit, dev_if_log("ERROR: Unable to start the USART recv thread.") );
  return kNoErr;
  
exit:
  return err;
}
Exemple #10
0
OSStatus startEasyLink( mico_Context_t * const inContext)
{
  easylink_log_trace();
  OSStatus err = kUnknownErr;
  easylinkClient_fd = -1;

  mico_mcu_powersave_config(true);
  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 ); 

  // Start the EasyLink thread
  ConfigWillStart(inContext);
  mico_rtos_init_semaphore(&easylink_sem, 1);
  err = mico_rtos_create_thread(NULL, 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;
}
Exemple #11
0
OSStatus MVDInit(mico_Context_t* const inContext)
{
  OSStatus err = kUnknownErr;
  
  //init MVD status
  inContext->appStatus.virtualDevStatus.isCloudConnected = false;
  inContext->appStatus.virtualDevStatus.RecvRomFileSize = 0;
  
  //init MCU connect interface
  //err = MVDDevInterfaceInit(inContext);
  //require_noerr_action(err, exit, 
  //                     mvd_log("ERROR: virtual device mcu interface init failed!") );
  
  //init cloud service interface
  err = MVDCloudInterfaceInit(inContext);
  require_noerr_action(err, exit, 
                       mvd_log("ERROR: virtual device cloud interface init failed!") );
  
  // wifi notify
  err = mico_rtos_init_semaphore(&_wifi_station_on_sem, 1);
  require_noerr_action(err, exit, 
                       mvd_log("ERROR: mico_rtos_init_semaphore (_wifi_station_on_sem) failed!") );
  
  err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)mvdNotify_WifiStatusHandler );
  require_noerr_action(err, exit, 
                       mvd_log("ERROR: MICOAddNotification (mico_notify_WIFI_STATUS_CHANGED) failed!") );
 
  // start MVD main thread
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "MVD main", 
                                MVDMainThread, STACK_SIZE_MVD_MAIN_THREAD, 
                                inContext );
  
exit:
  return err;
}
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;
}
Exemple #13
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);
  
//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;
 }
OSStatus MicoStartFogCloudConfigServer ( mico_Context_t * const inContext )
{
  return mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, 
                                 "fog_server", 
                                 fogCloudConfigServer_listener_thread, 
                                 STACK_SIZE_FOGCLOUD_CONFIG_SERVER_THREAD, (void*)inContext );
}
Exemple #15
0
int application_start( void )
{
  OSStatus err = kNoErr;
  IPStatusTypedef para;
  
  MicoInit( );
  
  /*The notification message for the registered WiFi status change*/
  err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler );
  require_noerr( err, exit ); 
  
  err = MICOAddNotification( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler );
  require_noerr( err, exit );
  
  err = mico_rtos_init_semaphore(&tcp_sem, 1);
  require_noerr( err, exit );
  
  connect_ap( );
  
  mico_rtos_get_semaphore(&tcp_sem, MICO_WAIT_FOREVER);
  
  micoWlanGetIPStatus(&para, Station);
  tcp_server_log("tcp server ip: %s", para.ip);

  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "TCP_server", tcp_server_thread, 0x800, NULL );
  require_noerr_action( err, exit, tcp_server_log("ERROR: Unable to start the tcp server thread.") );
  
  return err;

exit:
  tcp_server_log("ERROR, err: %d", err);
  return err;
}
Exemple #16
0
OSStatus MICOStartApplication( mico_Context_t * const inContext )
{
  app_log_trace();

  OSStatus err = kNoErr;
  require_action(inContext, exit, err = kParamErr);

  inContext->appStatus.statusNumber = 0x01;
#ifdef MICO_I2C_CP
  if( MicoMFiAuthInitialize( MICO_I2C_CP ) == kNoErr )
    inContext->appStatus.useMFiAuth = true;
  else
#endif
    inContext->appStatus.useMFiAuth = false;

  /*Bonjour for service searching*/
  if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true)
    MICOStartBonjourService( Station, inContext );

  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "HomeKit Server", homeKitListener_thread, 0x500, (void*)inContext );
  require_noerr_action( err, exit, app_log("ERROR: Unable to start the Homekit thread.") );

exit:
  return err;
}
Exemple #17
0
int application_start( void )
{
  OSStatus err = kNoErr;
  is_easylink_success = 0;
  
  MicoInit( );
  
  /*The notification message for the registered WiFi status change*/
  err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler );
  require_noerr( err, exit ); 
  
  err = MICOAddNotification( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler );
  require_noerr( err, exit );

  err = MICOAddNotification( mico_notify_EASYLINK_WPS_COMPLETED, (void *)EasyLinkNotify_EasyLinkCompleteHandler );
  require_noerr(err, exit);
  
  err = MICOAddNotification( mico_notify_EASYLINK_GET_EXTRA_DATA, (void *)EasyLinkNotify_EasyLinkGetExtraDataHandler );
  require_noerr(err, exit);
  
  // Start the EasyLink thread
  mico_rtos_init_semaphore(&easylink_sem, 1);
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "EASYLINK", easylink_thread, 0x800, NULL );
  require_noerr_action( err, exit, wifi_easylink_log("ERROR: Unable to start the EasyLink thread.") );
  
  return err;

exit:
  wifi_easylink_log("ERROR, err: %d", err);
  return err;
}
Exemple #18
0
//uart.setup(1,9600,'n','8','1')
//baud:all supported
//parity:
//      n,NO_PARITY;
//      o,ODD_PARITY;
//      e,EVEN_PARITY
//databits:
//      5:DATA_WIDTH_5BIT,
//      6:DATA_WIDTH_6BIT,
//      7:DATA_WIDTH_7BIT,
//      8:DATA_WIDTH_8BIT,
//      9:DATA_WIDTH_9BIT
//stopbits:
//      1,STOP_BITS_1
//      2,STOP_BITS_2
static int uart_setup( lua_State* L )
{
  uint16_t id, databits=DATA_WIDTH_8BIT, parity=NO_PARITY, stopbits=STOP_BITS_1;
  uint32_t baud=9600;
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( uart, id );
  baud = luaL_checkinteger( L, 2 );
  size_t sl=0;
  char const *str = luaL_checklstring( L, 3, &sl );
  if(sl == 1 && strcmp(str, "n") == 0)
    parity = NO_PARITY;
  else if(sl == 1 && strcmp(str, "o") == 0)
    parity = ODD_PARITY;
  else if(sl == 1 && strcmp(str, "e") == 0)
    parity = EVEN_PARITY;
  else
    return luaL_error( L, "arg parity should be 'n' or 'o' or 'e' " );
  
  str = luaL_checklstring( L, 4, &sl );
  if(sl == 1 && strcmp(str, "5") == 0)
    databits = DATA_WIDTH_5BIT;
  else if(sl == 1 && strcmp(str, "6") == 0)
    databits = DATA_WIDTH_6BIT;
  else if(sl == 1 && strcmp(str, "7") == 0)
    databits = DATA_WIDTH_7BIT;
  else if(sl == 1 && strcmp(str, "8") == 0)
    databits = DATA_WIDTH_8BIT;
  else if(sl == 1 && strcmp(str, "9") == 0)
    databits = DATA_WIDTH_9BIT;
  else
    return luaL_error( L, "arg databits should be '5'~'9' " );
  
  str = luaL_checklstring( L, 5, &sl );
  if(sl == 1 && strcmp(str, "1") == 0)
    stopbits = STOP_BITS_1;
  else if(sl == 1 && strcmp(str, "2") == 0)
    stopbits = STOP_BITS_2;
  else
    return luaL_error( L, "arg stopbits should be '1' or '2' " );

  lua_usr_uart_config.baud_rate = baud;
  lua_usr_uart_config.parity=(platform_uart_parity_t)parity;
  lua_usr_uart_config.data_width =(platform_uart_data_width_t)databits;
  lua_usr_uart_config.stop_bits =(platform_uart_stop_bits_t)stopbits;
  
  if(lua_usr_rx_data !=NULL) free(lua_usr_rx_data);
  lua_usr_rx_data = (uint8_t*)malloc(USR_INBUF_SIZE);
  if(pinbuf !=NULL) free(pinbuf);
  pinbuf = (uint8_t*)malloc(USR_UART_LENGTH);
  ring_buffer_init( (ring_buffer_t*)&lua_usr_rx_buffer, (uint8_t*)lua_usr_rx_data, USR_INBUF_SIZE );
  
  //MicoUartFinalize(LUA_USR_UART);
  MicoUartInitialize( LUA_USR_UART, &lua_usr_uart_config, (ring_buffer_t*)&lua_usr_rx_buffer );
  gL = L;
  usr_uart_cb_ref = LUA_NOREF;
  if(plua_usr_usart_thread !=NULL) mico_rtos_delete_thread(plua_usr_usart_thread);  
  mico_rtos_create_thread(plua_usr_usart_thread, MICO_DEFAULT_WORKER_PRIORITY, "lua_usr_usart_thread", lua_usr_usart_thread, 0x300, 0);
  return 0;
}
Exemple #19
0
OSStatus MicoStartFogCloudService(mico_Context_t* const inContext)
{
  OSStatus err = kUnknownErr;
  
  //init MicoFogCloud status
  inContext->appStatus.fogcloudStatus.isCloudConnected = false;
  inContext->appStatus.fogcloudStatus.RecvRomFileSize = 0;
  inContext->appStatus.fogcloudStatus.isActivated = inContext->flashContentInRam.appConfig.fogcloudConfig.isActivated;
  inContext->appStatus.fogcloudStatus.isOTAInProgress = false;
  
  //init fogcloud service interface
  err = fogCloudInit(inContext);
  require_noerr_action(err, exit, 
                       fogcloud_log("ERROR: FogCloud interface init failed!") );
  
  err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)fogNotify_WifiStatusHandler );
  require_noerr_action(err, exit, 
                       fogcloud_log("ERROR: MICOAddNotification (mico_notify_WIFI_STATUS_CHANGED) failed!") );
  
  // start MicoFogCloud main thread (dev reset && ota check, then start fogcloud service)
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "fog_main", 
                                fogcloud_main_thread, STACK_SIZE_FOGCLOUD_MAIN_THREAD, 
                                inContext );
  
exit:
  return err;
}
Exemple #20
0
OSStatus sntp_client_start( int tz, char *ntpserv )
{
  ntp_time_zone = tz;
  NTP_Server = ntpserv;
  
  mico_rtos_init_semaphore(&_wifiConnected_sem, 1);
  return mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "NTP Client", NTPClient_thread, STACK_SIZE_NTP_CLIENT_THREAD, NULL );
}
void ConfigSoftApWillStart(mico_Context_t * const inContext )
{
  OSStatus err;
  sppProtocolInit(inContext);
  PlatformUartInitialize(inContext);

  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, 0x500, (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, 0x200, (void*)inContext );
   require_noerr_action( err, exit, config_delegate_log("ERROR: Unable to start the local server thread.") );
 }

exit:
  return;
}
Exemple #22
0
void homeKitListener_thread(void *inContext)
{
  ha_log_trace();
  OSStatus err = kUnknownErr;
  int j;
  Context = inContext;
  struct sockaddr_t addr;
  int sockaddr_t_size;
  fd_set readfds;
  char ip_address[16];
  
  int homeKitlistener_fd = -1;
  //HKSetPassword (password, strlen(password));
  HKSetVerifier(verifier, sizeof(verifier), salt, sizeof(salt));

  Context->appStatus.haPairSetupRunning = false;
  HKCharacteristicInit(inContext);
  /*Establish a TCP server fd that accept the tcp clients connections*/ 
  homeKitlistener_fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
  require_action(IsValidSocket( homeKitlistener_fd ), exit, err = kNoResourcesErr );
  addr.s_ip = INADDR_ANY;
  addr.s_port = HA_SERVER_PORT;
  err = bind(homeKitlistener_fd, &addr, sizeof(addr));
  require_noerr( err, exit );

  err = listen(homeKitlistener_fd, 0);
  require_noerr( err, exit );

  ha_log("HomeKit Server established at port: %d, fd: %d", HA_SERVER_PORT, homeKitlistener_fd);
  
  while(1){
    FD_ZERO(&readfds);
    FD_SET(homeKitlistener_fd, &readfds);
    select(1, &readfds, NULL, NULL, NULL);

    /*Check tcp connection requests */
    if(FD_ISSET(homeKitlistener_fd, &readfds)){
      sockaddr_t_size = sizeof(struct sockaddr_t);
      j = accept(homeKitlistener_fd, &addr, &sockaddr_t_size);
      if (j > 0) {
        inet_ntoa(ip_address, addr.s_ip );
        ha_log("HomeKit Client %s:%d connected, fd: %d", ip_address, addr.s_port, j);
        ha_log("memory>>>>>>>>: %d", mico_memory_info()->free_memory);
        err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "HomeKit Client", homeKitClient_thread, 0x1000, &j);  
        if(err != kNoErr){
          ha_log("HomeKit Client for fd %d create failed", j);
          SocketClose(&j);
        }
      }
    }
   }

exit:
    ha_log("Exit: HomeKit Server exit with err = %d", err);
    mico_rtos_delete_thread(NULL);
    return;
}
bool ControllerBusInit(void)
{
    OSStatus err;

    // f411 reset pin initialize
    MicoGpioInitialize(F411_RESET_PIN, OUTPUT_OPEN_DRAIN_PULL_UP);

    // V2 PCB, spi pin reused for uart, can be remove at V3 PCB
    PinInitForUsart();

    err = user_uartInit();
    if(err != kNoErr) {
        AaSysLogPrint(LOGLEVEL_ERR, "mico uart initialize failed");
        return false;
    }
    
    // start the uart receive thread to handle controller bus data
    err = mico_rtos_create_thread(&bus_recv_handle, MICO_APPLICATION_PRIORITY, "CBusProtoHandler", 
                                ControllerBusProtocolHandler, CONTROLLERBUS_STACK_SIZE_RINGBUFFER_THREAD, 
                                NULL);
    if(err != kNoErr) {
        AaSysLogPrint(LOGLEVEL_ERR, "create controller bus protocol handler thread failed");
        return false;
    }
    else {
        AaSysLogPrint(LOGLEVEL_INF, "create controller bus protocol handler thread success");
    }

    // start the uart send thread to handle request message
    err = mico_rtos_create_thread(&bus_send_handle, MICO_APPLICATION_PRIORITY, "BusRequestSend", 
                                ControllerBusMsgHandler, CONTROLLERBUS_STACK_SIZE_RINGBUFFER_THREAD, 
                                NULL);
    if(err != kNoErr) {
        AaSysLogPrint(LOGLEVEL_ERR, "create controller bus message handler thread failed");
        return false;
    }
    else {
        AaSysLogPrint(LOGLEVEL_INF, "create controller bus message handler thread success");
    }

    AaSysLogPrint(LOGLEVEL_INF, "controller bus initialize success");

    return true;
}
Exemple #24
0
void localTcpServer_thread(void *inContext)
{
  server_log_trace();
  OSStatus err = kUnknownErr;
  int i, j;
  Context = inContext;
  struct sockaddr_t addr;
  int sockaddr_t_size;
  fd_set readfds;
  char ip_address[16];
  
  int localTcpListener_fd = -1;

  for(i=0; i < MAX_Local_Client_Num; i++) 
    Context->appStatus.loopBack_PortList[i] = 0;

  /*Establish a TCP server fd that accept the tcp clients connections*/ 
  localTcpListener_fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
  require_action(IsValidSocket( localTcpListener_fd ), exit, err = kNoResourcesErr );
  addr.s_ip = INADDR_ANY;
  addr.s_port = Context->flashContentInRam.appConfig.localServerPort;
  err = bind(localTcpListener_fd, &addr, sizeof(addr));
  require_noerr( err, exit );

  err = listen(localTcpListener_fd, 0);
  require_noerr( err, exit );

  server_log("Server established at port: %d, fd: %d", Context->flashContentInRam.appConfig.localServerPort, localTcpListener_fd);

  FD_ZERO(&readfds);
  FD_SET(localTcpListener_fd, &readfds);  
  
  while(1){
    
    select(1, &readfds, NULL, NULL, NULL);

    /*Check tcp connection requests */
    if(FD_ISSET(localTcpListener_fd, &readfds)){
      sockaddr_t_size = sizeof(struct sockaddr_t);
      j = accept(localTcpListener_fd, &addr, &sockaddr_t_size);
      if (j > 0) {
        inet_ntoa(ip_address, addr.s_ip );
        server_log("Client %s:%d connected, fd: %d", ip_address, addr.s_port, j);

        if(kNoErr != mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Clients", localTcpClient_thread, 0x500, &j) ) 
          SocketClose(&j);
      }
    }
   }

exit:
    server_log("Exit: Local controller exit with err = %d", err);
    mico_rtos_delete_thread(NULL);
    return;
}
Exemple #25
0
OSStatus internal_uart_init( mico_uart_t uart, const mico_uart_config_t* config, ring_buffer_t* optional_rx_buffer )
{
#ifndef NO_MICO_RTOS
  mico_rtos_init_semaphore(&uart_interfaces[uart].tx_complete, 1);
  mico_rtos_init_semaphore(&uart_interfaces[uart].rx_complete, 1);
#else
  uart_interfaces[uart].tx_complete = false;
  uart_interfaces[uart].rx_complete = false;
#endif  
  MicoMcuPowerSaveConfig(false);  
    /* Configure the UART TX/RX pins */
    configure_uart_pins(BOARD_APP_UART_INSTANCE);
#if ADD_OS_CODE
#ifndef NO_MICO_RTOS
  if(config->flags & UART_WAKEUP_ENABLE){
    current_uart = uart;
    mico_rtos_init_semaphore( &uart_interfaces[uart].sem_wakeup, 1 );
    mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART_WAKEUP", thread_wakeup, 0x100, &current_uart);
  }
#endif 
#endif 
	//OSA_Init();
#ifdef UART_IRQ_APP    
    /****************************************************************/
    uartConfig.baudRate = 115200;
    uartConfig.bitCountPerChar = kUart8BitsPerChar;
    uartConfig.parityMode = kUartParityDisabled;
    uartConfig.stopBitCount = kUartOneStopBit;
    /***************************************************************/
    UART_DRV_Init(BOARD_APP_UART_INSTANCE, &uartState, &uartConfig);
#else
    userConfig_app.chnArbitration = kEDMAChnArbitrationRoundrobin;
    userConfig_app.notHaltOnError = false;

    uartConfig_app.bitCountPerChar = kUart8BitsPerChar;
    uartConfig_app.parityMode = kUartParityDisabled;
    uartConfig_app.stopBitCount = kUartOneStopBit;
    uartConfig_app.baudRate = 115200;

    EDMA_DRV_Init(&state_app, &userConfig_app);    
    UART_DRV_EdmaInit(BOARD_APP_UART_INSTANCE, &uartStateEdma_app, &uartConfig_app); 
    INT_SYS_EnableIRQ(g_uartRxTxIrqId[BOARD_APP_UART_INSTANCE]);
#endif
#if RING_BUFF_ON 
  if (optional_rx_buffer != NULL)
  {
     //  Note that the ring_buffer should've been initialised first
    uart_interfaces[uart].rx_buffer = optional_rx_buffer;
    uart_interfaces[uart].rx_size   = 0;
    platform_uart_receive_bytes( uart, optional_rx_buffer->buffer, optional_rx_buffer->size, 0 );
  }  
#endif
  MicoMcuPowerSaveConfig(true);  
  return kNoErr;
}
Exemple #26
0
OSStatus MICOStartApplication( mico_Context_t * const inContext )
{
  app_log_trace();

  OSStatus err = kNoErr;
  mico_uart_config_t uart_config;
  require_action(inContext, exit, err = kParamErr);

  haProtocolInit(inContext);

  /*Bonjour for service searching*/
  if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true)
    MICOStartBonjourService( Station, 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;
  if(inContext->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true)
    uart_config.flags = UART_WAKEUP_ENABLE;
  else
    uart_config.flags = UART_WAKEUP_DISABLE;
  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, 0x200, (void*)inContext );
  require_noerr_action( err, exit, app_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, 0x350, (void*)inContext );
   require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") );
 }

 if(inContext->flashContentInRam.appConfig.remoteServerEnable == true){
   err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, 0x300, (void*)inContext );
   require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") );
 }

exit:
  return err;
}
Exemple #27
0
OSStatus MICOStartSystemMonitor (mico_Context_t * const inContext)
{
  OSStatus err = kNoErr;
  require_noerr(MicoWdgInitialize(  DEFAULT_SYSTEM_MONITOR_PERIOD + 500 ), exit);
  memset(system_monitors, 0, sizeof(system_monitors));

  err = mico_rtos_create_thread(NULL, 0, "SYS MONITOR", mico_system_monitor_thread_main, STACK_SIZE_MICO_SYSTEM_MONITOR_THREAD, (void*)inContext );
  require_noerr(err, exit);
exit:
  return err;
}
Exemple #28
0
OSStatus MICOStartApplication( mico_Context_t * const inContext )
{
    app_log_trace();
    OSStatus err = kNoErr;
    
    require_action(inContext, exit, err = kParamErr);
    
    MX_Init();
    AC_Init();
    
    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_REMOTE_TCP_CLIENT_THREAD, (void*)inContext );
    require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") );
    
    
    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "HF_Cloudfunc", MX_Cloudfunc, STACK_SIZE_REMOTE_TCP_CLIENT_THREAD, (void*)inContext );
    require_noerr_action( err, exit, app_log("ERROR: Unable to start the MX_Cloudfunc thread.") );

    exit:
    return err;
}
Exemple #29
0
/*************************************************
* Function: MICOBlinkRfLed
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
OSStatus MICOBlinkRfLed(mico_Context_t * const inContext)
{

  OSStatus err = kUnknownErr;
  mico_rtos_init_semaphore(&query_sem, 1);
    

  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "query", MICORfLed_thread, 0x500, (void*)inContext );

  return err;
}
Exemple #30
0
OSStatus start_fog_msg_handler(mico_Context_t *mico_context)
{
  user_log_trace();
  OSStatus err = kNoErr;
  require_action(mico_context, exit, err = kParamErr);
  
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "user_msg_handler", 
                                user_cloud_msg_handle_thread, STACK_SIZE_USER_MSG_HANDLER_THREAD, 
                                mico_context );
exit:
  return err;
}