Retire the Mbed OS 3 target (#2343)
Mbed OS 3 is discontinued, long live Mbed OS 5. resolves #2338 JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -29,10 +29,6 @@ ID
|
|||||||
|
|
||||||
# targets
|
# targets
|
||||||
jerry-targetjs.h
|
jerry-targetjs.h
|
||||||
targets/mbed/libjerry
|
|
||||||
targets/mbed/build
|
|
||||||
targets/mbed/yotta_modules
|
|
||||||
targets/mbed/yotta_targets
|
|
||||||
.output
|
.output
|
||||||
targets/esp8266/output.map
|
targets/esp8266/output.map
|
||||||
targets/esp8266/libs
|
targets/esp8266/libs
|
||||||
|
|||||||
-10
@@ -138,16 +138,6 @@ matrix:
|
|||||||
apt:
|
apt:
|
||||||
packages: [gperf, texinfo, wget]
|
packages: [gperf, texinfo, wget]
|
||||||
|
|
||||||
- env: JOBNAME="Mbed/K64F Build Test"
|
|
||||||
sudo: true # keep on sudo-enabled VM to avoid gcc dying of OOM
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- sourceline: ppa:team-gcc-arm-embedded/ppa
|
|
||||||
packages: [gcc-arm-embedded, ninja-build, libffi-dev, libssl-dev]
|
|
||||||
install: make -f ./targets/mbed/Makefile.travis install-noapt
|
|
||||||
script: make -f ./targets/mbed/Makefile.travis script
|
|
||||||
|
|
||||||
- env: JOBNAME="Mbed OS 5/K64F Build Test"
|
- env: JOBNAME="Mbed OS 5/K64F Build Test"
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
# use TAB-8
|
|
||||||
|
|
||||||
TARGET_LIST = k64f stm32f4 stm32f429i nucleo
|
|
||||||
JERRYHEAP ?= 16
|
|
||||||
|
|
||||||
ifneq ($(filter $(board), $(TARGET_LIST)),)
|
|
||||||
TARGET = $(board)
|
|
||||||
ifeq ($(TARGET), k64f)
|
|
||||||
YOTTA_TARGET = frdm-k64f-gcc
|
|
||||||
TARGET_DIR ?= /media/$(USER)/MBED
|
|
||||||
else ifeq ($(TARGET), stm32f4)
|
|
||||||
YOTTA_TARGET = stm32f4-disco-gcc
|
|
||||||
else ifeq ($(TARGET), stm32f429i)
|
|
||||||
YOTTA_TARGET = stm32f429i-disco-gcc
|
|
||||||
else ifeq ($(TARGET), nucleo)
|
|
||||||
YOTTA_TARGET = st-nucleo-f401re-gcc
|
|
||||||
TARGET_DIR ?= /media/$(USER)/NODE_F401RE
|
|
||||||
endif
|
|
||||||
|
|
||||||
BUILD_DIR ?= build/mbed
|
|
||||||
UPPERC_TARGET ?= $(shell echo $(TARGET) | tr a-z A-Z)
|
|
||||||
COPYTARGET ?= targets/mbed/libjerry
|
|
||||||
|
|
||||||
else
|
|
||||||
$(error This board ($(board)) is not supported!)
|
|
||||||
endif
|
|
||||||
|
|
||||||
EXT_CFLAGS := -D__TARGET_MBED_$(UPPERC_TARGET)
|
|
||||||
EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
|
|
||||||
EXT_CFLAGS += -Wno-error=format=
|
|
||||||
|
|
||||||
EXT_PORT_DIR := ""
|
|
||||||
|
|
||||||
.PHONY: jerry js2c yotta flash clean
|
|
||||||
|
|
||||||
all: jerry js2c yotta
|
|
||||||
|
|
||||||
jerry:
|
|
||||||
mkdir -p $(COPYTARGET)
|
|
||||||
mkdir -p $(BUILD_DIR)
|
|
||||||
cmake -B$(BUILD_DIR) -H./ \
|
|
||||||
-DCMAKE_SYSTEM_NAME=Mbed \
|
|
||||||
-DCMAKE_SYSTEM_PROCESSOR=armv7l-hf \
|
|
||||||
-DCMAKE_C_COMPILER=arm-none-eabi-gcc \
|
|
||||||
-DCMAKE_C_COMPILER_WORKS=TRUE \
|
|
||||||
-DENABLE_LTO=OFF \
|
|
||||||
-DENABLE_ALL_IN_ONE=OFF \
|
|
||||||
-DJERRY_LIBC=OFF \
|
|
||||||
-DJERRY_CMDLINE=OFF \
|
|
||||||
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
|
|
||||||
-DMEM_HEAP_SIZE_KB=$(JERRYHEAP) \
|
|
||||||
|
|
||||||
make -C$(BUILD_DIR) jerry-core
|
|
||||||
make -C$(BUILD_DIR) jerry-libm
|
|
||||||
cp $(BUILD_DIR)/lib/libjerry-core.a $(COPYTARGET)/libjerrycore.a
|
|
||||||
cp $(BUILD_DIR)/lib/libjerry-libm.a $(COPYTARGET)/libjerrylibm.a
|
|
||||||
|
|
||||||
js2c:
|
|
||||||
cd targets/mbed; ../../tools/js2c.py;
|
|
||||||
|
|
||||||
yotta:
|
|
||||||
cd targets/mbed; \
|
|
||||||
export WCMAKE=`which cmake`; export PATH=`pwd`:$$PATH; \
|
|
||||||
yotta target $(YOTTA_TARGET); \
|
|
||||||
yotta build
|
|
||||||
|
|
||||||
flash:
|
|
||||||
ifndef TARGET_DIR
|
|
||||||
st-flash write targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin 0x08000000
|
|
||||||
else
|
|
||||||
@if [ ! -d "${TARGET_DIR}" ] ; then \
|
|
||||||
echo "The board not mounted at ${TARGET_DIR}"; \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
cp targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin \
|
|
||||||
"$(TARGET_DIR)/."
|
|
||||||
endif
|
|
||||||
@echo "Wait till LED flashing stops..."
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf $(COPYTARGET)
|
|
||||||
rm -rf $(OUTPUT)
|
|
||||||
rm -rf targets/mbed/build
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
|
|
||||||
# Default target for running the build test outside the Travis CI environment.
|
|
||||||
all:
|
|
||||||
$(MAKE) install
|
|
||||||
$(MAKE) script
|
|
||||||
|
|
||||||
|
|
||||||
## Targets for installing build dependencies of the Mbed JerryScript target.
|
|
||||||
|
|
||||||
# Install tools via apt.
|
|
||||||
install-apt-get-deps:
|
|
||||||
sudo apt-get install -q -y ninja-build libffi-dev libssl-dev
|
|
||||||
|
|
||||||
# Install yotta
|
|
||||||
install-yotta:
|
|
||||||
pip install --user "pyOpenSSL<17.5" # fix for failures with pyOpenSSL 17.5
|
|
||||||
pip install --user yotta
|
|
||||||
|
|
||||||
# Perform all the necessary (JerryScript-independent) installation steps.
|
|
||||||
install-noapt: install-yotta
|
|
||||||
install: install-apt-get-deps install-noapt
|
|
||||||
|
|
||||||
|
|
||||||
## Targets for building Mbed with JerryScript.
|
|
||||||
|
|
||||||
# Build the firmware (Mbed with JerryScript).
|
|
||||||
script:
|
|
||||||
$(MAKE) -f targets/mbed/Makefile.mbed board=k64f
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
# HACK:
|
|
||||||
# Wrapping cmake to ensure that yotta-driven cmake (3.6+) accepts
|
|
||||||
# arm-none-eabi-gcc as working compiler.
|
|
||||||
# WCMAKE variable must be set to the full path of the wrapped cmake.
|
|
||||||
# Related yotta issue: https://github.com/ARMmbed/yotta/issues/783
|
|
||||||
$WCMAKE -DCMAKE_C_COMPILER_WORKS=TRUE $@
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var check = 1;
|
|
||||||
|
|
||||||
function blink ()
|
|
||||||
{
|
|
||||||
var blk = (check > 8) ? 1 : 0;
|
|
||||||
led (0, blk);
|
|
||||||
check = (check >= 10) ? 1 : check + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
print ("blink js OK");
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function sysloop (ticknow)
|
|
||||||
{
|
|
||||||
blink ();
|
|
||||||
}
|
|
||||||
|
|
||||||
print ("main js OK");
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "jerry",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"bin": "./source",
|
|
||||||
"private": true,
|
|
||||||
"description": "JerryScript in mbed",
|
|
||||||
"author": "",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"mbed-drivers": "^1.5.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
This folder contains files to run JerryScript in mbed / for:
|
|
||||||
|
|
||||||
* Freedom-K64F (k64)
|
|
||||||
* Discovery-STM32F4 (stm32f4)
|
|
||||||
* Discovery-STM32F429ZI (stm32f429i)
|
|
||||||
* Nucleo-F401RE (nucleo)
|
|
||||||
|
|
||||||
####Yotta
|
|
||||||
You need to install yotta before proceeding. Please visit [Yotta docs page](http://yottadocs.mbed.com/#installing-on-linux).
|
|
||||||
|
|
||||||
####Cross-compiler
|
|
||||||
For cross-compilation the GCC 5.2.1 is suggested to be used. All the supported targets were tested with this version. If you don't have any GCC compiler installed, please visit [this](https://launchpad.net/gcc-arm-embedded/+download) page to download GCC 5.2.1.
|
|
||||||
|
|
||||||
####How to build a target
|
|
||||||
Navigate to your JerryScript root folder (after you cloned this repository into the targets folder) and use the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
make -f targets/mbed/Makefile.mbed board=$(TARGET)
|
|
||||||
```
|
|
||||||
Where the `$(TARGET)` is one of the following options: `k64f`, `stm32f4`, `stm32f429i` or `nucleo`.
|
|
||||||
This command will create a new folder for your target and build the jerryscript and mbed OS into that folder.
|
|
||||||
|
|
||||||
####How to build a completely new target
|
|
||||||
If you want to build a new target (which is not available in this folder) you have to modify the makefile.
|
|
||||||
You have to add the new board name to the `TARGET_LIST` and you have to add a new branch with the new `YOTTA_TARGET` and a new `TARGET_DIR` path (if it neccessary) to the if at the top in the Makefile (just as you see right now).
|
|
||||||
There is a little code snippet:
|
|
||||||
|
|
||||||
```
|
|
||||||
ifeq ($(TARGET), k64f)
|
|
||||||
YOTTA_TARGET = frdm-k64f-gcc
|
|
||||||
TARGET_DIR ?= /media/$(USER)/MBED
|
|
||||||
else ifeq ($(TARGET), stm32f4)
|
|
||||||
YOTTA_TARGET =
|
|
||||||
```
|
|
||||||
|
|
||||||
Basically, you can create a new target in this way (If the mbed OS support your board).
|
|
||||||
|
|
||||||
#####Let's get into the details!
|
|
||||||
1. The next rule is the `jerry` rule. This rule builds the JerryScript and copy the output files into the target libjerry folder. Two files will be generated at `targets/mbed/libjerry`:
|
|
||||||
* libjerrycore.a
|
|
||||||
* libfdlibm.a
|
|
||||||
|
|
||||||
You can run this rule with the following command:
|
|
||||||
- `make -f targets/mbed/Makefile.mbed board=$(TARGET) jerry`
|
|
||||||
|
|
||||||
2. The next rule is the `js2c`. This rule calls a `js2c.py` python script from the `jerryscript/targets/tools` and creates the JavaScript builtin file into the `targets/mbed/source/` folder. This file is the `jerry-targetjs.h`. You can run this rule with the follwoing command:
|
|
||||||
|
|
||||||
- `make -f targets/mbed/Makefile.mbed board=$(TARGET) js2c`
|
|
||||||
|
|
||||||
3. The last rule is the `yotta`. This rule sets the yotta target and install the mbed-drivers module, install the dependencies for the mbed OS and finaly creates the mbed binary file. The binary file will be genrated at `targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin`. You can run this rule with the following command:
|
|
||||||
|
|
||||||
- `make -f targets/mbed/Makefile.mbed board=$(TARGET) yotta`
|
|
||||||
|
|
||||||
4. Optional rule: `clean`. It removes the build folder from the mbed and jerry. You can run this rule with this command:
|
|
||||||
|
|
||||||
- `make -f targets/mbed/Makefile.mbed board=$(TARGET) clean`
|
|
||||||
|
|
||||||
#####Flashing
|
|
||||||
When the build is finished you can flash the binary into your board if you want. In case of ST boards you have to install the `st-link` software. Please visit [this page](https://github.com/texane/stlink) to install STLink-v2.
|
|
||||||
You can flash your binary into your board with the following command:
|
|
||||||
```
|
|
||||||
make -f targets/mbed/Makefile.mbed board=$(TARGET) flash
|
|
||||||
```
|
|
||||||
The flash rule grabs the binary and copies it to the mounted board or use the STLink-v2 to flash.
|
|
||||||
When the status LED of the board stops blinking, press RESET button on the board to execute JerryScript led flashing sample program in js folder.
|
|
||||||
|
|
||||||
###Note
|
|
||||||
If you use an STM32F4 board your build will stop with missing header errors. To fix this error please visit to [this page](http://browser.sed.hu/blog/20160407/how-run-javascripts-jerryscript-mbed) and read about the fix in the `New target for STM32F4` block.
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "jerry-core/include/jerryscript.h"
|
|
||||||
#include "jerry_extapi.h"
|
|
||||||
|
|
||||||
#include "native_mbed.h"
|
|
||||||
|
|
||||||
#ifndef MIN
|
|
||||||
#define MIN(A,B) ((A)<(B)?(A):(B))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#define __UNSED__ __attribute__((unused))
|
|
||||||
|
|
||||||
#define DECLARE_HANDLER(NAME) \
|
|
||||||
static jerry_value_t \
|
|
||||||
NAME ## _handler (const jerry_value_t func_value __UNSED__, \
|
|
||||||
const jerry_value_t this_value __UNSED__, \
|
|
||||||
const jerry_value_t args[], \
|
|
||||||
const jerry_length_t args_cnt )
|
|
||||||
|
|
||||||
#define REGISTER_HANDLER(NAME) \
|
|
||||||
register_native_function ( # NAME, NAME ## _handler)
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
DECLARE_HANDLER(assert)
|
|
||||||
{
|
|
||||||
if (args_cnt == 1
|
|
||||||
&& jerry_value_is_boolean (args[0])
|
|
||||||
&& jerry_get_boolean_value (args[0]))
|
|
||||||
{
|
|
||||||
printf (">> Jerry assert true\r\n");
|
|
||||||
return jerry_create_boolean (true);
|
|
||||||
}
|
|
||||||
printf ("ERROR: Script assertion failed\n");
|
|
||||||
exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
|
|
||||||
return jerry_create_boolean (false);
|
|
||||||
}
|
|
||||||
|
|
||||||
DECLARE_HANDLER(led)
|
|
||||||
{
|
|
||||||
jerry_value_t ret_val;
|
|
||||||
|
|
||||||
if (args_cnt < 2)
|
|
||||||
{
|
|
||||||
ret_val = jerry_create_boolean (false);
|
|
||||||
printf ("Error: invalid arguments number!\r\n");
|
|
||||||
return ret_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(jerry_value_is_number (args[0])
|
|
||||||
&& jerry_value_is_number (args[1])))
|
|
||||||
{
|
|
||||||
ret_val = jerry_create_boolean (false);
|
|
||||||
printf ("Error: arguments must be numbers!\r\n");
|
|
||||||
return ret_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
int port, value;
|
|
||||||
port = (int) jerry_get_number_value (args[0]);
|
|
||||||
value = (int) jerry_get_number_value (args[1]);
|
|
||||||
|
|
||||||
if (port >= 0 && port <= 3)
|
|
||||||
{
|
|
||||||
native_led (port, value);
|
|
||||||
ret_val = jerry_create_boolean (true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret_val = jerry_create_boolean (false);
|
|
||||||
}
|
|
||||||
return ret_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
static bool
|
|
||||||
register_native_function (const char* name,
|
|
||||||
jerry_external_handler_t handler)
|
|
||||||
{
|
|
||||||
jerry_value_t global_object_val = jerry_get_global_object ();
|
|
||||||
jerry_value_t reg_function = jerry_create_external_function (handler);
|
|
||||||
|
|
||||||
bool is_ok = true;
|
|
||||||
|
|
||||||
if (!(jerry_value_is_function (reg_function)
|
|
||||||
&& jerry_value_is_constructor (reg_function)))
|
|
||||||
{
|
|
||||||
is_ok = false;
|
|
||||||
printf ("Error: create_external_function failed !!!\r\n");
|
|
||||||
jerry_release_value (global_object_val);
|
|
||||||
jerry_release_value (reg_function);
|
|
||||||
return is_ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jerry_value_is_error (reg_function))
|
|
||||||
{
|
|
||||||
is_ok = false;
|
|
||||||
printf ("Error: create_external_function has error flag! \n\r");
|
|
||||||
jerry_release_value (global_object_val);
|
|
||||||
jerry_release_value (reg_function);
|
|
||||||
return is_ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
jerry_value_t jerry_name = jerry_create_string ((jerry_char_t *) name);
|
|
||||||
|
|
||||||
jerry_value_t set_result = jerry_set_property (global_object_val,
|
|
||||||
jerry_name,
|
|
||||||
reg_function);
|
|
||||||
|
|
||||||
|
|
||||||
if (jerry_value_is_error (set_result))
|
|
||||||
{
|
|
||||||
is_ok = false;
|
|
||||||
printf ("Error: register_native_function failed: [%s]\r\n", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
jerry_release_value (jerry_name);
|
|
||||||
jerry_release_value (global_object_val);
|
|
||||||
jerry_release_value (reg_function);
|
|
||||||
jerry_release_value (set_result);
|
|
||||||
|
|
||||||
return is_ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
void js_register_functions (void)
|
|
||||||
{
|
|
||||||
REGISTER_HANDLER (assert);
|
|
||||||
REGISTER_HANDLER (led);
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __JERRY_EXTAPI_H__
|
|
||||||
#define __JERRY_EXTAPI_H__
|
|
||||||
|
|
||||||
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
|
|
||||||
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
|
|
||||||
|
|
||||||
void js_register_functions (void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "jerry-core/include/jerryscript.h"
|
|
||||||
#include "jerry_extapi.h"
|
|
||||||
#include "jerry_run.h"
|
|
||||||
|
|
||||||
static const char* fn_sys_loop_name = "sysloop";
|
|
||||||
|
|
||||||
int js_entry (const char *source_p, const size_t source_size)
|
|
||||||
{
|
|
||||||
const jerry_char_t *jerry_src = (const jerry_char_t *) source_p;
|
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
|
||||||
uint8_t ret_code = 0;
|
|
||||||
|
|
||||||
js_register_functions ();
|
|
||||||
|
|
||||||
jerry_value_t parsed_code = jerry_parse (NULL, 0, jerry_src, source_size, JERRY_PARSE_NO_OPTS);
|
|
||||||
|
|
||||||
if (!jerry_value_is_error (parsed_code))
|
|
||||||
{
|
|
||||||
jerry_value_t ret_value = jerry_run (parsed_code);
|
|
||||||
|
|
||||||
if (jerry_value_is_error (ret_value))
|
|
||||||
{
|
|
||||||
printf ("Error: ret_value has an error flag!\r\n");
|
|
||||||
return ret_code = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
jerry_release_value (ret_value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf ("Error: jerry_parse failed!\r\n");
|
|
||||||
ret_code = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
jerry_release_value (parsed_code);
|
|
||||||
|
|
||||||
return ret_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int js_eval (const char *source_p, const size_t source_size)
|
|
||||||
{
|
|
||||||
int status = 0;
|
|
||||||
|
|
||||||
jerry_value_t ret_val = jerry_eval ((jerry_char_t *) source_p,
|
|
||||||
source_size,
|
|
||||||
false);
|
|
||||||
|
|
||||||
if (jerry_value_is_error (ret_val))
|
|
||||||
{
|
|
||||||
printf ("Error: jerry_eval failed!\r\n");
|
|
||||||
status = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
jerry_release_value (ret_val);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
int js_loop (uint32_t ticknow)
|
|
||||||
{
|
|
||||||
int status = 0;
|
|
||||||
jerry_value_t global_obj = jerry_get_global_object ();
|
|
||||||
jerry_value_t sys_name = jerry_create_string ((const jerry_char_t *) fn_sys_loop_name);
|
|
||||||
jerry_value_t sysloop_func = jerry_get_property (global_obj, sys_name);
|
|
||||||
|
|
||||||
jerry_release_value (sys_name);
|
|
||||||
|
|
||||||
if (jerry_value_is_error (sysloop_func))
|
|
||||||
{
|
|
||||||
printf ("Error: '%s' not defined!!!\r\n", fn_sys_loop_name);
|
|
||||||
jerry_release_value (global_obj);
|
|
||||||
jerry_release_value (sysloop_func);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!jerry_value_is_function (sysloop_func))
|
|
||||||
{
|
|
||||||
printf ("Error: '%s' is not a function!!!\r\n", fn_sys_loop_name);
|
|
||||||
jerry_release_value (global_obj);
|
|
||||||
jerry_release_value (sysloop_func);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
jerry_value_t val_args[1];
|
|
||||||
uint16_t val_argv = 1;
|
|
||||||
|
|
||||||
val_args[0] = jerry_create_number (ticknow);
|
|
||||||
|
|
||||||
jerry_value_t ret_val_sysloop = jerry_call_function (sysloop_func,
|
|
||||||
global_obj,
|
|
||||||
val_args,
|
|
||||||
val_argv);
|
|
||||||
if (jerry_value_is_error (ret_val_sysloop))
|
|
||||||
{
|
|
||||||
status = -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
jerry_release_value (global_obj);
|
|
||||||
jerry_release_value (ret_val_sysloop);
|
|
||||||
jerry_release_value (sysloop_func);
|
|
||||||
jerry_release_value (val_args[0]);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
void js_exit (void)
|
|
||||||
{
|
|
||||||
jerry_cleanup ();
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __JERRY_RUN_H__
|
|
||||||
#define __JERRY_RUN_H__
|
|
||||||
|
|
||||||
int js_entry (const char *source_p, const size_t source_size);
|
|
||||||
int js_eval (const char *source_p, const size_t source_size);
|
|
||||||
int js_loop (uint32_t ticknow);
|
|
||||||
void js_exit (void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mbed-drivers/mbed.h"
|
|
||||||
|
|
||||||
#include "jerry-core/include/jerryscript.h"
|
|
||||||
#include "jerry-core/include/jerryscript-port.h"
|
|
||||||
#include "jerry_run.h"
|
|
||||||
|
|
||||||
#include "jerry-targetjs.h"
|
|
||||||
|
|
||||||
static Serial pc (USBTX, USBRX); //tx, rx
|
|
||||||
|
|
||||||
static int jerry_task_init (void)
|
|
||||||
{
|
|
||||||
srand ((unsigned) jerry_port_get_current_time ());
|
|
||||||
int retcode;
|
|
||||||
|
|
||||||
DECLARE_JS_CODES;
|
|
||||||
|
|
||||||
/* run main.js */
|
|
||||||
retcode = js_entry (js_codes[0].source, js_codes[0].length);
|
|
||||||
if (retcode != 0)
|
|
||||||
{
|
|
||||||
printf ("js_entry failed code(%d) [%s]\r\n", retcode, js_codes[0].name);
|
|
||||||
js_exit ();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/* run rest of the js files */
|
|
||||||
for (int src = 1; js_codes[src].source; src++)
|
|
||||||
{
|
|
||||||
retcode = js_eval (js_codes[src].source, js_codes[src].length);
|
|
||||||
if (retcode != 0)
|
|
||||||
{
|
|
||||||
printf ("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[src].name);
|
|
||||||
js_exit ();
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void jerry_loop (void)
|
|
||||||
{
|
|
||||||
static uint32_t _jcount = 0;
|
|
||||||
|
|
||||||
js_loop (_jcount++);
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_start (int, char**)
|
|
||||||
{
|
|
||||||
/* set 9600 baud rate for stdout */
|
|
||||||
pc.baud (9600);
|
|
||||||
|
|
||||||
printf ("\r\nJerryScript in mbed\r\n");
|
|
||||||
printf ("Version: \t%d.%d\n\n", JERRY_API_MAJOR_VERSION, JERRY_API_MINOR_VERSION);
|
|
||||||
|
|
||||||
if (jerry_task_init () == 0)
|
|
||||||
{
|
|
||||||
minar::Scheduler::postCallback(jerry_loop).period(minar::milliseconds(100));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
# application name
|
|
||||||
set(MBEDMODULE "jerry")
|
|
||||||
|
|
||||||
# add include jerry-core
|
|
||||||
set(LJCORE ${CMAKE_CURRENT_LIST_DIR}/../../../)
|
|
||||||
include_directories(${LJCORE})
|
|
||||||
|
|
||||||
# compile flags
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlittle-endian -mthumb -mcpu=cortex-m4" )
|
|
||||||
|
|
||||||
# link jerryscript
|
|
||||||
set(LJPATH ${CMAKE_CURRENT_LIST_DIR}/../libjerry)
|
|
||||||
set(LJFILES "")
|
|
||||||
set(LJFILES ${LJFILES} ${LJPATH}/libjerrylibm.a)
|
|
||||||
set(LJFILES ${LJFILES} ${LJPATH}/libjerrycore.a)
|
|
||||||
target_link_libraries(${MBEDMODULE} ${LJFILES})
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mbed-drivers/mbed.h"
|
|
||||||
|
|
||||||
#include "native_mbed.h"
|
|
||||||
|
|
||||||
void native_led (int port, int val)
|
|
||||||
{
|
|
||||||
static const PinName portmap[] = { LED1, LED2, LED3, LED4 };
|
|
||||||
static DigitalOut led (portmap[port]);
|
|
||||||
led = val;
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __NATIVE_MBED_H__
|
|
||||||
#define __NATIVE_MBED_H__
|
|
||||||
|
|
||||||
void native_led (int port, int val);
|
|
||||||
|
|
||||||
#endif /* !__NATIVE_MBED_H__ */
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _BSD_SOURCE
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "jerry-core/include/jerryscript-port.h"
|
|
||||||
|
|
||||||
#include "mbed-hal/us_ticker_api.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provide log message implementation for the engine.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
jerry_port_log (jerry_log_level_t level, /**< log level */
|
|
||||||
const char *format, /**< format string */
|
|
||||||
...) /**< parameters */
|
|
||||||
{
|
|
||||||
(void) level; /* ignore log level */
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start (args, format);
|
|
||||||
vfprintf (stderr, format, args);
|
|
||||||
va_end (args);
|
|
||||||
} /* jerry_port_log */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of jerry_port_fatal.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
jerry_port_fatal (jerry_fatal_code_t code) /**< fatal code enum item */
|
|
||||||
{
|
|
||||||
exit (code);
|
|
||||||
} /* jerry_port_fatal */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of jerry_port_get_time_zone.
|
|
||||||
*
|
|
||||||
* @return true - if success
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
jerry_port_get_time_zone (jerry_time_zone_t *tz_p) /**< timezone pointer */
|
|
||||||
{
|
|
||||||
tz_p->offset = 0;
|
|
||||||
tz_p->daylight_saving_time = 0;
|
|
||||||
return true;
|
|
||||||
} /* jerry_port_get_time_zone */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of jerry_port_get_current_time.
|
|
||||||
*
|
|
||||||
* @return current timer's counter value in milliseconds
|
|
||||||
*/
|
|
||||||
double
|
|
||||||
jerry_port_get_current_time (void)
|
|
||||||
{
|
|
||||||
/* Note: if the target has its own RTC, this value should be extended by the
|
|
||||||
* RTC's one. */
|
|
||||||
return (double) us_ticker_read () / 1000;
|
|
||||||
} /* jerry_port_get_current_time */
|
|
||||||
Reference in New Issue
Block a user