forked from xuos/xiuos
support jerryscript on edu-arm32 board and add test case
This commit is contained in:
parent
7ce3748947
commit
bb0fb51e7e
|
@ -3,6 +3,18 @@ SRC_FILES += jerryscript/build/lib/libjerry-core.a \
|
||||||
jerryscript/build/lib/libjerry-ext.a \
|
jerryscript/build/lib/libjerry-ext.a \
|
||||||
jerryscript/build/lib/libjerry-math.a
|
jerryscript/build/lib/libjerry-math.a
|
||||||
|
|
||||||
SRC_FILES += setjmp.S jerry_port.c jerry_main.c jerry_test.c
|
ifeq ($(CONFIG_BOARD_STM32F407_EVB),y)
|
||||||
|
SRC_FILES += mcu/stm32f4/setjmp.S
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_BOARD_CORTEX_M4_EVB),y)
|
||||||
|
SRC_FILES += mcu/cortex-m4-emulator/setjmp.S
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_BOARD_EDU_ARM32_EVB),y)
|
||||||
|
SRC_FILES += mcu/hc32f4a0/setjmp.S
|
||||||
|
endif
|
||||||
|
|
||||||
|
SRC_FILES += jerry_port.c jerry_main.c jerry_test.c
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# jerryscript编译步骤,依赖 Ubuntu 20.04 操作系统.
|
# jerryscript编译步骤,本文档依赖 Ubuntu 20.04 操作系统.
|
||||||
## 1、jerryscript源码下载
|
## 1、jerryscript源码下载
|
||||||
|
|
||||||
JerryScript 源码以子模块的形式保存在xiuos/APP_Framework/lib/JerryScript/jerryscript下,进行编译前需要下载,在xiuos根目录下执行:
|
JerryScript 源码以子模块的形式保存在xiuos/APP_Framework/lib/JerryScript/jerryscript下,进行编译前需要下载,在xiuos根目录下执行:
|
||||||
|
@ -25,7 +25,7 @@ sudo apt install \
|
||||||
|
|
||||||
## 3、jerryscript源码编译
|
## 3、jerryscript源码编译
|
||||||
|
|
||||||
在APP_Framework/lib/JerryScript路径下,以stm32f4discovery开发板为例,执行:
|
当前在XIZI操作系统下,支持HC32F4A0单片机和STM32F4单片机两个系列的开发板,在APP_Framework/lib/JerryScript路径下,以edu-arm32开发板(HC32F4A0单片机)为例,执行:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
jerryscript/tools/build.py \
|
jerryscript/tools/build.py \
|
||||||
|
@ -36,23 +36,37 @@ jerryscript/tools/build.py \
|
||||||
--amalgam=ON \
|
--amalgam=ON \
|
||||||
--mem-heap=70 \
|
--mem-heap=70 \
|
||||||
--profile=es.next \
|
--profile=es.next \
|
||||||
--toolchain=${PWD}/jerryscript/cmake/toolchain_mcu_stm32f4.cmake
|
--toolchain=${PWD}/jerryscript/cmake/toolchain_mcu_hc32f4a0.cmake
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4、stm32f4discovery开发板bin包构建
|
如果是STM32F4的单片机,将.cmake指定为toolchain_mcu_stm32f4.cmake即可。
|
||||||
|
|
||||||
|
## 4、edu-arm32开发板bin包构建
|
||||||
|
|
||||||
在xiuos/Ubiquitous/XiZi_IIoT目录下,执行
|
在xiuos/Ubiquitous/XiZi_IIoT目录下,执行
|
||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
make BOARD=stm32f407-st-discovery menuconfig
|
make BOARD=edu-arm32 menuconfig
|
||||||
```
|
```
|
||||||
|
|
||||||
然后在menuconfig界面进入APP_Framework → app lib → lib using JerryScript ,完成勾选,保存退出。
|
然后在menuconfig界面进入APP_Framework → app lib → lib using JerryScript ,完成勾选;
|
||||||
|
|
||||||
|
为了支持文件解析,需要存储js文件,勾选edu-arm32 feature → Using SD CARD device,使用sd卡进行.js文件的保存。
|
||||||
|
|
||||||
|
保存并,退出menuconfig
|
||||||
|
|
||||||
执行
|
执行
|
||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
make BOARD=stm32f407-st-discovery
|
make BOARD=BOARD=edu-arm32
|
||||||
```
|
```
|
||||||
|
|
||||||
完成编译。
|
完成编译,edu-arm32开发板的烧录方式参考xiuos/Ubiquitous/XiZi_IIoT/board/edu-arm32/目录下的README.md。
|
||||||
|
|
||||||
|
完成烧录后,插入存有js文件的内存卡,内存卡正确完成挂载后,执行:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
jerrytest xxx.js
|
||||||
|
```
|
||||||
|
|
||||||
|
即可看到执行js文件解析,如果jerrytest没有带文件参数,则执行一条js的语句退出。
|
||||||
|
|
|
@ -272,6 +272,41 @@ static void register_js_function (const char *name_p,jerry_external_handler_t ha
|
||||||
jerry_release_value (result_val);
|
jerry_release_value (result_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void js_add_function(const jerry_value_t obj, const char *name,
|
||||||
|
jerry_external_handler_t func)
|
||||||
|
{
|
||||||
|
jerry_value_t str = jerry_create_string((const jerry_char_t *)name);
|
||||||
|
jerry_value_t jfunc = jerry_create_external_function(func);
|
||||||
|
|
||||||
|
jerry_set_property(obj, str, jfunc);
|
||||||
|
|
||||||
|
jerry_release_value(str);
|
||||||
|
jerry_release_value(jfunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void js_set_property(const jerry_value_t obj, const char *name,
|
||||||
|
const jerry_value_t prop)
|
||||||
|
{
|
||||||
|
jerry_value_t str = jerry_create_string((const jerry_char_t *)name);
|
||||||
|
jerry_set_property(obj, str, prop);
|
||||||
|
jerry_release_value (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int js_console_init(void)
|
||||||
|
{
|
||||||
|
jerry_value_t console = jerry_create_object();
|
||||||
|
jerry_value_t global_obj = jerry_get_global_object();
|
||||||
|
|
||||||
|
js_add_function(console, "log", jerryx_handler_print);
|
||||||
|
|
||||||
|
js_set_property(global_obj, "console", console);
|
||||||
|
|
||||||
|
jerry_release_value(global_obj);
|
||||||
|
jerry_release_value(console);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static jerry_log_level_t jerry_log_level = JERRY_LOG_LEVEL_ERROR;
|
static jerry_log_level_t jerry_log_level = JERRY_LOG_LEVEL_ERROR;
|
||||||
|
|
||||||
|
|
||||||
|
@ -360,6 +395,8 @@ int jerrytest(int argc, char *argv[])
|
||||||
|
|
||||||
register_js_function ("gc", jerryx_handler_gc);
|
register_js_function ("gc", jerryx_handler_gc);
|
||||||
register_js_function ("print", jerryx_handler_print);
|
register_js_function ("print", jerryx_handler_print);
|
||||||
|
js_console_init();
|
||||||
|
|
||||||
|
|
||||||
jerry_value_t ret_value = jerry_create_undefined ();
|
jerry_value_t ret_value = jerry_create_undefined ();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* 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
|
||||||
|
stmdb sp!, {r4 - r11, lr}
|
||||||
|
mov r2, sp
|
||||||
|
add r0, r0, #4
|
||||||
|
str r2, [r0]
|
||||||
|
add r0, r0, #4
|
||||||
|
vstm r0!, {s16 - s31}
|
||||||
|
mov r0, #0
|
||||||
|
ldmia sp!, {r4 - r11, pc}
|
||||||
|
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
|
||||||
|
beq 1f
|
||||||
|
mov r0, #1
|
||||||
|
1:
|
||||||
|
ldmia sp!, {r4 - r11, pc}
|
||||||
|
endfunc longjmp
|
|
@ -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,10 @@
|
||||||
|
var str2 = "hello"
|
||||||
|
var num = 3.1415
|
||||||
|
|
||||||
|
console.log("helo world!!");
|
||||||
|
console.log("helo jerryscript run ok!!");
|
||||||
|
console.log("helo js engine!!");
|
||||||
|
console.log("helo world!!" + str2);
|
||||||
|
console.log("num=" + num);
|
||||||
|
console.log("[hello world] end");
|
||||||
|
|
|
@ -107,6 +107,7 @@ SECTIONS
|
||||||
|
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_etext = .;
|
_etext = .;
|
||||||
|
_exit = .;
|
||||||
} >FLASH
|
} >FLASH
|
||||||
|
|
||||||
.rodata :
|
.rodata :
|
||||||
|
|
Loading…
Reference in New Issue