Skip to content
A JavaScript runtime library for RTOS.
C Python C++ JavaScript CMake Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
deps fix: fix leak & add napi helper Dec 11, 2019
include
samples chore: update sample Dec 11, 2019
src fix: fix leak & add napi helper Dec 11, 2019
tools reactor: remove extra modules & add http napi test Dec 10, 2019
.clang-format
.gitignore add N-API support & optimize Nov 9, 2019
CMakeLists.txt
LICENSE chore: add READEME.md and LICENSE Nov 4, 2019
README.md

README.md

rt-node

License

rt-node is a lightweight JavaScript framework for RTOS, also support unix like systems for debugging.

The following runtime modules are built in:

  • timer
  • require
  • utils
  • console
  • N-API

N-API is supported in order to be compatible with different embed JavaScript engines, the following N-API features are WIP:

  • thread safe function

Dependencies

  • JerryScript, a lightweight JavaScript engine
  • rv, a tiny event loop library

JavaScript Sample

speaker.js

'use strict';
class Speaker {
  constructor(content) {
    this.content = content;
  }
  say() {
    console.log(this.content);
  }
}
module.exports = Speaker;

app.js

'use strict';
const Speaker = require('speaker');
const speaker = new Speaker('hello world');
setTimeout(() => {
  speaker.say();
}, 3000);

N-API Sample

'use strict';
// The curl module depends on libcurl, the source file is sample/unix/curl.c
const curl = require('curl');
const startTime = Date.now();
curl.get('http://www.example.com', (body) => {
  console.log(`get body in ${Date.now() - startTime}ms`, body);
});

Build

JavaScript sources are packaged in src/rtnode-snapshots.c/h, set JS_ROOT as your JavaScript sources root directory for cmake to package them, app.js is the entry of user code.

rtnode use CMake to build library or samples. The easiest way to build is as follows:

$ cmake -B./build -H. -DJS_ROOT=Your_js_files_root_directory
$ make -C./build -j8

The above commands will generate librtnode.a in ./build directory.

For cross compile, add the following flags:

  • CMAKE_C_COMPILER, full path for c compiler
  • CMAKE_SYSTEM_PROCESSOR, the name of the CPU CMake is building for
  • CMAKE_SYSTEM_NAME, set Generic to indicate cross compile

Here is an example for Xtensa toolchain:

$ cmake -B./build-xtensa -H. \
  -DCMAKE_C_COMPILER=xtensa-esp32-elf-gcc \
  -DCMAKE_SYSTEM_PROCESSOR=xtensa \
  -DCMAKE_SYSTEM_NAME=Generic \
  -DJS_ROOT=Your_js_files_root_directory
$ make -C./build-xtensa -j8

Sample

Currently support unix and esp-idf build framework.

For unix like systems

$ cmake -B./build -H. -DSAMPLE=unix -DJS_ROOT=./samples -DJERRY_PROFILE=es2015-subset
$ make -C./build
$ ./build/rtnode-unix/rtnode-unix # run sample

For esp-idf:

$ cmake -B./build-espidf -H. \
  -DCMAKE_C_COMPILER=xtensa-esp32-elf-gcc \
  -DCMAKE_SYSTEM_PROCESSOR=xtensa \
  -DCMAKE_SYSTEM_NAME=Generic \
  -DSAMPLE=esp-idf \
  -DJS_ROOT=./samples \
  -DJERRY_PROFILE=es2015-subset
$ make -C./build-espidf -j8

The esp-idf products will generate in ./build-espidf/rtnode-build, then use idf.py flash to flash the binaries that you just built onto your ESP32 board. For more information, please refer to the esp-idf document.

LICENSE

Apache-2.0

You can’t perform that action at this time.