https://github.com/yodaos-project/rt-node
A JavaScript runtime library for RTOS.
https://github.com/yodaos-project/rt-node
nodejs rtos
Last synced: 9 months ago
JSON representation
A JavaScript runtime library for RTOS.
- Host: GitHub
- URL: https://github.com/yodaos-project/rt-node
- Owner: yodaos-project
- License: apache-2.0
- Created: 2019-10-21T09:28:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-11T16:21:39.000Z (about 6 years ago)
- Last Synced: 2024-05-14T00:26:59.534Z (over 1 year ago)
- Topics: nodejs, rtos
- Language: C
- Homepage:
- Size: 4.09 MB
- Stars: 25
- Watchers: 8
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](./deps/jerryscript), a lightweight JavaScript engine
- [rv](./deps/rv), a tiny event loop library
## JavaScript Sample
`speaker.js`
```javascript
'use strict';
class Speaker {
constructor(content) {
this.content = content;
}
say() {
console.log(this.content);
}
}
module.exports = Speaker;
```
`app.js`
```javascript
'use strict';
const Speaker = require('speaker');
const speaker = new Speaker('hello world');
setTimeout(() => {
speaker.say();
}, 3000);
```
## N-API Sample
```javascript
'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](https://cmake.org) to build library or samples. The easiest way to build is as follows:
```shell
$ 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:
```shell
$ 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
```shell
$ 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:
```shell
$ 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](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/#step-9-flash-onto-the-device).
## LICENSE
[Apache-2.0](./LICENSE)