Merge esp8266-rtos-sdk and esp-idf targets (#4958)
This patch bumps esp8266-rtos-sdk to the latest release. This required to modify the directory structure and the build system to conform to ESP-IDF Style. Since esp-idf target already supports ESP-IDF Style, the espressif targets has been merged to eliminate code duplication. The target application code has been modified from blinking leds to hello world to be aligned to other targets. JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# 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.
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
|
||||
# Workaround to generate sdkconfig into the build directory.
|
||||
file(TOUCH ${SDKCONFIG})
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(jerryscript)
|
||||
@@ -0,0 +1,13 @@
|
||||
### About
|
||||
|
||||
This folder contains files to run JerryScript on
|
||||
[ESP8666 board](https://www.espressif.com/en/products/socs/esp8266) with
|
||||
[ESP8266 RTOS SDK](https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/) and
|
||||
[ESP32 board](https://www.espressif.com/en/products/socs/esp32) with
|
||||
[esp-idf](https://docs.espressif.com/projects/esp-idf/en/latest/).
|
||||
|
||||
Both targets is based on ESP-IDF Style so the build system and the directory structure is the same.
|
||||
Please see the following documents for additional information about the targets:
|
||||
|
||||
- [esp8266-rtos-sdk](esp8266-rtos-sdk/README.md)
|
||||
- [esp-idf](esp-idf/README.md)
|
||||
@@ -0,0 +1,52 @@
|
||||
# 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 ESP8266 JerryScript target.
|
||||
|
||||
# Install tools via apt.
|
||||
install-apt-get-deps:
|
||||
sudo apt-get install -q -y wget
|
||||
|
||||
# Fetch and extract Xtensa toolchain.
|
||||
install-xtensa-esp32-gcc:
|
||||
wget https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz --no-check-certificate --directory-prefix /tmp
|
||||
tar xvfz /tmp/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz --directory /tmp
|
||||
|
||||
# Fetch Espressif IoT Development Framework and install its dependencies.
|
||||
install-esp-idf:
|
||||
git clone https://github.com/espressif/esp-idf.git /tmp/esp-idf -b release/v4.4
|
||||
IDF_PATH=/tmp/esp-idf python -m pip install --user -r /tmp/esp-idf/requirements.txt
|
||||
|
||||
# Perform all the necessary (JerryScript-independent) installation steps.
|
||||
install-noapt: install-xtensa-esp32-gcc install-esp-idf
|
||||
install: install-apt-get-deps install-noapt
|
||||
|
||||
|
||||
## Targets for building ESP-IDF with JerryScript.
|
||||
|
||||
# Build the firmware (ESP-IDF with JerryScript).
|
||||
script:
|
||||
PATH=/tmp/xtensa-esp32-elf/bin:$(PATH) \
|
||||
python /tmp/esp-idf/tools/idf.py \
|
||||
--project-dir ./targets/baremetal-sdk/espressif \
|
||||
--build-dir ./build/esp-idf \
|
||||
set-target esp32 \
|
||||
all
|
||||
@@ -0,0 +1,129 @@
|
||||
### About
|
||||
|
||||
This folder contains files to run JerryScript on
|
||||
[ESP32 board](https://www.espressif.com/en/products/socs/esp32) with
|
||||
[ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/).
|
||||
The document had been validated on Ubuntu 20.04 operating system.
|
||||
|
||||
### How to build
|
||||
|
||||
#### 1. Setup the build environment
|
||||
|
||||
Clone the necessary projects into a `jerry-esp` directory.
|
||||
The latest tested working version of ESP-IDF SDK is `release/v4.4`.
|
||||
|
||||
```sh
|
||||
# Create a base folder for all the projects.
|
||||
mkdir jerry-esp && cd jerry-esp
|
||||
|
||||
git clone https://github.com/jerryscript-project/jerryscript.git
|
||||
git clone https://github.com/espressif/esp-idf.git -b release/v4.4
|
||||
|
||||
# SDK requires Xtensa toolchain.
|
||||
wget https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz
|
||||
```
|
||||
|
||||
The following directory structure has been created:
|
||||
|
||||
```
|
||||
jerry-esp
|
||||
+ jerryscript
|
||||
| + targets
|
||||
| + baremetal-sdk
|
||||
| + espressif
|
||||
|
|
||||
+ esp-idf
|
||||
+ xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz
|
||||
```
|
||||
|
||||
#### 2. Install dependencies of the projects
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
jerryscript/tools/apt-get-install-deps.sh
|
||||
|
||||
# Install dependencies of esp-idf.
|
||||
python -m pip install --user -r esp-idf/requirements.txt
|
||||
|
||||
# Extract the downloaded toolchain.
|
||||
tar -xvf xtensa-esp32-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz
|
||||
```
|
||||
|
||||
#### 3. Build ESP-IDF (with JerryScript)
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
PATH=${PWD}/xtensa-esp32-elf/bin:$PATH esp-idf/tools/idf.py \
|
||||
--project-dir jerryscript/targets/baremetal-sdk/espressif \
|
||||
--build-dir jerryscript/build/esp-idf \
|
||||
set-target esp32 \
|
||||
all
|
||||
```
|
||||
|
||||
The created binary is a `jerrycript.bin` named file located in `jerryscript/build/esp-idf` folder.
|
||||
|
||||
#### 4. Flash the device
|
||||
|
||||
Connect Micro-USB for charging and flashing the device. The device should be visible as /dev/ttyUSB0.
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
sudo python esp-idf/components/esptool_py/esptool/esptool.py \
|
||||
--chip esp32 \
|
||||
--port /dev/ttyUSB0 \
|
||||
--baud 460800 \
|
||||
--before default_reset \
|
||||
--after hard_reset \
|
||||
write_flash \
|
||||
--flash_mode dio \
|
||||
--flash_size detect \
|
||||
--flash_freq 40m \
|
||||
0x1000 jerryscript/build/esp-idf/bootloader/bootloader.bin \
|
||||
0x8000 jerryscript/build/esp-idf/partition_table/partition-table.bin \
|
||||
0x10000 jerryscript/build/esp-idf/jerryscript.bin
|
||||
```
|
||||
|
||||
#### 5. Connect to the device
|
||||
|
||||
esp-idf provides a Python script for serial communication.
|
||||
Other programs also can be used such as minicom, picocom, etc.
|
||||
|
||||
* The device should be visible as `/dev/ttyUSB0`
|
||||
* The device uses `115200` baud rate for serial communication
|
||||
* Press `CTRL` + `ALT` + `]` to exit monitor program
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
PATH=${PWD}/xtensa-esp32-elf/bin:$PATH esp-idf/tools/idf_monitor.py \
|
||||
--port /dev/ttyUSB0 \
|
||||
--baud 115200 \
|
||||
--toolchain-prefix=xtensa-esp32-elf- \
|
||||
jerryscript/build/esp-idf/jerryscript.elf
|
||||
```
|
||||
|
||||
The following output should be captured:
|
||||
|
||||
```
|
||||
I (0) cpu_start: App cpu up.
|
||||
I (326) cpu_start: Pro cpu start user code
|
||||
I (326) cpu_start: cpu freq: 160000000
|
||||
I (326) cpu_start: Application information:
|
||||
I (331) cpu_start: Project name: jerryscript
|
||||
I (336) cpu_start: App version: v2.4.0-278-ge815e540-dirty
|
||||
I (342) cpu_start: Compile time: Jan 21 2022 11:38:44
|
||||
I (349) cpu_start: ELF file SHA256: 2e874acb5a45c0cb...
|
||||
I (355) cpu_start: ESP-IDF: v4.4-beta1-284-gd83021a6e8-dirt
|
||||
I (362) heap_init: Initializing. RAM available for dynamic allocation:
|
||||
I (369) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
|
||||
I (375) heap_init: At 3FFB8510 len 00027AF0 (158 KiB): DRAM
|
||||
I (381) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
|
||||
I (387) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
|
||||
I (394) heap_init: At 4008B3E8 len 00014C18 (83 KiB): IRAM
|
||||
I (401) spi_flash: detected chip: generic
|
||||
I (405) spi_flash: flash io: dio
|
||||
I (410) cpu_start: Starting scheduler on PRO CPU.
|
||||
I (0) cpu_start: Starting scheduler on APP CPU.
|
||||
I (420) JS: This test run the following script code:
|
||||
I (430) JS: print ('Hello, World!');
|
||||
Hello, World!
|
||||
```
|
||||
@@ -0,0 +1,51 @@
|
||||
# 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 ESP8266 JerryScript target.
|
||||
|
||||
# Install tools via apt.
|
||||
install-apt-get-deps:
|
||||
sudo apt-get install -q -y wget
|
||||
|
||||
# Fetch and extract Xtensa toolchain.
|
||||
install-xtensa-lx106-gcc:
|
||||
wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz --no-check-certificate --directory-prefix /tmp
|
||||
tar xvfz /tmp/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz --directory /tmp
|
||||
|
||||
# Fetch Espressif SDK and install its dependencies.
|
||||
install-espressif-sdk:
|
||||
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git /tmp/ESP8266_RTOS_SDK -b release/v3.4
|
||||
python -m pip install --user -r /tmp/ESP8266_RTOS_SDK/requirements.txt
|
||||
|
||||
# Perform all the necessary (JerryScript-independent) installation steps. - edited -
|
||||
install-noapt: install-xtensa-lx106-gcc install-espressif-sdk
|
||||
install: install-apt-get-deps install-noapt
|
||||
|
||||
|
||||
## Targets for building ESP8266 with JerryScript.
|
||||
|
||||
# Build the firmware (ESP8266 with JerryScript).
|
||||
script:
|
||||
PATH=/tmp/xtensa-lx106-elf/bin:$(PATH) \
|
||||
python /tmp/ESP8266_RTOS_SDK/tools/idf.py \
|
||||
--project-dir ./targets/baremetal-sdk/espressif \
|
||||
--build-dir ./build/esp8266-rtos-sdk \
|
||||
all
|
||||
@@ -0,0 +1,128 @@
|
||||
### About
|
||||
|
||||
This folder contains files to run JerryScript on
|
||||
[ESP8666 board](https://www.espressif.com/en/products/socs/esp8266) with
|
||||
[ESP8266 RTOS SDK](https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/).
|
||||
The document had been validated on Ubuntu 20.04 operating system.
|
||||
|
||||
### How to build
|
||||
|
||||
#### 1. Setup the build environment
|
||||
|
||||
Clone the necessary projects into a `jerry-esp` directory.
|
||||
The latest tested working version of ESP8266 RTOS SDK is `release/v3.4`.
|
||||
|
||||
```sh
|
||||
# Create a base folder for all the projects.
|
||||
mkdir jerry-esp && cd jerry-esp
|
||||
|
||||
git clone https://github.com/jerryscript-project/jerryscript.git
|
||||
git clone https://github.com/espressif/ESP8266_RTOS_SDK -b release/v3.4
|
||||
|
||||
# SDK requires Xtensa toolchain.
|
||||
wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
|
||||
```
|
||||
|
||||
The following directory structure has been created:
|
||||
|
||||
```
|
||||
jerry-esp
|
||||
+ jerryscript
|
||||
| + targets
|
||||
| + baremetal-sdk
|
||||
| + espressif
|
||||
|
|
||||
+ ESP8266_RTOS_SDK
|
||||
+ xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
|
||||
```
|
||||
|
||||
#### 2. Install dependencies of the projects
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
jerryscript/tools/apt-get-install-deps.sh
|
||||
|
||||
# Install dependencies of ESP8266-RTOS-SDK.
|
||||
python -m pip install --user -r ESP8266_RTOS_SDK/requirements.txt
|
||||
|
||||
# Extract the downloaded toolchain.
|
||||
tar -xvf xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
|
||||
```
|
||||
|
||||
#### 3. Build ESP8266-RTOS-SDK (with JerryScript)
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
PATH=${PWD}/xtensa-lx106-elf/bin:$PATH ESP8266_RTOS_SDK/tools/idf.py \
|
||||
--project-dir jerryscript/targets/baremetal-sdk/espressif \
|
||||
--build-dir jerryscript/build/esp8266-rtos-sdk \
|
||||
all
|
||||
```
|
||||
|
||||
The created binary is a `jerryscript.bin` named file located in `jerryscript/build/esp8266-rtos-sdk` folder.
|
||||
|
||||
#### 4. Flash the device
|
||||
|
||||
Connect Micro-USB for charging and flashing the device. The device should be visible as /dev/ttyUSB0.
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
sudo python ESP8266_RTOS_SDK/components/esptool_py/esptool/esptool.py \
|
||||
--port /dev/ttyUSB0 \
|
||||
--baud 460800 \
|
||||
--before default_reset \
|
||||
--after hard_reset \
|
||||
write_flash \
|
||||
--flash_mode dio \
|
||||
--flash_freq 40m \
|
||||
--flash_size 2MB \
|
||||
0x0 jerryscript/build/esp8266-rtos-sdk/bootloader/bootloader.bin \
|
||||
0x8000 jerryscript/build/esp8266-rtos-sdk/partition_table/partition-table.bin \
|
||||
0x10000 jerryscript/build/esp8266-rtos-sdk/jerryscript.bin
|
||||
```
|
||||
|
||||
#### 5. Connect to the device
|
||||
|
||||
ESP8266-RTOS-SDK provides a Python script for serial communication.
|
||||
Other programs also can be used such as minicom, picocom, etc.
|
||||
|
||||
* The device should be visible as `/dev/ttyUSB0`
|
||||
* The device uses `74880` baud rate for serial communication
|
||||
* Press `CTRL` + `ALT` + `]` to exit monitor program
|
||||
|
||||
```sh
|
||||
# Assuming you are in jerry-esp folder.
|
||||
sudo PATH=${PWD}/xtensa-lx106-elf/bin:$PATH ESP8266_RTOS_SDK/tools/idf_monitor.py \
|
||||
--port /dev/ttyUSB0 \
|
||||
--baud 78880 \
|
||||
--toolchain-prefix=xtensa-lx106-elf- \
|
||||
jerryscript/build/esp8266-rtos-sdk/jerryscript.elf
|
||||
```
|
||||
|
||||
The following output should be captured:
|
||||
|
||||
```
|
||||
I (43) boot: ESP-IDF v3.4-43-ge9516e4c 2nd stage bootloader
|
||||
I (43) boot: compile time 11:14:06
|
||||
I (43) qio_mode: Enabling default flash chip QIO
|
||||
I (51) boot: SPI Speed : 40MHz
|
||||
I (57) boot: SPI Mode : QIO
|
||||
I (63) boot: SPI Flash Size : 2MB
|
||||
I (69) boot: Partition Table:
|
||||
I (75) boot: ## Label Usage Type ST Offset Length
|
||||
I (86) boot: 0 nvs WiFi data 01 02 00009000 00006000
|
||||
I (97) boot: 1 phy_init RF data 01 01 0000f000 00001000
|
||||
I (108) boot: 2 factory factory app 00 00 00010000 000f0000
|
||||
I (120) boot: End of partition table
|
||||
I (126) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x5c540 (378176) map
|
||||
0x40210010: _stext at ??:?
|
||||
|
||||
I (140) esp_image: segment 1: paddr=0x0006c558 vaddr=0x4026c550 size=0x0baa8 ( 47784) map
|
||||
I (153) esp_image: segment 2: paddr=0x00078008 vaddr=0x3ffe8000 size=0x0042c ( 1068) load
|
||||
I (167) esp_image: segment 3: paddr=0x0007843c vaddr=0x40100000 size=0x00080 ( 128) load
|
||||
I (181) esp_image: segment 4: paddr=0x000784c4 vaddr=0x40100080 size=0x0484c ( 18508) load
|
||||
I (194) boot: Loaded app from partition at offset 0x10000
|
||||
I (215) JS: This test run the following script code:
|
||||
I (216) JS: print ('Hello, World!');
|
||||
Hello, World!
|
||||
```
|
||||
@@ -0,0 +1,52 @@
|
||||
# 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.
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# Set JerryScript variables
|
||||
set(JERRY_ROOT_DIR ${PROJECT_DIR}/../../..)
|
||||
set(JERRY_BUILD_DIR ${JERRY_ROOT_DIR}/build/jerry)
|
||||
set(JERRY_INCLUDE_DIRS "${JERRY_ROOT_DIR}/jerry-ext/include" "${JERRY_ROOT_DIR}/jerry-core/include")
|
||||
set(JERRY_HEAP_SIZE 20)
|
||||
|
||||
# Make compile flags separated by spaces
|
||||
string(REPLACE ";" " " COMPILE_FLAGS "${COMPILE_OPTIONS};${C_COMPILE_OPTIONS}")
|
||||
|
||||
# Build JerryScript
|
||||
execute_process(COMMAND ${JERRY_ROOT_DIR}/tools/build.py
|
||||
--clean
|
||||
--builddir=${JERRY_BUILD_DIR}
|
||||
--lto=OFF
|
||||
--jerry-cmdline=OFF
|
||||
--jerry-math=OFF
|
||||
--amalgam=ON
|
||||
--mem-heap=${JERRY_HEAP_SIZE}
|
||||
--profile=es.next
|
||||
--compile-flag=${COMPILE_FLAGS}
|
||||
--toolchain=${CMAKE_TOOLCHAIN_FILE})
|
||||
|
||||
# Register JerryScript target application
|
||||
idf_component_register(SRCS "jerry-main.c" "jerry-port.c" INCLUDE_DIRS ${JERRY_INCLUDE_DIRS})
|
||||
|
||||
add_library(jerry-core STATIC IMPORTED)
|
||||
add_library(jerry-ext STATIC IMPORTED)
|
||||
add_library(jerry-port STATIC IMPORTED)
|
||||
|
||||
set_target_properties(jerry-core PROPERTIES IMPORTED_LOCATION "${JERRY_BUILD_DIR}/lib/libjerry-core.a")
|
||||
set_target_properties(jerry-ext PROPERTIES IMPORTED_LOCATION "${JERRY_BUILD_DIR}/lib/libjerry-ext.a")
|
||||
set_target_properties(jerry-port PROPERTIES IMPORTED_LOCATION "${JERRY_BUILD_DIR}/lib/libjerry-port.a")
|
||||
|
||||
# jerry-core has espressif/main/jerry-port.c as dependency
|
||||
target_link_libraries(jerry-core INTERFACE ${COMPONENT_LIB})
|
||||
# jerry-main has jerry-core, jerry-ext, jerry-port as dependencies
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE jerry-core jerry-ext jerry-port)
|
||||
@@ -0,0 +1,54 @@
|
||||
/* 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 "jerryscript.h"
|
||||
#include "jerryscript-ext/handlers.h"
|
||||
#include "jerryscript-ext/properties.h"
|
||||
|
||||
/**
|
||||
* Jerryscript simple test
|
||||
*/
|
||||
void app_main()
|
||||
{
|
||||
jerry_value_t ret_value = jerry_undefined ();
|
||||
const jerry_char_t script[] = "print ('Hello, World!');";
|
||||
|
||||
/* Initialize engine */
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
jerry_log_set_level (JERRY_LOG_LEVEL_DEBUG);
|
||||
jerry_log (JERRY_LOG_LEVEL_DEBUG, "This test run the following script code: %s", script);
|
||||
|
||||
/* Register the print function in the global object */
|
||||
jerryx_register_global ("print", jerryx_handler_print);
|
||||
|
||||
/* Setup Global scope code */
|
||||
ret_value = jerry_parse (script, sizeof (script) - 1, NULL);
|
||||
|
||||
if (!jerry_value_is_exception (ret_value))
|
||||
{
|
||||
/* Execute the parsed source code in the Global scope */
|
||||
ret_value = jerry_run (ret_value);
|
||||
}
|
||||
|
||||
if (jerry_value_is_exception (ret_value))
|
||||
{
|
||||
jerry_log (JERRY_LOG_LEVEL_DEBUG, "Script error...\n\n");
|
||||
}
|
||||
|
||||
jerry_value_free (ret_value);
|
||||
|
||||
/* Cleanup engine */
|
||||
jerry_cleanup ();
|
||||
} /* test_jerry */
|
||||
@@ -0,0 +1,91 @@
|
||||
/* 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 <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
static const char ESP_JS_TAG[] = "JS";
|
||||
|
||||
/**
|
||||
* Provide log message implementation for the engine.
|
||||
*/
|
||||
void
|
||||
jerry_port_log (const char *message_p) /**< message */
|
||||
{
|
||||
ESP_LOGI (ESP_JS_TAG, "%s", message_p);
|
||||
} /* jerry_port_log */
|
||||
|
||||
/**
|
||||
* Implementation of jerry_port_fatal.
|
||||
* Calls 'abort' if exit code is non-zero, 'exit' otherwise.
|
||||
*/
|
||||
void
|
||||
jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
|
||||
{
|
||||
ESP_LOGE (ESP_JS_TAG, "Fatal error: %d", code);
|
||||
vTaskSuspend (NULL);
|
||||
abort ();
|
||||
} /* jerry_port_fatal */
|
||||
|
||||
/**
|
||||
* Default implementation of jerry_port_local_tza. Uses the 'tm_gmtoff' field
|
||||
* of 'struct tm' (a GNU extension) filled by 'localtime_r' if available on the
|
||||
* system, does nothing otherwise.
|
||||
*
|
||||
* @return offset between UTC and local time at the given unix timestamp, if
|
||||
* available. Otherwise, returns 0, assuming UTC time.
|
||||
*/
|
||||
int32_t
|
||||
jerry_port_local_tza (double unix_ms)
|
||||
{
|
||||
struct tm tm;
|
||||
char buf[8];
|
||||
time_t now = (time_t) unix_ms / 1000;
|
||||
|
||||
localtime_r (&now, &tm);
|
||||
strftime (buf, 8, "%z", &tm);
|
||||
return -atoi (buf) * 3600 * 1000 / 100;
|
||||
} /* jerry_port_local_tza */
|
||||
|
||||
/**
|
||||
* Implementation of jerry_port_get_current_time.
|
||||
* Uses 'gettimeofday' if available on the system, does nothing otherwise.
|
||||
*
|
||||
* @return milliseconds since Unix epoch if 'gettimeofday' is available
|
||||
* 0 - otherwise.
|
||||
*/
|
||||
double
|
||||
jerry_port_current_time (void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
if (gettimeofday (&tv, NULL) == 0)
|
||||
{
|
||||
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
|
||||
}
|
||||
return 0.0;
|
||||
} /* jerry_port_current_time */
|
||||
Reference in New Issue
Block a user