Example #1
0
void main_task(void *arg) {
  struct miot_event e;
  osi_MsgQCreate(&s_main_queue, "main", sizeof(e), 32 /* len */);

  enum cc3200_init_result r = cc3200_init(NULL);
  bool success = (r == CC3200_INIT_OK);
  if (!success) LOG(LL_ERROR, ("Init failed: %d", r));

#if MIOT_ENABLE_UPDATER
  miot_upd_boot_finish((r == CC3200_INIT_OK),
                       (g_boot_cfg.flags & BOOT_F_FIRST_BOOT));
#endif

  if (!success) {
    /* Arbitrary delay to make potential reboot loop less tight. */
    miot_usleep(500000);
    miot_system_restart(0);
  }

  while (1) {
    mongoose_poll(0);
    if (osi_MsgQRead(&s_main_queue, &e, V7_POLL_LENGTH_MS) == OSI_OK) {
      e.cb(e.arg);
    }
  }
}
Example #2
0
void main_task(void *arg) {
  (void) arg;
  osi_MsgQCreate(&s_main_queue, "main", sizeof(struct sj_event), 32 /* len */);

  if (!sj_init()) {
    LOG(LL_ERROR, ("Init failed"));
    sj_system_restart(0);
    return;
  }

  while (1) {
    struct sj_event e;
    mongoose_poll(0);
    if (osi_MsgQRead(&s_main_queue, &e, V7_POLL_LENGTH_MS) != OSI_OK) continue;
    switch (e.type) {
#ifndef CS_DISABLE_JS
      case PROMPT_CHAR_EVENT: {
        long c;
        while ((c = UARTCharGetNonBlocking(CONSOLE_UART)) >= 0) {
          sj_prompt_process_char(c);
        }
        MAP_UARTIntEnable(CONSOLE_UART, UART_INT_RX | UART_INT_RT);
        break;
      }
#endif
      case INVOKE_CB_EVENT: {
        cb_t cb = (cb_t)(e.cb | CB_ADDR_PREFIX);
        cb(e.data);
        break;
      }
    }
  }
}
Example #3
0
static IRAM void mgos_mg_poll_cb(void *arg) {
  mgos_ints_disable();
  s_mg_polls_in_flight--;
  mgos_ints_enable();
  int timeout_ms = 0;
  if (mongoose_poll(0) == 0) {
    /* Nothing is happening now, see when next timer is due. */
    double min_timer = mg_mgr_min_timer(mgos_get_mgr());
    if (min_timer > 0) {
      /* Note: timeout_ms can get negative if a timer is past due. That's ok. */
      timeout_ms = (int) ((min_timer - mg_time()) * 1000.0);
      if (timeout_ms < 0) {
        timeout_ms = 0; /* Now */
      } else if (timeout_ms > MGOS_MONGOOSE_MAX_POLL_SLEEP_MS) {
        timeout_ms = MGOS_MONGOOSE_MAX_POLL_SLEEP_MS;
      }
    } else {
      timeout_ms = MGOS_MONGOOSE_MAX_POLL_SLEEP_MS;
    }
  } else {
    /* Things are happening, we need another poll ASAP. */
  }
  if (timeout_ms == 0) {
    mongoose_schedule_poll(false /* from_isr */);
  } else {
    os_timer_disarm(&s_mg_poll_tmr);
    /* We set repeat = true in case things get stuck for any reason. */
    os_timer_arm(&s_mg_poll_tmr, timeout_ms, 1 /* repeat */);
  }
  (void) arg;
}
Example #4
0
int main(int argc, char *argv[]) {
  (void) argc;
  (void) argv;
  mongoose_init();
  for (;;) {
    mongoose_poll(1000);
  }
  mongoose_destroy();
  return EXIT_SUCCESS;
}
Example #5
0
static void post_init(struct v7 *v7) {
  sj_prompt_init(v7);
  do {
    /*
     * Now waiting until mongoose has active connections
     * and there are active gpio ISR and then exiting
     * TODO(alashkin): change this to something smart
     */
  } while ((mongoose_poll(100) || gpio_poll()) && !sj_please_quit);
  mongoose_destroy();
}
Example #6
0
static void disp_task(void *params) {
  struct rtos_event ev;

  while (1) {
    if (xQueueReceive(main_queue_handle, (void *) &ev,
                      500 / portTICK_RATE_MS)) {
      switch (ev.event_id) {
        case RTE_INIT:
          sjs_init(0);
          break;
        case RTE_UART_NEWCHAR:
          process_rx_buf(ev.params.uart_rx_params.tail);
          break;
        case RTE_CALLBACK:
          _sj_invoke_cb(ev.params.callback_params->v7,
                        ev.params.callback_params->func,
                        ev.params.callback_params->this_obj,
                        ev.params.callback_params->args);
          v7_disown(ev.params.callback_params->v7,
                    &ev.params.callback_params->func);
          v7_disown(ev.params.callback_params->v7,
                    &ev.params.callback_params->this_obj);
          v7_disown(ev.params.callback_params->v7,
                    &ev.params.callback_params->args);
          free(ev.params.callback_params);
          break;
        case RTE_GPIO_INTR_CALLBACK:
          ev.params.gpio_intr_callback_params.cb(
              ev.params.gpio_intr_callback_params.p1,
              ev.params.gpio_intr_callback_params.p2);
          break;
        default:
          printf("Unknown event_id: %d\n", ev.event_id);
          break;
      }
    } else {
      /* Put periodic event handlers here */
      mongoose_poll(2);
    }
  }
}
Example #7
0
static void disp_task(void *params) {
  struct mg_connection *conn = NULL;
  struct conn_ctx ctx;
  printf("Starting network test...\n");
  memset(data, 'A', sizeof(data));
  memset(&ctx, 0, sizeof(ctx));
  wifi_connect();
  int i = 0;
  while (1) {
    mongoose_poll(2);
    if (!wifi_connected) continue;
    switch (ctx.state) {
      case DISCONNECTED:
        memset(&ctx, 0, sizeof(ctx));
        conn = mg_connect(&sj_mgr, ADDR_TO_CONNECT, conn_handler);
        if (conn == NULL) {
          vTaskDelay(100);
          printf("reconnecting\n");
          continue;
        }
        printf("conn = %p\n", conn);
        conn->user_data = &ctx;
        ctx.state = CONNECTING;
        break;
      case CONNECTING:
        break;
      case CONNECTED:
        i++;
        if (i % 10000 == 0) {
          printf("sent %u, recv %u heap free: %u uptime %d\n", ctx.num_sent,
                 ctx.num_received, system_get_free_heap_size(),
                 system_get_time() / 1000000);
        }
        break;
    }
  }
}
Example #8
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;
}
Example #9
0
/* Main application's state machine polled by SYS_Tasks */
void APP_Tasks(void) {
  pic32_ethernet_poll();
  mongoose_poll(0);
}
Example #10
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_timers_api_setup(v7);
  sj_v7_ext_api_setup(v7);
  sj_init_sys(v7);
  init_wifi(v7);
  if (init_fs(v7) != 0) {
    fprintf(stderr, "FS initialization failed.\n");
  }
  mongoose_init();
  sj_http_api_setup(v7);
  sj_i2c_api_setup(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(0);
}