Skip to content

Commit ed2a360

Browse files
committed
Fix ESP8266 build
This change is to fix build for ESP8266 board with jerry_api_value_t changes. JerryScript-DCO-1.0-Signed-off-by: SaeHie Park saehie.park@samsung.com
1 parent 36c7440 commit ed2a360

File tree

7 files changed

+75
-37
lines changed

7 files changed

+75
-37
lines changed

targets/esp8266/Makefile.esp8266

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ JERRY_BUILD_FILES := $(SRCPATH)/jerry_extapi.c
4848
JERRY_BUILD_FILES := $(JERRY_BUILD_FILES);$(SRCPATH)/jerry_run.c
4949

5050

51-
.PHONY: jerry js2c mbed check-env flash clean
51+
.PHONY: jerry js2c mkbin check-env flash clean
5252

5353

54-
all: check-env jerry js2c mbed
54+
all: check-env jerry js2c mkbin
5555

5656

5757
jerry:
@@ -83,7 +83,7 @@ js2c:
8383
cd targets/esp8266; ../tools/js2c.py
8484

8585

86-
mbed:
86+
mkbin:
8787
cd targets/esp8266; \
8888
make clean; \
8989
BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=3 make; \

targets/esp8266/include/jerry_extapi.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
#define API_DATA_IS_FUNCTION(val_p) \
2626
(API_DATA_IS_OBJECT(val_p) && \
27-
jerry_api_is_function((val_p)->v_object))
27+
jerry_api_is_function((val_p)->u.v_object))
2828

2929
#define JS_VALUE_TO_NUMBER(val_p) \
3030
((val_p)->type == JERRY_API_DATA_TYPE_FLOAT32 ? \
31-
(double) ((val_p)->v_float32) : \
31+
(double) ((val_p)->u.v_float32) : \
3232
(val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \
33-
(double) ((val_p)->v_float64) : \
34-
(double) ((val_p)->v_uint32))
33+
(double) ((val_p)->u.v_float64) : \
34+
(double) ((val_p)->u.v_uint32))
3535

3636

3737
#ifdef __cplusplus

targets/esp8266/readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
### About
22

33
Files in this folder (embedding/esp8266) are copied from
4-
examples/project_template of esp_iot_rtos_sdk and modified for JerryScript.
5-
You can view online from [this](https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/project_template) page.
4+
`examples/project_template` of `esp_iot_rtos_sdk` and modified for JerryScript.
5+
You can view online from
6+
[this](https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/project_template) page.
67

78

89
### How to build JerryScript for ESP8266
@@ -21,15 +22,17 @@ Below is a summary after SDK patch is applied.
2122

2223
```
2324
cd ~/harmony/jerryscript
25+
# clean build
2426
make -f ./targets/esp8266/Makefile.esp8266 clean
27+
# or just normal build
2528
make -f ./targets/esp8266/Makefile.esp8266
2629
```
2730

2831
Output files should be placed at $BIN_PATH
2932

3033
#### 4. Flashing for ESP8266 ESP-01 board (WiFi Module)
3134

32-
Steps are for ESP8266 ESP-01(WiFi) board. Others may vary.
35+
Steps are for `ESP8266 ESP-01(WiFi)` board. Others may vary.
3336
Refer http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family page.
3437

3538
##### 4.1 GPIO0 and GPIO2

targets/esp8266/source/jerry_extapi.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
4141
#define REGISTER_HANDLER(NAME) \
4242
register_native_function ( # NAME, NAME ## _handler)
4343

44-
//-----------------------------------------------------------------------------
44+
/*---------------------------------------------------------------------------*/
4545

4646
DELCARE_HANDLER(assert) {
4747
if (args_cnt == 1
4848
&& args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN
49-
&& args_p[0].v_bool == true)
49+
&& args_p[0].u.v_bool == true)
5050
{
5151
printf (">> Jerry assert true\r\n");
5252
return true;
@@ -65,13 +65,13 @@ DELCARE_HANDLER(print) {
6565
printf(">> print(%d) :", (int)args_cnt);
6666
for (cc=0; cc<args_cnt; cc++)
6767
{
68-
if (args_p[cc].type == JERRY_API_DATA_TYPE_STRING && args_p[cc].v_string)
68+
if (args_p[cc].type == JERRY_API_DATA_TYPE_STRING && args_p[cc].u.v_string)
6969
{
7070
static char buffer[128];
71-
int length, maxlength;
72-
length = -jerry_api_string_to_char_buffer (args_p[0].v_string, NULL, 0);
71+
jerry_api_size_t length, maxlength;
72+
length = -jerry_api_string_to_char_buffer (args_p[0].u.v_string, NULL, 0);
7373
maxlength = MIN(length, 126);
74-
jerry_api_string_to_char_buffer (args_p[cc].v_string,
74+
jerry_api_string_to_char_buffer (args_p[cc].u.v_string,
7575
(jerry_api_char_t *) buffer,
7676
maxlength);
7777
*(buffer + length) = 0;
@@ -88,15 +88,15 @@ DELCARE_HANDLER(print) {
8888
}
8989

9090

91-
//-----------------------------------------------------------------------------
91+
/*---------------------------------------------------------------------------*/
9292

9393
DELCARE_HANDLER(gpio_dir) {
94+
int port, value;
9495
if (args_cnt < 2)
9596
{
9697
return false;
9798
}
9899

99-
int port, value;
100100
port = (int)JS_VALUE_TO_NUMBER (&args_p[0]);
101101
value = (int)JS_VALUE_TO_NUMBER (&args_p[1]);
102102

@@ -106,12 +106,12 @@ DELCARE_HANDLER(gpio_dir) {
106106
} /* gpio_dir_handler */
107107

108108
DELCARE_HANDLER(gpio_set) {
109+
int port, value;
109110
if (args_cnt < 2)
110111
{
111112
return false;
112113
}
113114

114-
int port, value;
115115
port = (int)JS_VALUE_TO_NUMBER (&args_p[0]);
116116
value = (int)JS_VALUE_TO_NUMBER (&args_p[1]);
117117

@@ -122,24 +122,25 @@ DELCARE_HANDLER(gpio_set) {
122122

123123

124124
DELCARE_HANDLER(gpio_get) {
125+
int port, value;
125126
if (args_cnt < 1)
126127
{
127128
return false;
128129
}
129130

130-
int port, value;
131131
port = (int)JS_VALUE_TO_NUMBER (&args_p[0]);
132132

133133
value = native_gpio_get (port) ? 1 : 0;
134134

135135
ret_val_p->type = JERRY_API_DATA_TYPE_FLOAT64;
136-
ret_val_p->v_float64 = (double)value;
136+
ret_val_p->u.v_float64 = (double)value;
137137

138138
return true;
139139
} /* gpio_dir_handler */
140140

141141

142-
//-----------------------------------------------------------------------------
142+
/*---------------------------------------------------------------------------*/
143+
143144
static bool
144145
register_native_function (const char* name,
145146
jerry_external_handler_t handler)
@@ -163,7 +164,7 @@ register_native_function (const char* name,
163164

164165
jerry_api_acquire_object (reg_func_p);
165166
reg_value.type = JERRY_API_DATA_TYPE_OBJECT;
166-
reg_value.v_object = reg_func_p;
167+
reg_value.u.v_object = reg_func_p;
167168

168169
bok = jerry_api_set_object_field_value (global_obj_p,
169170
(jerry_api_char_t *)name,
@@ -182,7 +183,7 @@ register_native_function (const char* name,
182183
}
183184

184185

185-
//-----------------------------------------------------------------------------
186+
/*---------------------------------------------------------------------------*/
186187

187188
void js_register_functions (void)
188189
{

targets/esp8266/source/jerry_run.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424
static const char* fn_sys_loop_name = "sysloop";
2525

2626

27-
//-----------------------------------------------------------------------------
27+
/*---------------------------------------------------------------------------*/
2828

2929
int js_entry (const char *source_p, const size_t source_size)
3030
{
3131
const jerry_api_char_t *jerry_src = (const jerry_api_char_t *) source_p;
3232
jerry_completion_code_t ret_code = JERRY_COMPLETION_CODE_OK;
3333
jerry_flag_t flags = JERRY_FLAG_EMPTY;
34+
jerry_api_object_t *err_obj_p = NULL;
3435

3536
jerry_init (flags);
3637

3738
js_register_functions ();
3839

39-
if (!jerry_parse (jerry_src, source_size))
40+
if (!jerry_parse ((jerry_api_char_t *)jerry_src, source_size, &err_obj_p))
4041
{
4142
printf ("Error: jerry_parse failed\r\n");
4243
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
@@ -45,7 +46,8 @@ int js_entry (const char *source_p, const size_t source_size)
4546
{
4647
if ((flags & JERRY_FLAG_PARSE_ONLY) == 0)
4748
{
48-
ret_code = jerry_run ();
49+
jerry_api_value_t err_value = jerry_api_create_void_value ();
50+
ret_code = jerry_run (&err_value);
4951
}
5052
}
5153

@@ -72,6 +74,9 @@ int js_loop (uint32_t ticknow)
7274
{
7375
jerry_api_object_t *global_obj_p;
7476
jerry_api_value_t sysloop_func;
77+
jerry_api_value_t* val_args;
78+
uint16_t val_argv;
79+
jerry_api_value_t res;
7580
bool is_ok;
7681

7782
global_obj_p = jerry_api_get_global ();
@@ -93,16 +98,12 @@ int js_loop (uint32_t ticknow)
9398
return -2;
9499
}
95100

96-
jerry_api_value_t* val_args;
97-
uint16_t val_argv;
98-
99101
val_argv = 1;
100102
val_args = (jerry_api_value_t*)malloc (sizeof (jerry_api_value_t) * val_argv);
101103
val_args[0].type = JERRY_API_DATA_TYPE_UINT32;
102-
val_args[0].v_uint32 = ticknow;
104+
val_args[0].u.v_uint32 = ticknow;
103105

104-
jerry_api_value_t res;
105-
is_ok = jerry_api_call_function (sysloop_func.v_object,
106+
is_ok = jerry_api_call_function (sysloop_func.u.v_object,
106107
global_obj_p,
107108
&res,
108109
val_args,

targets/esp8266/user/jerry_port.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
1+
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -46,11 +46,45 @@ int jerry_port_errormsg (const char* format, ...)
4646
return count;
4747
}
4848

49+
50+
/** exit - cause normal process termination */
4951
void exit (int status)
5052
{
51-
printf ("!!!! EXIT: %d\n", status);
5253
while (true)
5354
{
54-
;
5555
}
5656
} /* exit */
57+
58+
/** abort - cause abnormal process termination */
59+
void abort (void)
60+
{
61+
while (true)
62+
{
63+
}
64+
} /* abort */
65+
66+
/**
67+
* fwrite
68+
*
69+
* @return number of bytes written
70+
*/
71+
size_t
72+
fwrite (const void *ptr, /**< data to write */
73+
size_t size, /**< size of elements to write */
74+
size_t nmemb, /**< number of elements */
75+
FILE *stream) /**< stream pointer */
76+
{
77+
return size * nmemb;
78+
} /* fwrite */
79+
80+
/**
81+
* This function can get the time as well as a timezone.
82+
*
83+
* @return 0 if success, -1 otherwise
84+
*/
85+
int
86+
gettimeofday (void *tp, /**< struct timeval */
87+
void *tzp) /**< struct timezone */
88+
{
89+
return -1;
90+
} /* gettimeofday */

targets/esp8266/user/user_main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ void jerry_task(void *pvParameters) {
9898
*/
9999
void ICACHE_FLASH_ATTR user_init(void)
100100
{
101-
const portTickType onesec = 1000 / portTICK_RATE_MS;
102101
uart_div_modify(UART0, UART_CLK_FREQ / (BIT_RATE_115200));
103102

104103
show_free_mem(0);

0 commit comments

Comments
 (0)