Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion targets/mbedk64f/.yotta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"build": {
"target": "frdm-k64f-gcc,*"
"target": "frdm-k64f-gcc,*",
"targetSetExplicitly": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@
* limitations under the License.
*/

#include "jerry-core/jerry.h"

#include <stdlib.h>
#include <stdio.h>

#include "jerry-core/jerry.h"
#include "jerry_extapi.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two empty lines help to separate the include types, such as jerry API, system and target headers. Why did you remove them?

#include "native_mbedk64f.h"


#ifndef MIN
#define MIN(A,B) ((A)<(B)?(A):(B))
#endif


//-----------------------------------------------------------------------------

#define __UNSED__ __attribute__((unused))
Expand All @@ -40,16 +37,15 @@ NAME ## _handler (const jerry_api_object_t * function_obj_p __UNSED__, \
const jerry_api_length_t args_cnt)

#define REGISTER_HANDLER(NAME) \
register_native_function ( # NAME, NAME ## _handler)

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;
Expand All @@ -59,39 +55,6 @@ DELCARE_HANDLER(assert)
return false;
}


DELCARE_HANDLER(print)
{
jerry_api_length_t cc;

if (args_cnt)
{
printf(">> print(%d) :", (int)args_cnt);
for (cc=0; cc<args_cnt; cc++)
{
if (args_p[cc].type == JERRY_API_DATA_TYPE_STRING && args_p[cc].v_string)
{
static char buffer[128];
int length, maxlength;
length = -jerry_api_string_to_char_buffer (args_p[0].v_string, NULL, 0);
maxlength = MIN(length, 126);
jerry_api_string_to_char_buffer (args_p[cc].v_string,
(jerry_api_char_t *) buffer,
maxlength);
*(buffer + length) = 0;
printf("[%s] ", buffer);
}
else
{
printf ("(%d) ", args_p[cc].type);
}
}
printf ("\r\n");
}
return true;
}


DELCARE_HANDLER(led)
{
if (args_cnt < 2)
Expand All @@ -104,17 +67,17 @@ DELCARE_HANDLER(led)
value = (int)JS_VALUE_TO_NUMBER (&args_p[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->v_bool = true;
ret_val_p->u.v_bool = true;
}
else {
ret_val_p->v_bool = false;
ret_val_p->u.v_bool = false;
}
return true;
}


//-----------------------------------------------------------------------------

static bool
Expand All @@ -140,7 +103,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,
Expand All @@ -158,10 +121,8 @@ register_native_function (const char* name,
return bok;
}


void js_register_functions (void)
{
REGISTER_HANDLER (assert);
REGISTER_HANDLER (print);
REGISTER_HANDLER (led);
}
8 changes: 4 additions & 4 deletions targets/mbedk64f/source/jerry_extapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,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))


void js_register_functions (void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
* limitations under the License.
*/

#include "jerry-core/jerry.h"

#include <stdlib.h>
#include <stdio.h>

#include "jerry-core/jerry.h"
#include "jerry_run.h"
#include "jerry_extapi.h"

Expand All @@ -27,6 +26,7 @@ static const char* fn_sys_loop_name = "sysloop";

int js_entry (const char *source_p, const size_t source_size)
{
jerry_api_object_t *err_obj_p = NULL;
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;
Expand All @@ -35,19 +35,23 @@ int js_entry (const char *source_p, const size_t source_size)

js_register_functions ();

if (!jerry_parse (jerry_src, source_size))
if (!jerry_parse (jerry_src, source_size, &err_obj_p))
{
printf ("Error: jerry_parse failed\r\n");
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'err_obj_p' must be released here.

jerry_api_release_object (err_obj_p);
}
else
{
if ((flags & JERRY_FLAG_PARSE_ONLY) == 0)
{
ret_code = jerry_run ();
ret_code = jerry_run (&err_obj_p);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check err_obj_p and release if it is not NULL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey.

if (err_obj_p != NULL)
{
jerry_api_release_object (err_obj_p);
}
}
}

return ret_code;
}

Expand Down Expand Up @@ -98,10 +102,10 @@ int js_loop (uint32_t ticknow)
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,
Expand All @@ -119,4 +123,3 @@ void js_exit (void)
{
jerry_cleanup ();
}

2 changes: 0 additions & 2 deletions targets/mbedk64f/source/jerry_run.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
#ifndef __JERRY_RUN_H__
#define __JERRY_RUN_H__


int js_entry (const char *source_p, const size_t source_size);
int js_eval (const char *source_p, const size_t source_size);
int js_loop (uint32_t ticknow);
void js_exit (void);


#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

#include "jerry_targetjs.h"

static int jerry_init(void) {
static int jerry_init(void)
{
int retcode;
int src;

Expand All @@ -36,7 +37,8 @@ static int jerry_init(void) {
return -1;
}
/* run rest of the js files */
for (src=1; js_codes[src].source; src++) {
for (src=1; js_codes[src].source; src++)
{
retcode = js_eval(js_codes[src].source, js_codes[src].length);
if (retcode != 0) {
printf("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[src].name);
Expand All @@ -47,14 +49,15 @@ static int jerry_init(void) {
return 0;
}

static void jerry_loop(void) {
static void jerry_loop(void)
{
static uint32_t _jcount = 0;

js_loop(_jcount++);
}


void app_start(int, char**){
void app_start(int, char**)
{
// set 115200 baud rate for stdout
static Serial pc(USBTX, USBRX);
pc.baud(115200);
Expand All @@ -64,7 +67,8 @@ void app_start(int, char**){
printf (" hash %s\r\n", jerry_commit_hash);
printf (" branch %s\r\n", jerry_branch_name);

if (jerry_init() == 0) {
if (jerry_init() == 0)
{
minar::Scheduler::postCallback(jerry_loop)
.period(minar::milliseconds(100))
;
Expand Down
6 changes: 1 addition & 5 deletions targets/mbedk64f/source/makejerry.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ set(LJCORE ${CMAKE_CURRENT_LIST_DIR}/../../../)
include_directories(${LJCORE})

# compile flags
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS}
-mlittle-endian
-mthumb
-mcpu=cortex-m4
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlittle-endian -mthumb -mcpu=cortex-m4")

# link jerryscript
set(LJPATH ${CMAKE_CURRENT_LIST_DIR}/../libjerry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
*/

#include "mbed-drivers/mbed.h"

#include "native_mbedk64f.h"


void native_led(int port, int val) {
void native_led(int port, int val)
{
static const PinName portmap[] = { LED1, LED2, LED3, LED4 };
DigitalOut led(portmap[port]);
led = val;
Expand Down
2 changes: 0 additions & 2 deletions targets/mbedk64f/source/native_mbedk64f.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#ifndef __NATIVE_MBEDK64F_H__
#define __NATIVE_MBEDK64F_H__


void native_led(int port, int val);


#endif