mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Follow the API & build system update in mbed targets
- Update the API changes in mbed targets - Build fix for mbed target after the build system patch. JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
This commit is contained in:
parent
d5eb2f0be1
commit
91e29120d2
@ -15,7 +15,6 @@
|
||||
|
||||
# use TAB-8
|
||||
|
||||
TYPE = release
|
||||
TARGET_LIST = k64f stm32f4 stm32f429i nucleo
|
||||
JERRYHEAP ?= 16
|
||||
|
||||
@ -33,10 +32,9 @@ else ifeq ($(TARGET), nucleo)
|
||||
TARGET_DIR ?= /media/$(USER)/NODE_F401RE
|
||||
endif
|
||||
|
||||
UPPERC_TARGET = $(shell echo $(TARGET) | tr a-z A-Z)
|
||||
INTERM = build/obj-mbed-$(TARGET)
|
||||
OUTPUT = build/bin/$(TYPE).mbed$(TARGET)
|
||||
COPYTARGET = targets/mbed/libjerry
|
||||
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!)
|
||||
@ -53,25 +51,26 @@ EXT_PORT_DIR := ""
|
||||
all: jerry js2c yotta
|
||||
|
||||
jerry:
|
||||
mkdir -p $(INTERM)
|
||||
mkdir -p $(OUTPUT)
|
||||
mkdir -p $(COPYTARGET)
|
||||
cmake -B$(INTERM) -H./ \
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cmake -B$(BUILD_DIR) -H./ \
|
||||
-DENABLE_LTO=OFF \
|
||||
-DENABLE_VALGRIND=OFF \
|
||||
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
|
||||
-DFEATURE_VALGRIND=OFF \
|
||||
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain_external.cmake \
|
||||
-DJERRY_LIBC=OFF \
|
||||
-DJERRY_CMDLINE=OFF \
|
||||
-DCOMPILER_DEFAULT_LIBC=ON \
|
||||
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm7-m \
|
||||
-DENABLE_ALL_IN_ONE=OFF \
|
||||
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=armv7l-hf \
|
||||
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
|
||||
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
|
||||
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
|
||||
-DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP) \
|
||||
-DEXTERNAL_PORT_DIR=$(EXT_PORT_DIR)
|
||||
-DMEM_HEAP_SIZE_KB=$(JERRYHEAP) \
|
||||
|
||||
make -C $(INTERM) $(TYPE).external
|
||||
cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/.
|
||||
cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a
|
||||
cp $(OUTPUT)/lib$(TYPE).jerry-libm.lib.a $(COPYTARGET)/libjerrylibm.a
|
||||
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;
|
||||
@ -83,7 +82,7 @@ yotta:
|
||||
|
||||
flash:
|
||||
ifndef TARGET_DIR
|
||||
st-flash write targets/mbed/build/$(YOTTA_TARGET)/source/jerry.bin 0x08000000
|
||||
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}"; \
|
||||
@ -95,6 +94,6 @@ flash:
|
||||
@echo "Wait till LED flashing stops..."
|
||||
|
||||
clean:
|
||||
rm -rf $(INTERM)
|
||||
rm -rf $(COPYTARGET)
|
||||
rm -rf $(OUTPUT)
|
||||
rm -rf targets/mbed/build
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -16,9 +17,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jerry-core/jerry.h"
|
||||
#include "jerry-core/jerry-api.h"
|
||||
#include "jerry_extapi.h"
|
||||
|
||||
|
||||
#include "native_mbed.h"
|
||||
|
||||
#ifndef MIN
|
||||
@ -30,12 +31,11 @@
|
||||
#define __UNSED__ __attribute__((unused))
|
||||
|
||||
#define DECLARE_HANDLER(NAME) \
|
||||
static bool \
|
||||
NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
|
||||
const jerry_api_value_t * this_p __UNSED__, \
|
||||
jerry_api_value_t * ret_val_p __UNSED__, \
|
||||
const jerry_api_value_t args_p[], \
|
||||
const jerry_api_length_t args_cnt)
|
||||
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)
|
||||
@ -45,39 +45,50 @@ NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
|
||||
DECLARE_HANDLER(assert)
|
||||
{
|
||||
if (args_cnt == 1
|
||||
&& args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN
|
||||
&& args_p[0].u.v_bool == true)
|
||||
&& jerry_value_is_boolean (args[0])
|
||||
&& jerry_get_boolean_value (args[0]))
|
||||
{
|
||||
printf (">> Jerry assert true\r\n");
|
||||
return true;
|
||||
return jerry_create_boolean (true);
|
||||
}
|
||||
printf ("ERROR: Script assertion failed\n");
|
||||
exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
|
||||
return false;
|
||||
return jerry_create_boolean (false);
|
||||
}
|
||||
|
||||
DECLARE_HANDLER(led)
|
||||
{
|
||||
jerry_value_t ret_val;
|
||||
|
||||
if (args_cnt < 2)
|
||||
{
|
||||
return false;
|
||||
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)JS_VALUE_TO_NUMBER (&args_p[0]);
|
||||
value = (int)JS_VALUE_TO_NUMBER (&args_p[1]);
|
||||
port = (int) jerry_get_number_value (args[0]);
|
||||
value = (int) jerry_get_number_value (args[1]);
|
||||
|
||||
ret_val_p->type = JERRY_API_DATA_TYPE_BOOLEAN;
|
||||
if (port >=0 && port <= 3)
|
||||
if (port >= 0 && port <= 3)
|
||||
{
|
||||
native_led(port, value);
|
||||
ret_val_p->u.v_bool = true;
|
||||
native_led (port, value);
|
||||
ret_val = jerry_create_boolean (true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_val_p->u.v_bool = false;
|
||||
ret_val = jerry_create_boolean (false);
|
||||
}
|
||||
return true;
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -86,41 +97,49 @@ static bool
|
||||
register_native_function (const char* name,
|
||||
jerry_external_handler_t handler)
|
||||
{
|
||||
jerry_api_object_t *global_obj_p;
|
||||
jerry_api_object_t *reg_func_p;
|
||||
jerry_api_value_t reg_value;
|
||||
bool bok;
|
||||
jerry_value_t global_object_val = jerry_get_global_object ();
|
||||
jerry_value_t reg_function = jerry_create_external_function (handler);
|
||||
|
||||
global_obj_p = jerry_api_get_global ();
|
||||
reg_func_p = jerry_api_create_external_function (handler);
|
||||
bool is_ok = true;
|
||||
|
||||
if (!(reg_func_p != NULL
|
||||
&& jerry_api_is_function (reg_func_p)
|
||||
&& jerry_api_is_constructor (reg_func_p)))
|
||||
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_api_release_object (global_obj_p);
|
||||
return false;
|
||||
jerry_release_value (global_object_val);
|
||||
jerry_release_value (reg_function);
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
jerry_api_acquire_object (reg_func_p);
|
||||
reg_value.type = JERRY_API_DATA_TYPE_OBJECT;
|
||||
reg_value.u.v_object = reg_func_p;
|
||||
|
||||
bok = jerry_api_set_object_field_value (global_obj_p,
|
||||
(jerry_api_char_t *) name,
|
||||
®_value);
|
||||
|
||||
jerry_api_release_value (®_value);
|
||||
jerry_api_release_object (reg_func_p);
|
||||
jerry_api_release_object (global_obj_p);
|
||||
|
||||
if (!bok)
|
||||
if (jerry_value_has_error_flag (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_has_error_flag (set_result))
|
||||
{
|
||||
is_ok = false;
|
||||
printf ("Error: register_native_function failed: [%s]\r\n", name);
|
||||
}
|
||||
|
||||
return bok;
|
||||
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)
|
||||
|
||||
@ -19,20 +19,6 @@
|
||||
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
|
||||
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
|
||||
|
||||
#define API_DATA_IS_OBJECT(val_p) \
|
||||
((val_p)->type == JERRY_API_DATA_TYPE_OBJECT)
|
||||
|
||||
#define API_DATA_IS_FUNCTION(val_p) \
|
||||
(API_DATA_IS_OBJECT (val_p) && \
|
||||
jerry_api_is_function ((val_p)->u.v_object))
|
||||
|
||||
#define JS_VALUE_TO_NUMBER(val_p) \
|
||||
((val_p)->type == JERRY_API_DATA_TYPE_FLOAT32 ? \
|
||||
static_cast<double>((val_p)->u.v_float32) : \
|
||||
(val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \
|
||||
static_cast<double>((val_p)->u.v_float64) : \
|
||||
static_cast<double>((val_p)->u.v_uint32))
|
||||
|
||||
void js_register_functions (void);
|
||||
|
||||
#endif
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jerry-core/jerry.h"
|
||||
#include "jerry-core/jerry-api.h"
|
||||
#include "jerry_extapi.h"
|
||||
#include "jerry_run.h"
|
||||
|
||||
@ -25,101 +25,101 @@ static const char* fn_sys_loop_name = "sysloop";
|
||||
|
||||
int js_entry (const char *source_p, const size_t source_size)
|
||||
{
|
||||
const jerry_api_char_t *jerry_src = (const jerry_api_char_t *) source_p;
|
||||
jerry_completion_code_t ret_code = JERRY_COMPLETION_CODE_OK;
|
||||
jerry_flag_t flags = JERRY_FLAG_EMPTY;
|
||||
jerry_api_object_t *err_obj_p = NULL;
|
||||
jerry_api_value_t err_value = jerry_api_create_void_value ();
|
||||
|
||||
jerry_init (flags);
|
||||
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 ();
|
||||
|
||||
if (!jerry_parse (jerry_src, source_size, &err_obj_p))
|
||||
jerry_value_t parsed_code = jerry_parse (jerry_src, source_size, false);
|
||||
|
||||
if (!jerry_value_has_error_flag (parsed_code))
|
||||
{
|
||||
printf ("Error: jerry_parse failed\r\n");
|
||||
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
|
||||
jerry_api_release_object (err_obj_p);
|
||||
jerry_value_t ret_value = jerry_run (parsed_code);
|
||||
|
||||
if (jerry_value_has_error_flag (ret_value))
|
||||
{
|
||||
printf ("Error: ret_value has an error flag!\r\n");
|
||||
return ret_code = -1;
|
||||
}
|
||||
|
||||
jerry_release_value (ret_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((flags & JERRY_FLAG_PARSE_ONLY) == 0)
|
||||
{
|
||||
ret_code = jerry_run (&err_value);
|
||||
jerry_api_string_t *err_str_p = NULL;
|
||||
|
||||
if (err_str_p != NULL)
|
||||
{
|
||||
jerry_api_release_string (err_str_p);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
jerry_completion_code_t status;
|
||||
jerry_api_value_t res;
|
||||
int status = 0;
|
||||
|
||||
status = jerry_api_eval ((jerry_api_char_t *) source_p,
|
||||
source_size,
|
||||
false,
|
||||
false,
|
||||
&res);
|
||||
jerry_value_t ret_val = jerry_eval ((jerry_char_t *) source_p,
|
||||
source_size,
|
||||
false);
|
||||
|
||||
jerry_api_release_value (&res);
|
||||
if (jerry_value_has_error_flag (ret_val))
|
||||
{
|
||||
printf ("Error: jerry_eval failed!\r\n");
|
||||
status = -1;
|
||||
}
|
||||
|
||||
jerry_release_value (ret_val);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int js_loop (uint32_t ticknow)
|
||||
{
|
||||
jerry_api_object_t *global_obj_p;
|
||||
jerry_api_value_t sysloop_func;
|
||||
bool is_ok;
|
||||
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);
|
||||
|
||||
global_obj_p = jerry_api_get_global ();
|
||||
is_ok = jerry_api_get_object_field_value (global_obj_p,
|
||||
(const jerry_api_char_t*) fn_sys_loop_name,
|
||||
&sysloop_func);
|
||||
if (!is_ok)
|
||||
if (jerry_value_has_error_flag (sysloop_func))
|
||||
{
|
||||
printf ("Error: '%s' not defined!!!\r\n", fn_sys_loop_name);
|
||||
jerry_api_release_object (global_obj_p);
|
||||
jerry_release_value (global_obj);
|
||||
jerry_release_value (sysloop_func);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!API_DATA_IS_FUNCTION (&sysloop_func))
|
||||
if (!jerry_value_is_function (sysloop_func))
|
||||
{
|
||||
printf ("Error: '%s' is not a function!!!\r\n", fn_sys_loop_name);
|
||||
jerry_api_release_value (&sysloop_func);
|
||||
jerry_api_release_object (global_obj_p);
|
||||
jerry_release_value (global_obj);
|
||||
jerry_release_value (sysloop_func);
|
||||
return -2;
|
||||
}
|
||||
|
||||
jerry_api_value_t* val_args;
|
||||
uint16_t val_argv;
|
||||
jerry_value_t val_args[1];
|
||||
uint16_t val_argv = 1;
|
||||
|
||||
val_argv = 1;
|
||||
val_args = (jerry_api_value_t*) malloc (sizeof (jerry_api_value_t) * val_argv);
|
||||
val_args[0].type = JERRY_API_DATA_TYPE_UINT32;
|
||||
val_args[0].u.v_uint32 = ticknow;
|
||||
val_args[0] = jerry_create_number (ticknow);
|
||||
|
||||
jerry_api_value_t res;
|
||||
is_ok = jerry_api_call_function (sysloop_func.u.v_object,
|
||||
global_obj_p,
|
||||
&res,
|
||||
val_args,
|
||||
val_argv);
|
||||
jerry_api_release_value (&res);
|
||||
free (val_args);
|
||||
jerry_value_t ret_val_sysloop = jerry_call_function (sysloop_func,
|
||||
global_obj,
|
||||
val_args,
|
||||
val_argv);
|
||||
if (jerry_value_has_error_flag (ret_val_sysloop))
|
||||
{
|
||||
status = -3;
|
||||
}
|
||||
|
||||
jerry_api_release_value (&sysloop_func);
|
||||
jerry_api_release_object (global_obj_p);
|
||||
jerry_release_value (global_obj);
|
||||
jerry_release_value (ret_val_sysloop);
|
||||
jerry_release_value (sysloop_func);
|
||||
jerry_release_value (val_args[0]);
|
||||
|
||||
return 0;
|
||||
return status;
|
||||
}
|
||||
|
||||
void js_exit (void)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -15,17 +16,16 @@
|
||||
|
||||
#include "mbed-drivers/mbed.h"
|
||||
|
||||
#include "jerry-core/jerry.h"
|
||||
#include "jerry-core/jerry-api.h"
|
||||
#include "jerry_run.h"
|
||||
|
||||
#include "jerry_targetjs.h"
|
||||
|
||||
static Serial pc (USBTX, USBRX); //tx, rx
|
||||
|
||||
static int jerry_init (void)
|
||||
static int jerry_task_init (void)
|
||||
{
|
||||
int retcode;
|
||||
int src;
|
||||
|
||||
DECLARE_JS_CODES;
|
||||
|
||||
@ -38,7 +38,7 @@ static int jerry_init (void)
|
||||
return -1;
|
||||
}
|
||||
/* run rest of the js files */
|
||||
for (src = 1; js_codes[src].source; src++)
|
||||
for (int src = 1; js_codes[src].source; src++)
|
||||
{
|
||||
retcode = js_eval (js_codes[src].source, js_codes[src].length);
|
||||
if (retcode != 0)
|
||||
@ -60,15 +60,13 @@ static void jerry_loop (void)
|
||||
|
||||
void app_start (int, char**)
|
||||
{
|
||||
// set 9600 baud rate for stdout
|
||||
/* set 9600 baud rate for stdout */
|
||||
pc.baud (9600);
|
||||
|
||||
printf ("\r\nJerryScript in mbed\r\n");
|
||||
printf (" build %s\r\n", jerry_build_date);
|
||||
printf (" hash %s\r\n", jerry_commit_hash);
|
||||
printf (" branch %s\r\n", jerry_branch_name);
|
||||
printf ("Version: \t%d.%d\n\n", JERRY_API_MAJOR_VERSION, JERRY_API_MINOR_VERSION);
|
||||
|
||||
if (jerry_init () == 0)
|
||||
if (jerry_task_init () == 0)
|
||||
{
|
||||
minar::Scheduler::postCallback(jerry_loop).period(minar::milliseconds(100));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user