コード例 #1
0
ファイル: esp_main.c プロジェクト: cesanta/mongoose-iot
enum mgos_init_result esp_mgos_init2(void) {
#ifdef CS_MMAP
  mgos_vfs_mmap_init();
#endif
  enum mgos_init_result ir = mgos_debug_uart_init();
  if (ir != MGOS_INIT_OK) return ir;
  uart_initialized = true;
  cs_log_set_level(MGOS_EARLY_DEBUG_LEVEL);
  setvbuf(stdout, NULL, _IOLBF, 256);
  setvbuf(stderr, NULL, _IOLBF, 256);
  /* Note: putc can be invoked from int handlers. */
  os_install_putc1(sdk_putc);
  fputc('\n', stderr);

  if (strcmp(MGOS_APP, "mongoose-os") != 0) {
    LOG(LL_INFO, ("%s %s (%s)", MGOS_APP, build_version, build_id));
  }
  LOG(LL_INFO, ("Mongoose OS %s (%s)", mg_build_version, mg_build_id));
  LOG(LL_INFO, ("CPU: %s, %d MHz, RAM: %u total, %u free",
                esp_chip_type_str(esp_get_chip_type()),
                (int) (mgos_get_cpu_freq() / 1000000), mgos_get_heap_size(),
                mgos_get_free_heap_size()));
  LOG(LL_INFO, ("SDK %s; flash: %uM", system_get_sdk_version(),
                esp_vfs_dev_sysflash_get_size(NULL) / 1048576));
  esp_print_reset_info();

  system_soft_wdt_stop();
  ir = mgos_init();
  if (ir != MGOS_INIT_OK) {
    LOG(LL_ERROR, ("%s init error: %d", "MG", ir));
    return ir;
  }

  return MGOS_INIT_OK;
}
コード例 #2
0
ファイル: esp_config.c プロジェクト: ifzz/smart.js
int device_init_platform(struct sys_config *cfg) {
  /* Initialize debug first */
  uart_debug_init(0, 0);
  uart_redirect_debug(cfg->debug.mode);
  cs_log_set_level(cfg->debug.level);

  return do_wifi(cfg);
}
コード例 #3
0
ファイル: user_main.c プロジェクト: kirikiwi/smart.js
/*
 * SmartJS initialization; for non-RTOS env, called as an SDK timer callback
 * (`os_timer_...()`). For RTOS env, called by the dispatcher task.
 */
void sjs_init(void *dummy) {
  /*
   * In order to see debug output (at least errors) during boot we have to
   * initialize debug in this point. But default we put debug to UART0 with
   * level=LL_ERROR, then configuration is loaded this settings are overridden
   */
  uart_debug_init(0, 0);
  uart_redirect_debug(1);
  cs_log_set_level(LL_ERROR);

#ifndef V7_NO_FS
#ifndef DISABLE_OTA
  fs_init(get_fs_addr(get_current_rom()), get_fs_size(get_current_rom()));
  finish_update();
#else
  fs_init(FS_ADDR, FS_SIZE);
#endif
#endif

  init_v7(&dummy);

  /* disable GC during further initialization */
  v7_set_gc_enabled(v7, 0);

#if !defined(NO_PROMPT)
  uart_main_init(0);
#endif

#ifndef V7_NO_FS
  init_smartjs();
#endif

#if !defined(NO_PROMPT)
  sj_prompt_init(v7);
#endif

#ifdef ESP_UMM_ENABLE
  /*
   * We want to use our own heap functions instead of the ones provided by the
   * SDK.
   *
   * We have marked `pvPortMalloc` and friends weak, so that we can override
   * them with our own implementations, but to actually make it work, we have
   * to reference any function from the file with our implementation, so that
   * linker will not garbage-collect the whole compilation unit.
   *
   * So, we have a call to the no-op `esp_umm_init()` here.
   */
  esp_umm_init();
#endif

  /* SJS initialized, enable GC back, and trigger it */
  v7_set_gc_enabled(v7, 1);
  v7_gc(v7, 1);
}
コード例 #4
0
ファイル: main.c プロジェクト: cobookman/mongoose
int main() {
#ifndef USE_TIRTOS
  MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]);
#endif
  MAP_IntEnable(FAULT_SYSTICK);
  MAP_IntMasterEnable();
  PRCMCC3200MCUInit();

  /* Console UART init. */
  MAP_PRCMPeripheralClkEnable(CONSOLE_UART_PERIPH, PRCM_RUN_MODE_CLK);
  MAP_PinTypeUART(PIN_55, PIN_MODE_3); /* PIN_55 -> UART0_TX */
  MAP_PinTypeUART(PIN_57, PIN_MODE_3); /* PIN_57 -> UART0_RX */
  MAP_UARTConfigSetExpClk(
      CONSOLE_UART, MAP_PRCMPeripheralClockGet(CONSOLE_UART_PERIPH),
      CONSOLE_BAUD_RATE,
      (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
  MAP_UARTFIFOLevelSet(CONSOLE_UART, UART_FIFO_TX1_8, UART_FIFO_RX4_8);
  MAP_UARTFIFOEnable(CONSOLE_UART);

  setvbuf(stdout, NULL, _IOLBF, 0);
  setvbuf(stderr, NULL, _IOLBF, 0);
  cs_log_set_level(LL_INFO);
  cs_log_set_file(stdout);

  LOG(LL_INFO, ("Hello, world!"));

  MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* SDA */
  MAP_PinTypeI2C(PIN_02, PIN_MODE_1); /* SCL */
  I2C_IF_Open(I2C_MASTER_MODE_FST);

  /* Set up the red LED. Note that amber and green cannot be used as they share
   * pins with I2C. */
  MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK);
  MAP_PinTypeGPIO(PIN_64, PIN_MODE_0, false);
  MAP_GPIODirModeSet(GPIOA1_BASE, 0x2, GPIO_DIR_MODE_OUT);
  GPIO_IF_LedConfigure(LED1);
  GPIO_IF_LedOn(MCU_RED_LED_GPIO);

  if (VStartSimpleLinkSpawnTask(8) != 0) {
    LOG(LL_ERROR, ("Failed to create SL task"));
  }

  if (!mg_start_task(MG_TASK_PRIORITY, MG_TASK_STACK_SIZE, mg_init)) {
    LOG(LL_ERROR, ("Failed to create MG task"));
  }

  osi_start();

  return 0;
}
コード例 #5
0
int main(void) {
  Board_initGeneral();
  Board_initGPIO();
  Board_initWiFi();

  setvbuf(stdout, NULL, _IOLBF, 0);
  setvbuf(stderr, NULL, _IOLBF, 0);
  cs_log_set_level(LL_INFO);
  cs_log_set_file(stdout);

  if (!mg_start_task(MIOT_TASK_PRIORITY, MG_TASK_STACK_SIZE, mg_init)) {
    LOG(LL_ERROR, ("Error starting Mongoose task"));
    return 1;
  }

  osi_start();

  return 0;
}
コード例 #6
0
ファイル: sj_v7_ext.c プロジェクト: GDI123/smart.js
static enum v7_err Sys_setLogLevel(struct v7 *v7, v7_val_t *res) {
  enum v7_err rcode = V7_OK;
  v7_val_t llv = v7_arg(v7, 0);
  int ll;
  if (!v7_is_number(llv)) {
    *res = v7_mk_boolean(0);
    goto clean;
  }
  ll = v7_to_number(llv);
  if (ll <= _LL_MIN || ll >= _LL_MAX) {
    *res = v7_mk_boolean(0);
    goto clean;
  }
  cs_log_set_level((enum cs_log_level) ll);
  *res = v7_mk_boolean(1);
  goto clean;

clean:
  return rcode;
}
コード例 #7
0
ファイル: user_main.c プロジェクト: TimBNelson/polly
static void mg_task(void *arg) {
  struct mg_mgr mgr;
  struct mg_connection *nc;

  cs_log_set_level(LL_INFO);

  LOG(LL_INFO, ("SDK version: %s", system_get_sdk_version()));
  setup_ap();

  mg_mgr_init(&mgr, NULL);

  nc = mg_bind(&mgr, MG_LISTEN_ADDR, ev_handler);
  if (nc == NULL) {
    LOG(LL_ERROR, ("Error setting up listener!"));
    return;
  }
  mg_set_protocol_http_websocket(nc);

  while (1) {
    mg_mgr_poll(&mgr, 1000);
  }
}
コード例 #8
0
ファイル: main.c プロジェクト: GDI123/smart.js
int device_init_platform(struct sys_config *cfg) {
  cs_log_set_level(cfg->debug.level);

  return 1;
}
コード例 #9
0
ファイル: main.c プロジェクト: ALLTERCO/mongoose-iot
enum mgos_init_result mgos_sys_config_init_platform(struct mgos_config *cfg) {
  cs_log_set_level(cfg->debug.level);
  return MGOS_INIT_OK;
}
コード例 #10
0
ファイル: user_main.c プロジェクト: a-kazantsev/smart.js
/*
 * SmartJS initialization, called as an SDK timer callback (`os_timer_...()`).
 */
void sjs_init(void *dummy) {
  /*
   * In order to see debug output (at least errors) during boot we have to
   * initialize debug in this point. But default we put debug to UART0 with
   * level=LL_ERROR, then configuration is loaded this settings are overridden
   */
  {
    struct esp_uart_config *u0cfg = esp_sj_uart_default_config(0);
#if ESP_DEBUG_UART == 0
    u0cfg->baud_rate = ESP_DEBUG_UART_BAUD_RATE;
#endif
    esp_uart_init(u0cfg);
    struct esp_uart_config *u1cfg = esp_sj_uart_default_config(1);
    /* UART1 has no RX pin, no point in allocating a buffer. */
    u1cfg->rx_buf_size = 0;
#if ESP_DEBUG_UART == 1
    u1cfg->baud_rate = ESP_DEBUG_UART_BAUD_RATE;
#endif
    esp_uart_init(u1cfg);
    fs_set_stdout_uart(0);
    fs_set_stderr_uart(ESP_DEBUG_UART);
    setvbuf(stdout, NULL, _IONBF, 0);
    setvbuf(stderr, NULL, _IONBF, 0);
    cs_log_set_level(LL_DEBUG);
    os_install_putc1(dbg_putc);
    system_set_os_print(1);
#ifdef ESP_ENABLE_HEAP_LOG
    uart_initialized = 1;
#endif
  }

  init_v7(&dummy);
  /* disable GC during further initialization */
  v7_set_gc_enabled(v7, 0);

  esp_sj_uart_init(v7);

#ifndef V7_NO_FS
#ifndef DISABLE_OTA
  fs_init(get_fs_addr(get_current_rom()), get_fs_size(get_current_rom()));
  finish_update();
#else
  fs_init(FS_ADDR, FS_SIZE);
#endif
#endif

  sj_common_api_setup(v7);
  sj_common_init(v7);

  sj_init_sys(v7);

  mongoose_init();

  /* NOTE(lsm): must be done after mongoose_init(). */
  if (!init_device(v7)) {
    LOG(LL_ERROR, ("init_device failed"));
    abort();
  }

  esp_print_reset_info();

#ifndef DISABLE_OTA
  init_updater(v7);
#endif
  LOG(LL_INFO, ("Sys init done, SDK %s", system_get_sdk_version()));

  if (!sj_app_init(v7)) {
    LOG(LL_ERROR, ("App init failed"));
    abort();
  }
  LOG(LL_INFO, ("App init done"));

  /* SJS initialized, enable GC back, and trigger it */
  v7_set_gc_enabled(v7, 1);
  v7_gc(v7, 1);

#ifndef V7_NO_FS
  run_init_script();
#endif

  /* Install prompt if enabled in the config and user's app has not installed
   * a custom RX handler. */
  if (get_cfg()->debug.enable_prompt &&
      v7_is_undefined(esp_sj_uart_get_recv_handler(0))) {
    sj_prompt_init(v7);
    esp_sj_uart_set_prompt(0);
  }

#ifdef ESP_UMM_ENABLE
  /*
   * We want to use our own heap functions instead of the ones provided by the
   * SDK.
   *
   * We have marked `pvPortMalloc` and friends weak, so that we can override
   * them with our own implementations, but to actually make it work, we have
   * to reference any function from the file with our implementation, so that
   * linker will not garbage-collect the whole compilation unit.
   *
   * So, we have a call to the no-op `esp_umm_init()` here.
   */
  esp_umm_init();
#endif
}