Example #1
0
int main(void){
#ifdef STM32F103RB_MAPLE
  // get in quick and relocate vector table!
  SCB->VTOR = 0x08005000;
#else // quickly set up the vector table...
  SCB->VTOR = (unsigned int)&_VECTOR_TABLE;
#endif

  jshInit();
#ifdef USB
  MX_USB_DEVICE_Init();
#endif

  bool buttonState = false;
#ifdef BTN1_PININDEX
  buttonState = jshPinInput(BTN1_PININDEX) == BTN1_ONSTATE;
#endif
  jsvInit();
  jsiInit(!buttonState); // pressing USER button skips autoload

  while (1) {
    jsiLoop();
  }
  //jsiKill();
  //jsvKill();
  //jshKill();
}
Example #2
0
int main(void){
#ifdef STM32F103RB_MAPLE
  // get in quick and relocate vector table!
  SCB->VTOR = 0x08005000;
#else // quickly set up the vector table...
  SCB->VTOR = (unsigned int)&_VECTOR_TABLE;
#endif

  jshInit();
#ifdef USB
#if defined(STM32F1) || defined(STM32F3)
  USB_Init_Hardware();
  USB_Init();
#endif
#ifdef STM32F4
  USBD_Init(&USB_OTG_dev,
#ifdef USE_USB_OTG_HS
            USB_OTG_HS_CORE_ID,
#else
            USB_OTG_FS_CORE_ID,
#endif
            &USR_desc,
            &USBD_CDC_cb,
            &USR_cb);
#endif
#endif

  volatile int w,h;
//#ifndef ECU
#ifdef USB
  for (w=0;w<1000000;w++)
 #ifdef STM32F4 // IT's FAST!
    for (h=0;h<10;h++); // wait for things to settle (for USB)
 #else
    for (h=0;h<2;h++); // wait for things to settle (for USB)
 #endif
#else
  for (w=0;w<100000;w++)
    for (h=0;h<2;h++); // wait for things to settle (for Serial comms)
#endif
//#endif

  bool buttonState = false;
  buttonState = jshPinInput(BTN1_PININDEX) == BTN1_ONSTATE;
  jsvInit();
  jsiInit(!buttonState); // pressing USER button skips autoload

  while (1) {
    jsiLoop();

/*#ifdef LED1_PORT
    counter++;
    GPIO_WriteBit(LED1_PORT,LED1_PIN, (counter>>13) & 1);
#endif*/
  }
  //jsiKill();
  //jsvKill();
  //jshKill();
}
Example #3
0
int jsMain(){
	jshInit();
	jsvInit();
	jsiInit(false);
	while (1) {
		jsiLoop();
	}
}
Example #4
0
bool run_test(const char *filename) {
  printf("----------------------------------\r\n");
  printf("----------------------------- TEST %s \r\n", filename);
  char *buffer = read_file(filename);
  if (!buffer) exit(1);

  jshInit();
  jsvInit();
  jsiInit(false /* do not autoload!!! */);

  addNativeFunction("quit", nativeQuit);
  addNativeFunction("interrupt", nativeInterrupt);

  jsvUnLock(jspEvaluate(buffer, true));

  isRunning = true;
  bool isBusy = true;
  while (isRunning && (jsiHasTimers() || isBusy))
    isBusy = jsiLoop();

  JsVar *result = jsvObjectGetChild(execInfo.root, "result", 0/*no create*/);
  bool pass = jsvGetBool(result);
  jsvUnLock(result);

  if (pass)
    printf("----------------------------- PASS %s\r\n", filename);
  else {
    printf("----------------------------------\r\n");
    printf("----------------------------- FAIL %s <-------\r\n", filename);
    jsvTrace(execInfo.root, 0);
    printf("----------------------------- FAIL %s <-------\r\n", filename);
    printf("----------------------------------\r\n");
  }
  printf("BEFORE: %d Memory Records Used\r\n", jsvGetMemoryUsage());
 // jsvTrace(execInfo.root, 0);
  jsiKill();
  printf("AFTER: %d Memory Records Used\r\n", jsvGetMemoryUsage());
  jsvGarbageCollect();
  unsigned int unfreed = jsvGetMemoryUsage();
  printf("AFTER GC: %d Memory Records Used (should be 0!)\r\n", unfreed);
  jsvShowAllocated();
  jsvKill();
  jshKill();

  if (unfreed) {
    printf("FAIL because of unfreed memory.\r\n");
    pass = false;
  }

  //jsvDottyOutput();
  printf("\r\n");

  free(buffer);
  return pass;
}
Example #5
0
int main() {
  jshInit();
  jsvInit();
  jsiInit(false);
  debug_all_leds_on();

  while (1) 
  {
    jsiLoop();
  }
  //jsiKill();
  //jsvKill();
  //jshKill();
}
Example #6
0
int main() {

  jshInit();
  jsvInit();
  jsiInit(false);

  while (1) 
  {
    jsiLoop();
  }
  //jsiKill();
  //jsvKill();
  //jshKill();
}
Example #7
0
int main() {

  jshInit();

  bool buttonState = false;
#ifdef BTN1_PININDEX
  buttonState = jshPinGetValue(BTN1_PININDEX) == BTN1_ONSTATE;
#endif
  jsvInit(0);
  jsiInit(!buttonState /* load from flash by default */); // pressing USER button skips autoload

  while (1) 
  {
    jsiLoop();
  }
  //jsiKill();
  //jsvKill();
  //jshKill();
}
Example #8
0
/**
 * The ESP8266 provides a mechanism to register a callback that is invoked when initialization
 * of the ESP8266 is complete.  This is the implementation of that callback.  At this point
 * we can assume that the ESP8266 is fully ready to do work for us.
 */
static void initDone() {
	os_printf("initDone invoked\n");

	// Discard any junk data in the input as this is a boot.
	//uart_rx_discard();

	jshInit(); // Initialize the hardware
	jsvInit(); // Initialize the variables
	jsiInit(false); // Initialize the interactive subsystem

	// Register the event handlers.
	system_os_task(eventHandler, TASK_APP_QUEUE, taskAppQueue, TASK_QUEUE_LENGTH);

	// At this point, our JavaScript environment should be up and running.

	// Initialize the networking subsystem.
	jswrap_ESP8266WiFi_init();

	// Post the first event to get us going.
	queueTaskMainLoop();

	return;
}
Example #9
0
/**
 * The ESP8266 provides a mechanism to register a callback that is invoked when initialization
 * of the ESP8266 is complete.  This is the implementation of that callback.  At this point
 * we can assume that the ESP8266 is fully ready to do work for us.
 */
static void initDone() {
  os_printf("> initDone\n");
  otaInit(88);

  // Discard any junk data in the input as this is a boot.
  //uart_rx_discard();

  jshInit(); // Initialize the hardware
  jsvInit(); // Initialize the variables
  jsiInit(true); // Initialize the interactive subsystem
  jswrap_ESP8266WiFi_init(); // Initialize the networking subsystem

  // Register the event handlers.
  system_os_task(eventHandler, TASK_APP_QUEUE, taskAppQueue, TASK_QUEUE_LENGTH);

  // At this point, our JavaScript environment should be up and running.

  // Register the idle callback handler to run the main loop
  //ets_set_idle_cb(idle_cb, NULL); //
  queueTaskMainLoop(); // get things going without idle callback

  os_printf("< initDone\n");
  return;
}
Example #10
0
int main(int argc, char **argv) {
  int i;
  for (i=1;i<argc;i++) {
    if (argv[i][0]=='-') {
      // option
      char *a = argv[i];
      if (!strcmp(a,"-h") || !strcmp(a,"--help")) {
        show_help();
        exit(1);
      } else if (!strcmp(a,"-e") || !strcmp(a,"--eval")) {
        if (i+1>=argc) die("Expecting an extra argument\n");
        jshInit();
        jsvInit();
        jsiInit(true);
        addNativeFunction("quit", nativeQuit);
        jsvUnLock(jspEvaluate(argv[i+1], false));
        int errCode = handleErrors();
        isRunning = !errCode;
        bool isBusy = true;
        while (isRunning && (jsiHasTimers() || isBusy))
          isBusy = jsiLoop();
        jsiKill();
        jsvKill();
        jshKill();
        exit(errCode);
      } else if (!strcmp(a,"--test")) {
        if (i+1>=argc) die("Expecting an extra argument\n");
        bool ok = run_test(argv[i+1]);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-all")) {
        bool ok = run_all_tests();
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem-all")) {
        bool ok = run_memory_tests(0);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem")) {
        if (i+1>=argc) die("Expecting an extra argument\n");
        bool ok = run_memory_test(argv[i+1], 0);
        exit(ok ? 0 : 1);
      } else if (!strcmp(a,"--test-mem-n")) {
        if (i+2>=argc) die("Expecting an extra 2 arguments\n");
        bool ok = run_memory_test(argv[i+1], atoi(argv[i+2]));
        exit(ok ? 0 : 1);
      } else {
        printf("Unknown Argument %s\n", a);
        show_help();
        exit(1);
      }
    }
  }

  if (argc==1) {
    printf("Interactive mode.\n");
  } else if (argc==2) {
    // single file - just run it
    char *buffer = read_file(argv[1]);
    if (!buffer) exit(1);
    // check for '#' as the first char, and if so, skip the first line
    char *cmd = buffer;
    if (cmd[0]=='#') {
      while (cmd[0] && cmd[0]!='\n') cmd++;
      if (cmd[0]=='\n') cmd++;
    }
    jshInit();
    jsvInit();
    jsiInit(false /* do not autoload!!! */);
    addNativeFunction("quit", nativeQuit);
    jsvUnLock(jspEvaluate(cmd, true));
    int errCode = handleErrors();
    free(buffer);
    isRunning = !errCode;
    bool isBusy = true;
    while (isRunning && (jsiHasTimers() || isBusy))
      isBusy = jsiLoop();
    jsiKill();
    jsvKill();
    jshKill();
    exit(errCode);
  } else {
    printf("Unknown arguments!\n");
    show_help();
    exit(1);
  }

  printf("Size of JsVar is now %d bytes\n", (int)sizeof(JsVar));
  printf("Size of JsVarRef is now %d bytes\n", (int)sizeof(JsVarRef));

#ifndef __MINGW32__
  struct sigaction sa;
  sa.sa_handler = sig_handler;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  if (sigaction(SIGINT, &sa, NULL) == -1)
    printf("Adding SIGINT hook failed\n");
  else
    printf("Added SIGINT hook\n");
  if (sigaction(SIGHUP, &sa, NULL) == -1)
    printf("Adding SIGHUP hook failed\n");
  else
    printf("Added SIGHUP hook\n");
  if (sigaction(SIGTERM, &sa, NULL) == -1)
    printf("Adding SIGTERM hook failed\n");
  else
    printf("Added SIGTERM hook\n");
#endif//!__MINGW32__

  jshInit();
  jsvInit();
  jsiInit(true);

  addNativeFunction("quit", nativeQuit);
  addNativeFunction("interrupt", nativeInterrupt);

  while (isRunning) {
    jsiLoop();
  }
  jsiConsolePrint("\n");
  jsiKill();
  jsvGarbageCollect();
  jsvShowAllocated();
  jsvKill();
  jshKill();

  return 0;
}