Add target build for mbed / FRDM-K64F board.
JerryScript-DCO-1.0-Signed-off-by: SaeHie Park saehie.park@samsung.com
This commit is contained in:
@@ -34,3 +34,10 @@ third-party/STM32F4-Discovery_FW_V1.1.0
|
||||
third-party/nuttx
|
||||
third-party/vera++
|
||||
third-party/cppcheck
|
||||
|
||||
# targets
|
||||
jerry_targetjs.h
|
||||
targets/mbedk64f/libjerry
|
||||
targets/mbedk64f/build
|
||||
targets/mbedk64f/yotta_modules
|
||||
targets/mbedk64f/yotta_targets
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"build": {
|
||||
"target": "frdm-k64f-gcc,*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
# Copyright 2015 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.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# use TAB-8
|
||||
|
||||
CURDIR = `pwd`
|
||||
TYPE = release
|
||||
INTERM = build/obj-mbed-k64f
|
||||
OUTPUT = build/bin/$(TYPE).mbedk64f
|
||||
COPYTARGET = targets/mbedk64f/libjerry
|
||||
JERRYHEAP ?= 16
|
||||
TARGET_DIR ?= /media/$(USER)/MBED
|
||||
|
||||
EXT_CFLAGS := -D__TARGET_MBED_K64F
|
||||
EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
|
||||
EXT_CFLAGS += -Wno-error=format=
|
||||
|
||||
|
||||
all: jerry js2c yotta
|
||||
|
||||
|
||||
jerry:
|
||||
mkdir -p $(INTERM)
|
||||
mkdir -p $(OUTPUT)
|
||||
mkdir -p $(COPYTARGET)
|
||||
cmake -B$(INTERM) -H./ \
|
||||
-DENABLE_LTO=OFF \
|
||||
-DENABLE_VALGRIND=OFF \
|
||||
-DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \
|
||||
-DUSE_COMPILER_DEFAULT_LIBC=YES \
|
||||
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=arm7-m \
|
||||
-DEXTERNAL_CMAKE_C_COMPILER=arm-none-eabi-gcc \
|
||||
-DEXTERNAL_CMAKE_CXX_COMPILER=arm-none-eabi-g++ \
|
||||
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
|
||||
-DEXTERNAL_MEM_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-fdlibm.third_party.lib.a $(COPYTARGET)/libfdlibm.a
|
||||
|
||||
|
||||
js2c:
|
||||
cd targets/mbedk64f; ./js2c.py;
|
||||
|
||||
|
||||
yotta:
|
||||
cd targets/mbedk64f; \
|
||||
yotta target frdm-k64f-gcc; \
|
||||
yotta build
|
||||
|
||||
|
||||
flash: check_mbed
|
||||
cp targets/mbedk64f/build/frdm-k64f-gcc/source/jerry.bin \
|
||||
"$(TARGET_DIR)/."
|
||||
@echo "Wait till LED flashing stops..."
|
||||
|
||||
|
||||
check_mbed:
|
||||
@if [ ! -d "${TARGET_DIR}" ] ; then \
|
||||
echo "MBED not mounted at ${TARGET_DIR}"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf $(INTERM)
|
||||
rm -rf $(OUTPUT)
|
||||
rm -rf targets/mbedk64f/build
|
||||
@@ -0,0 +1,9 @@
|
||||
var check = 1;
|
||||
|
||||
function blink() {
|
||||
var blk = (check > 8) ? 1 : 0;
|
||||
led(1, blk);
|
||||
check = (check >= 10) ? 1 : check+1;
|
||||
}
|
||||
|
||||
print("blink js OK");
|
||||
@@ -0,0 +1,4 @@
|
||||
function sysloop(ticknow) {
|
||||
blink();
|
||||
};
|
||||
print("main js OK");
|
||||
Executable
+144
@@ -0,0 +1,144 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright 2015 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.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# This file converts ./js/*.js to a C-array in source/jerry_targetjs.h file
|
||||
|
||||
import sys
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
|
||||
def extractName(path):
|
||||
return os.path.splitext(os.path.basename(path))[0]
|
||||
|
||||
def writeLine(fo, content, indent=0):
|
||||
buf = ' ' * indent + content + '\n'
|
||||
fo.write(buf)
|
||||
|
||||
def regroup(l, n):
|
||||
return [ l[i:i+n] for i in range(0, len(l), n) ]
|
||||
|
||||
def removeComments(code):
|
||||
pattern = r'(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)'
|
||||
regex = re.compile(pattern, re.MULTILINE | re.DOTALL)
|
||||
def _replacer(match):
|
||||
if match.group(2) is not None:
|
||||
return ""
|
||||
else:
|
||||
return match.group(1)
|
||||
return regex.sub(_replacer, code)
|
||||
|
||||
def removeWhitespaces(code):
|
||||
return re.sub('\n+', '\n', re.sub('\n +', '\n', code))
|
||||
|
||||
|
||||
LICENSE = '''/* Copyright 2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an \"AS IS\" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is generated by js2c.py. Please do not modify.
|
||||
*/
|
||||
|
||||
'''
|
||||
|
||||
HEADER = '''#ifndef JERRY_TARGETJS_H
|
||||
#define JERRY_TARGETJS_H
|
||||
|
||||
'''
|
||||
|
||||
FOOTER = '''
|
||||
#endif
|
||||
|
||||
'''
|
||||
|
||||
OUT_PATH = './source/'
|
||||
SRC_PATH = './js/'
|
||||
|
||||
# argument processing
|
||||
buildtype = 'release'
|
||||
if len(sys.argv) >= 2:
|
||||
buildtype = sys.argv[1]
|
||||
|
||||
fout = open(OUT_PATH + 'jerry_targetjs.h', 'w')
|
||||
fout.write(LICENSE);
|
||||
fout.write(HEADER);
|
||||
|
||||
def exportOneFile(path, name):
|
||||
fout.write('const static char ' + name + '_n[] = "' + name + '";\n')
|
||||
fout.write('const static char ' + name + '_s[] =\n{\n')
|
||||
|
||||
fin = open(path, 'r');
|
||||
code = fin.read() + '\0'
|
||||
|
||||
# minimize code when release mode
|
||||
if buildtype != 'debug':
|
||||
code = removeComments(code)
|
||||
code = removeWhitespaces(code)
|
||||
|
||||
for line in regroup(code, 10):
|
||||
buf = ', '.join(map(lambda ch: format(ord(ch),"#04x"), line))
|
||||
if line[-1] != '\0':
|
||||
buf += ','
|
||||
writeLine(fout, buf, 1)
|
||||
writeLine(fout, '};')
|
||||
writeLine(fout, 'const static int ' + name + '_l = ' + str(len(code)-1) + ';')
|
||||
writeLine(fout, '')
|
||||
|
||||
fin.close();
|
||||
|
||||
def exportOneName(name):
|
||||
writeLine(fout, '{ ' + name + '_n, ' + name + '_s, ' + name + '_l }, \\', 1)
|
||||
|
||||
files = glob.glob(SRC_PATH + '*.js')
|
||||
for path in files:
|
||||
name = extractName(path)
|
||||
exportOneFile(path, name)
|
||||
|
||||
|
||||
NATIVE_STRUCT = '''
|
||||
struct js_source_all {
|
||||
const char* name;
|
||||
const char* source;
|
||||
const int length;
|
||||
};
|
||||
|
||||
#define DECLARE_JS_CODES \\
|
||||
struct js_source_all js_codes[] = \\
|
||||
{ \\
|
||||
'''
|
||||
|
||||
fout.write(NATIVE_STRUCT)
|
||||
exportOneName('main')
|
||||
filenames = map(extractName, files)
|
||||
for name in filenames:
|
||||
if name != 'main':
|
||||
exportOneName(name)
|
||||
|
||||
writeLine(fout, '{ NULL, NULL, 0 } \\', 1)
|
||||
writeLine(fout, '};')
|
||||
|
||||
fout.write(FOOTER)
|
||||
fout.close()
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "jerry",
|
||||
"version": "0.0.0",
|
||||
"bin": "./source",
|
||||
"private": true,
|
||||
"description": "JerryScript in mbed",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"mbed-drivers": "~0.11.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
### About
|
||||
|
||||
This folder contains files to run JerryScript in mbed / FRDM-K64F board.
|
||||
|
||||
#### Installing yotta
|
||||
|
||||
You need to install yotta before proceeding.
|
||||
Please visit http://yottadocs.mbed.com/#installing-on-linux
|
||||
|
||||
##### Cross-compiler for FRDM-K64F
|
||||
|
||||
If you don't have any GCC compiler installed, please visit [this]
|
||||
(https://launchpad.net/gcc-arm-embedded/+download) page to download GCC 4.8.4
|
||||
which was tested for building JerryScript for K64F.
|
||||
|
||||
#### How to build JerryScript
|
||||
|
||||
```
|
||||
make -f targets/mbedk64f/Makefile.mbedk64f clean
|
||||
make -f targets/mbedk64f/Makefile.mbedk64f jerry
|
||||
```
|
||||
|
||||
#### JerryScript output files
|
||||
|
||||
Two files will be generated at `targets/mbedk64f/libjerry`
|
||||
* libjerrycore.a
|
||||
* libfdlibm.a
|
||||
|
||||
#### Building mbed binary
|
||||
|
||||
```
|
||||
make -f targets/mbedk64f/Makefile.mbedk64f js2c yotta
|
||||
```
|
||||
|
||||
Or, cd to `targets/mbedk64f` where `Makefile.mbedk64f` exist
|
||||
|
||||
```
|
||||
cd targets/mbedk64f
|
||||
yotta target frdm-k64f-gcc
|
||||
yotta build
|
||||
```
|
||||
|
||||
#### Build at once
|
||||
|
||||
Omit target name to build both jerry library and mbed binary.
|
||||
|
||||
```
|
||||
make -f targets/mbedk64f/Makefile.mbedk64f
|
||||
```
|
||||
|
||||
#### Flashing to k64f
|
||||
|
||||
|
||||
```
|
||||
make -f targets/mbedk64f/Makefile.mbedk64f flash
|
||||
```
|
||||
|
||||
It assumes default mound folder is `/media/(user)/MBED`
|
||||
|
||||
If its mounted to other path, give it with `TARGET_DIR` variable, for example,
|
||||
```
|
||||
TARGET_DIR=/mnt/media/MBED make -f targets/mbedk64f/Makefile.mbedk64f flash
|
||||
```
|
||||
|
||||
Or you can just copy `targets/mbedk64f/build/frdm-k64f-gcc/source/jerry.bin`
|
||||
file to mounted folder.
|
||||
|
||||
When LED near the USB port flashing stops and `MBED` folder shows up on the
|
||||
desktop(if you are using GUI), press RESET button on the board to execute
|
||||
JerryScript led flashing sample program in js folder.
|
||||
|
||||
#### How blink sample program works
|
||||
|
||||
All `.js` files in `js` folder are executed, with `main.js` in first order.
|
||||
`sysloop()` function in main.js is called periodically in every 100msec by
|
||||
below code in `main.cpp` `jerry_loop()`, which calls `js_loop()` in
|
||||
`jerry_mbedk64f.cpp`
|
||||
|
||||
```
|
||||
minar::Scheduler::postCallback(jerry_loop)
|
||||
.period(minar::milliseconds(100))
|
||||
```
|
||||
|
||||
`sysloop()` then calls `blink()` in `blink.js` which blinks the `LED` in
|
||||
every second.
|
||||
@@ -0,0 +1,167 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerry-core/jerry.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jerry_extapi.h"
|
||||
#include "native_mbedk64f.h"
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(A,B) ((A)<(B)?(A):(B))
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define __UNSED__ __attribute__((unused))
|
||||
|
||||
#define DELCARE_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)
|
||||
|
||||
#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)
|
||||
{
|
||||
printf (">> Jerry assert true\r\n");
|
||||
return true;
|
||||
}
|
||||
printf ("ERROR: Script assertion failed\n");
|
||||
exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
|
||||
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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int port, value;
|
||||
port = (int)JS_VALUE_TO_NUMBER (&args_p[0]);
|
||||
value = (int)JS_VALUE_TO_NUMBER (&args_p[1]);
|
||||
|
||||
ret_val_p->type = JERRY_API_DATA_TYPE_BOOLEAN;
|
||||
if (port >=0 && port <= 3) {
|
||||
native_led(port, value);
|
||||
ret_val_p->v_bool = true;
|
||||
}
|
||||
else {
|
||||
ret_val_p->v_bool = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
|
||||
global_obj_p = jerry_api_get_global ();
|
||||
reg_func_p = jerry_api_create_external_function (handler);
|
||||
|
||||
if (!(reg_func_p != NULL
|
||||
&& jerry_api_is_function (reg_func_p)
|
||||
&& jerry_api_is_constructor (reg_func_p)))
|
||||
{
|
||||
printf ("Error: create_external_function failed !!!\r\n");
|
||||
jerry_api_release_object (global_obj_p);
|
||||
return false;
|
||||
}
|
||||
|
||||
jerry_api_acquire_object (reg_func_p);
|
||||
reg_value.type = JERRY_API_DATA_TYPE_OBJECT;
|
||||
reg_value.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)
|
||||
{
|
||||
printf ("Error: register_native_function failed: [%s]\r\n", name);
|
||||
}
|
||||
|
||||
return bok;
|
||||
}
|
||||
|
||||
|
||||
void js_register_functions (void)
|
||||
{
|
||||
REGISTER_HANDLER (assert);
|
||||
REGISTER_HANDLER (print);
|
||||
REGISTER_HANDLER (led);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/* Copyright 2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __JERRY_EXTAPI_H__
|
||||
#define __JERRY_EXTAPI_H__
|
||||
|
||||
|
||||
#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)->v_object))
|
||||
|
||||
#define JS_VALUE_TO_NUMBER(val_p) \
|
||||
((val_p)->type == JERRY_API_DATA_TYPE_FLOAT32 ? \
|
||||
static_cast<double>((val_p)->v_float32) : \
|
||||
(val_p)->type == JERRY_API_DATA_TYPE_FLOAT64 ? \
|
||||
static_cast<double>((val_p)->v_float64) : \
|
||||
static_cast<double>((val_p)->v_uint32))
|
||||
|
||||
|
||||
void js_register_functions (void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed-drivers/mbed.h"
|
||||
|
||||
#include "jerry-core/jerry.h"
|
||||
|
||||
|
||||
/**
|
||||
* Provide log message to filestream implementation for the engine.
|
||||
*/
|
||||
int jerry_port_logmsg (FILE* stream, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int count;
|
||||
va_start (args, format);
|
||||
count = vfprintf (stream, format, args);
|
||||
va_end (args);
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide error message to console implementation for the engine.
|
||||
*/
|
||||
int jerry_port_errormsg (const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int count;
|
||||
va_start (args, format);
|
||||
count = vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide output character to console implementation for the engine.
|
||||
*/
|
||||
int jerry_port_putchar (int c)
|
||||
{
|
||||
return putchar(c);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerry-core/jerry.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jerry_run.h"
|
||||
#include "jerry_extapi.h"
|
||||
|
||||
|
||||
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_init (flags);
|
||||
|
||||
js_register_functions ();
|
||||
|
||||
if (!jerry_parse (jerry_src, source_size))
|
||||
{
|
||||
printf ("Error: jerry_parse failed\r\n");
|
||||
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((flags & JERRY_FLAG_PARSE_ONLY) == 0)
|
||||
{
|
||||
ret_code = jerry_run ();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
status = jerry_api_eval ((jerry_api_char_t *) source_p,
|
||||
source_size,
|
||||
false,
|
||||
false,
|
||||
&res);
|
||||
|
||||
jerry_api_release_value (&res);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int js_loop (uint32_t ticknow)
|
||||
{
|
||||
jerry_api_object_t *global_obj_p;
|
||||
jerry_api_value_t sysloop_func;
|
||||
bool is_ok;
|
||||
|
||||
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)
|
||||
{
|
||||
printf ("Error: '%s' not defined!!!\r\n", fn_sys_loop_name);
|
||||
jerry_api_release_object (global_obj_p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!API_DATA_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);
|
||||
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;
|
||||
|
||||
jerry_api_value_t res;
|
||||
is_ok = jerry_api_call_function (sysloop_func.v_object,
|
||||
global_obj_p,
|
||||
&res,
|
||||
val_args,
|
||||
val_argv);
|
||||
jerry_api_release_value (&res);
|
||||
free (val_args);
|
||||
|
||||
jerry_api_release_value (&sysloop_func);
|
||||
jerry_api_release_object (global_obj_p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void js_exit (void)
|
||||
{
|
||||
jerry_cleanup ();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Copyright 2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed-drivers/mbed.h"
|
||||
|
||||
#include "jerry-core/jerry.h"
|
||||
#include "jerry_run.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "jerry_targetjs.h"
|
||||
|
||||
static int jerry_init(void) {
|
||||
int retcode;
|
||||
int src;
|
||||
|
||||
DECLARE_JS_CODES;
|
||||
|
||||
/* run main.js */
|
||||
retcode = js_entry(js_codes[0].source, js_codes[0].length);
|
||||
if (retcode != 0) {
|
||||
printf("js_entry failed code(%d) [%s]\r\n", retcode, js_codes[0].name);
|
||||
js_exit();
|
||||
return -1;
|
||||
}
|
||||
/* run rest of the js files */
|
||||
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);
|
||||
js_exit();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void jerry_loop(void) {
|
||||
static uint32_t _jcount = 0;
|
||||
|
||||
js_loop(_jcount++);
|
||||
}
|
||||
|
||||
|
||||
void app_start(int, char**){
|
||||
// set 115200 baud rate for stdout
|
||||
static Serial pc(USBTX, USBRX);
|
||||
pc.baud(115200);
|
||||
|
||||
printf ("\r\nJerryScript in mbed K64F\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);
|
||||
|
||||
if (jerry_init() == 0) {
|
||||
minar::Scheduler::postCallback(jerry_loop)
|
||||
.period(minar::milliseconds(100))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright 2015 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.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# application name
|
||||
set(MBEDMODULE "jerry")
|
||||
|
||||
# add include jerry-core
|
||||
set(LJCORE ${CMAKE_CURRENT_LIST_DIR}/../../../)
|
||||
include_directories(${LJCORE})
|
||||
|
||||
# compile flags
|
||||
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS}
|
||||
-mlittle-endian
|
||||
-mthumb
|
||||
-mcpu=cortex-m4
|
||||
)
|
||||
|
||||
# link jerryscript
|
||||
set(LJPATH ${CMAKE_CURRENT_LIST_DIR}/../libjerry)
|
||||
set(LJFILES "")
|
||||
set(LJFILES ${LJFILES} ${LJPATH}/libfdlibm.a)
|
||||
set(LJFILES ${LJFILES} ${LJPATH}/libjerrycore.a)
|
||||
target_link_libraries(${MBEDMODULE} ${LJFILES})
|
||||
@@ -0,0 +1,25 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed-drivers/mbed.h"
|
||||
|
||||
#include "native_mbedk64f.h"
|
||||
|
||||
|
||||
void native_led(int port, int val) {
|
||||
static const PinName portmap[] = { LED1, LED2, LED3, LED4 };
|
||||
DigitalOut led(portmap[port]);
|
||||
led = val;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __NATIVE_MBEDK64F_H__
|
||||
#define __NATIVE_MBEDK64F_H__
|
||||
|
||||
|
||||
void native_led(int port, int val);
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user