Skip to content

Commit

Permalink
Initial support for mbed OS 5.1
Browse files Browse the repository at this point in the history
- Wrappers for mbed I/O drivers
- Makefile for automating build process
- Script to generate pin definitions from mbed OS source tree
- Updates to js2c to enable building without a main.js file

JerryScript-DCO-1.0-Signed-off-by: Matthew Else Matthew.Else@arm.com
  • Loading branch information
Matthew Else authored and Matthew Else committed Sep 21, 2016
1 parent 316223e commit 577c7f4
Show file tree
Hide file tree
Showing 47 changed files with 2,427 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Produced files

.mbedignore
build/*

# IDE related files
Expand Down
8 changes: 8 additions & 0 deletions targets/mbedos5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mbed-os
mbed-events
.build
.mbed
mbed_settings.py
js/pins.js
source/pins.cpp
source/jerry_targetjs.h
89 changes: 89 additions & 0 deletions targets/mbedos5/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2016 ARM Limited
#
# 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.

# USAGE:
# specify the board using the command line:
# make BOARD=[mbed board name]

BOARD=$(subst [mbed] ,,$(shell mbed target))
HEAPSIZE=16

DEBUG=0
NO_JS=0
MBED_VERBOSE=0

MBED_CLI_FLAGS=-j0 --source . --source ../../

EXTRA_SRC=

ifneq ($(EXTRA_SRC),)
EXTRA_SRC_MOD=--source $(subst :, --source ,$(EXTRA_SRC))
MBED_CLI_FLAGS += $(EXTRA_SRC_MOD)
endif

EXTERN_BUILD_DIR=

ifneq ($(EXTERN_BUILD_DIR),)
MBED_CLI_FLAGS += --build $(EXTERN_BUILD_DIR)
endif

ifeq ($(DEBUG), 1)
MBED_CLI_FLAGS += -o debug-info
endif

ifeq ($(MBED_VERBOSE), 1)
MBED_CLI_FLAGS += -v
else ifeq ($(MBED_VERBOSE), 2)
MBED_CLI_FLAGS += -vv
endif

MBED_CLI_FLAGS += -D "CONFIG_MEM_HEAP_AREA_SIZE=(1024*$(HEAPSIZE))"
MBED_CLI_FLAGS += -t GCC_ARM

.PHONY: all js2c getlibs rebuild library
all: source/jerry_targetjs.h source/pins.cpp .mbed ../../.mbedignore
mbed target $(BOARD)
mbed compile $(MBED_CLI_FLAGS)

library: .mbed ../../.mbedignore
# delete encoded js code if it exists
rm -f source/jerry_targetjs.h
mbed target $(BOARD)
mbed compile $(MBED_CLI_FLAGS) --library

clean:
rm -rf .build/$(BOARD)

js2c: js/main.js js/flash_leds.js
python ../tools/js2c.py --ignore pins.js

source/pins.cpp:
python tools/generate_pins.py ${BOARD}

ifeq ($(NO_JS),0)
source/jerry_targetjs.h: js2c
else
source/jerry_targetjs.h: ;
endif

getlibs: .mbed

.mbed:
mbed config root .
mbed toolchain GCC_ARM
mbed target $(BOARD)
mbed deploy

../../.mbedignore:
cp ./template-mbedignore.txt ../../.mbedignore
75 changes: 75 additions & 0 deletions targets/mbedos5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# JerryScript with mbed OS 5

TL;DR? jump straight to [quickstart](#quick-start)

## Introduction

This directory contains the necessary code to build JerryScript for devices
capable of running mbed OS 5. It has been tested with the following boards
so far:

- [Nordic Semiconductor NRF52 Development Kit](https://developer.mbed.org/platforms/Nordic-nRF52-DK/)
- [NXP Freedom K64F](https://developer.mbed.org/platforms/FRDM-K64F/)
- [STM NUCLEO F401RE](https://developer.mbed.org/platforms/ST-Nucleo-F401RE/)
- [Silicon Labs EFM32 Giant Gecko](https://developer.mbed.org/platforms/EFM32-Giant-Gecko/)

## Features

### Peripheral Drivers

Peripheral Drivers are intended as a 1-to-1 mapping to mbed C++ APIs, with a few
differences (due to differences between JavaScript and C++ like lack of operator
overloading).

- [DigitalOut](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/io/DigitalOut/)
- [InterruptIn](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/io/InterruptIn/)
- [I2C](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/interfaces/digital/I2C/)
- setInterval and setTimeout using [mbed-event](https://github.com/ARMmbed/mbed-events)

## Dependencies

### mbed CLI

mbed CLI is used as the build tool for mbed OS 5. You can find out how to install
it in the [official documentation](https://docs.mbed.com/docs/mbed-os-handbook/en/5.1/dev_tools/cli/#installing-mbed-cli).

### arm-none-eabi-gcc

arm-none-eabi-gcc is the only currently tested compiler for jerryscript on mbed,
and instructions for building can be found as part of the mbed-cli installation
instructions above.

### make

make is used to automate the process of fetching dependencies, and making sure that
mbed-cli is called with the correct arguments.

### (optional) jshint

jshint is used to statically check your JavaScript code, as part of the build process.
This ensures that pins you are using in your code are available on your chosen target
platform.

## Quick Start

Once you have all of your dependencies installed, you can build the project as follows:

```bash
git clone https://github.com/Samsung/jerryscript
cd jerryscript/targets/mbedos5
make getlibs
# NRF52 Development Kit:
make BOARD=NRF52_DK
# FRDM K64F
make BOARD=K64F
```

The produced file (in .build/**[BOARD]**/GCC_ARM) can then be uploaded to your board, and will
run when you press reset.

If you make a modification to main.js, you can simply rerun make, and it will remember your
previous choice of board:

```bash
make
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_DIGITALOUT_H
#define _JERRYSCRIPT_MBED_DRIVERS_DIGITALOUT_H

#include "jerryscript-mbed-library-registry/wrap_tools.h"

DECLARE_CLASS_CONSTRUCTOR(DigitalOut);

#endif // _JERRYSCRIPT_MBED_DRIVERS_DIGITALOUT_H
22 changes: 22 additions & 0 deletions targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/I2C-js.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_I2C_H
#define _JERRYSCRIPT_MBED_DRIVERS_I2C_H

#include "jerryscript-mbed-library-registry/wrap_tools.h"

DECLARE_CLASS_CONSTRUCTOR(I2C);

#endif // _JERRYSCRIPT_MBED_DRIVERS_I2C_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_INTERRUPTIN_H
#define _JERRYSCRIPT_MBED_DRIVERS_INTERRUPTIN_H

#include "jerryscript-mbed-library-registry/wrap_tools.h"

DECLARE_CLASS_CONSTRUCTOR(InterruptIn);

#endif // _JERRYSCRIPT_MBED_DRIVERS_INTERRUPTIN_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H
#define _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H

#include "jerryscript-mbed-library-registry/wrap_tools.h"
#include "jerryscript-mbed-util/logging.h"

DECLARE_GLOBAL_FUNCTION(assert);

#endif // _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H
23 changes: 23 additions & 0 deletions targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/gc-js.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_GC_H
#define _JERRYSCRIPT_MBED_DRIVERS_GC_H

#include "jerryscript-mbed-library-registry/wrap_tools.h"
#include "jerryscript-mbed-util/logging.h"

DECLARE_GLOBAL_FUNCTION(gc);

#endif // _JERRYSCRIPT_MBED_DRIVERS_GC_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H
#define _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H

#include "jerryscript-mbed-drivers/InterruptIn-js.h"
#include "jerryscript-mbed-drivers/DigitalOut-js.h"
#include "jerryscript-mbed-drivers/setInterval-js.h"
#include "jerryscript-mbed-drivers/setTimeout-js.h"
#include "jerryscript-mbed-drivers/assert-js.h"
#include "jerryscript-mbed-drivers/I2C-js.h"
#include "jerryscript-mbed-drivers/gc-js.h"

DECLARE_JS_WRAPPER_REGISTRATION (base) {
REGISTER_GLOBAL_FUNCTION(assert);
REGISTER_GLOBAL_FUNCTION(gc);
REGISTER_GLOBAL_FUNCTION(setInterval);
REGISTER_GLOBAL_FUNCTION(setTimeout);
REGISTER_CLASS_CONSTRUCTOR(DigitalOut);
REGISTER_CLASS_CONSTRUCTOR(I2C);
REGISTER_CLASS_CONSTRUCTOR(InterruptIn);
}

#endif // _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_SET_INTERVAL_H
#define _JERRYSCRIPT_MBED_DRIVERS_SET_INTERVAL_H

#include "jerryscript-mbed-library-registry/wrap_tools.h"

DECLARE_GLOBAL_FUNCTION(setInterval);

#endif // _JERRYSCRIPT_MBED_DRIVERS_SET_INTERVAL_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2016 ARM Limited
*
* 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 _JERRYSCRIPT_MBED_DRIVERS_SET_TIMEOUT_H
#define _JERRYSCRIPT_MBED_DRIVERS_SET_TIMEOUT_H

#include "jerryscript-mbed-library-registry/wrap_tools.h"

DECLARE_GLOBAL_FUNCTION(setTimeout);

#endif // _JERRYSCRIPT_MBED_DRIVERS_SET_TIMEOUT_H
Loading

0 comments on commit 577c7f4

Please sign in to comment.