diff --git a/targets/esp8266/Makefile.esp8266 b/targets/esp8266/Makefile.esp8266 index e400d4dade..cea2c02d95 100644 --- a/targets/esp8266/Makefile.esp8266 +++ b/targets/esp8266/Makefile.esp8266 @@ -48,10 +48,10 @@ JERRY_BUILD_FILES := $(SRCPATH)/jerry_extapi.c JERRY_BUILD_FILES := $(JERRY_BUILD_FILES);$(SRCPATH)/jerry_run.c -.PHONY: jerry js2c mbed check-env flash clean +.PHONY: jerry js2c mkbin check-env flash clean -all: check-env jerry js2c mbed +all: check-env jerry js2c mkbin jerry: @@ -83,7 +83,7 @@ js2c: cd targets/esp8266; ../tools/js2c.py -mbed: +mkbin: cd targets/esp8266; \ make clean; \ BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=3 make; \ diff --git a/targets/esp8266/include/jerry_extapi.h b/targets/esp8266/include/jerry_extapi.h index f10d527fd1..856a79c587 100644 --- a/targets/esp8266/include/jerry_extapi.h +++ b/targets/esp8266/include/jerry_extapi.h @@ -24,14 +24,14 @@ #define API_DATA_IS_FUNCTION(val_p) \ (API_DATA_IS_OBJECT(val_p) && \ - jerry_api_is_function((val_p)->v_object)) + jerry_api_is_function((val_p)->u.v_object)) #define JS_VALUE_TO_NUMBER(val_p) \ ((val_p)->type == JERRY_API_DATA_TYPE_FLOAT32 ? \ - (double) ((val_p)->v_float32) : \ + (double) ((val_p)->u.v_float32) : \ (val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \ - (double) ((val_p)->v_float64) : \ - (double) ((val_p)->v_uint32)) + (double) ((val_p)->u.v_float64) : \ + (double) ((val_p)->u.v_uint32)) #ifdef __cplusplus diff --git a/targets/esp8266/readme.md b/targets/esp8266/readme.md index 44c5f2c590..396677cf3f 100644 --- a/targets/esp8266/readme.md +++ b/targets/esp8266/readme.md @@ -1,8 +1,9 @@ ### About Files in this folder (embedding/esp8266) are copied from -examples/project_template of esp_iot_rtos_sdk and modified for JerryScript. -You can view online from [this](https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/project_template) page. +`examples/project_template` of `esp_iot_rtos_sdk` and modified for JerryScript. +You can view online from +[this](https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/project_template) page. ### How to build JerryScript for ESP8266 @@ -21,7 +22,9 @@ Below is a summary after SDK patch is applied. ``` cd ~/harmony/jerryscript +# clean build make -f ./targets/esp8266/Makefile.esp8266 clean +# or just normal build make -f ./targets/esp8266/Makefile.esp8266 ``` @@ -29,7 +32,7 @@ Output files should be placed at $BIN_PATH #### 4. Flashing for ESP8266 ESP-01 board (WiFi Module) -Steps are for ESP8266 ESP-01(WiFi) board. Others may vary. +Steps are for `ESP8266 ESP-01(WiFi)` board. Others may vary. Refer http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family page. ##### 4.1 GPIO0 and GPIO2 diff --git a/targets/esp8266/source/jerry_extapi.c b/targets/esp8266/source/jerry_extapi.c index c4fb8ae969..9698929cb9 100644 --- a/targets/esp8266/source/jerry_extapi.c +++ b/targets/esp8266/source/jerry_extapi.c @@ -41,12 +41,12 @@ NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \ #define REGISTER_HANDLER(NAME) \ register_native_function ( # NAME, NAME ## _handler) -//----------------------------------------------------------------------------- +/*---------------------------------------------------------------------------*/ DELCARE_HANDLER(assert) { if (args_cnt == 1 && args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN - && args_p[0].v_bool == true) + && args_p[0].u.v_bool == true) { printf (">> Jerry assert true\r\n"); return true; @@ -65,13 +65,13 @@ DELCARE_HANDLER(print) { printf(">> print(%d) :", (int)args_cnt); for (cc=0; cctype = JERRY_API_DATA_TYPE_FLOAT64; - ret_val_p->v_float64 = (double)value; + ret_val_p->u.v_float64 = (double)value; return true; } /* gpio_dir_handler */ -//----------------------------------------------------------------------------- +/*---------------------------------------------------------------------------*/ + static bool register_native_function (const char* name, jerry_external_handler_t handler) @@ -163,7 +164,7 @@ register_native_function (const char* name, jerry_api_acquire_object (reg_func_p); reg_value.type = JERRY_API_DATA_TYPE_OBJECT; - reg_value.v_object = reg_func_p; + reg_value.u.v_object = reg_func_p; bok = jerry_api_set_object_field_value (global_obj_p, (jerry_api_char_t *)name, @@ -182,7 +183,7 @@ register_native_function (const char* name, } -//----------------------------------------------------------------------------- +/*---------------------------------------------------------------------------*/ void js_register_functions (void) { diff --git a/targets/esp8266/source/jerry_run.c b/targets/esp8266/source/jerry_run.c index 6ecda39f0c..cb483bdc82 100644 --- a/targets/esp8266/source/jerry_run.c +++ b/targets/esp8266/source/jerry_run.c @@ -24,19 +24,20 @@ 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_init (flags); js_register_functions (); - if (!jerry_parse (jerry_src, source_size)) + if (!jerry_parse ((jerry_api_char_t *)jerry_src, source_size, &err_obj_p)) { printf ("Error: jerry_parse failed\r\n"); ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION; @@ -45,7 +46,8 @@ int js_entry (const char *source_p, const size_t source_size) { if ((flags & JERRY_FLAG_PARSE_ONLY) == 0) { - ret_code = jerry_run (); + jerry_api_value_t err_value = jerry_api_create_void_value (); + ret_code = jerry_run (&err_value); } } @@ -72,6 +74,9 @@ int js_loop (uint32_t ticknow) { jerry_api_object_t *global_obj_p; jerry_api_value_t sysloop_func; + jerry_api_value_t* val_args; + uint16_t val_argv; + jerry_api_value_t res; bool is_ok; global_obj_p = jerry_api_get_global (); @@ -93,16 +98,12 @@ int js_loop (uint32_t ticknow) return -2; } - jerry_api_value_t* val_args; - uint16_t val_argv; - 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].v_uint32 = ticknow; + val_args[0].u.v_uint32 = ticknow; - jerry_api_value_t res; - is_ok = jerry_api_call_function (sysloop_func.v_object, + is_ok = jerry_api_call_function (sysloop_func.u.v_object, global_obj_p, &res, val_args, diff --git a/targets/esp8266/user/jerry_port.c b/targets/esp8266/user/jerry_port.c index a17e459562..2c3fffe33c 100644 --- a/targets/esp8266/user/jerry_port.c +++ b/targets/esp8266/user/jerry_port.c @@ -1,4 +1,4 @@ -/* Copyright 2014-2015 Samsung Electronics Co., Ltd. +/* Copyright 2014-2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,11 +46,45 @@ int jerry_port_errormsg (const char* format, ...) return count; } + +/** exit - cause normal process termination */ void exit (int status) { - printf ("!!!! EXIT: %d\n", status); while (true) { - ; } } /* exit */ + +/** abort - cause abnormal process termination */ +void abort (void) +{ + while (true) + { + } +} /* abort */ + +/** + * fwrite + * + * @return number of bytes written + */ +size_t +fwrite (const void *ptr, /**< data to write */ + size_t size, /**< size of elements to write */ + size_t nmemb, /**< number of elements */ + FILE *stream) /**< stream pointer */ +{ + return size * nmemb; +} /* fwrite */ + +/** + * This function can get the time as well as a timezone. + * + * @return 0 if success, -1 otherwise + */ +int +gettimeofday (void *tp, /**< struct timeval */ + void *tzp) /**< struct timezone */ +{ + return -1; +} /* gettimeofday */ diff --git a/targets/esp8266/user/user_main.c b/targets/esp8266/user/user_main.c index 925c994498..c53a43aa9e 100644 --- a/targets/esp8266/user/user_main.c +++ b/targets/esp8266/user/user_main.c @@ -98,7 +98,6 @@ void jerry_task(void *pvParameters) { */ void ICACHE_FLASH_ATTR user_init(void) { - const portTickType onesec = 1000 / portTICK_RATE_MS; uart_div_modify(UART0, UART_CLK_FREQ / (BIT_RATE_115200)); show_free_mem(0);