Пример #1
0
void init_v7() {
  struct v7_create_opts opts = {0, 0, 0};

  v7 = v7_create_opt(opts);

  sj_init_v7_ext(v7);
  init_conf(v7);
}
Пример #2
0
void init_v7(void *stack_base) {
  struct v7_create_opts opts;
  v7_val_t dht11, debug;

  opts.object_arena_size = 164;
  opts.function_arena_size = 26;
  opts.property_arena_size = 400;
  opts.c_stack_base = stack_base;
  v7 = v7_create_opt(opts);

  v7_set_method(v7, v7_get_global(v7), "dsleep", dsleep);
  v7_set_method(v7, v7_get_global(v7), "crash", crash);

#if V7_ESP_ENABLE__DHT11
  dht11 = v7_create_object(v7);
  v7_set(v7, v7_get_global(v7), "DHT11", 5, 0, dht11);
  v7_set_method(v7, dht11, "read", DHT11_read);
#else
  (void) dht11;
#endif /* V7_ESP_ENABLE__DHT11 */

  debug = v7_create_object(v7);
  v7_set(v7, v7_get_global(v7), "Debug", 5, 0, debug);
  v7_set_method(v7, debug, "mode", Debug_mode);
  v7_set_method(v7, debug, "print", Debug_print);

  sj_init_timers(v7);
  sj_init_v7_ext(v7);

  init_gpiojs(v7);
  init_adcjs(v7);
  init_i2cjs(v7);
  init_pwm(v7);
  init_spijs(v7);
  init_wifi(v7);

  mongoose_init();
  sj_init_http(v7);
  sj_init_ws_client(v7);

  /* NOTE(lsm): must be done after mongoose_init(). */
  init_device(v7);

#ifndef DISABLE_OTA
  init_updater(v7);
#endif

#ifndef DISABLE_C_CLUBBY
  sj_init_clubby(v7);
#endif

  v7_gc(v7, 1);
}
Пример #3
0
void init_v7(void *stack_base) {
  struct v7_create_opts opts;
  v7_val_t dht11, debug;

  opts.object_arena_size = 164;
  opts.function_arena_size = 26;
  opts.property_arena_size = 400;
  opts.c_stack_base = stack_base;
  v7 = v7_create_opt(opts);

  v7_set_method(v7, v7_get_global_object(v7), "dsleep", dsleep);
  v7_set_method(v7, v7_get_global_object(v7), "crash", crash);

#if V7_ESP_ENABLE__DHT11
  dht11 = v7_create_object(v7);
  v7_set(v7, v7_get_global_object(v7), "DHT11", 5, 0, dht11);
  v7_set_method(v7, dht11, "read", DHT11_read);
#else
  (void) dht11;
#endif /* V7_ESP_ENABLE__DHT11 */

  debug = v7_create_object(v7);
  v7_set(v7, v7_get_global_object(v7), "Debug", 5, 0, debug);
  v7_set_method(v7, debug, "mode", Debug_mode);
  v7_set_method(v7, debug, "print", Debug_print);

  sj_init_timers(v7);
  sj_init_v7_ext(v7);

  init_gpiojs(v7);
  init_i2cjs(v7);
  init_spijs(v7);
  init_wifi(v7);

#ifndef RTOS_TODO
  init_data_gen_server(v7);
#endif

  esp_init_conf(v7);

#ifdef RTOS_SDK
  mongoose_init();
#endif

  sj_init_simple_http_client(v7);

#ifdef RTOS_SDK
  sj_init_ws_client(v7);
#endif

  v7_gc(v7, 1);
}
Пример #4
0
static void pre_init(struct v7 *v7) {
  static const char *init_files[] = {"smart.js", "user.js"};
  const char *dir = s_argv0 + strlen(s_argv0) - 1;
  char path[512];
  size_t i;
  v7_val_t res;

  /*
   * Point `dir` to the right-most directory separator of the smartjs binary.
   * Thus string between `s_argv0` and `dir` pointers would contain a directory
   * name where our executable lives.
   */
  while (dir > s_argv0 && *dir != '/' && *dir != '\\') {
    dir--;
  }

  snprintf(path, sizeof(path), "%.*s/%s", (int) (dir - s_argv0), s_argv0,
           JS_FS_ROOT);
  /* All the files, conf, JS, etc are addressed relative to the current dir */
  if (chdir(path) != 0) {
    fprintf(stderr, "cannot chdir to %s\n", path);
  }

  sj_init_v7_ext(v7);
  init_smartjs(v7);

  /*
   * Run startup scripts from the directory JS_DIR_NAME.
   * That directory should be located where the binary (s_argv0) lives.
   */
  for (i = 0; i < sizeof(init_files) / sizeof(init_files[0]); i++) {
    if (v7_exec_file(v7, &res, init_files[i]) != V7_OK) {
      fprintf(stderr, "Failed to run %s: ", init_files[i]);
      v7_fprintln(stderr, v7, res);
    }
  }
}
Пример #5
0
static void uart_int() {
    int c = UARTCharGet(CONSOLE_UART);
    struct prompt_event pe = {.type = PROMPT_CHAR_EVENT, .data = (void *) c};
    osi_MsgQWrite(&s_v7_q, &pe, OSI_NO_WAIT);
    MAP_UARTIntClear(CONSOLE_UART, UART_INT_RX);
}

void sj_prompt_init_hal(struct v7 *v7) {
    (void) v7;
}

static void v7_task(void *arg) {
    struct v7 *v7 = s_v7;
    printf("\n\nSmart.JS for CC3200\n");

    osi_MsgQCreate(&s_v7_q, "V7", sizeof(struct prompt_event), 32 /* len */);
    osi_InterruptRegister(CONSOLE_UART_INT, uart_int, INT_PRIORITY_LVL_1);
    MAP_UARTIntEnable(CONSOLE_UART, UART_INT_RX);
    sl_Start(NULL, NULL, NULL);

    v7 = s_v7 = init_v7(&v7);
    sj_init_timers(v7);
    sj_init_v7_ext(v7);
    init_wifi(v7);
    if (init_fs(v7) != 0) {
        fprintf(stderr, "FS initialization failed.\n");
    }
    mongoose_init();
    sj_init_http(v7);
    init_i2cjs(v7);

    /* Common config infrastructure. Mongoose & v7 must be initialized. */
    init_device(v7);

    v7_val_t res;
    if (v7_exec_file(v7, "sys_init.js", &res) != V7_OK) {
        fprintf(stderr, "Error: ");
        v7_fprint(stderr, v7, res);
    }
    sj_prompt_init(v7);

    while (1) {
        struct prompt_event pe;
        mongoose_poll(MONGOOSE_POLL_LENGTH_MS);
        if (osi_MsgQRead(&s_v7_q, &pe, V7_POLL_LENGTH_MS) != OSI_OK) continue;
        switch (pe.type) {
        case PROMPT_CHAR_EVENT: {
            sj_prompt_process_char((char) ((int) pe.data));
            break;
        }
        case V7_INVOKE_EVENT: {
            struct v7_invoke_event_data *ied =
                (struct v7_invoke_event_data *) pe.data;
            _sj_invoke_cb(v7, ied->func, ied->this_obj, ied->args);
            v7_disown(v7, &ied->args);
            v7_disown(v7, &ied->this_obj);
            v7_disown(v7, &ied->func);
            free(ied);
            break;
        }
        }
    }
}

/* Int vector table, defined in startup_gcc.c */
extern void (*const g_pfnVectors[])(void);

void device_reboot(void) {
    sj_system_restart();
}

int main() {
    MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]);
    MAP_IntEnable(FAULT_SYSTICK);
    MAP_IntMasterEnable();
    PRCMCC3200MCUInit();

    cc3200_leds_init();

    /* 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_UARTFIFODisable(CONSOLE_UART);

    setvbuf(stdout, NULL, _IONBF, 0);
    setvbuf(stderr, NULL, _IONBF, 0);

    VStartSimpleLinkSpawnTask(8);
    osi_TaskCreate(v7_task, (const signed char *) "v7", V7_STACK_SIZE + 256, NULL,
                   3, NULL);
    osi_TaskCreate(blinkenlights_task, (const signed char *) "blink", 256, NULL,
                   9, NULL);
    osi_start();

    return 0;
}