forked from xuos/xiuos
1、git submodule add jerryscript v2.4.0
2、support JerryScript on XiZi for stm32f407-st-discovery board and cortex-m4-emulator
This commit is contained in:
parent
e2edd918c3
commit
fa2c91e690
|
@ -32,3 +32,6 @@
|
||||||
[submodule "APP_Framework/lib/lorawan/lorawan_gateway_single_channel"]
|
[submodule "APP_Framework/lib/lorawan/lorawan_gateway_single_channel"]
|
||||||
path = APP_Framework/lib/lorawan/lorawan_gateway_single_channel
|
path = APP_Framework/lib/lorawan/lorawan_gateway_single_channel
|
||||||
url = https://gitlink.org.cn/IACU/lorawan_gateway_single_channel.git
|
url = https://gitlink.org.cn/IACU/lorawan_gateway_single_channel.git
|
||||||
|
[submodule "APP_Framework/lib/JerryScript/jerryscript"]
|
||||||
|
path = APP_Framework/lib/JerryScript/jerryscript
|
||||||
|
url = https://gitlink.org.cn/wgzAIIT/jerryscript.git
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
menu "lib using JerryScript"
|
||||||
|
menuconfig PKG_USING_JERRYSCRIPT
|
||||||
|
bool "JerryScript: Ultra-lightweight JavaScript engine for the Internet of Things."
|
||||||
|
default n
|
||||||
|
endmenu
|
|
@ -0,0 +1,8 @@
|
||||||
|
SRC_FILES :=
|
||||||
|
SRC_FILES += jerryscript/build/lib/libjerry-core.a \
|
||||||
|
jerryscript/build/lib/libjerry-ext.a \
|
||||||
|
jerryscript/build/lib/libjerry-math.a
|
||||||
|
|
||||||
|
SRC_FILES += setjmp.S jerry_port.c jerry_main.c
|
||||||
|
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,58 @@
|
||||||
|
# jerryscript编译步骤,依赖 Ubuntu 20.04 操作系统.
|
||||||
|
## 1、jerryscript源码下载
|
||||||
|
|
||||||
|
JerryScript 源码以子模块的形式保存在xiuos/APP_Framework/lib/JerryScript/jerryscript下,进行编译前需要下载,在xiuos根目录下执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git submodule
|
||||||
|
git submodule init
|
||||||
|
git submodule update APP_Framework/lib/JerryScript/jerryscript
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2、jerryscript编译依赖安装
|
||||||
|
|
||||||
|
第一次编译需要安装依赖,在APP_Framework/lib/JerryScript路径下,依次执行:
|
||||||
|
|
||||||
|
```
|
||||||
|
jerryscript/tools/apt-get-install-deps.sh
|
||||||
|
sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi
|
||||||
|
sudo apt install \
|
||||||
|
bison flex gettext texinfo libncurses5-dev libncursesw5-dev \
|
||||||
|
gperf automake libtool pkg-config build-essential gperf genromfs \
|
||||||
|
libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \
|
||||||
|
libexpat-dev gcc-multilib g++-multilib picocom u-boot-tools util-linux
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3、jerryscript源码编译
|
||||||
|
|
||||||
|
在APP_Framework/lib/JerryScript路径下,以stm32f4discovery开发板为例,执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
jerryscript/tools/build.py \
|
||||||
|
--clean \
|
||||||
|
--lto=OFF \
|
||||||
|
--jerry-cmdline=OFF \
|
||||||
|
--jerry-math=ON \
|
||||||
|
--amalgam=ON \
|
||||||
|
--mem-heap=70 \
|
||||||
|
--profile=es.next \
|
||||||
|
--toolchain=${PWD}/jerryscript/cmake/toolchain_mcu_stm32f4.cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4、stm32f4discovery开发板bin包构建
|
||||||
|
|
||||||
|
在xiuos/Ubiquitous/XiZi_IIoT目录下,执行
|
||||||
|
|
||||||
|
```makefile
|
||||||
|
make BOARD=stm32f407-st-discovery menuconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
然后在menuconfig界面进入APP_Framework → app lib → lib using JerryScript ,完成勾选,保存退出。
|
||||||
|
|
||||||
|
执行
|
||||||
|
|
||||||
|
```makefile
|
||||||
|
make BOARD=stm32f407-st-discovery
|
||||||
|
```
|
||||||
|
|
||||||
|
完成编译。
|
|
@ -0,0 +1,242 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file jerry_main.c
|
||||||
|
* @brief support jerryscript
|
||||||
|
* @version 1.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2023.08.07
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <jerryscript.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <transform.h>
|
||||||
|
|
||||||
|
bool js_parse_test1(void* parameter)
|
||||||
|
{
|
||||||
|
bool run_ok = false;
|
||||||
|
|
||||||
|
const jerry_char_t script[] = "var str = 'Hello, World!';";
|
||||||
|
|
||||||
|
/* Initialize engine */
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
/* Setup Global scope code */
|
||||||
|
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
|
||||||
|
|
||||||
|
/* Check if there is any JS code parse error */
|
||||||
|
if (!jerry_value_is_error (parsed_code))
|
||||||
|
{
|
||||||
|
/* Execute the parsed source code in the Global scope */
|
||||||
|
jerry_value_t ret_value = jerry_run (parsed_code);
|
||||||
|
|
||||||
|
/* Check the execution return value if there is any error */
|
||||||
|
run_ok = !jerry_value_is_error (ret_value);
|
||||||
|
|
||||||
|
/* Returned value must be freed */
|
||||||
|
jerry_release_value (ret_value);
|
||||||
|
printf("jerry_run ret=%d\n", ret_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parsed source code must be freed */
|
||||||
|
jerry_release_value (parsed_code);
|
||||||
|
|
||||||
|
/* Cleanup engine */
|
||||||
|
jerry_cleanup ();
|
||||||
|
|
||||||
|
printf("run_ok is %d.\n", run_ok);
|
||||||
|
|
||||||
|
return (run_ok ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int js_parse_test2(void* parameter)
|
||||||
|
{
|
||||||
|
int return_value = 1;
|
||||||
|
|
||||||
|
/* Initialize engine */
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
/* Parse the 'function (a,b) { return a + b; }' function */
|
||||||
|
const char function_args[] = "a, b";
|
||||||
|
const char function_source[] = "return a * b";
|
||||||
|
|
||||||
|
jerry_value_t parsed_function = jerry_parse_function (NULL,
|
||||||
|
0,
|
||||||
|
(const jerry_char_t *) function_args,
|
||||||
|
strlen (function_args),
|
||||||
|
(const jerry_char_t *) function_source,
|
||||||
|
strlen (function_source),
|
||||||
|
JERRY_PARSE_NO_OPTS);
|
||||||
|
|
||||||
|
if (!jerry_value_is_error (parsed_function))
|
||||||
|
{
|
||||||
|
/* Run the parsed function */
|
||||||
|
jerry_value_t args[] = {
|
||||||
|
jerry_create_number (3),
|
||||||
|
jerry_create_number (55),
|
||||||
|
};
|
||||||
|
jerry_size_t argc = sizeof (args) / sizeof (args[0]);
|
||||||
|
jerry_value_t ret_value = jerry_call_function (parsed_function,
|
||||||
|
jerry_create_undefined(),
|
||||||
|
args,
|
||||||
|
argc);
|
||||||
|
|
||||||
|
/* Process result value */
|
||||||
|
if (jerry_value_is_number (ret_value)) {
|
||||||
|
double value = jerry_get_number_value (ret_value);
|
||||||
|
printf ("Function result: %lf\n", value);
|
||||||
|
|
||||||
|
return_value = !(value == (3 * 55));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Release the function arguments */
|
||||||
|
for (jerry_size_t idx = 0; idx < argc; idx++) {
|
||||||
|
jerry_release_value (args[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returned value must be freed */
|
||||||
|
jerry_release_value (ret_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parsed function must be freed */
|
||||||
|
jerry_release_value (parsed_function);
|
||||||
|
|
||||||
|
/* Cleanup engine */
|
||||||
|
jerry_cleanup ();
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int js_parse_test3(void* parameter)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
jerry_value_t value;
|
||||||
|
// create or acquire value
|
||||||
|
value = jerry_create_string ((const jerry_char_t *) "Demo string");
|
||||||
|
|
||||||
|
// Read the string into a byte buffer.
|
||||||
|
jerry_size_t string_size = jerry_get_string_size (value);
|
||||||
|
jerry_char_t *string_buffer_p = (jerry_char_t *) malloc (sizeof (jerry_char_t) * (string_size + 1));
|
||||||
|
|
||||||
|
jerry_size_t copied_bytes = jerry_string_to_char_buffer (value, string_buffer_p, string_size);
|
||||||
|
string_buffer_p[copied_bytes] = '\0';
|
||||||
|
|
||||||
|
jerry_release_value (value);
|
||||||
|
|
||||||
|
jerry_cleanup ();
|
||||||
|
|
||||||
|
printf ("Test string: %s\n", string_buffer_p);
|
||||||
|
free (string_buffer_p);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int counter = 0;
|
||||||
|
|
||||||
|
static jerry_value_t
|
||||||
|
method_getter (const jerry_value_t this_obj,
|
||||||
|
const jerry_value_t func_obj,
|
||||||
|
const jerry_value_t args[],
|
||||||
|
const jerry_length_t argc)
|
||||||
|
{
|
||||||
|
counter++;
|
||||||
|
printf("Getter called, returning: %d\n", counter);
|
||||||
|
|
||||||
|
return jerry_create_number (counter);
|
||||||
|
}
|
||||||
|
|
||||||
|
static jerry_value_t
|
||||||
|
method_setter (const jerry_value_t this_obj,
|
||||||
|
const jerry_value_t func_obj,
|
||||||
|
const jerry_value_t args[],
|
||||||
|
const jerry_length_t argc)
|
||||||
|
{
|
||||||
|
// Note: the arguments count and type should be checked
|
||||||
|
// in this example it is ommitted!
|
||||||
|
|
||||||
|
double new_value = jerry_get_number_value (args[0]);
|
||||||
|
counter = (int) new_value;
|
||||||
|
|
||||||
|
printf("Setter called, setting: %d\n", counter);
|
||||||
|
|
||||||
|
return jerry_create_undefined ();
|
||||||
|
}
|
||||||
|
|
||||||
|
int js_parse_test4(void* parameter)
|
||||||
|
{
|
||||||
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
|
jerry_value_t global_obj_val = jerry_get_global_object ();
|
||||||
|
|
||||||
|
// configure the property
|
||||||
|
jerry_property_descriptor_t prop_desc;
|
||||||
|
jerry_init_property_descriptor_fields (&prop_desc);
|
||||||
|
|
||||||
|
// set the property descriptor fields:
|
||||||
|
|
||||||
|
prop_desc.is_get_defined = true;
|
||||||
|
prop_desc.getter = jerry_create_external_function (method_getter);
|
||||||
|
prop_desc.is_set_defined = true;
|
||||||
|
prop_desc.setter = jerry_create_external_function (method_setter);
|
||||||
|
|
||||||
|
// add the property as "my_prop" for the global object
|
||||||
|
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop");
|
||||||
|
jerry_value_t return_value = jerry_define_own_property (global_obj_val, prop_name, &prop_desc);
|
||||||
|
if (jerry_value_is_error (return_value))
|
||||||
|
{
|
||||||
|
// there was an error
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there was no error at this point the global object should have a "my_prop" property
|
||||||
|
|
||||||
|
jerry_release_value (return_value);
|
||||||
|
jerry_release_value (prop_name);
|
||||||
|
|
||||||
|
jerry_free_property_descriptor_fields (&prop_desc);
|
||||||
|
jerry_release_value (global_obj_val);
|
||||||
|
|
||||||
|
// run an example js code to use the getter/setters
|
||||||
|
|
||||||
|
const char *src_p = "this.my_prop; this.my_prop; this.my_prop = 4; this.my_prop";
|
||||||
|
jerry_value_t eval_result = jerry_eval ((const jerry_char_t *) src_p, strlen (src_p), JERRY_PARSE_NO_OPTS);
|
||||||
|
|
||||||
|
// "eval_result" is the last result of "this.my_prop" that is "5" currently.
|
||||||
|
double result_number = jerry_get_number_value (eval_result);
|
||||||
|
printf("output: %lf\n", result_number);
|
||||||
|
|
||||||
|
jerry_cleanup ();
|
||||||
|
|
||||||
|
return result_number != 5.0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jstest(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
pthread_t thread;
|
||||||
|
pthread_attr_t attr;
|
||||||
|
attr.schedparam.sched_priority = 22;
|
||||||
|
attr.stacksize = 8192;
|
||||||
|
int32 task = 0;
|
||||||
|
|
||||||
|
ret = PrivTaskCreate(&thread, &attr, (void*)js_parse_test4, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("taskcreate failed, status=%d\n", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PRIV_SHELL_CMD_FUNCTION(jstest, jerryscript test cmd, PRIV_SHELL_CMD_FUNC_ATTR);
|
|
@ -0,0 +1,264 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file jerry_port.c
|
||||||
|
* @brief support jerryscript
|
||||||
|
* @version 1.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2023.08.07
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "jerryscript.h"
|
||||||
|
#include "jerryscript-port.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JerryScript log level
|
||||||
|
*/
|
||||||
|
static jerry_log_level_t jerry_log_level = JERRY_LOG_LEVEL_ERROR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets log level.
|
||||||
|
*/
|
||||||
|
void set_log_level (jerry_log_level_t level)
|
||||||
|
{
|
||||||
|
jerry_log_level = level;
|
||||||
|
} /* set_log_level */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aborts the program.
|
||||||
|
*/
|
||||||
|
void jerry_port_fatal (jerry_fatal_code_t code)
|
||||||
|
{
|
||||||
|
exit (1);
|
||||||
|
} /* jerry_port_fatal */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide log message implementation for the engine.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
jerry_port_log (jerry_log_level_t level, /**< log level */
|
||||||
|
const char *format, /**< format string */
|
||||||
|
...) /**< parameters */
|
||||||
|
{
|
||||||
|
if (level <= jerry_log_level)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start (args, format);
|
||||||
|
vfprintf (stderr, format, args);
|
||||||
|
va_end (args);
|
||||||
|
}
|
||||||
|
} /* jerry_port_log */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the size of the given file.
|
||||||
|
* @return size of the file
|
||||||
|
*/
|
||||||
|
static size_t
|
||||||
|
jerry_port_get_file_size (FILE *file_p) /**< opened file */
|
||||||
|
{
|
||||||
|
fseek (file_p, 0, SEEK_END);
|
||||||
|
long size = ftell (file_p);
|
||||||
|
fseek (file_p, 0, SEEK_SET);
|
||||||
|
|
||||||
|
return (size_t) size;
|
||||||
|
} /* jerry_port_get_file_size */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens file with the given path and reads its source.
|
||||||
|
* @return the source of the file
|
||||||
|
*/
|
||||||
|
uint8_t *
|
||||||
|
jerry_port_read_source (const char *file_name_p, /**< file name */
|
||||||
|
size_t *out_size_p) /**< [out] read bytes */
|
||||||
|
{
|
||||||
|
FILE *file_p = fopen (file_name_p, "rb");
|
||||||
|
|
||||||
|
if (file_p == NULL)
|
||||||
|
{
|
||||||
|
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to open file: %s\n", file_name_p);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t file_size = jerry_port_get_file_size (file_p);
|
||||||
|
uint8_t *buffer_p = (uint8_t *) malloc (file_size);
|
||||||
|
|
||||||
|
if (buffer_p == NULL)
|
||||||
|
{
|
||||||
|
fclose (file_p);
|
||||||
|
|
||||||
|
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to allocate memory for module");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bytes_read = fread (buffer_p, 1u, file_size, file_p);
|
||||||
|
|
||||||
|
if (!bytes_read)
|
||||||
|
{
|
||||||
|
fclose (file_p);
|
||||||
|
free (buffer_p);
|
||||||
|
|
||||||
|
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to read file: %s\n", file_name_p);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (file_p);
|
||||||
|
*out_size_p = bytes_read;
|
||||||
|
|
||||||
|
return buffer_p;
|
||||||
|
} /* jerry_port_read_source */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the previously opened file's content.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
|
||||||
|
{
|
||||||
|
free (buffer_p);
|
||||||
|
} /* jerry_port_release_source */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a file path
|
||||||
|
*
|
||||||
|
* @return length of the path written to the output buffer
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
jerry_port_normalize_path (const char *in_path_p, /**< input file path */
|
||||||
|
char *out_buf_p, /**< output buffer */
|
||||||
|
size_t out_buf_size, /**< size of output buffer */
|
||||||
|
char *base_file_p) /**< base file path */
|
||||||
|
{
|
||||||
|
(void) base_file_p;
|
||||||
|
|
||||||
|
size_t len = strlen (in_path_p);
|
||||||
|
if (len + 1 > out_buf_size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the original string. */
|
||||||
|
strcpy (out_buf_p, in_path_p);
|
||||||
|
return len;
|
||||||
|
} /* jerry_port_normalize_path */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the module object of a native module.
|
||||||
|
*
|
||||||
|
* @return undefined
|
||||||
|
*/
|
||||||
|
jerry_value_t
|
||||||
|
jerry_port_get_native_module (jerry_value_t name) /**< module specifier */
|
||||||
|
{
|
||||||
|
(void) name;
|
||||||
|
return jerry_create_undefined ();
|
||||||
|
} /* jerry_port_get_native_module */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy function to get the time zone adjustment.
|
||||||
|
*
|
||||||
|
* @return 0
|
||||||
|
*/
|
||||||
|
double
|
||||||
|
jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc)
|
||||||
|
{
|
||||||
|
/* We live in UTC. */
|
||||||
|
return 0;
|
||||||
|
} /* jerry_port_get_local_time_zone_adjustment */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy function to get the current time.
|
||||||
|
*
|
||||||
|
* @return 0
|
||||||
|
*/
|
||||||
|
double
|
||||||
|
jerry_port_get_current_time (void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
} /* jerry_port_get_current_time */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide the implementation of jerry_port_print_char.
|
||||||
|
* Uses 'printf' to print a single character to standard output.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
jerry_port_print_char (char c) /**< the character to print */
|
||||||
|
{
|
||||||
|
printf ("%c", c);
|
||||||
|
} /* jerry_port_print_char */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide implementation of jerry_port_sleep.
|
||||||
|
*/
|
||||||
|
void jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
|
||||||
|
{
|
||||||
|
usleep ((useconds_t) sleep_time * 1000);
|
||||||
|
} /* jerry_port_sleep */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pointer to the current context.
|
||||||
|
*/
|
||||||
|
static jerry_context_t *current_context_p = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current_context_p as the passed pointer.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
jerry_port_default_set_current_context (jerry_context_t *context_p) /**< points to the created context */
|
||||||
|
{
|
||||||
|
current_context_p = context_p;
|
||||||
|
} /* jerry_port_default_set_current_context */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current context.
|
||||||
|
*
|
||||||
|
* @return the pointer to the current context
|
||||||
|
*/
|
||||||
|
jerry_context_t *
|
||||||
|
jerry_port_get_current_context (void)
|
||||||
|
{
|
||||||
|
return current_context_p;
|
||||||
|
} /* jerry_port_get_current_context */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Track unhandled promise rejections.
|
||||||
|
*
|
||||||
|
* Note:
|
||||||
|
* This port function is called by jerry-core when JERRY_BUILTIN_PROMISE
|
||||||
|
* is enabled.
|
||||||
|
*
|
||||||
|
* @param promise rejected promise
|
||||||
|
* @param operation HostPromiseRejectionTracker operation
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
jerry_port_track_promise_rejection (const jerry_value_t promise,
|
||||||
|
const jerry_promise_rejection_operation_t operation)
|
||||||
|
{
|
||||||
|
(void) operation; /* unused */
|
||||||
|
|
||||||
|
jerry_value_t reason = jerry_get_promise_result (promise);
|
||||||
|
jerry_value_t reason_to_string = jerry_value_to_string (reason);
|
||||||
|
jerry_size_t req_sz = jerry_get_utf8_string_size (reason_to_string);
|
||||||
|
jerry_char_t str_buf_p[req_sz + 1];
|
||||||
|
jerry_string_to_utf8_char_buffer (reason_to_string, str_buf_p, req_sz);
|
||||||
|
str_buf_p[req_sz] = '\0';
|
||||||
|
|
||||||
|
jerry_release_value (reason_to_string);
|
||||||
|
jerry_release_value (reason);
|
||||||
|
|
||||||
|
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught (in promise) %s\n", str_buf_p);
|
||||||
|
} /* jerry_port_track_promise_rejection */
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 8ba0d1b6ee5a065a42f3b306771ad8e3c0d819bc
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.syntax unified
|
||||||
|
|
||||||
|
.macro func _name
|
||||||
|
.global \_name
|
||||||
|
.type \_name, %function
|
||||||
|
\_name:
|
||||||
|
.endm
|
||||||
|
.macro endfunc _name
|
||||||
|
.size \_name, .-\_name
|
||||||
|
.endm
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setjmp (jmp_buf env)
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* longjmp
|
||||||
|
*
|
||||||
|
* @return 0 - if returns from direct call,
|
||||||
|
* nonzero - if returns after longjmp.
|
||||||
|
*/
|
||||||
|
func setjmp
|
||||||
|
stmia r0!, {r4 - r11, lr}
|
||||||
|
str sp, [r0], #4
|
||||||
|
vstm r0, {s16 - s31}
|
||||||
|
mov r0, #0
|
||||||
|
bx lr
|
||||||
|
endfunc setjmp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* longjmp (jmp_buf env, int val)
|
||||||
|
*
|
||||||
|
* Note:
|
||||||
|
* if val is not 0, then it would be returned from setjmp,
|
||||||
|
* otherwise - 0 would be returned.
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* setjmp
|
||||||
|
*/
|
||||||
|
func longjmp
|
||||||
|
ldmia r0!, {r4 - r11, lr}
|
||||||
|
ldr sp, [r0]
|
||||||
|
add r0, r0, #4
|
||||||
|
vldm r0, {s16 - s31}
|
||||||
|
mov r0, r1
|
||||||
|
cmp r0, #0
|
||||||
|
bne 1f
|
||||||
|
mov r0, #1
|
||||||
|
1:
|
||||||
|
bx lr
|
||||||
|
endfunc longjmp
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file setjmp.h
|
||||||
|
* @brief support jerryscript
|
||||||
|
* @version 1.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2023.08.07
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SETJMP_H
|
||||||
|
#define SETJMP_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef uint64_t jmp_buf[14];
|
||||||
|
|
||||||
|
int setjmp (jmp_buf env);
|
||||||
|
void longjmp (jmp_buf env, int val);
|
||||||
|
|
||||||
|
#endif /* !SETJMP_H */
|
|
@ -15,4 +15,5 @@ menu "app lib"
|
||||||
source "$APP_DIR/lib/embedded_database/Kconfig"
|
source "$APP_DIR/lib/embedded_database/Kconfig"
|
||||||
source "$APP_DIR/lib/lorawan/Kconfig"
|
source "$APP_DIR/lib/lorawan/Kconfig"
|
||||||
source "$APP_DIR/lib/mqtt/Kconfig"
|
source "$APP_DIR/lib/mqtt/Kconfig"
|
||||||
|
source "$APP_DIR/lib/JerryScript/Kconfig"
|
||||||
endmenu
|
endmenu
|
||||||
|
|
|
@ -22,4 +22,8 @@ ifeq ($(CONFIG_TOOL_USING_MQTT),y)
|
||||||
SRC_DIR += mqtt
|
SRC_DIR += mqtt
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_PKG_USING_JERRYSCRIPT),y)
|
||||||
|
SRC_DIR += JerryScript
|
||||||
|
endif
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
||||||
|
|
||||||
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
|
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
|
||||||
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
|
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb
|
||||||
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-cortex-m4-emulator.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-cortex-m4-emulator.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
||||||
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
|
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -Werror
|
||||||
|
|
||||||
ifeq ($(CONFIG_LIB_MUSLLIB), y)
|
ifeq ($(CONFIG_LIB_MUSLLIB), y)
|
||||||
export LFLAGS += -nostdlib -nostdinc -fno-builtin -nodefaultlibs
|
export LFLAGS += -nostdlib -nostdinc -fno-builtin -nodefaultlibs
|
||||||
|
|
|
@ -63,6 +63,7 @@ SECTIONS
|
||||||
PROVIDE(g_service_table_end = ABSOLUTE(.));
|
PROVIDE(g_service_table_end = ABSOLUTE(.));
|
||||||
|
|
||||||
PROVIDE(_etext = ABSOLUTE(.));
|
PROVIDE(_etext = ABSOLUTE(.));
|
||||||
|
_exit = .;
|
||||||
} > flash
|
} > flash
|
||||||
|
|
||||||
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
||||||
|
|
||||||
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb
|
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Dgcc -O0 -fgnu89-inline -Wa,-mimplicit-it=thumb
|
||||||
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
|
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb
|
||||||
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-stm32f407-st-discovery.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-stm32f407-st-discovery.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
||||||
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
|
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Dgcc -O0 -Werror
|
||||||
|
|
||||||
ifeq ($(CONFIG_LIB_MUSLLIB), y)
|
ifeq ($(CONFIG_LIB_MUSLLIB), y)
|
||||||
export LFLAGS += -nostdlib -nostdinc -fno-builtin -nodefaultlibs
|
export LFLAGS += -nostdlib -nostdinc -fno-builtin -nodefaultlibs
|
||||||
|
|
|
@ -63,6 +63,7 @@ SECTIONS
|
||||||
PROVIDE(g_service_table_end = ABSOLUTE(.));
|
PROVIDE(g_service_table_end = ABSOLUTE(.));
|
||||||
|
|
||||||
PROVIDE(_etext = ABSOLUTE(.));
|
PROVIDE(_etext = ABSOLUTE(.));
|
||||||
|
_exit = .;
|
||||||
} > flash
|
} > flash
|
||||||
|
|
||||||
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||||
|
|
|
@ -584,6 +584,13 @@ ifeq ($(CONFIG_TOOL_USING_MQTT), y)
|
||||||
KERNELPATHS +=-I$(KERNEL_ROOT)/../../APP_Framework/lib/mqtt
|
KERNELPATHS +=-I$(KERNEL_ROOT)/../../APP_Framework/lib/mqtt
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_PKG_USING_JERRYSCRIPT), y)
|
||||||
|
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/lib/JerryScript
|
||||||
|
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/lib/JerryScript/jerryscript/jerry-core/include
|
||||||
|
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/lib/JerryScript/jerryscript/jerry-ext/include
|
||||||
|
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/lib/JerryScript/jerryscript/jerry-math/include
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_FS_LWEXT4),y)
|
ifeq ($(CONFIG_FS_LWEXT4),y)
|
||||||
KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/blockdev/xiuos #
|
KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/blockdev/xiuos #
|
||||||
KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/include #
|
KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/include #
|
||||||
|
|
Loading…
Reference in New Issue