Skip to content

targets: zephyr: Reinstate "print" function and error printing. #1851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2017
Merged
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
2 changes: 1 addition & 1 deletion targets/zephyr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ZEPHYRLIB = $(ZEPHYR_BASE)/lib
TARGET_ZEPHYR ?= ./targets/zephyr
SOURCE_DIR = $(TARGET_ZEPHYR)/src

export JERRY_INCLUDE = $(CURDIR)/jerry-core/include
export JERRY_INCLUDE = -I$(CURDIR)/jerry-core/include -I$(CURDIR)/jerry-ext/include

MDEF_FILE = $(realpath $(SOURCE_DIR)/../prj.mdef)
CONF_FILE = $(realpath $(SOURCE_DIR)/../prj.conf)
Expand Down
8 changes: 4 additions & 4 deletions targets/zephyr/Makefile.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export BOARD
TARGET_ZEPHYR ?= ./targets/zephyr
TARGET_ZEPHYR_SRC_DIR = $(TARGET_ZEPHYR)/src

TYPE ?= jerry-core
COMPONENTS ?= jerry-core jerry-ext
JERRYHEAP ?= 16
JERRYPROFILE ?= minimal

Expand Down Expand Up @@ -61,9 +61,9 @@ EXT_CFLAGS += -D_XOPEN_SOURCE=700

EXT_CFLAGS += -Wno-error=conversion

EXTERNAL_LIB = $(INTERM)/lib/libjerry-core.a
EXTERNAL_LIB = $(INTERM)/lib/libjerry-core.a $(INTERM)/lib/libjerry-ext.a

LIBS = jerry-core
LIBS = jerry-core jerry-ext

BUILD_CONFIG = O="$(OUTPUT)" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(INTERM)/lib" TARGET_ZEPHYR=$(TARGET_ZEPHYR)

Expand Down Expand Up @@ -94,7 +94,7 @@ endif
-DJERRY_LIBC=OFF \
$(EXT_JERRY_FLAGS)

make -C $(INTERM) $(TYPE)$(VARIETY) V=1
make -C $(INTERM) $(COMPONENTS) V=1

$(OUTPUT)/Makefile.export: $(OUTPUT)/include/config/auto.conf
make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) outputexports
Expand Down
2 changes: 1 addition & 1 deletion targets/zephyr/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ $(info Compiling application)
endif

# Adding path for jerry script APIs
ZEPHYRINCLUDE += -I$(JERRY_INCLUDE)
ZEPHYRINCLUDE += $(JERRY_INCLUDE)

obj-y += main-zephyr.o getline-zephyr.o jerry-port.o
10 changes: 10 additions & 0 deletions targets/zephyr/src/jerry-port.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ jerry_port_get_time_zone (jerry_time_zone_t *tz_p)

return true;
} /* jerry_port_get_time_zone */

/**
* Provide the implementation of jerryx_port_handler_print_char.
* Uses 'printf' to print a single character to standard output.
*/
void
jerryx_port_handler_print_char (char c) /**< the character to print */
{
printf ("%c", c);
} /* jerryx_port_handler_print_char */
20 changes: 20 additions & 0 deletions targets/zephyr/src/main-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,28 @@
#include "getline-zephyr.h"

#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-ext/handler.h"

static jerry_value_t print_function;

/**
* Register a JavaScript function in the global object.
*/
static void
register_js_function (const char *name_p, /**< name of the function */
jerry_external_handler_t handler_p) /**< function callback */
{
jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p);

if (jerry_value_has_error_flag (result_val))
{
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register '%s' method.", name_p);
}

jerry_release_value (result_val);
} /* register_js_function */

static int shell_cmd_handler (char *source_buffer)
{
jerry_value_t ret_val;
Expand Down Expand Up @@ -69,6 +88,7 @@ void main (void)

zephyr_getline_init ();
jerry_init (JERRY_INIT_EMPTY);
register_js_function ("print", jerryx_handler_print);
jerry_value_t global_obj_val = jerry_get_global_object ();

jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print");
Expand Down