mirror of
https://github.com/google/pebble.git
synced 2025-05-28 14:03:12 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
63
third_party/jerryscript/targets/zephyr/Makefile
vendored
Normal file
63
third_party/jerryscript/targets/zephyr/Makefile
vendored
Normal file
|
@ -0,0 +1,63 @@
|
|||
# Copyright © 2016 Intel Corporation
|
||||
#
|
||||
# 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
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
ifndef ZEPHYR_BASE
|
||||
$(error Missing zephyr base)
|
||||
endif
|
||||
|
||||
# For testing without real hardware use qemu_x86 instead of arduino_101
|
||||
BOARD ?= arduino_101_factory
|
||||
|
||||
O ?= $(PROJECT_BASE)/outdir
|
||||
|
||||
ZEPHYR ?= $(ZEPHYR_BASE)
|
||||
TYPE ?= release
|
||||
JERRYHEAP ?= 16
|
||||
|
||||
ZEPHYRINC = $(ZEPHYR_BASE)/include
|
||||
ZEPHYRLIB = $(ZEPHYR_BASE)/lib
|
||||
|
||||
TARGET_ZEPHYR ?= ./targets/zephyr
|
||||
SOURCE_DIR = $(TARGET_ZEPHYR)/src
|
||||
|
||||
export JERRY_INCLUDE = $(CURDIR)/jerry-core/
|
||||
|
||||
MDEF_FILE = $(realpath $(SOURCE_DIR)/../prj.mdef)
|
||||
CONF_FILE = $(realpath $(SOURCE_DIR)/../prj.conf)
|
||||
|
||||
ifdef V
|
||||
$(info Zephyr)
|
||||
$(info SOURCE_DIR=$(SOURCE_DIR))
|
||||
$(info JERRY_INCLUDE=$(JERRY_INCLUDE))
|
||||
$(info CONF_FILE =$(CONF_FILE))
|
||||
endif
|
||||
|
||||
KERNEL_TYPE = micro
|
||||
|
||||
KBUILD_VERBOSE = $(V)
|
||||
|
||||
APP = main-zephyr.c
|
||||
|
||||
ALL_LIBS += $(USER_LIBS)
|
||||
export ALL_LIBS
|
||||
LDFLAGS_zephyr += $(USER_LIB_INCLUDE_DIR)
|
||||
export LDFLAGS_zephyr
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
||||
|
||||
.PHONY = showconfig
|
||||
|
204
third_party/jerryscript/targets/zephyr/Makefile.zephyr
vendored
Normal file
204
third_party/jerryscript/targets/zephyr/Makefile.zephyr
vendored
Normal file
|
@ -0,0 +1,204 @@
|
|||
# Copyright © 2016 Intel Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
ifeq ($(.DEFAULT_GOAL),)
|
||||
$(warning no default goal is set)
|
||||
endif
|
||||
|
||||
BOARD ?= arduino_101_factory
|
||||
BOARD_NAME ?= arduino_101
|
||||
|
||||
ifeq ($(BOARD),qemu_x86)
|
||||
BOARD_NAME = qemu_x86
|
||||
endif
|
||||
|
||||
TARGET_ZEPHYR ?= ./targets/zephyr
|
||||
TARGET_ZEPHYR_SRC_DIR = $(TARGET_ZEPHYR)/src
|
||||
|
||||
TYPE ?= jerry-core
|
||||
JERRYHEAP ?= 16
|
||||
JERRYPROFILE ?= minimal
|
||||
|
||||
# Include functionality like regular expressions
|
||||
# check Jerry script documentation
|
||||
#
|
||||
# -cp
|
||||
# -cp_minimal
|
||||
# -cp_minimal-mem_stats
|
||||
# -mem_stats
|
||||
# -mem_stress_test
|
||||
|
||||
ifndef ZEPHYR_BASE
|
||||
$(error Missing Zephyr base, did you source zephyr-env.sh? )
|
||||
endif
|
||||
|
||||
INTERM = build/$(BOARD)/obj-$(BOARD)
|
||||
OUTPUT = build/$(BOARD)
|
||||
|
||||
-include $(ZEPHYR_BASE)/boards/$(BOARD_NAME)/Makefile.board
|
||||
-include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)
|
||||
|
||||
EXT_CFLAGS := -fno-asynchronous-unwind-tables -fno-omit-frame-pointer
|
||||
EXT_CFLAGS += -fno-stack-protector -fno-strict-overflow -ffreestanding
|
||||
EXT_CFLAGS += -fno-reorder-functions -fno-defer-pop -fdata-sections
|
||||
EXT_CFLAGS += -ffunction-sections -fno-inline-functions
|
||||
|
||||
ifeq ($(BOARD),qemu_x86)
|
||||
CONFIG_TOOLCHAIN_VARIANT = x86
|
||||
CPU = i686
|
||||
EXT_CFLAGS += -march=pentium
|
||||
EXT_CFLAGS += -mpreferred-stack-boundary=2 -mno-sse
|
||||
else ifeq ($(BOARD),qemu_cortex_m3)
|
||||
CONFIG_TOOLCHAIN_VARIANT = arm
|
||||
CPU = arm7-m
|
||||
EXT_CFLAGS += -march=armv7-m -mthumb -mcpu=cortex-m3 -mabi=aapcs
|
||||
else ifeq ($(BOARD),frdm_k64f)
|
||||
CONFIG_TOOLCHAIN_VARIANT = arm
|
||||
CPU = arm7e-m
|
||||
EXT_CFLAGS += -march=armv7e-m -mthumb -mcpu=cortex-m4 -mabi=aapcs -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||
else ifeq ($(BOARD),em_starterkit)
|
||||
# TODO: Tested only to build, untested to boot
|
||||
CONFIG_TOOLCHAIN_VARIANT = arc
|
||||
CPU = arc
|
||||
EXT_CFLAGS += -mARCv2EM -mav2em -mno-sdata
|
||||
else
|
||||
CONFIG_TOOLCHAIN_VARIANT = iamcu
|
||||
CPU = i686
|
||||
EXT_CFLAGS += -march=lakemont -mtune=lakemont -miamcu -msoft-float
|
||||
EXT_CFLAGS += -mpreferred-stack-boundary=2 -mno-sse
|
||||
endif
|
||||
|
||||
EXT_CFLAGS += -Wall -Wno-format-zero-length -Wno-pointer-sign
|
||||
EXT_CFLAGS += -Werror=format -Werror=implicit-int -Wno-unused-but-set-variable
|
||||
EXT_CFLAGS += -Wno-main -Wno-strict-aliasing -Wno-old-style-declaration
|
||||
EXT_CFLAGS += -Wno-error=format=
|
||||
EXT_CFLAGS += -D_XOPEN_SOURCE=700
|
||||
EXT_CFLAGS += -nostdlib
|
||||
|
||||
# Pass2
|
||||
-include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)
|
||||
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
|
||||
ZEPHYR_LIBC_INC = $(subst -I,,$(TOOLCHAIN_CFLAGS))
|
||||
LIB_INCLUDE_DIR += -L $(CURDIR)/$(OUTPUT)
|
||||
|
||||
# TODO: There is a warning when compiling in some architectures related to __sputc_r
|
||||
EXT_CFLAGS += -Wno-error=conversion
|
||||
EXT_CFLAGS += $(LIB_INCLUDE_DIR)
|
||||
EXT_CFLAGS += $(TOOLCHAIN_CFLAGS)
|
||||
|
||||
EXTERNAL_LIB = $(INTERM)/lib/libjerry-core.a
|
||||
ZEPHYR_BIN = $(OUTPUT)/zephyr/zephyr.strip
|
||||
|
||||
LIBS = jerry-core
|
||||
|
||||
BUILD_CONFIG = O="$(OUTPUT)/zephyr" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(INTERM)/lib" TARGET_ZEPHYR=$(TARGET_ZEPHYR)
|
||||
|
||||
.PHONY: all
|
||||
all: jerry zephyr
|
||||
|
||||
$(EXTERNAL_LIB):
|
||||
ifdef V
|
||||
@echo "- JERRY SCRIPT -------------------------------------------------"
|
||||
endif
|
||||
mkdir -p $(INTERM)
|
||||
mkdir -p $(OUTPUT)
|
||||
cmake -B$(INTERM) -H./ \
|
||||
-DENABLE_LTO=OFF \
|
||||
-DFEATURE_VALGRIND=OFF \
|
||||
-DFEATURE_PROFILE=$(JERRYPROFILE) \
|
||||
-DFEATURE_ERROR_MESSAGES=ON \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_VERBOSE_MAKEFILE=$(V) \
|
||||
-DMEM_HEAP_SIZE_KB=$(JERRYHEAP) \
|
||||
-DEXTERNAL_CMAKE_C_COMPILER=$(CC) \
|
||||
-DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \
|
||||
-DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=$(CPU) \
|
||||
-DJERRY_CMDLINE=OFF \
|
||||
-DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
|
||||
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain_external.cmake \
|
||||
-DFEATURE_SNAPSHOT_EXEC=OFF \
|
||||
-DENABLE_ALL_IN_ONE=OFF \
|
||||
-DJERRY_LIBC=OFF \
|
||||
$(EXT_JERRY_FLAGS)
|
||||
|
||||
make -C $(INTERM) $(TYPE)$(VARIETY) V=1
|
||||
|
||||
$(ZEPHYR_BIN):
|
||||
ifdef V
|
||||
@echo "- ZEPHYR -------------------------------------------------------"
|
||||
endif
|
||||
make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG)
|
||||
@echo "Finished"
|
||||
@file $(OUTPUT)/zephyr/zephyr.strip
|
||||
@size $(OUTPUT)/zephyr/zephyr.strip
|
||||
|
||||
jerry: $(EXTERNAL_LIB)
|
||||
@touch $(EXTERNAL_LIB)
|
||||
|
||||
zephyr: $(EXTERNAL_LIB) $(ZEPHYR_BIN)
|
||||
@touch $(ZEPHYR_BIN)
|
||||
|
||||
qemu: $(EXTERNAL_LIB) $(ZEPHYR_BIN)
|
||||
make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) qemu
|
||||
|
||||
flash: $(EXTERNAL_LIB) $(OUTPUT)/zephyr/zephyr.strip
|
||||
make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) flash
|
||||
|
||||
debugserver:
|
||||
make -f $(TARGET_ZEPHYR)/Makefile BOARD=$(BOARD_NAME) debugserver
|
||||
|
||||
dfu-x86: all
|
||||
@- dfu-util -a x86_app -D build/$(BOARD)/zephyr/zephyr.bin; \
|
||||
if [ $$? -eq 0 ] ; then echo "\nYour program will launch in 5 seconds." ; \
|
||||
else echo "\nProgram didn't flash, try pressing the reset buttons \nand wait a second for the bootloader to load, \nor flash again the factory bootloader."; fi
|
||||
|
||||
usage:
|
||||
help:
|
||||
@echo Usage:
|
||||
@echo showconfig Show parameters and configuration
|
||||
@echo flash Flash into board
|
||||
@echo all Compile jerryscript and zephyr
|
||||
|
||||
showconfig:
|
||||
@echo "- CONFIGURATION ------------------------------------------------"
|
||||
@echo "INTERM = $(INTERM)"
|
||||
@echo "OUTPUT = $(OUTPUT)"
|
||||
@echo "CC = $(CC) "
|
||||
@echo "BOARD = $(ZEPHYR_BASE)/boards/$(BOARD)/Makefile.board "
|
||||
@echo "TOOLCHAIN = $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) "
|
||||
@echo "TOOLCHAIN_CFLAGS = $(TOOLCHAIN_CFLAGS) "
|
||||
@echo "CROSS_COMPILE = $(CROSS_COMPILE) "
|
||||
@echo "TOOLCHAIN_LIBS = $(TOOLCHAIN_LIBS) "
|
||||
@echo "LIBS = $(LIBS) "
|
||||
@echo "LIB_INCLUDE_DIR = $(LIB_INCLUDE_DIR) "
|
||||
@echo "BUILD_CONFIG = $(BUILD_CONFIG) "
|
||||
@echo "ZEPHYR_LIBC_INC = $(ZEPHYR_LIBC_INC) "
|
||||
make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) showconfig
|
||||
|
||||
clean:
|
||||
@echo "Clearing Jerryscript"
|
||||
@rm -rf $(OUTPUT)
|
||||
@rm -rf $(INTERM)
|
||||
@rm -f $(TARGET_ZEPHYR_SRC_DIR)/*.o
|
||||
@echo "Clearing Zephyr"
|
||||
make -f $(TARGET_ZEPHYR)/Makefile clean
|
||||
make -f $(TARGET_ZEPHYR)/Makefile pristine
|
||||
|
||||
mrproper:
|
||||
make -f $(TARGET_ZEPHYR)/Makefile mrproper
|
||||
|
152
third_party/jerryscript/targets/zephyr/README.md
vendored
Normal file
152
third_party/jerryscript/targets/zephyr/README.md
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
### About
|
||||
|
||||
This folder contains files to integrate JerryScript with Zephyr RTOS to
|
||||
run on a number of supported boards (like
|
||||
[Arduino 101 / Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101),
|
||||
[Zephyr Arduino 101](https://www.zephyrproject.org/doc/board/arduino_101.html)).
|
||||
|
||||
### How to build
|
||||
|
||||
#### 1. Preface
|
||||
|
||||
1. Directory structure
|
||||
|
||||
Assume `harmony` as the path to the projects to build.
|
||||
The folder tree related would look like this.
|
||||
|
||||
```
|
||||
harmony
|
||||
+ jerryscript
|
||||
| + targets
|
||||
| + zephyr
|
||||
+ zephyr-project
|
||||
```
|
||||
|
||||
|
||||
2. Target boards/emulations
|
||||
|
||||
Following Zephyr boards were tested: qemu_x86, qemu_cortex_m3, arduino_101,
|
||||
frdm_k64f.
|
||||
|
||||
|
||||
#### 2. Prepare Zephyr
|
||||
|
||||
Follow [this](https://www.zephyrproject.org/doc/getting_started/getting_started.html) page to get
|
||||
the Zephyr source and configure the environment.
|
||||
|
||||
If you just start with Zephyr, you may want to follow "Building a Sample
|
||||
Application" section in the doc above and check that you can flash your
|
||||
target board.
|
||||
|
||||
Remember to source the Zephyr environment as explained in the zephyr documenation:
|
||||
|
||||
```
|
||||
cd zephyr-project
|
||||
source zephyr-env.sh
|
||||
|
||||
export ZEPHYR_GCC_VARIANT=zephyr
|
||||
export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>
|
||||
```
|
||||
|
||||
#### 3. Build JerryScript for Zephyr
|
||||
|
||||
The easiest way is to build and run on a QEMU emulator:
|
||||
|
||||
For x86 architecture:
|
||||
|
||||
```
|
||||
make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_x86 qemu
|
||||
```
|
||||
|
||||
For ARM (Cortex-M) architecture:
|
||||
|
||||
```
|
||||
make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_cortex_m3 qemu
|
||||
```
|
||||
|
||||
#### 4. Build for Arduino 101
|
||||
|
||||
```
|
||||
# assume you are in harmony folder
|
||||
cd jerryscript
|
||||
make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory
|
||||
```
|
||||
|
||||
This will generate the following libraries:
|
||||
```
|
||||
./build/arduino_101_factory/librelease-cp_minimal.jerry-core.a
|
||||
./build/arduino_101_factory/librelease-cp_minimal.jerry-libm.lib.a
|
||||
./build/arduino_101_factory/librelease.external-cp_minimal-entry.a
|
||||
```
|
||||
|
||||
The final Zephyr image will be located here:
|
||||
```
|
||||
./build/arduino_101_factory/zephyr/zephyr.strip
|
||||
```
|
||||
|
||||
#### 5. Flashing
|
||||
|
||||
Details on how to flash the image can be found here:
|
||||
[Flashing image](https://www.zephyrproject.org/doc/board/arduino_101.html)
|
||||
(or similar page for other supported boards).
|
||||
|
||||
To be able to use this demo in hardware you will need the serial console
|
||||
which will be generating output to Pins 0 & 1.
|
||||
|
||||
You will need a 3.3v TTL to RS232, please follow the zephyr documentation on it.
|
||||
|
||||
Some examples of building the software
|
||||
|
||||
```
|
||||
make -f ./targets/zephyr/Makefile.zephyr BOARD=<board> clean
|
||||
```
|
||||
|
||||
- Not using a Jtag and having a factory stock Arduino 101.
|
||||
You can follow the Zephyr instructions to flash using the dfu-util command
|
||||
or use this helper:
|
||||
|
||||
```
|
||||
make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory dfu-x86
|
||||
```
|
||||
|
||||
Make sure you have the factory bootloader in your device to use this method or it will not flash.
|
||||
|
||||
- Using JTAG
|
||||
|
||||
There is a helper function to flash using the JTAG and Flywatter2
|
||||
|
||||

|
||||
|
||||
```
|
||||
make -f ./targets/zephyr/Makefile.zephyr BOARD=arduino_101_factory flash
|
||||
```
|
||||
|
||||
<warning> Careful if you flash the BOARD arduino_101, you will lose the bootloader
|
||||
and you will have to follow the zephyr documentation to get it back from
|
||||
the backup we all know you did at the setup. </warning>
|
||||
|
||||
#### 6. Serial terminal
|
||||
|
||||
Test command line in a serial terminal.
|
||||
|
||||
|
||||
You should see something similar to this:
|
||||
```
|
||||
JerryScript build: Aug 12 2016 17:12:55
|
||||
JerryScript API 1.0
|
||||
Zephyr version 1.4.0
|
||||
js>
|
||||
```
|
||||
|
||||
|
||||
Run the example javascript command test function
|
||||
```
|
||||
js> var test=0; for (t=100; t<1000; t++) test+=t; print ('Hi JS World! '+test);
|
||||
Hi JS World! 494550
|
||||
```
|
||||
|
||||
|
||||
Try a more complex function:
|
||||
```
|
||||
js> function hello(t) {t=t*10;return t}; print("result"+hello(10.5));
|
||||
```
|
BIN
third_party/jerryscript/targets/zephyr/docs/arduino_101.jpg
vendored
Normal file
BIN
third_party/jerryscript/targets/zephyr/docs/arduino_101.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
7
third_party/jerryscript/targets/zephyr/prj.conf
vendored
Normal file
7
third_party/jerryscript/targets/zephyr/prj.conf
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_NEWLIB_LIBC=y
|
||||
CONFIG_FLOAT=y
|
||||
CONFIG_CONSOLE_HANDLER=y
|
||||
CONFIG_CONSOLE_HANDLER_SHELL=y
|
||||
CONFIG_ARC_INIT=n
|
||||
|
5
third_party/jerryscript/targets/zephyr/prj.mdef
vendored
Normal file
5
third_party/jerryscript/targets/zephyr/prj.mdef
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
% Application : JerryScript Sample
|
||||
|
||||
% TASK NAME PRIO ENTRY STACK GROUPS
|
||||
% ==================================
|
||||
TASK TASKA 7 main 2048 [EXE]
|
22
third_party/jerryscript/targets/zephyr/src/Makefile
vendored
Normal file
22
third_party/jerryscript/targets/zephyr/src/Makefile
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Copyright © 2016 Intel Corporation
|
||||
#
|
||||
# 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.
|
||||
|
||||
ifdef V
|
||||
$(info Compiling application)
|
||||
endif
|
||||
|
||||
# Adding path for jerry script APIs
|
||||
ZEPHYRINCLUDE += -I$(JERRY_INCLUDE)
|
||||
|
||||
obj-y += main-zephyr.o getline-zephyr.o
|
57
third_party/jerryscript/targets/zephyr/src/getline-zephyr.c
vendored
Normal file
57
third_party/jerryscript/targets/zephyr/src/getline-zephyr.c
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* Copyright (c) 2016 Linaro
|
||||
*
|
||||
* 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 <zephyr.h>
|
||||
#include <uart.h>
|
||||
#include <drivers/console/uart_console.h>
|
||||
#include "getline-zephyr.h"
|
||||
|
||||
/* While app processes one input line, Zephyr will have another line
|
||||
buffer to accumulate more console input. */
|
||||
static struct uart_console_input line_bufs[2];
|
||||
|
||||
static struct nano_fifo free_queue;
|
||||
static struct nano_fifo used_queue;
|
||||
|
||||
char *zephyr_getline(void)
|
||||
{
|
||||
static struct uart_console_input *cmd;
|
||||
|
||||
/* Recycle cmd buffer returned previous time */
|
||||
if (cmd != NULL)
|
||||
{
|
||||
nano_fifo_put(&free_queue, cmd);
|
||||
}
|
||||
|
||||
cmd = nano_fifo_get(&used_queue, TICKS_UNLIMITED);
|
||||
return cmd->line;
|
||||
}
|
||||
|
||||
void zephyr_getline_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
nano_fifo_init(&used_queue);
|
||||
nano_fifo_init(&free_queue);
|
||||
for (i = 0; i < sizeof(line_bufs) / sizeof(*line_bufs); i++)
|
||||
{
|
||||
nano_fifo_put(&free_queue, &line_bufs[i]);
|
||||
}
|
||||
|
||||
/* Zephyr UART handler takes an empty buffer from free_queue,
|
||||
stores UART input in it until EOL, and then puts it into
|
||||
used_queue. */
|
||||
uart_register_input(&free_queue, &used_queue, NULL);
|
||||
}
|
17
third_party/jerryscript/targets/zephyr/src/getline-zephyr.h
vendored
Normal file
17
third_party/jerryscript/targets/zephyr/src/getline-zephyr.h
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* Copyright (c) 2016 Linaro
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void zephyr_getline_init(void);
|
||||
char *zephyr_getline(void);
|
48
third_party/jerryscript/targets/zephyr/src/jerry-entry.c
vendored
Normal file
48
third_party/jerryscript/targets/zephyr/src/jerry-entry.c
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* Copyright 2016 Intel Corporation
|
||||
*
|
||||
* 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 <stdarg.h>
|
||||
|
||||
#include "jerry-port.h"
|
||||
|
||||
/**
|
||||
* Provide console message implementation for the engine.
|
||||
*/
|
||||
void
|
||||
jerry_port_console (const char *format, /**< format string */
|
||||
...) /**< parameters */
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
vfprintf (stdout, format, args);
|
||||
va_end (args);
|
||||
} /* jerry_port_console */
|
||||
|
||||
|
||||
/**
|
||||
* Provide log message implementation for the engine.
|
||||
*/
|
||||
void
|
||||
jerry_port_log (jerry_log_level_t level, /**< log level */
|
||||
const char *format, /**< format string */
|
||||
...) /**< parameters */
|
||||
{
|
||||
(void) level; /* ignore log level */
|
||||
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
} /* jerry_port_log */
|
97
third_party/jerryscript/targets/zephyr/src/main-zephyr.c
vendored
Normal file
97
third_party/jerryscript/targets/zephyr/src/main-zephyr.c
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* Copyright 2016 Intel Corporation
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <misc/printk.h>
|
||||
#include <misc/shell.h>
|
||||
#include "getline-zephyr.h"
|
||||
|
||||
#include "jerry-api.h"
|
||||
|
||||
static jerry_value_t print_function;
|
||||
|
||||
static int shell_cmd_handler (char *source_buffer)
|
||||
{
|
||||
jerry_value_t ret_val;
|
||||
|
||||
ret_val = jerry_eval ((jerry_char_t *) source_buffer,
|
||||
strlen (source_buffer),
|
||||
false);
|
||||
|
||||
if (jerry_value_has_error_flag (ret_val))
|
||||
{
|
||||
/* User-friendly error messages require at least "cp" JerryScript
|
||||
profile. Include a message prefix in case "cp_minimal" profile
|
||||
is used. */
|
||||
printf ("Error executing statement: ");
|
||||
/* Clear error flag, otherwise print call below won't produce any
|
||||
output. */
|
||||
jerry_value_clear_error_flag (&ret_val);
|
||||
}
|
||||
|
||||
if (!jerry_value_has_error_flag (print_function))
|
||||
{
|
||||
jerry_value_t ret_val_print = jerry_call_function (print_function,
|
||||
jerry_create_undefined (),
|
||||
&ret_val,
|
||||
1);
|
||||
jerry_release_value (ret_val_print);
|
||||
}
|
||||
|
||||
jerry_release_value (ret_val);
|
||||
|
||||
return 0;
|
||||
} /* shell_cmd_handler */
|
||||
|
||||
void main (void)
|
||||
{
|
||||
uint32_t zephyr_ver = sys_kernel_version_get ();
|
||||
printf ("JerryScript build: " __DATE__ " " __TIME__ "\n");
|
||||
printf ("JerryScript API %d.%d\n", JERRY_API_MAJOR_VERSION, JERRY_API_MINOR_VERSION);
|
||||
printf ("Zephyr version %d.%d.%d\n", (int)SYS_KERNEL_VER_MAJOR (zephyr_ver),
|
||||
(int)SYS_KERNEL_VER_MINOR (zephyr_ver),
|
||||
(int)SYS_KERNEL_VER_PATCHLEVEL (zephyr_ver));
|
||||
|
||||
zephyr_getline_init ();
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
jerry_value_t global_obj_val = jerry_get_global_object ();
|
||||
|
||||
jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print");
|
||||
print_function = jerry_get_property (global_obj_val, print_func_name_val);
|
||||
jerry_release_value (print_func_name_val);
|
||||
jerry_release_value (global_obj_val);
|
||||
if (jerry_value_has_error_flag (print_function))
|
||||
{
|
||||
printf ("Error: could not look up print function, expression results won't be printed\n");
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
char *s;
|
||||
printf("js> ");
|
||||
fflush(stdout);
|
||||
s = zephyr_getline ();
|
||||
if (*s)
|
||||
{
|
||||
shell_cmd_handler (s);
|
||||
}
|
||||
}
|
||||
|
||||
/* As we never retturn from REPL above, don't call jerry_cleanup() here. */
|
||||
} /* main */
|
Loading…
Add table
Add a link
Reference in a new issue