Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)

* Implement memory profiler, optimize memory usage, modify code indent

* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default

* Add a new extension library: connection

* Fix bug of reading magic number and version in big endian platform

* Re-org platform APIs: move most platform APIs from iwasm to shared-lib

* Enhance wasm loader to fix some security issues

* Fix issue about illegal load of EXC_RETURN into PC on stm32 board

* Updates that let a restricted version of the interpreter run in SGX

* Enable native/app address validation and conversion for wasm app

* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused

* Refine binary size and fix several minor issues

Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c

* Add more strict security checks for libc wrapper API's

* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files

* Enhance security of libc strcpy/sprintf wrapper function

* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions

* Remove get_module_inst() and fix issue of call native

* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate

* Refine interpreter call native process, refine memory boudary check

* Fix issues of invokeNative function of arm/mips/general version

* Add a switch to build simple sample without gui support

* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code

* Re-org shared lib header files, remove unused info; fix compile issues of vxworks

* Add build target general

* Remove unused files

* Update license header

* test push

* Restore file

* Sync up with internal/feature

* Sync up with internal/feature

* Rename build_wamr_app to build_wasm_app

* Fix small issues of README

* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc

* Sync up with internal/feature

* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue

* Sync up with internal/feature

* Fix bug of config.h and rename wasi config.h to ssp_config.h

* Sync up with internal/feature

* Import wamr aot

* update document

* update document

* Update document, disable WASI in 32bit

* update document

* remove files

* update document

* Update document

* update document

* update document

* update samples

* Sync up with internal repo
This commit is contained in:
wenyongh
2020-01-21 13:26:14 +08:00
committed by Wang Xin
parent 2a4528c749
commit 46b93b9d22
464 changed files with 25137 additions and 7911 deletions

View File

@ -1,27 +1,22 @@
Introduction
"gui" sample introduction
==============
This sample demonstrates that a graphic user interface application in WebAssembly programming with WAMR graphic library(WGL) extension. WGL defined a WASM application API set for programming the UI applications.
This sample demonstrates that a graphic user interface application in WebAssembly programming with WAMR graphic library(WGL) which is part of WAMR app-framework.
WGL implemention is based on [LittlevGL](https://github.com/littlevgl/), an open-source embedded 2d graphic library. Comparing the building the LittlevGL into WASM bytecode in the [littlevgl](../littlevgl) sample, WGL compiled LittlevGL source code into the WAMR runtime and defined a wrapper API for exporting to Webassembly application. These extension API's are listed in: `<wamr_root>/core/iwasm/lib/app-libs/extension/gui/wgl.h`. Currently only a small set of API's are provided and that would be extended in future.
Compared with the [littlevgl](../littlevgl) sample, WGL compiles LittlevGL source code into the WAMR runtime and defines a set of wrapper API's for exporting to Webassembly application.
The runtime component supports building target for Linux and Zephyr/STM Nucleo board. The beauty of this sample is the WebAssembly application can have identical display and behavior when running from both runtime environments. That implies we can do majority of application validation from desktop environment as long as two runtime distributions support the same set of application interface.
Below pictures show the WASM application is running on an STM board with an LCD touch panel. When users click the blue button, the WASM application increases the counter, and the latest counter value is displayed on the top banner of the touch panel. The number on top will plus one each second, and the number on the bottom will plus one when clicked.
Below picture shows the WASM application is running on an STM board with an LCD touch panel.
![WAMR UI SAMPLE](../../doc/pics/vgl_demo2.png "WAMR UI DEMO")
Configure 32 bit or 64 bit build
==============
On 64 bit operating system, there is an option to build 32 bit or 64 bit binaries. In file `./lvgl-native-ui-app/CMakeLists.txt` and/or `./wasm-runtime-wgl/linux-build/CMakeLists.txt` , modify the line:
`set (BUILD_AS_64BIT_SUPPORT "YES")`
where `YES` means 64 bit build while `NO` means 32 bit build.
When users click the blue button, the WASM application increases the counter, and the latest counter value is displayed on the top banner of the touch panel. The number on top will plus one each second, and the number on the bottom will plus one when clicked.
# Test on Linux
Install required SDK and libraries
==============
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `BUILD_AS_64BIT_SUPPORT` is set to `NO`)
--------------
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_32` when building WAMR runtime)
Use apt-get:
`sudo apt-get install libsdl2-dev:i386`
Or download source from www.libsdl.org:
@ -30,7 +25,7 @@ Or download source from www.libsdl.org:
make
sudo make install
```
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `BUILD_AS_64BIT_SUPPORT` is set to `YES`)
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_64` when building WAMR runtime)
Use apt-get:
`sudo apt-get install libsdl2-dev`
Or download source from www.libsdl.org:
@ -40,16 +35,9 @@ make
sudo make install
```
- Install EMSDK
```
https://emscripten.org/docs/tools_reference/emsdk.html
```
Build and Run
==============
--------------
Linux
--------------------------------
- Build</br>
`./build.sh`</br>
All binaries are in "out", which contains "host_tool", "lvgl_native_ui_app", "ui_app.wasm", "ui_app_lvgl_compatible.wasm" and "wasm_runtime_wgl".
@ -63,9 +51,12 @@ Linux
`./host_tool -i ui_app -f ui_app.wasm`</br>
`./host_tool -i ui_app -f ui_app_lvgl_compatible.wasm`</br>
Zephyr
--------------------------------
WASM VM and native extension method can be built into Zephyr, Then we can install wasm app into STM32.</br>
Test on Zephyr
================================
We can use a STM32 NUCLEO_F767ZI board with ILI9341 display and XPT2046 touch screen to run the test. Then use host_tool to remotely install wasm app into STM32.
- Build WASM VM into Zephyr system</br>
a. clone zephyr source code</br>
Refer to Zephyr getting started.</br>
@ -77,16 +68,15 @@ https://docs.zephyrproject.org/latest/getting_started/index.html</br>
`cd zephyr/samples/`</br>
`cp -a <wamr_root>samples/gui/wasm-runtime-wgl wasm-runtime-wgl`</br>
`cd wasm-runtime-wgl/zephyr_build`</br>
c. create a link to wamr core</br>
` ln -s <wamr_root>/core core`</br>
c. create a link to wamr root dir</br>
` ln -s <wamr_root> wamr`</br>
d. build source code</br>
`mkdir build && cd build`</br>
`source ../../../../zephyr-env.sh`</br>
`cmake -GNinja -DBOARD=nucleo_f746zg ..`</br>
` ninja flash`</br>
- Test on STM32 NUCLEO_F767ZI with ILI9341 Display with XPT2046 touch</br>
Hardware Connections
- Hardware Connections
```
+-------------------+-+------------------+

View File

@ -4,6 +4,8 @@ PROJECT_DIR=$PWD
WAMR_DIR=${PWD}/../..
OUT_DIR=${PWD}/out
BUILD_DIR=${PWD}/build
WAMR_RUNTIME_CFG=${PROJECT_DIR}/wamr_config_gui.cmake
LV_CFG_PATH=${PROJECT_DIR}/lv_config
if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then
echo "Local Build Env"
@ -23,12 +25,12 @@ rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
cd ${WAMR_DIR}/core/shared-lib/mem-alloc
cd ${WAMR_DIR}/core/shared/mem-alloc
if [ ! -d "tlsf" ]; then
git clone https://github.com/mattconte/tlsf
fi
cd ${WAMR_DIR}/core/iwasm/lib/3rdparty
cd ${WAMR_DIR}/core/deps
if [ ! -d "lvgl" ]; then
git clone https://github.com/littlevgl/lvgl.git --branch v6.0.1
fi
@ -36,11 +38,22 @@ if [ ! -d "lv_drivers" ]; then
git clone https://github.com/littlevgl/lv_drivers.git
fi
echo -e "\n\n"
echo "##################### 0. build wamr-sdk gui start#####################"
cd ${WAMR_DIR}/wamr-sdk
./build_sdk.sh -n gui -x ${WAMR_RUNTIME_CFG} -e ${LV_CFG_PATH}
[ $? -eq 0 ] || exit $?
echo "#####################build wamr-sdk success"
echo -e "\n\n"
echo "##################### 1. build native-ui-app start#####################"
cd $BUILD_DIR
mkdir -p lvgl-native-ui-app
cd lvgl-native-ui-app
$cmakewrap ${PROJECT_DIR}/lvgl-native-ui-app
[ $? -eq 0 ] || exit $?
$makewrap
if [ $? != 0 ];then
echo "BUILD_FAIL native-ui-app $?\n"
@ -49,17 +62,22 @@ fi
echo $PWD
cp lvgl_native_ui_app ${OUT_DIR}
echo "#####################build native-ui-app success"
echo -e "\n\n"
echo "##################### 2. build littlevgl wasm runtime start#####################"
echo "##################### 2. build wasm runtime start#####################"
cd $BUILD_DIR
mkdir -p wasm-runtime-wgl
cd wasm-runtime-wgl
$cmakewrap ${PROJECT_DIR}/wasm-runtime-wgl/linux-build
$cmakewrap ${PROJECT_DIR}/wasm-runtime-wgl/linux-build -DWAMR_BUILD_SDK_PROFILE=gui
[ $? -eq 0 ] || exit $?
$makewrap
[ $? -eq 0 ] || exit $?
cp wasm_runtime_wgl ${OUT_DIR}/
echo "##################### build littlevgl wasm runtime end#####################"
echo -e "\n\n"
echo "#####################build host-tool"
cd $BUILD_DIR
@ -73,13 +91,23 @@ if [ $? != 0 ];then
fi
cp host_tool ${OUT_DIR}
echo "#####################build host-tool success"
echo -e "\n\n"
echo "##################### 3. build wasm ui app start#####################"
cd ${PROJECT_DIR}/wasm-apps/wgl
rm -rf build
mkdir build && cd build
$cmakewrap .. -DCMAKE_TOOLCHAIN_FILE=${WAMR_DIR}/wamr-sdk/out/gui/app-sdk/wamr_toolchain.cmake
$makewrap
cp ui_app.wasm ${OUT_DIR}/
[ $? -eq 0 ] || exit $?
mv ui_app.wasm ${OUT_DIR}/
# $makewrap
# mv ui_app.wasm ${OUT_DIR}/
cd ${PROJECT_DIR}/wasm-apps/lvgl-compatible
$makewrap
cp ui_app_lvgl_compatible.wasm ${OUT_DIR}/
[ $? -eq 0 ] || exit $?
mv ui_app_lvgl_compatible.wasm ${OUT_DIR}/
echo "##################### build wasm ui app end#####################"

View File

@ -66,7 +66,10 @@ typedef int16_t lv_coord_t;
* The graphical objects and other related data are stored here. */
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#ifndef LV_MEM_CUSTOM
#define LV_MEM_CUSTOM 0
#endif
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (128U * 1024U)
@ -81,9 +84,9 @@ typedef int16_t lv_coord_t;
/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
# define LV_MEM_AUTO_DEFRAG 1
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
# define LV_MEM_CUSTOM_INCLUDE "bh_memory.h" /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC bh_malloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE bh_free /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings

View File

@ -22,16 +22,18 @@ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
endif ()
endif ()
set(THIRDPARTY_DIR ../../../core/iwasm/lib/3rdparty)
set(LVGL_SOURCE_DIR ${THIRDPARTY_DIR}/lvgl)
set(LVGL_DRIVER_DIR ${THIRDPARTY_DIR}/lv_drivers)
set(WAMR_DEPS_DIR ../../../core/deps)
set(LVGL_SOURCE_DIR ${WAMR_DEPS_DIR}/lvgl)
set(LVGL_DRIVER_DIR ${WAMR_DEPS_DIR}/lv_drivers)
#################################
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${THIRDPARTY_DIR})
INCLUDE_DIRECTORIES(${WAMR_DEPS_DIR})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/../lv_config)
add_definitions (-DLV_CONF_INCLUDE_SIMPLE)
file(GLOB_RECURSE INCLUDES "${LVGL_DRIVER_DIR}/*.h" "${LVGL_SOURCE_DIR}/*.h" "./*.h" )
file(GLOB_RECURSE SOURCES "${LVGL_DRIVER_DIR}/*.c" "${LVGL_SOURCE_DIR}/*.c" )

View File

@ -0,0 +1,9 @@
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET "X86_64")
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_ALL)

View File

@ -1,30 +1,27 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = clang-8
CC = /opt/wasi-sdk/bin/clang
APP_DIR = ${shell pwd}
IWASM_DIR=../../../../core/iwasm
IWASM_DIR = $(APP_DIR)/../../../../core/iwasm
SDK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk
APP_FRAMEWORK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk/wamr-app-framework
DEPS_DIR = $(APP_DIR)/../../../../core/deps
CFLAGS += -O3 \
-Wno-int-conversion \
-DLV_CONF_INCLUDE_SIMPLE \
-DENABLE_WGL=1 \
-I$(APP_DIR)/src/ \
-I$(IWASM_DIR)/lib/app-libs/base/ \
-I$(IWASM_DIR)/lib/native-interface/ \
-I$(IWASM_DIR)/lib/app-libs/extension/sensor \
-I$(IWASM_DIR)/lib/app-libs/extension/gui \
-I$(IWASM_DIR)/lib/app-libs/extension/connection
-Wno-int-conversion \
-I$(APP_DIR)/src \
-I$(APP_FRAMEWORK_DIR)/include \
-I${DEPS_DIR}
SRCS += $(APP_DIR)/src/main.c
# For app size consideration, not all but necessary app libs are included
SRCS += $(IWASM_DIR)/lib/app-libs/base/timer.c
SRCS += $(IWASM_DIR)/lib/app-libs/extension/gui/src/*.c
all:
all:
@$(CC) $(CFLAGS) $(SRCS) \
--target=wasm32 -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-Wl,--allow-undefined \
--sysroot=$(SDK_DIR)/libc-builtin-sysroot \
-L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \
-Wl,--allow-undefined-file=$(SDK_DIR)/libc-builtin-sysroot/share/defined-symbols.txt \
-Wl,--no-threads,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_timer_callback \
-Wl,--export=on_widget_event \

View File

@ -4,9 +4,9 @@
*/
#include <stdlib.h>
#include <unistd.h>
#include "wasm_app.h"
#include "lvgl.h"
#include "wa-inc/lvgl.h"
#include "wa-inc/timer_wasm_app.h"
extern char g_widget_text[];

View File

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 2.8)
project(wgl)
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/gui/app-sdk/wamr-app-framework/include
${WAMR_ROOT_DIR}/core/deps
)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},-L${WAMR_ROOT_DIR}/wamr-sdk/out/gui/app-sdk/wamr-app-framework/lib")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},--export=on_init,--export=on_timer_callback,--export=on_widget_event")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-unused-command-line-argument")
add_executable(ui_app.wasm
${CMAKE_CURRENT_LIST_DIR}/src/main.c
)
target_link_libraries(ui_app.wasm app_framework)

View File

@ -1,27 +1,29 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = clang-8
CC = /opt/wasi-sdk/bin/clang
APP_DIR = ${shell pwd}
IWASM_DIR=../../../../core/iwasm
IWASM_DIR = ../../../../core/iwasm
APP_FRAMEWORK_DIR = ../../../../core/app-framework
DEPS_DIR = ../../../../core/deps
CFLAGS += -O3 \
-Wno-int-conversion \
-DLV_CONF_INCLUDE_SIMPLE \
-DENABLE_WGL=1 \
-I$(APP_DIR)/src/ \
-I$(IWASM_DIR)/lib/app-libs/base/ \
-I$(IWASM_DIR)/lib/native-interface/ \
-I$(IWASM_DIR)/lib/app-libs/extension/sensor \
-I$(IWASM_DIR)/lib/app-libs/extension/gui \
-I$(IWASM_DIR)/lib/app-libs/extension/connection
-I$(APP_DIR)/src \
-I$(APP_FRAMEWORK_DIR)/base/app \
-I$(APP_FRAMEWORK_DIR)/app-native-shared \
-I$(APP_FRAMEWORK_DIR)/sensor/app \
-I$(APP_FRAMEWORK_DIR)/wgl/app \
-I$(APP_FRAMEWORK_DIR)/connection/app \
-I${DEPS_DIR}
SRCS += $(APP_DIR)/src/main.c
# For app size consideration, not all but necessary app libs are included
SRCS += $(IWASM_DIR)/lib/app-libs/base/timer.c
SRCS += $(IWASM_DIR)/lib/app-libs/extension/gui/src/*.c
SRCS += $(APP_FRAMEWORK_DIR)/base/app/timer.c
SRCS += $(APP_FRAMEWORK_DIR)/wgl/app/src/*.c
all:
all:
@$(CC) $(CFLAGS) $(SRCS) \
--target=wasm32 -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-Wl,--allow-undefined \

View File

@ -4,8 +4,9 @@
*/
#include <stdlib.h>
#include <unistd.h>
#include "wasm_app.h"
#include "wa-inc/wgl.h"
#include "wa-inc/timer_wasm_app.h"
static void btn_event_cb(wgl_obj_t btn, wgl_event_t event);

View File

@ -1,137 +1,43 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
project (wasm_runtime_wgl)
set(REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
set(WASM_DIR ${REPO_ROOT_DIR}/core/iwasm)
set(APP_MGR_DIR ${REPO_ROOT_DIR}/core/app-mgr)
set(SHARED_DIR ${REPO_ROOT_DIR}/core/shared-lib)
set (LV_DRIVERS_DIR ${WASM_DIR}/lib/3rdparty/lv_drivers)
set (LVGL_DIR ${WASM_DIR}/lib/3rdparty/lvgl)
file(GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c" )
set (TARGET_PLATFORM "linux")
set (WAMR_BUILD_PLATFORM "linux")
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
add_definitions(-DNVALGRIND)
endif ()
################ wamr runtime settings ################
# Set BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
if (NOT DEFINED BUILD_TARGET)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (BUILD_TARGET "X86_32")
endif ()
endif ()
string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
# Add definitions for the build target
if (BUILD_TARGET STREQUAL "X86_64")
add_definitions(-DBUILD_TARGET_X86_64)
elseif (BUILD_TARGET STREQUAL "AMD_64")
add_definitions(-DBUILD_TARGET_AMD_64)
elseif (BUILD_TARGET STREQUAL "X86_32")
add_definitions(-DBUILD_TARGET_X86_32)
elseif (BUILD_TARGET MATCHES "ARM.*")
add_definitions(-DBUILD_TARGET_ARM)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET MATCHES "THUMB.*")
add_definitions(-DBUILD_TARGET_THUMB)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET STREQUAL "MIPS")
add_definitions(-DBUILD_TARGET_MIPS)
elseif (BUILD_TARGET STREQUAL "XTENSA")
add_definitions(-DBUILD_TARGET_XTENSA)
else ()
message (FATAL_ERROR "-- Build target isn't set")
endif ()
message ("-- Build as target ${BUILD_TARGET}")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
# Add -fPIC flag if build as 64-bit
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
else ()
add_definitions (-m32)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
endif (NOT CMAKE_BUILD_TYPE)
message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
if (NOT PLATFORM)
SET(PLATFORM linux)
endif (NOT PLATFORM)
message ("-- PLATFORM = " ${PLATFORM})
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps)
enable_language (ASM)
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
include (${WASM_DIR}/runtime/utils/utils.cmake)
include (${WASM_DIR}/runtime/vmcore-wasm/vmcore.cmake)
include (${WASM_DIR}/lib/native/base/wasm_lib_base.cmake)
include (${WASM_DIR}/lib/native/libc/wasm_libc.cmake)
include (${WASM_DIR}/lib/native/extension/sensor/wasm_lib_sensor.cmake)
include (${WASM_DIR}/lib/native/extension/gui/wasm_lib_gui.cmake)
include (${WASM_DIR}/lib/native/extension/connection/wasm_lib_conn.cmake)
include (${WASM_DIR}/lib/native/extension/connection/${TARGET_PLATFORM}/connection_mgr.cmake)
include (${WASM_DIR}/lib/native-interface/native_interface.cmake)
include (${APP_MGR_DIR}/app-manager/app_mgr.cmake)
include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake)
include (${SHARED_DIR}/platform/${TARGET_PLATFORM}/shared_platform.cmake)
include (${SHARED_DIR}/utils/shared_utils.cmake)
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_DIR}/coap/lib_coap.cmake)
## use library and headers in the SDK
link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/lib)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/include
${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/include/bi-inc/deps
)
set (PROJECT_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../src/platform/${TARGET_PLATFORM})
################ application related ################
include_directories(${SHARED_DIR}/include)
include_directories(${WASM_DIR}/runtime/platform/include)
include_directories(${PROJECT_SRC_DIR})
set (LV_DRIVERS_DIR ${WAMR_ROOT_DIR}/core/deps/lv_drivers)
file (GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c")
add_definitions (-DWASM_ENABLE_BASE_LIB)
add_definitions (-Dattr_container_malloc=bh_malloc)
add_definitions (-Dattr_container_free=bh_free)
add_definitions (-DLV_CONF_INCLUDE_SIMPLE)
add_definitions (-DWASM_ENABLE_GUI=1)
add_library (vmlib
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_LIBC_SOURCE}
${APP_MGR_SOURCE}
${WASM_LIB_BASE_SOURCE}
${WASM_LIB_EXT_SOURCE}
${WASM_LIB_SENSOR_SOURCE}
${WASM_LIB_GUI_SOURCE}
${WASM_LIB_CONN_SOURCE}
${WASM_LIB_CONN_MGR_SOURCE}
${PLATFORM_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}
${NATIVE_INTERFACE_SOURCE}
)
set (PROJECT_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../src/platform/${WAMR_BUILD_PLATFORM})
include_directories(
${PROJECT_SRC_DIR}
${DEPS_DIR}
${DEPS_DIR}/lvgl
${DEPS_DIR}/lvgl/src
)
set (SOURCES
${PROJECT_SRC_DIR}/main.c

View File

@ -29,7 +29,7 @@
#include "bh_thread.h"
#include "bh_memory.h"
#include "runtime_sensor.h"
#include "attr_container.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#include "wgl.h"

View File

@ -2,8 +2,21 @@
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <sys/time.h>
extern int iwasm_main(int argc, char *argv[]);
int main(int argc, char *argv[])
{
return iwasm_main(argc,argv);
}
int time_get_ms()
{
static struct timeval tv;
gettimeofday(&tv, NULL);
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
return (int) time_in_mill;
}

View File

@ -7,9 +7,6 @@
#define XPT2046_H
#define USE_XPT2046 1
#ifndef LV_CONF_INCLUDE_SIMPLE
#define LV_CONF_INCLUDE_SIMPLE
#endif
# define XPT2046_HOR_RES 320
# define XPT2046_VER_RES 240
@ -30,11 +27,7 @@ extern "C" {
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
//#include "lv_drv_conf.h"
#else
//#include "../../lv_drv_conf.h"
#endif
#if USE_XPT2046
#include <autoconf.h>

View File

@ -12,7 +12,7 @@
#include "bh_thread.h"
#include "bh_memory.h"
#include "runtime_sensor.h"
#include "attr_container.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#include "display.h"

View File

@ -6,12 +6,10 @@
#include <stdlib.h>
#include <string.h>
#include "bh_platform.h"
#include "wasm_assert.h"
#include "wasm_log.h"
#include "wasm_platform_log.h"
#include "wasm_thread.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "bh_platform_log.h"
#include "wasm_export.h"
#include "wasm_memory.h"
#include "bh_memory.h"
extern int iwasm_main();
@ -24,3 +22,7 @@ void main(void)
}
}
int time_get_ms()
{
return k_uptime_get_32();
}

View File

@ -6,68 +6,62 @@ cmake_minimum_required(VERSION 3.8.2)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)
enable_language (ASM)
set (WAMR_BUILD_PLATFORM "zephyr")
zephyr_compile_definitions (-DNVALGRIND
-D__JLF__
-D__ZEPHYR__
-DWASM_ENABLE_BASE_LIB
-Dattr_container_malloc=bh_malloc
-Dattr_container_free=bh_free
-DWASM_ENABLE_GUI=1)
enable_language (ASM)
# Build as THUMB by default
# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS" or "XTENSA"
# if we want to support arm_32, x86, mips or xtensa
if (NOT DEFINED BUILD_TARGET)
set (BUILD_TARGET "THUMB")
if (NOT DEFINED WAMR_BUILD_TARGET)
set (WAMR_BUILD_TARGET "THUMB")
endif ()
string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
if (BUILD_TARGET STREQUAL "X86_32")
add_definitions(-DBUILD_TARGET_X86_32)
elseif (BUILD_TARGET MATCHES "ARM.*")
add_definitions(-DBUILD_TARGET_ARM)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET MATCHES "THUMB.*")
add_definitions(-DBUILD_TARGET_THUMB)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET STREQUAL "MIPS")
add_definitions(-DBUILD_TARGET_MIPS)
elseif (BUILD_TARGET STREQUAL "XTENSA")
add_definitions(-DBUILD_TARGET_XTENSA)
else ()
message (FATAL_ERROR "-- Build target isn't set")
if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()
message ("-- Build as target ${BUILD_TARGET}")
if (NOT DEFINED WAMR_BUILD_AOT)
# Disable AOT by default.
set (WAMR_BUILD_AOT 0)
endif ()
set (WASM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm)
set (APP_MGR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr)
set (SHARED_DIR ${WASM_DIR}/../shared-lib)
if (NOT DEFINED WAMR_BUILD_JIT)
# Disable JIT by default.
set (WAMR_BUILD_JIT 0)
endif ()
set (TARGET_PLATFORM "zephyr")
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
# Enable libc builtin support by default
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()
include (${WASM_DIR}/runtime/utils/utils.cmake)
include (${WASM_DIR}/runtime/vmcore-wasm/vmcore.cmake)
include (${WASM_DIR}/lib/native/base/wasm_lib_base.cmake)
include (${WASM_DIR}/lib/native/libc/wasm_libc.cmake)
include (${WASM_DIR}/lib/native/extension/sensor/wasm_lib_sensor.cmake)
include (${WASM_DIR}/lib/native/extension/gui/wasm_lib_gui.cmake)
include (${WASM_DIR}/lib/native/extension/connection/wasm_lib_conn.cmake)
include (${WASM_DIR}/lib/native/extension/connection/${TARGET_PLATFORM}/connection_mgr.cmake)
include (${WASM_DIR}/lib/native-interface/native_interface.cmake)
include (${APP_MGR_DIR}/app-manager/app_mgr.cmake)
include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake)
include (${SHARED_DIR}/platform/${TARGET_PLATFORM}/shared_platform.cmake)
include (${SHARED_DIR}/utils/shared_utils.cmake)
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_DIR}/coap/lib_coap.cmake)
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
# Disable libc wasi support by default
set (WAMR_BUILD_LIBC_WASI 0)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
set (WAMR_BUILD_APP_FRAMEWORK 1)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_LIST)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_ALL)
endif ()
################ wamr runtime settings ################
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
################ sample project related ################
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
add_definitions(-DLV_MEM_CUSTOM=1)
include_directories(${WASM_DIR}/runtime/platform/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr)
include_directories(${WAMR_ROOT_DIR}/samples/gui/lv_config)
set (LVGL_DRV_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340_adafruit_1480.c
@ -75,26 +69,8 @@ set (LVGL_DRV_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/XPT2046.c
)
set (IWASM_SRCS
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_LIBC_SOURCE}
${APP_MGR_SOURCE}
${WASM_LIB_BASE_SOURCE}
${WASM_LIB_EXT_SOURCE}
${WASM_LIB_SENSOR_SOURCE}
${WASM_LIB_GUI_SOURCE}
${WASM_LIB_CONN_SOURCE}
${WASM_LIB_CONN_MGR_SOURCE}
${PLATFORM_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}
${NATIVE_INTERFACE_SOURCE}
)
target_sources(app PRIVATE
${IWASM_SRCS}
${WAMR_RUNTIME_LIB_SOURCE}
${LVGL_DRV_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c

View File

@ -1,4 +1,4 @@
Introduction
"littlevgl" sample introduction
==============
This sample demonstrates that a graphic user interface application in WebAssembly by compiling the LittlevGL, an open-source embedded 2d graphic library into the WASM bytecode.
@ -10,7 +10,7 @@ In this sample, the whole LittlevGL source code is built into the WebAssembly co
EXPORT_WASM_API(display_fill),
EXPORT_WASM_API(display_vdb_write),
EXPORT_WASM_API(display_map),
EXPORT_WASM_API(time_get_ms), };
EXPORT_WASM_API(time_get_ms),
The runtime component supports building target for Linux and Zephyr/STM Nucleo board. The beauty of this sample is the WebAssembly application can have identical display and behavior when running from both runtime environments. That implies we can do majority of application validation from desktop environment as long as two runtime distributions support the same set of application interface.
@ -26,18 +26,12 @@ The number on top will plus one each second, and the number on the bottom will p
The sample also provides the native Linux version of application without the runtime under folder "vgl-native-ui-app". It can help to check differences between the implementations in native and WebAssembly.
Configure 32 bit or 64 bit build
==============
On 64 bit operating system, there is an option to build 32 bit or 64 bit binaries. In file `./vgl-native-ui-app/CMakeLists.txt` and/or `./vgl-wasm-runtime/CMakeLists.txt` , modify the line:
`set (BUILD_AS_64BIT_SUPPORT "YES")`
where `YES` means 64 bit build while `NO` means 32 bit build.
Test on Linux
================================
Install required SDK and libraries
==============
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `BUILD_AS_64BIT_SUPPORT` is set to `NO`)
--------------
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_32` when building WAMR runtime)
Use apt-get:
`sudo apt-get install libsdl2-dev:i386`
Or download source from www.libsdl.org:
@ -46,7 +40,7 @@ Or download source from www.libsdl.org:
make
sudo make install
```
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `BUILD_AS_64BIT_SUPPORT` is set to `YES`)
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_64` when building WAMR runtime)
Use apt-get:
`sudo apt-get install libsdl2-dev`
Or download source from www.libsdl.org:
@ -56,20 +50,13 @@ make
sudo make install
```
- Install EMSDK
```
https://emscripten.org/docs/tools_reference/emsdk.html
```
Build and Run
==============
--------------
Linux
--------------------------------
- Build</br>
`./build.sh`</br>
All binaries are in "out", which contains "host_tool", "vgl_native_ui_app", "ui_app.wasm" and "vgl_wasm_runtime".
All binaries are in "out", which contains "host_tool", "vgl_native_ui_app", "ui_app.wasm" "ui_app_no_wasi.wasm "and "vgl_wasm_runtime".
- Run native Linux application</br>
`./vgl_native_ui_app`</br>
@ -79,9 +66,9 @@ Linux
Then install wasm APP use host tool.</br>
`./host_tool -i ui_app -f ui_app.wasm`</br>
Zephyr
--------------------------------
WASM VM and native extension method can be built into Zephyr, Then we can install wasm app into STM32.</br>
Test on Zephyr
================================
We can use a STM32 NUCLEO_F767ZI board with ILI9341 display and XPT2046 touch screen to run the test. Then use host_tool to remotely install wasm app into STM32.
- Build WASM VM into Zephyr system</br>
a. clone zephyr source code</br>
Refer to Zephyr getting started.</br>
@ -93,8 +80,8 @@ https://docs.zephyrproject.org/latest/getting_started/index.html</br>
`cd zephyr/samples/`</br>
`cp -a <wamr_root>samples/littlevgl/vgl-wasm-runtime vgl-wasm-runtime`</br>
`cd vgl-wasm-runtime/zephyr_build`</br>
c. create a link to wamr core</br>
` ln -s <wamr_root>/core core`</br>
c. create a link to wamr root dir</br>
` ln -s <wamr_root> wamr`</br>
d. build source code</br>
Since ui_app incorporated LittlevGL source code, so it needs more RAM on the device to install the application.
It is recommended that RAM SIZE not less than 320KB.
@ -108,8 +95,7 @@ https://docs.zephyrproject.org/latest/getting_started/index.html</br>
`cmake -GNinja -DBOARD=nucleo_f746zg ..`</br>
` ninja flash`</br>
- Test on STM32 NUCLEO_F767ZI with ILI9341 Display with XPT2046 touch</br>
Hardware Connections
- Hardware Connections
```
+-------------------+-+------------------+
@ -140,5 +126,6 @@ Hardware Connections
- Install WASM application to Zephyr using host_tool</br>
First, connect PC and STM32 with UART. Then install to use host_tool.</br>
`./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app.wasm`
`./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app_no_wasi.wasm`
**Note**: WASI is unavailable on zephyr currently, so you have to use the ui_app_no_wasi.wasm which doesn't depend on WASI.

View File

@ -23,17 +23,22 @@ rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
cd ${WAMR_DIR}/core/shared-lib/mem-alloc
cd ${WAMR_DIR}/core/shared/mem-alloc
if [ ! -d "tlsf" ]; then
git clone https://github.com/mattconte/tlsf
fi
cd ${WAMR_DIR}/core/iwasm/lib/3rdparty
cd ${WAMR_DIR}/core/deps
if [ ! -d "lvgl" ]; then
git clone https://github.com/littlevgl/lvgl.git --branch v6.0.1
fi
echo "##################### 0. build wamr-sdk littlevgl start#####################"
cd ${WAMR_DIR}/wamr-sdk
./build_sdk.sh -n littlevgl -x ${PROJECT_DIR}/wamr_config_littlevgl.cmake
echo "#####################build wamr-sdk littlevgl success"
echo -e "\n\n"
echo "##################### 1. build native-ui-app start#####################"
cd $BUILD_DIR
mkdir -p vgl-native-ui-app
@ -48,7 +53,7 @@ echo $PWD
cp vgl_native_ui_app ${OUT_DIR}
echo "#####################build native-ui-app success"
echo -e "\n\n"
echo "##################### 2. build littlevgl wasm runtime start#####################"
cd $BUILD_DIR
mkdir -p vgl-wasm-runtime
@ -59,6 +64,7 @@ cp vgl_wasm_runtime ${OUT_DIR}/
echo "##################### build littlevgl wasm runtime end#####################"
echo -e "\n\n"
echo "#####################build host-tool"
cd $BUILD_DIR
mkdir -p host-tool
@ -72,7 +78,7 @@ fi
cp host_tool ${OUT_DIR}
echo "#####################build host-tool success"
echo -e "\n\n"
echo "##################### 3. build wasm ui app start#####################"
cd ${PROJECT_DIR}/wasm-apps
if [ ! -d "${PROJECT_DIR}/wasm-apps/lvgl" ]; then
@ -81,5 +87,7 @@ if [ ! -d "${PROJECT_DIR}/wasm-apps/lvgl" ]; then
fi
fi
./build_wasm_app.sh
cp ui_app.wasm ${OUT_DIR}/
mv ui_app.wasm ${OUT_DIR}/
mv ui_app_no_wasi.wasm ${OUT_DIR}/
rm -fr ${PROJECT_DIR}/wasm-apps/lvgl
echo "##################### build wasm ui app end#####################"

View File

@ -6,7 +6,7 @@ message ("vgl_native_ui_app...")
project (vgl_native_ui_app)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLV_CONF_INCLUDE_SIMPLE -DPLATFORM_NATIVE_LINUX -DUSE_MONITOR -DUSE_MOUSE=1")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_NATIVE_LINUX -DUSE_MONITOR -DUSE_MOUSE=1")
# Currently build as 64-bit by default. Set to "NO" to build 32-bit binaries.
set (BUILD_AS_64BIT_SUPPORT "YES")
@ -30,6 +30,9 @@ set(LVGL_DRIVER_DIR ${CMAKE_CURRENT_LIST_DIR}/lv-drivers)
message(${LVGL_SOURCE_DIR})
include( ExternalProject )
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/download_lvgl/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
@ -142,6 +145,7 @@ include_directories(
${LVGL_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/../lv_config
)
add_executable(vgl_native_ui_app ${SOURCES} )
target_link_libraries( vgl_native_ui_app -lSDL2)

View File

@ -13,11 +13,8 @@ extern "C" {
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
//#include "lv_drv_conf.h"
#else
#include "../../lv_drv_conf.h"
#endif
#include "lv_drv_conf.h"
#if USE_MOUSE

View File

@ -1,128 +1,34 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
project (vgl_wasm_runtime)
set (TARGET_PLATFORM "linux")
set (WAMR_BUILD_PLATFORM "linux")
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
add_definitions(-DNVALGRIND)
endif ()
################ wamr runtime settings ################
# Set BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
if (NOT DEFINED BUILD_TARGET)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (BUILD_TARGET "X86_32")
endif ()
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
## use library and headers in the SDK
link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/lib)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/include
${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/include/bi-inc/deps
)
# Add definitions for the build target
if (BUILD_TARGET STREQUAL "X86_64")
add_definitions(-DBUILD_TARGET_X86_64)
elseif (BUILD_TARGET STREQUAL "AMD_64")
add_definitions(-DBUILD_TARGET_AMD_64)
elseif (BUILD_TARGET STREQUAL "X86_32")
add_definitions(-DBUILD_TARGET_X86_32)
elseif (BUILD_TARGET MATCHES "ARM.*")
add_definitions(-DBUILD_TARGET_ARM)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET MATCHES "THUMB.*")
add_definitions(-DBUILD_TARGET_THUMB)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET STREQUAL "MIPS")
add_definitions(-DBUILD_TARGET_MIPS)
elseif (BUILD_TARGET STREQUAL "XTENSA")
add_definitions(-DBUILD_TARGET_XTENSA)
else ()
message (FATAL_ERROR "-- Build target isn't set")
endif ()
message ("-- Build as target ${BUILD_TARGET}")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
# Add -fPIC flag if build as 64-bit
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
else ()
add_definitions (-m32)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
endif (NOT CMAKE_BUILD_TYPE)
message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
if (NOT PLATFORM)
SET(PLATFORM linux)
endif (NOT PLATFORM)
message ("-- PLATFORM = " ${PLATFORM})
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
set(REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
set(WASM_DIR ${REPO_ROOT_DIR}/core/iwasm)
set(APP_MGR_DIR ${REPO_ROOT_DIR}/core/app-mgr)
set(SHARED_DIR ${REPO_ROOT_DIR}/core/shared-lib)
enable_language (ASM)
include (${WASM_DIR}/runtime/utils/utils.cmake)
include (${WASM_DIR}/runtime/vmcore-wasm/vmcore.cmake)
include (${WASM_DIR}/lib/native/base/wasm_lib_base.cmake)
include (${WASM_DIR}/lib/native/libc/wasm_libc.cmake)
include (${WASM_DIR}/lib/native/extension/sensor/wasm_lib_sensor.cmake)
include (${WASM_DIR}/lib/native/extension/connection/wasm_lib_conn.cmake)
include (${WASM_DIR}/lib/native/extension/connection/${TARGET_PLATFORM}/connection_mgr.cmake)
include (${WASM_DIR}/lib/native-interface/native_interface.cmake)
include (${APP_MGR_DIR}/app-manager/app_mgr.cmake)
include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake)
include (${SHARED_DIR}/platform/${TARGET_PLATFORM}/shared_platform.cmake)
include (${SHARED_DIR}/utils/shared_utils.cmake)
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_DIR}/coap/lib_coap.cmake)
include_directories(${SHARED_DIR}/include)
include_directories(${WASM_DIR}/runtime/platform/include)
############### application related ###############
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
add_definitions (-DWASM_ENABLE_BASE_LIB)
add_definitions (-Dattr_container_malloc=bh_malloc)
add_definitions (-Dattr_container_free=bh_free)
add_library (vmlib
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_LIBC_SOURCE}
${APP_MGR_SOURCE}
${WASM_LIB_BASE_SOURCE}
${WASM_LIB_EXT_SOURCE}
${WASM_LIB_SENSOR_SOURCE}
${WASM_LIB_CONN_SOURCE}
${WASM_LIB_CONN_MGR_SOURCE}
${PLATFORM_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}
${NATIVE_INTERFACE_SOURCE}
)
add_executable (vgl_wasm_runtime src/platform/${TARGET_PLATFORM}/main.c src/platform/${TARGET_PLATFORM}/iwasm_main.c src/ext_lib_export.c src/platform/${TARGET_PLATFORM}/display_indev.c src/platform/${TARGET_PLATFORM}/mouse.c)
add_executable (vgl_wasm_runtime src/platform/${WAMR_BUILD_PLATFORM}/main.c
src/platform/${WAMR_BUILD_PLATFORM}/iwasm_main.c
src/ext_lib_export.c src/platform/${WAMR_BUILD_PLATFORM}/display_indev.c
src/platform/${WAMR_BUILD_PLATFORM}/mouse.c)
target_link_libraries (vgl_wasm_runtime vmlib -lm -ldl -lpthread -lSDL2)

View File

@ -62,28 +62,28 @@ extern bool touchscreen_read(lv_indev_data_t * data);
extern bool mouse_read(lv_indev_data_t * data);
extern void display_init(wasm_module_inst_t module_inst);
extern void display_init(wasm_exec_env_t exec_env);
extern void display_deinit(wasm_module_inst_t module_inst);
extern void display_deinit(wasm_exec_env_t exec_env);
extern int time_get_ms(wasm_module_inst_t module_inst);
extern int time_get_ms(wasm_exec_env_t exec_env);
extern void display_flush(wasm_module_inst_t module_inst,
extern void display_flush(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
int32 color_p_offset);
extern void display_fill(wasm_module_inst_t module_inst,
extern void display_fill(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
lv_color_t color_p);
extern void display_map(wasm_module_inst_t module_inst,
extern void display_map(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
const lv_color_t * color_p);
extern bool display_input_read(wasm_module_inst_t module_inst,
extern bool display_input_read(wasm_exec_env_t exec_env,
int32 data_offset);
void display_vdb_write(wasm_module_inst_t module_inst,
void display_vdb_write(wasm_exec_env_t exec_env,
int32 buf_offset, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, int32 color_p_offset, lv_opa_t opa);

View File

@ -9,6 +9,7 @@
#include "SDL2/SDL.h"
#include "sys/time.h"
#include "wasm_export.h"
#include "app_manager_export.h"
#define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240
@ -23,7 +24,7 @@ void monitor_sdl_clean_up(void);
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES];
int
time_get_ms(wasm_module_inst_t module_inst)
time_get_ms(wasm_exec_env_t exec_env)
{
static struct timeval tv;
gettimeofday(&tv, NULL);
@ -146,15 +147,16 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
void
display_init(wasm_module_inst_t module_inst)
display_init(wasm_exec_env_t exec_env)
{
}
void
display_flush(wasm_module_inst_t module_inst,
display_flush(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
int32 color_p_offset)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
return;
lv_color_t * color_p = wasm_runtime_addr_app_to_native(module_inst,
@ -164,7 +166,7 @@ display_flush(wasm_module_inst_t module_inst,
}
void
display_fill(wasm_module_inst_t module_inst,
display_fill(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
lv_color_t color_p)
{
@ -172,7 +174,7 @@ display_fill(wasm_module_inst_t module_inst,
}
void
display_map(wasm_module_inst_t module_inst,
display_map(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
const lv_color_t * color_p)
{
@ -180,9 +182,10 @@ display_map(wasm_module_inst_t module_inst,
}
bool
display_input_read(wasm_module_inst_t module_inst,
display_input_read(wasm_exec_env_t exec_env,
int32 data_p_offset)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
bool ret;
if (!wasm_runtime_validate_app_addr(module_inst, data_p_offset, 1))
return false;
@ -209,15 +212,16 @@ display_input_read(wasm_module_inst_t module_inst,
}
void
display_deinit(wasm_module_inst_t module_inst)
display_deinit(wasm_exec_env_t exec_env)
{
}
void
display_vdb_write(wasm_module_inst_t module_inst,
display_vdb_write(wasm_exec_env_t exec_env,
int32 buf_offset, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, int32 color_p_offset, lv_opa_t opa)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
return;
lv_color_t *color = wasm_runtime_addr_app_to_native(module_inst,

View File

@ -29,7 +29,7 @@
#include "bh_thread.h"
#include "bh_memory.h"
#include "runtime_sensor.h"
#include "attr_container.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#define MAX 2048
@ -345,7 +345,7 @@ static host_interface interface = { .send = uart_send, .destroy = uart_destroy }
#endif
#ifdef __x86_64__
static char global_heap_buf[300 * 1024] = { 0 };
static char global_heap_buf[400 * 1024] = { 0 };
#else
static char global_heap_buf[270 * 1024] = { 0 };
#endif
@ -370,6 +370,8 @@ static void showUsage()
printf("\t<Uart Device> represents the UART device name and the default is /dev/ttyS2\n");
printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n");
#endif
printf("\nNote:\n");
printf("\tUse -w|--wasi_root to specify the root dir (default to '.') of WASI wasm modules. \n");
}
static bool parse_args(int argc, char *argv[])
@ -378,7 +380,7 @@ static bool parse_args(int argc, char *argv[])
while (1) {
int optIndex = 0;
static struct option longOpts[] = {
static struct option longOpts[] = {
#ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' },
@ -387,11 +389,12 @@ static bool parse_args(int argc, char *argv[])
{ "uart", required_argument, NULL, 'u' },
{ "baudrate", required_argument, NULL, 'b' },
#endif
{ "wasi_root", required_argument, NULL, 'w' },
{ "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
{ 0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "sa:p:u:b:h", longOpts, &optIndex);
c = getopt_long(argc, argv, "sa:p:u:b:w:h", longOpts, &optIndex);
if (c == -1)
break;
@ -418,6 +421,12 @@ static bool parse_args(int argc, char *argv[])
printf("uart baudrate: %s\n", optarg);
break;
#endif
case 'w':
if (!wasm_set_wasi_root_dir(optarg)) {
printf("Fail to set wasi root dir: %s\n", optarg);
return false;
}
break;
case 'h':
showUsage();
return false;

View File

@ -7,9 +7,7 @@
#define XPT2046_H
#define USE_XPT2046 1
#ifndef LV_CONF_INCLUDE_SIMPLE
#define LV_CONF_INCLUDE_SIMPLE
#endif
# define XPT2046_HOR_RES 320
# define XPT2046_VER_RES 240
@ -30,11 +28,6 @@ extern "C" {
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
//#include "lv_drv_conf.h"
#else
//#include "../../lv_drv_conf.h"
#endif
#if USE_XPT2046
#include <autoconf.h>

View File

@ -7,6 +7,7 @@
#include "display_indev.h"
#include "display.h"
#include "wasm_export.h"
#include "app_manager_export.h"
#define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240
@ -17,7 +18,7 @@
static int lcd_initialized = 0;
void
display_init(wasm_module_inst_t module_inst)
display_init(wasm_exec_env_t exec_env)
{
if (lcd_initialized != 0) {
return;
@ -29,10 +30,11 @@ display_init(wasm_module_inst_t module_inst)
}
void
display_flush(wasm_module_inst_t module_inst,
display_flush(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
int32 color_p_offset)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
return;
lv_color_t * color_p = wasm_runtime_addr_app_to_native(module_inst,
@ -52,42 +54,42 @@ display_flush(wasm_module_inst_t module_inst,
}
void
display_fill(wasm_module_inst_t module_inst,
display_fill(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
lv_color_t color_p)
{
}
void
display_map(wasm_module_inst_t module_inst,
display_map(wasm_exec_env_t exec_env,
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
const lv_color_t * color_p)
{
}
bool
display_input_read(wasm_module_inst_t module_inst, int32 data_p_offset)
display_input_read(wasm_exec_env_t exec_env, int32 data_p_offset)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!wasm_runtime_validate_app_addr(module_inst, data_p_offset, 1))
return false;
lv_indev_data_t * data = wasm_runtime_addr_app_to_native(module_inst,
data_p_offset);
return touchscreen_read(data);
}
void
display_deinit(wasm_module_inst_t module_inst)
display_deinit(wasm_exec_env_t exec_env)
{
}
void
display_vdb_write(wasm_module_inst_t module_inst,
display_vdb_write(wasm_exec_env_t exec_env,
int32 buf_offset, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, int32 color_p_offset, lv_opa_t opa)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
return;
lv_color_t *color = wasm_runtime_addr_app_to_native(module_inst,
@ -112,7 +114,7 @@ display_vdb_write(wasm_module_inst_t module_inst,
}
int
time_get_ms(wasm_module_inst_t module_inst)
time_get_ms(wasm_exec_env_t exec_env)
{
return k_uptime_get_32();
}

View File

@ -12,7 +12,7 @@
#include "bh_thread.h"
#include "bh_memory.h"
#include "runtime_sensor.h"
#include "attr_container.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"

View File

@ -6,12 +6,10 @@
#include <stdlib.h>
#include <string.h>
#include "bh_platform.h"
#include "wasm_assert.h"
#include "wasm_log.h"
#include "wasm_platform_log.h"
#include "wasm_thread.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "bh_platform_log.h"
#include "wasm_export.h"
#include "wasm_memory.h"
#include "bh_memory.h"
extern void display_init(void);
extern int iwasm_main();

View File

@ -6,63 +6,51 @@ cmake_minimum_required(VERSION 3.8.2)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)
enable_language (ASM)
set (WAMR_BUILD_PLATFORM "zephyr")
zephyr_compile_definitions (-DNVALGRIND
-D__JLF__
-D__ZEPHYR__
-DWASM_ENABLE_BASE_LIB
-Dattr_container_malloc=bh_malloc
-Dattr_container_free=bh_free)
enable_language (ASM)
# Build as THUMB by default
# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS_32" or "XTENSA_32"
# if we want to support arm_32, x86, mips or xtensa
if (NOT DEFINED BUILD_TARGET)
set (BUILD_TARGET "THUMB")
if (NOT DEFINED WAMR_BUILD_TARGET)
set (WAMR_BUILD_TARGET "THUMB")
endif ()
string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
if (BUILD_TARGET STREQUAL "X86_32")
add_definitions(-DBUILD_TARGET_X86_32)
elseif (BUILD_TARGET MATCHES "ARM.*")
add_definitions(-DBUILD_TARGET_ARM)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET MATCHES "THUMB.*")
add_definitions(-DBUILD_TARGET_THUMB)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET STREQUAL "MIPS")
add_definitions(-DBUILD_TARGET_MIPS)
elseif (BUILD_TARGET STREQUAL "XTENSA")
add_definitions(-DBUILD_TARGET_XTENSA)
else ()
message (FATAL_ERROR "-- Build target isn't set")
if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()
message ("-- Build as target ${BUILD_TARGET}")
set (WASM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm)
set (APP_MGR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr)
set (SHARED_DIR ${WASM_DIR}/../shared-lib)
if (NOT DEFINED WAMR_BUILD_AOT)
# Disable AOT by default.
set (WAMR_BUILD_AOT 0)
endif ()
set (TARGET_PLATFORM "zephyr")
if (NOT DEFINED WAMR_BUILD_JIT)
# Disable JIT by default.
set (WAMR_BUILD_JIT 0)
endif ()
include (${WASM_DIR}/runtime/utils/utils.cmake)
include (${WASM_DIR}/runtime/vmcore-wasm/vmcore.cmake)
include (${WASM_DIR}/lib/native/base/wasm_lib_base.cmake)
include (${WASM_DIR}/lib/native/libc/wasm_libc.cmake)
include (${WASM_DIR}/lib/native/extension/sensor/wasm_lib_sensor.cmake)
include (${WASM_DIR}/lib/native/extension/connection/wasm_lib_conn.cmake)
include (${WASM_DIR}/lib/native/extension/connection/${TARGET_PLATFORM}/connection_mgr.cmake)
include (${WASM_DIR}/lib/native-interface/native_interface.cmake)
include (${APP_MGR_DIR}/app-manager/app_mgr.cmake)
include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake)
include (${SHARED_DIR}/platform/${TARGET_PLATFORM}/shared_platform.cmake)
include (${SHARED_DIR}/utils/shared_utils.cmake)
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_DIR}/coap/lib_coap.cmake)
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
set (WAMR_BUILD_LIBC_WASI 0)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
set (WAMR_BUILD_APP_FRAMEWORK 1)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_LIST)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_SENSOR WAMR_APP_BUILD_CONNECTION)
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
include_directories(${WASM_DIR}/runtime/platform/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr)
@ -73,24 +61,8 @@ set (LVGL_DRV_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/XPT2046.c
)
set (IWASM_SRCS
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_LIBC_SOURCE}
${APP_MGR_SOURCE}
${WASM_LIB_BASE_SOURCE}
${WASM_LIB_EXT_SOURCE}
${WASM_LIB_SENSOR_SOURCE}
${WASM_LIB_CONN_SOURCE}
${WASM_LIB_CONN_MGR_SOURCE}
${PLATFORM_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}
${NATIVE_INTERFACE_SOURCE}
)
target_sources(app PRIVATE
${IWASM_SRCS}
${WAMR_RUNTIME_LIB_SOURCE}
${LVGL_DRV_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c

View File

@ -0,0 +1,9 @@
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET X86_64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 0)
set (WAMR_BUILD_LIBC_WASI 1)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_SENSOR WAMR_APP_BUILD_CONNECTION)

View File

@ -1,20 +1,18 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = clang-8
CC = /opt/wasi-sdk/bin/clang
LVGL_DIR = ${shell pwd}
IWASM_DIR=../../../core/iwasm
SDK_DIR = $(LVGL_DIR)/../../../wamr-sdk/out/littlevgl/app-sdk
APP_FRAMEWORK_DIR = $(SDK_DIR)/wamr-app-framework
CFLAGS += -O3 \
-DLV_CONF_INCLUDE_SIMPLE=1 \
-I$(LVGL_DIR)/ \
-I$(LVGL_DIR)/lvgl/ \
-I$(LVGL_DIR)/lv_drivers/ \
-I$(LVGL_DIR)/src/ \
-I$(IWASM_DIR)/lib/app-libs/base/ \
-I$(IWASM_DIR)/lib/native-interface/ \
-I$(IWASM_DIR)/lib/app-libs/extension/sensor \
-I$(IWASM_DIR)/lib/app-libs/extension/gui \
-I$(IWASM_DIR)/lib/app-libs/extension/connection
-I$(LVGL_DIR) \
-I$(LVGL_DIR)/lvgl \
-I$(LVGL_DIR)/lv_drivers \
-I$(LVGL_DIR)/src \
-I$(LVGL_DIR)/../lv_config \
-I$(APP_FRAMEWORK_DIR)/include
SRCS += lvgl/lv_draw/lv_draw_line.c lvgl/lv_draw/lv_draw_rbasic.c
SRCS += lvgl/lv_draw/lv_draw_img.c lvgl/lv_draw/lv_draw_arc.c
@ -46,12 +44,12 @@ SRCS += lvgl/lv_core/lv_group.c lvgl/lv_core/lv_style.c lvgl/lv_core/lv_indev.c
SRCS += lvgl/lv_core/lv_vdb.c lvgl/lv_core/lv_obj.c lvgl/lv_core/lv_refr.c
SRCS += $(LVGL_DIR)/src/main.c
# For app size consideration, not all but necessary app libs are included
SRCS += $(IWASM_DIR)/lib/app-libs/base/timer.c
all:
all:
@$(CC) $(CFLAGS) $(SRCS) \
--target=wasm32 -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-Wl,--allow-undefined \
-Wl,--no-threads,--strip-all,--no-entry -nostdlib \
-O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-DLV_CONF_INCLUDE_SIMPLE \
-L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \
-Wl,--allow-undefined \
-Wl,--no-threads,--strip-all,--no-entry \
-Wl,--export=on_init -Wl,--export=on_timer_callback \
-o ui_app.wasm

View File

@ -0,0 +1,58 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = /opt/wasi-sdk/bin/clang
LVGL_DIR = ${shell pwd}
WAMR_DIR = ${LVGL_DIR}/../../..
SDK_DIR = $(LVGL_DIR)/../../../wamr-sdk/out/littlevgl/app-sdk
APP_FRAMEWORK_DIR = $(SDK_DIR)/wamr-app-framework
CFLAGS += -O3 \
-I$(LVGL_DIR) \
-I$(LVGL_DIR)/lvgl \
-I$(LVGL_DIR)/lv_drivers \
-I$(LVGL_DIR)/src \
-I$(LVGL_DIR)/../lv_config \
-I$(APP_FRAMEWORK_DIR)/include
SRCS += lvgl/lv_draw/lv_draw_line.c lvgl/lv_draw/lv_draw_rbasic.c
SRCS += lvgl/lv_draw/lv_draw_img.c lvgl/lv_draw/lv_draw_arc.c
SRCS += lvgl/lv_draw/lv_draw_rect.c lvgl/lv_draw/lv_draw_triangle.c
SRCS += lvgl/lv_draw/lv_draw.c lvgl/lv_draw/lv_draw_label.c
SRCS += lvgl/lv_draw/lv_draw_vbasic.c lvgl/lv_fonts/lv_font_builtin.c
SRCS += lvgl/lv_fonts/lv_font_dejavu_20.c
SRCS += lvgl/lv_objx/lv_img.c
SRCS += lvgl/lv_objx/lv_roller.c lvgl/lv_objx/lv_cb.c lvgl/lv_objx/lv_led.c lvgl/lv_objx/lv_cont.c
SRCS += lvgl/lv_objx/lv_calendar.c lvgl/lv_objx/lv_gauge.c lvgl/lv_objx/lv_page.c
SRCS += lvgl/lv_objx/lv_list.c lvgl/lv_objx/lv_bar.c lvgl/lv_objx/lv_tabview.c
SRCS += lvgl/lv_objx/lv_mbox.c lvgl/lv_objx/lv_objx_templ.c lvgl/lv_objx/lv_sw.c
SRCS += lvgl/lv_objx/lv_label.c lvgl/lv_objx/lv_slider.c lvgl/lv_objx/lv_ddlist.c
SRCS += lvgl/lv_objx/lv_imgbtn.c lvgl/lv_objx/lv_line.c lvgl/lv_objx/lv_chart.c
SRCS += lvgl/lv_objx/lv_btnm.c lvgl/lv_objx/lv_arc.c lvgl/lv_objx/lv_preload.c
SRCS += lvgl/lv_objx/lv_win.c lvgl/lv_objx/lv_lmeter.c lvgl/lv_objx/lv_btn.c
SRCS += lvgl/lv_objx/lv_ta.c lvgl/lv_misc/lv_log.c lvgl/lv_misc/lv_fs.c
SRCS += lvgl/lv_misc/lv_task.c lvgl/lv_misc/lv_circ.c lvgl/lv_misc/lv_anim.c
SRCS += lvgl/lv_misc/lv_color.c lvgl/lv_misc/lv_txt.c lvgl/lv_misc/lv_math.c
SRCS += lvgl/lv_misc/lv_mem.c lvgl/lv_misc/lv_font.c lvgl/lv_misc/lv_ll.c
SRCS += lvgl/lv_misc/lv_area.c lvgl/lv_misc/lv_templ.c lvgl/lv_misc/lv_ufs.c
SRCS += lvgl/lv_misc/lv_gc.c
SRCS += lvgl/lv_hal/lv_hal_tick.c lvgl/lv_hal/lv_hal_indev.c lvgl/lv_hal/lv_hal_disp.c
SRCS += lvgl/lv_themes/lv_theme_mono.c lvgl/lv_themes/lv_theme_templ.c
SRCS += lvgl/lv_themes/lv_theme_material.c lvgl/lv_themes/lv_theme.c
SRCS += lvgl/lv_themes/lv_theme_night.c lvgl/lv_themes/lv_theme_zen.c lvgl/lv_themes/lv_theme_nemo.c
SRCS += lvgl/lv_themes/lv_theme_alien.c lvgl/lv_themes/lv_theme_default.c
SRCS += lvgl/lv_core/lv_group.c lvgl/lv_core/lv_style.c lvgl/lv_core/lv_indev.c
SRCS += lvgl/lv_core/lv_vdb.c lvgl/lv_core/lv_obj.c lvgl/lv_core/lv_refr.c
SRCS += $(LVGL_DIR)/src/main.c
all:
@$(CC) $(CFLAGS) $(SRCS) \
--target=wasm32 -Wl,--allow-undefined \
--sysroot=$(WAMR_DIR)/wamr-sdk/app/libc-builtin-sysroot \
-O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-DLV_CONF_INCLUDE_SIMPLE \
-L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \
-Wl,--allow-undefined \
-Wl,--no-threads,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_timer_callback \
-o ui_app_no_wasi.wasm

View File

@ -1,8 +1,8 @@
#!/bin/sh
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/sh
WAMR_DIR=${PWD}/../../..
if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then
@ -17,4 +17,5 @@ if [ ! -d "lvgl" ]; then
git clone https://github.com/littlevgl/lvgl.git --branch v5.3
fi
$makewrap -f Makefile_wasm_app
$makewrap -f Makefile_wasm_app_no_wasi

View File

@ -1,389 +0,0 @@
/**
* @file lv_conf.h
*
*/
#if 1 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/*===================
Dynamic memory
*===================*/
/* Memory size which will be used by the library
* to store the graphical objects and other data */
#define LV_MEM_CUSTOM 1 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/
#if LV_MEM_CUSTOM == 0
# define LV_MEM_SIZE (64U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_ATTR /*Complier prefix for big array declaration*/
# define LV_MEM_ADR 0 /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/
# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher language and the memory is managed by that language */
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
#endif /* LV_ENABLE_GC */
/*===================
Graphical settings
*===================*/
/* Horizontal and vertical resolution of the library.*/
#define LV_HOR_RES (320)
#define LV_VER_RES (240)
/* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI 100
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#define LV_ANTIALIAS 0 /*1: Enable anti-aliasing*/
/*Screen refresh period in milliseconds*/
#define LV_REFR_PERIOD 30
/*-----------------
* VDB settings
*----------------*/
/* VDB (Virtual Display Buffer) is an internal graphics buffer.
* The GUI will be drawn into this buffer first and then
* the buffer will be passed to your `disp_drv.disp_flush` function to
* copy it to your frame buffer.
* VDB is required for: buffered drawing, opacity, anti-aliasing and shadows
* Learn more: https://docs.littlevgl.com/#Drawing*/
/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES
* Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions
* will be called to draw to the frame buffer directly*/
#define LV_VDB_SIZE ((LV_VER_RES * LV_HOR_RES) / 10)
/* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays.
* Special formats are handled with `disp_drv.vdb_wr`)*/
#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */
/* Place VDB to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#define LV_VDB_ADR 0
/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing
* The flushing should use DMA to write the frame buffer in the background */
#define LV_VDB_DOUBLE 0
/* Place VDB2 to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#define LV_VDB2_ADR 0
/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen.
* Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display.
* The best if you do in the blank period of you display to avoid tearing effect.
* Requires:
* - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES
* - LV_VDB_DOUBLE = 1
*/
#define LV_VDB_TRUE_DOUBLE_BUFFERED 0
/*=================
Misc. setting
*=================*/
/*Input device settings*/
#define LV_INDEV_READ_PERIOD 50 /*Input device read period in milliseconds*/
#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/
#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */
#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */
#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/
#define LV_INDEV_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */
/*Color settings*/
#define LV_COLOR_DEPTH 32 /*Color depth: 1/8/16/32*/
#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/
#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/
/*Text settings*/
#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */
#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/
#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */
/*Feature usage*/
#define USE_LV_ANIMATION 1 /*1: Enable all animations*/
#define USE_LV_SHADOW 1 /*1: Enable shadows*/
#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/
#define USE_LV_GPU 0 /*1: Enable GPU interface*/
#define USE_LV_REAL_DRAW 1 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/
#define USE_LV_FILESYSTEM 0 /*1: Enable file system (might be required for images*/
#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/
/*Compiler settings*/
#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */
#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */
#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/
#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */
/*HAL settings*/
#define LV_TICK_CUSTOM 1 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */
#if LV_TICK_CUSTOM == 1
#define LV_TICK_CUSTOM_INCLUDE "system_header.h" /*Header for the sys time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (time_get_ms()) /*Expression evaluating to current systime in ms*/
#endif /*LV_TICK_CUSTOM*/
/*Log settings*/
#define USE_LV_LOG 1 /*Enable/disable the log module*/
#if USE_LV_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't caused problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
*/
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
/* 1: Print the log with 'printf'; 0: user need to register a callback*/
# define LV_LOG_PRINTF 0
#endif /*USE_LV_LOG*/
/*================
* THEME USAGE
*================*/
#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#define USE_LV_THEME_TEMPL 0 /*Just for test*/
#define USE_LV_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#define USE_LV_THEME_ALIEN 0 /*Dark futuristic theme*/
#define USE_LV_THEME_NIGHT 0 /*Dark elegant theme*/
#define USE_LV_THEME_MONO 0 /*Mono color theme for monochrome displays*/
#define USE_LV_THEME_MATERIAL 0 /*Flat theme with bold colors and light shadows*/
#define USE_LV_THEME_ZEN 0 /*Peaceful, mainly light theme */
#define USE_LV_THEME_NEMO 0 /*Water-like theme based on the movie "Finding Nemo"*/
/*==================
* FONT USAGE
*===================*/
/* More info about fonts: https://docs.littlevgl.com/#Fonts
* To enable a built-in font use 1,2,4 or 8 values
* which will determine the bit-per-pixel. Higher value means smoother fonts */
#define USE_LV_FONT_DEJAVU_10 0
#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_10_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_10 0
#define USE_LV_FONT_DEJAVU_20 4
#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_20_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_20 0
#define USE_LV_FONT_DEJAVU_30 0
#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_30_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_30 0
#define USE_LV_FONT_DEJAVU_40 0
#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_40_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_40 0
#define USE_LV_FONT_MONOSPACE_8 1
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2) \
*/
#define LV_FONT_CUSTOM_DECLARE
#define LV_FONT_DEFAULT &lv_font_dejavu_20 /*Always set a default font from the built-in fonts*/
/*===================
* LV_OBJ SETTINGS
*==================*/
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
*/
/*****************
* Simple object
*****************/
/*Label (dependencies: -*/
#define USE_LV_LABEL 1
#if USE_LV_LABEL != 0
# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/
#endif
/*Image (dependencies: lv_label*/
#define USE_LV_IMG 1
#if USE_LV_IMG != 0
# define LV_IMG_CF_INDEXED 1 /*Enable indexed (palette) images*/
# define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/
#endif
/*Line (dependencies: -*/
#define USE_LV_LINE 1
/*Arc (dependencies: -)*/
#define USE_LV_ARC 1
/*******************
* Container objects
*******************/
/*Container (dependencies: -*/
#define USE_LV_CONT 1
/*Page (dependencies: lv_cont)*/
#define USE_LV_PAGE 1
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#define USE_LV_WIN 1
/*Tab (dependencies: lv_page, lv_btnm)*/
#define USE_LV_TABVIEW 1
# if USE_LV_TABVIEW != 0
# define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
/*Tileview (dependencies: lv_page) */
#define USE_LV_TILEVIEW 1
#if USE_LV_TILEVIEW
# define LV_TILEVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
/*************************
* Data visualizer objects
*************************/
/*Bar (dependencies: -)*/
#define USE_LV_BAR 1
/*Line meter (dependencies: *;)*/
#define USE_LV_LMETER 1
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
#define USE_LV_GAUGE 1
/*Chart (dependencies: -)*/
#define USE_LV_CHART 1
/*Table (dependencies: lv_label)*/
#define USE_LV_TABLE 1
#if USE_LV_TABLE
# define LV_TABLE_COL_MAX 12
#endif
/*LED (dependencies: -)*/
#define USE_LV_LED 1
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#define USE_LV_MBOX 1
/*Text area (dependencies: lv_label, lv_page)*/
#define USE_LV_TA 1
#if USE_LV_TA != 0
# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
#endif
/*Spinbox (dependencies: lv_ta)*/
#define USE_LV_SPINBOX 1
/*Calendar (dependencies: -)*/
#define USE_LV_CALENDAR 1
/*Preload (dependencies: lv_arc)*/
#define USE_LV_PRELOAD 1
#if USE_LV_PRELOAD != 0
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
#endif
/*Canvas (dependencies: lv_img)*/
#define USE_LV_CANVAS 1
/*************************
* User input objects
*************************/
/*Button (dependencies: lv_cont*/
#define USE_LV_BTN 1
#if USE_LV_BTN != 0
# define LV_BTN_INK_EFFECT 1 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/
#endif
/*Image Button (dependencies: lv_btn*/
#define USE_LV_IMGBTN 1
#if USE_LV_IMGBTN
# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
#endif
/*Button matrix (dependencies: -)*/
#define USE_LV_BTNM 1
/*Keyboard (dependencies: lv_btnm)*/
#define USE_LV_KB 1
/*Check box (dependencies: lv_btn, lv_label)*/
#define USE_LV_CB 1
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#define USE_LV_LIST 1
#if USE_LV_LIST != 0
# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */
#endif
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#define USE_LV_DDLIST 1
#if USE_LV_DDLIST != 0
# define LV_DDLIST_ANIM_TIME 200 /*Open and close default animation time [ms] (0: no animation)*/
#endif
/*Roller (dependencies: lv_ddlist)*/
#define USE_LV_ROLLER 1
#if USE_LV_ROLLER != 0
# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/
#endif
/*Slider (dependencies: lv_bar)*/
#define USE_LV_SLIDER 1
/*Switch (dependencies: lv_slider)*/
#define USE_LV_SW 1
/*************************
* Non-user section
*************************/
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
# define _CRT_SECURE_NO_WARNINGS
#endif
/*--END OF LV_CONF_H--*/
/*Be sure every define has a default value*/
#include "lvgl/lv_conf_checker.h"
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -17,6 +17,7 @@
#include "lvgl/lvgl.h"
#include "display_indev.h"
#include "wasm_app.h"
#include "wa-inc/timer_wasm_app.h"
/*********************
* DEFINES
*********************/

View File

@ -1,156 +1,32 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
project (simple)
set (TARGET_PLATFORM "linux")
################ wamr runtime settings ################
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
add_definitions(-DNVALGRIND)
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
set (BUILD_AS_64BIT_SUPPORT "YES")
## use library and headers in the SDK
link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/simple/runtime-sdk/lib)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/simple/runtime-sdk/include
)
# Set BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
if (NOT DEFINED BUILD_TARGET)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (BUILD_AS_64BIT_SUPPORT STREQUAL "YES")
# Build as X86_64 by default in 64-bit platform
set (BUILD_TARGET "X86_64")
else ()
set (BUILD_TARGET "X86_32")
endif ()
else ()
# Build as X86_32 by default in 32-bit platform
set (BUILD_TARGET "X86_32")
endif ()
endif ()
################ application related ################
string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
# Add definitions for the build target
if (BUILD_TARGET STREQUAL "X86_64")
add_definitions(-DBUILD_TARGET_X86_64)
elseif (BUILD_TARGET STREQUAL "AMD_64")
add_definitions(-DBUILD_TARGET_AMD_64)
elseif (BUILD_TARGET STREQUAL "X86_32")
add_definitions(-DBUILD_TARGET_X86_32)
elseif (BUILD_TARGET MATCHES "ARM.*")
add_definitions(-DBUILD_TARGET_ARM)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET MATCHES "THUMB.*")
add_definitions(-DBUILD_TARGET_THUMB)
add_definitions(-DBUILD_TARGET="${BUILD_TARGET}")
elseif (BUILD_TARGET STREQUAL "MIPS")
add_definitions(-DBUILD_TARGET_MIPS)
elseif (BUILD_TARGET STREQUAL "XTENSA")
add_definitions(-DBUILD_TARGET_XTENSA)
else ()
message (FATAL_ERROR "-- Build target isn't set")
endif ()
message ("-- Build as target ${BUILD_TARGET}")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
# Add -fPIC flag if build as 64-bit
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
else ()
add_definitions (-m32)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
endif (NOT CMAKE_BUILD_TYPE)
message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
if (NOT PLATFORM)
SET(PLATFORM linux)
endif (NOT PLATFORM)
message ("-- PLATFORM = " ${PLATFORM})
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
set(WASM_DIR ${WAMR_ROOT_DIR}/core/iwasm)
set(APP_MGR_DIR ${WAMR_ROOT_DIR}/core/app-mgr)
set(SHARED_DIR ${WAMR_ROOT_DIR}/core/shared-lib)
if ("${ENABLE_GUI}" STREQUAL "YES")
set (LV_DRIVERS_DIR ${WASM_DIR}/lib/3rdparty/lv_drivers)
set (LVGL_DIR ${WASM_DIR}/lib/3rdparty/lvgl)
file(GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c" )
endif()
enable_language (ASM)
include (${WASM_DIR}/runtime/utils/utils.cmake)
include (${WASM_DIR}/runtime/vmcore-wasm/vmcore.cmake)
include (${WASM_DIR}/lib/native/base/wasm_lib_base.cmake)
include (${WASM_DIR}/lib/native/libc/wasm_libc.cmake)
include (${WASM_DIR}/lib/native/extension/sensor/wasm_lib_sensor.cmake)
if ("${ENABLE_GUI}" STREQUAL "YES")
include (${WASM_DIR}/lib/native/extension/gui/wasm_lib_gui.cmake)
endif()
include (${WASM_DIR}/lib/native/extension/connection/wasm_lib_conn.cmake)
include (${WASM_DIR}/lib/native/extension/connection/${TARGET_PLATFORM}/connection_mgr.cmake)
include (${WASM_DIR}/lib/native-interface/native_interface.cmake)
include (${APP_MGR_DIR}/app-manager/app_mgr.cmake)
include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake)
include (${SHARED_DIR}/platform/${TARGET_PLATFORM}/shared_platform.cmake)
include (${SHARED_DIR}/utils/shared_utils.cmake)
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_DIR}/coap/lib_coap.cmake)
include_directories(${SHARED_DIR}/include)
include_directories(${WASM_DIR}/runtime/platform/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
#Note: uncomment below line to use UART mode
#add_definitions (-DCONNECTION_UART)
add_definitions (-DWASM_ENABLE_BASE_LIB)
add_definitions (-Dattr_container_malloc=bh_malloc)
add_definitions (-Dattr_container_free=bh_free)
add_definitions (-DLV_CONF_INCLUDE_SIMPLE)
if ("${ENABLE_GUI}" STREQUAL "YES")
add_definitions (-DWASM_ENABLE_GUI=1)
endif()
add_library (vmlib
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_LIBC_SOURCE}
${APP_MGR_SOURCE}
${WASM_LIB_BASE_SOURCE}
${WASM_LIB_EXT_SOURCE}
${WASM_LIB_SENSOR_SOURCE}
${WASM_LIB_GUI_SOURCE}
${WASM_LIB_CONN_SOURCE}
${WASM_LIB_CONN_MGR_SOURCE}
${PLATFORM_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}
${NATIVE_INTERFACE_SOURCE}
)
if ("${ENABLE_GUI}" STREQUAL "YES")
add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c ${LV_DRIVERS_SOURCES})
target_link_libraries (simple vmlib -lm -ldl -lpthread -lSDL2)
else ()
add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c)
target_link_libraries (simple vmlib -lm -ldl -lpthread)
endif ()
add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c)
target_link_libraries (simple vmlib -lm -ldl -lpthread)

View File

@ -1,8 +1,16 @@
Introduction
==============
This project builds out both host tools running on the host side, and an application running on the device side. The device application consists of iwasm, application library, application manager, timers and sensors support. The device runs on Linux OS and interacts with host tools.
It demonstrates an end to end scenario, the wasm applications life cycle management and communication programming models.
"simple" sample introduction
==============
This sample demonstrates following scenarios:
- Use tool "host_tool" to remotely install/uninstall wasm applications from the WAMR runtime over either TCP socket or UART cable
- Inter-app communication programming models
- Communication between WASM applications and the remote app host_tool
- A number of WASM applications built on top of WAMR application framework API sets
Directory structure
------------------------------
@ -19,25 +27,20 @@ simple/
├── connection.c
├── event_publisher.c
├── event_subscriber.c
├── gui.c
├── request_handler.c
├── request_sender.c
├── sensor.c
└── timer.c
```
- build.sh<br/>
The script to build all binaries.
- build_no_gui.sh<br/>
The script to build all binaries without gui library support.
- CMakeLists.txt<br/>
CMake file used to build the simple application.
- README.md<br/>
The file you are reading currently.
- src/ext_lib_export.c<br/>
This file is used to export native APIs. See the `The mechanism of exporting Native API to WASM application` section in WAMR README.md for detail.
- src/iwam_main.c<br/>
This file is the implementation by platform integrator. It implements the interfaces that enable the application manager communicating with the host side. See `{WAMR_ROOT}/core/app-mgr/app-mgr-shared/app_manager_export.h` for the definition of the host interface.
## Set physical communication between device and remote
```
/* Interfaces of host communication */
typedef struct host_interface {
@ -45,69 +48,45 @@ typedef struct host_interface {
host_send_fun send;
host_destroy_fun destroy;
} host_interface;
```
The `host_init_func` is called when the application manager starts up. And `host_send_fun` is called by the application manager to send data to the host.
Define a global variable "interface" of the data structure:
```
host_interface interface = {
.init = host_init,
.send = host_send,
.destroy = host_destroy
};
```
This interface is passed to application manager by calling
This interface is passed to application manager during the runtime startup:
```
app_manager_startup(&interface);
```
The `host_init_func` is called when the application manager starts up. And `host_send_fun` is called by the application manager to send data to the host.
>**Note:** Currently application manager keeps running and never exit, `host_destroy_fun` has no chance to get executed. So you can leave this API implementation empty.
>
- src/main.c<br/>
The main file.
- wasm-apps<br/>
Source files of sample wasm applications.
**Note:** The connection between simple and host_tool is TCP by default. The simple application works as a server and the host_tool works as a client. You can also use UART connection. To achieve this you have to uncomment the below line in CMakeLists.txt and rebuild.
Configure 32 bit or 64 bit build
==============
On 64 bit operating system, there is an option to build 32 bit or 64 bit binaries. In file `CMakeLists.txt`, modify the line:
`set (BUILD_AS_64BIT_SUPPORT "YES")`
where `YES` means 64 bit build while `NO` means 32 bit build.
Install required SDK and libraries
==============
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `BUILD_AS_64BIT_SUPPORT` is set to `NO`)
Use apt-get:
`sudo apt-get install libsdl2-dev:i386`
Or download source from www.libsdl.org:
```
./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32
make
sudo make install
```
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `BUILD_AS_64BIT_SUPPORT` is set to `YES`)
Use apt-get:
`sudo apt-get install libsdl2-dev`
Or download source from www.libsdl.org:
```
./configure
make
sudo make install
#add_definitions (-DCONNECTION_UART)`
```
- Install EMSDK
```
https://emscripten.org/docs/tools_reference/emsdk.html
```
To run the UART based test, you have to set up a UART hardware connection between host_tool and the simple application. See the help of host_tool for how to specify UART device parameters.
Build all binaries
Build the sample
==============
Execute the build.sh script then all binaries including wasm application files would be generated in 'out' directory.
`./build.sh`
Or execute the build_no_gui.sh script to build all binaries without gui library support.
`./build_no_gui.sh`
Out directory structure
------------------------------
**Out directory structure**
```
out/
├── host_tool
@ -116,7 +95,6 @@ out/
├── connection.wasm
├── event_publisher.wasm
├── event_subscriber.wasm
├── gui.wasm
├── request_handler.wasm
├── request_sender.wasm
├── sensor.wasm
@ -130,42 +108,22 @@ out/
- simple:
A simple testing tool running on the host side that interact with WAMR. It is used to install, uninstall and query WASM applications in WAMR, and send request or subscribe event, etc. See the usage of this application by executing "./simple -h".
`./simple -h`
>****Note:**** The connection between simple and host_tool is TCP by default and is what this guide uses. The simple application works as a server and the host_tool works as a client. You can also use UART connection. To achieve this you have to uncomment the below line in CMakeLists.txt and rebuild. You have to set up a UART hardware connection between 2 machines one of which runs the host_tool and the other runs the simple application. See the help of host_tool and the simple application to know how to specify UART device parameters.<br/>
`#add_definitions (-DCONNECTION_UART)`
>
- wasm-apps:
Sample wasm applications that demonstrate all APIs of the WAMR programming model. The source codes are in the wasm-apps directory under the root of this project.
+ connection.wasm<br/>
This application shows the connection programming model. It connects to a TCP server on 127.0.0.1:7777 and periodically sends message to it.
+ event_publisher.wasm<br/>
This application shows the sub/pub programming model. The pub application publishes the event "alert/overheat" by calling api_publish_event() API. The subscriber could be host_tool or other wasm application.
+ event_subscriber.wasm<br/>
This application shows the sub/pub programming model. The sub application subscribes the "alert/overheat" event by calling api_subscribe_event() API so that it is able to receive the event once generated and published by the pub application. To make the process clear to interpret, the sub application dumps the event when receiving it.
+ gui.wasm<br/>
This application shows the built-in 2D graphical user interface API with which various widgets could be created.
+ request_handler.wasm<br/>
This application shows the request/response programming model. The request handler application registers 2 resources(/url1 and /url2) by calling api_register_resource_handler() API. The request sender could be host_tool or other wasm application.
+ request_sender.wasm<br/>
This application shows the request/response programming model. The sender application sends 2 requests, one is "/app/request_handler/url1" and the other is "url1". The former is an accurate request which explicitly specifies the name of request handler application in the middle of the URL and the later is a general request.
+ sensor.wasm<br/>
This application shows the sensor programming model. It opens a test sensor and configures the sensor event generating interval to 1 second. To make the process clear to interpret, the application dumps the sensor event when receiving it.
+ timer.wasm<br/>
This application shows the timer programming model. It creates a periodic timer that prints the current expiry number in every second.
Run the scenario
Run the sample
==========================
- Enter the out directory<br/>
- Enter the out directory
```
$ cd ./out/
```
- Startup the 'simple' process works in TCP server mode and you would see "App Manager started." is printed.<br/>
- Startup the 'simple' process works in TCP server mode and you would see "App Manager started." is printed.
```
$ ./simple -s
App Manager started.
```
- Query all installed applications<br/>
- Query all installed applications
```
$ ./host_tool -q
@ -175,7 +133,7 @@ response status 69
}
```
The `69` stands for response status to this query request which means query success and a payload is attached with the response. See `{WAMR_ROOT}/core/iwasm/lib/app-libs/base/wasm_app.h` for the definitions of response codes. The payload is printed with JSON format where the `num` stands for application installations number and value `0` means currently no application is installed yet.
The `69` stands for response code SUCCESS. The payload is printed with JSON format where the `num` stands for application installations number and value `0` means currently no application is installed yet.
- Install the request handler wasm application<br/>
```
@ -183,20 +141,11 @@ $ ./host_tool -i request_handler -f ./wasm-apps/request_handler.wasm
response status 65
```
The `65` stands for response status to this installation request which means success.
Output of simple
```
Install WASM app success!
sent 16 bytes to host
WASM app 'request_handler' started
```
Now the request handler application is running and waiting for host or other wasm application to send a request.
- Query again<br/>
- Query again
```
$ ./host_tool -q
$ ./host_tool -q
response status 69
{
@ -207,7 +156,7 @@ response status 69
```
In the payload, we can see `num` is 1 which means 1 application is installed. `applet1`stands for the name of the 1st application. `heap1` stands for the heap size of the 1st application.
- Send request from host to specific wasm application<br/>
- Send request from host to specific wasm application
```
$ ./host_tool -r /app/request_handler/url1 -A GET
@ -220,7 +169,7 @@ response status 69
We can see a response with status `69` and a payload is received.
Output of simple
Output of simple application:
```
connection established!
Send request to applet: request_handler
@ -242,7 +191,7 @@ response status 69
}
```
Output of simple
Output of simple application:
```
connection established!
Send request to app request_handler success.
@ -252,7 +201,7 @@ sent 150 bytes to host
Wasm app process request success.
```
- Install the event publisher wasm application<br/>
- Install the event publisher wasm application
```
$ ./host_tool -i pub -f ./wasm-apps/event_publisher.wasm

View File

@ -6,44 +6,67 @@ OUT_DIR=${PWD}/out
BUILD_DIR=${PWD}/build
IWASM_ROOT=${PWD}/../../core/iwasm
APP_LIBS=${IWASM_ROOT}/lib/app-libs
NATIVE_LIBS=${IWASM_ROOT}/lib/native-interface
APP_LIB_SRC="${APP_LIBS}/base/*.c ${APP_LIBS}/extension/sensor/*.c ${APP_LIBS}/extension/connection/*.c ${APP_LIBS}/extension/gui/src/*.c ${NATIVE_LIBS}/*.c"
APP_FRAMEWORK_DIR=${PWD}/../../core/app-framework
NATIVE_LIBS=${APP_FRAMEWORK_DIR}/app-native-shared
APP_LIB_SRC="${APP_FRAMEWORK_DIR}/base/app/*.c ${APP_FRAMEWORK_DIR}/sensor/app/*.c \
${APP_FRAMEWORK_DIR}/connection/app/*.c ${NATIVE_LIBS}/*.c"
WASM_APPS=${PWD}/wasm-apps
CLEAN=
usage ()
{
echo "build.sh [options]"
echo " -p [platform]"
echo " -t [target]"
echo " -c, rebuild SDK"
exit 1
}
while getopts "p:t:ch" opt
do
case $opt in
p)
PLATFORM=$OPTARG
;;
t)
TARGET=$OPTARG
;;
c)
CLEAN="TRUE"
;;
h)
usage
exit 1;
;;
?)
echo "Unknown arg: $arg"
usage
exit 1
;;
esac
done
if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then
echo "Local Build Env"
cmakewrap="cmake"
makewrap="make"
else
echo "Klocwork Build Env"
cmakewrap="cmake -DCMAKE_BUILD_TYPE=Debug"
makewrap="kwinject -o $KW_OUT_FILE make"
fi
rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
mkdir ${OUT_DIR}/wasm-apps
cd ${WAMR_DIR}/core/shared-lib/mem-alloc
cd ${WAMR_DIR}/core/shared/mem-alloc
if [ ! -d "tlsf" ]; then
git clone https://github.com/mattconte/tlsf
fi
cd ${WAMR_DIR}/core/iwasm/lib/3rdparty
if [ ! -d "lvgl" ]; then
git clone https://github.com/littlevgl/lvgl.git --branch v6.0.1
fi
if [ ! -d "lv_drivers" ]; then
git clone https://github.com/littlevgl/lv_drivers.git
fi
echo "#####################build wamr sdk"
cd ${WAMR_DIR}/wamr-sdk
./build_sdk.sh -n simple -x ${CURR_DIR}/wamr_config_simple.cmake $*
echo "#####################build simple project"
cd ${CURR_DIR}
mkdir -p cmake_build
cd cmake_build
$cmakewrap -DENABLE_GUI=YES ..
$makewrap
cmake .. -DWAMR_BUILD_SDK_PROFILE=simple
make
if [ $? != 0 ];then
echo "BUILD_FAIL simple exit as $?\n"
exit 2
@ -51,12 +74,13 @@ fi
cp -a simple ${OUT_DIR}
echo "#####################build simple project success"
echo -e "\n\n"
echo "#####################build host-tool"
cd ${WAMR_DIR}/test-tools/host-tool
mkdir -p bin
cd bin
$cmakewrap ..
$makewrap
cmake ..
make
if [ $? != 0 ];then
echo "BUILD_FAIL host tool exit as $?\n"
exit 2
@ -64,26 +88,28 @@ fi
cp host_tool ${OUT_DIR}
echo "#####################build host-tool success"
echo -e "\n\n"
echo "#####################build wasm apps"
cd ${WASM_APPS}
for i in `ls *.c`
do
APP_SRC="$i ${APP_LIB_SRC}"
APP_SRC="$i"
OUT_FILE=${i%.*}.wasm
clang-8 -I${APP_LIBS}/base -I${APP_LIBS}/extension/sensor -I${NATIVE_LIBS} \
-I${APP_LIBS}/extension/connection \
-I${APP_LIBS}/extension/gui \
-DENABLE_WGL=1 \
/opt/wasi-sdk/bin/clang \
-I${WAMR_DIR}/wamr-sdk/out/simple/app-sdk/wamr-app-framework/include \
-L${WAMR_DIR}/wamr-sdk/out/simple/app-sdk/wamr-app-framework/lib \
-lapp_framework \
--target=wasm32 -O3 -z stack-size=4096 -Wl,--initial-memory=65536 \
-Wl,--allow-undefined \
--sysroot=${WAMR_DIR}/wamr-sdk/out/simple/app-sdk/libc-builtin-sysroot \
-Wl,--allow-undefined-file=${WAMR_DIR}/wamr-sdk/out/simple/app-sdk/libc-builtin-sysroot/share/defined-symbols.txt \
-Wl,--no-threads,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_destroy \
-Wl,--export=on_request -Wl,--export=on_response \
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
-Wl,--export=on_connection_data -Wl,--export=on_widget_event \
-Wl,--export=on_connection_data \
-o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
echo "build ${OUT_FILE} success"
@ -91,4 +117,5 @@ else
echo "build ${OUT_FILE} fail"
fi
done
echo "#####################build wasm apps done"

View File

@ -1,74 +0,0 @@
#!/bin/bash
CURR_DIR=$PWD
WAMR_DIR=${PWD}/../..
OUT_DIR=${PWD}/out
BUILD_DIR=${PWD}/build
IWASM_ROOT=${PWD}/../../core/iwasm
APP_LIBS=${IWASM_ROOT}/lib/app-libs
NATIVE_LIBS=${IWASM_ROOT}/lib/native-interface
APP_LIB_SRC="${APP_LIBS}/base/*.c ${APP_LIBS}/extension/sensor/*.c ${APP_LIBS}/extension/connection/*.c ${NATIVE_LIBS}/*.c"
WASM_APPS=${PWD}/wasm-apps
rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
mkdir ${OUT_DIR}/wasm-apps
cd ${WAMR_DIR}/core/shared-lib/mem-alloc
if [ ! -d "tlsf" ]; then
git clone https://github.com/mattconte/tlsf
fi
echo "#####################build simple project"
cd ${CURR_DIR}
mkdir -p cmake_build
cd cmake_build
cmake -DENABLE_GUI=NO ..
make
if [ $? != 0 ];then
echo "BUILD_FAIL simple exit as $?\n"
exit 2
fi
cp -a simple ${OUT_DIR}
echo "#####################build simple project success"
echo "#####################build host-tool"
cd ${WAMR_DIR}/test-tools/host-tool
mkdir -p bin
cd bin
cmake ..
make
if [ $? != 0 ];then
echo "BUILD_FAIL host tool exit as $?\n"
exit 2
fi
cp host_tool ${OUT_DIR}
echo "#####################build host-tool success"
echo "#####################build wasm apps"
cd ${WASM_APPS}
for i in `ls *.c | grep -v gui`
do
APP_SRC="$i ${APP_LIB_SRC}"
OUT_FILE=${i%.*}.wasm
clang-8 -I${APP_LIBS}/base -I${APP_LIBS}/extension/sensor -I${NATIVE_LIBS} \
-I${APP_LIBS}/extension/connection \
--target=wasm32 -O3 -z stack-size=4096 -Wl,--initial-memory=65536 \
-Wl,--allow-undefined \
-Wl,--no-threads,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_destroy \
-Wl,--export=on_request -Wl,--export=on_response \
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
-Wl,--export=on_connection_data \
-o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
echo "build ${OUT_FILE} success"
else
echo "build ${OUT_FILE} fail"
fi
done
echo "#####################build wasm apps done"

View File

@ -2,16 +2,9 @@
#include "sensor_api.h"
#include "connection_api.h"
#if WASM_ENABLE_GUI != 0
#include "gui_api.h"
#endif
static NativeSymbol extended_native_symbol_defs[] = {
#include "runtime_sensor.inl"
#include "connection.inl"
#if WASM_ENABLE_GUI != 0
#include "wamr_gui.inl"
#endif
};
};
#include "ext_lib_export.h"

View File

@ -29,17 +29,9 @@
#include "bh_thread.h"
#include "bh_memory.h"
#include "runtime_sensor.h"
#include "attr_container.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#if WASM_ENABLE_GUI != 0
#include "wgl.h"
#endif
#if WASM_ENABLE_GUI != 0
#include "lv_drivers/display/monitor.h"
#include "lv_drivers/indev/mouse.h"
#endif
#define MAX 2048
@ -362,7 +354,7 @@ static host_interface interface = { .send = uart_send, .destroy = uart_destroy }
#endif
static char global_heap_buf[512 * 1024] = { 0 };
static char global_heap_buf[1024 * 1024] = { 0 };
static void showUsage()
{
@ -392,7 +384,7 @@ static bool parse_args(int argc, char *argv[])
while (1) {
int optIndex = 0;
static struct option longOpts[] = {
static struct option longOpts[] = {
#ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' },
@ -402,10 +394,10 @@ static bool parse_args(int argc, char *argv[])
{ "baudrate", required_argument, NULL, 'b' },
#endif
{ "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
{ 0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "sa:p:u:b:h", longOpts, &optIndex);
c = getopt_long(argc, argv, "sa:p:u:b:w:h", longOpts, &optIndex);
if (c == -1)
break;
@ -444,40 +436,6 @@ static bool parse_args(int argc, char *argv[])
return true;
}
#if WASM_ENABLE_GUI != 0
/**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
*/
static void hal_init(void)
{
/* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
monitor_init();
/*Create a display buffer*/
static lv_disp_buf_t disp_buf1;
static lv_color_t buf1_1[480*10];
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 480*10);
/*Create a display*/
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.buffer = &disp_buf1;
disp_drv.flush_cb = monitor_flush;
// disp_drv.hor_res = 200;
// disp_drv.ver_res = 100;
lv_disp_drv_register(&disp_drv);
/* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse*/
mouse_init();
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
lv_indev_drv_register(&indev_drv);
}
#endif
// Driver function
int iwasm_main(int argc, char *argv[])
{
@ -486,7 +444,11 @@ int iwasm_main(int argc, char *argv[])
if (!parse_args(argc, argv))
return -1;
#if 1
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
#else
if (bh_memory_init_with_allocator(malloc, free)
#endif
!= 0) {
printf("Init global heap failed.\n");
return -1;
@ -501,11 +463,6 @@ int iwasm_main(int argc, char *argv[])
goto fail1;
}
#if WASM_ENABLE_GUI != 0
wgl_init();
hal_init();
#endif
init_sensor_framework();
// timer manager
@ -525,9 +482,6 @@ int iwasm_main(int argc, char *argv[])
exit_wasm_timer();
exit_sensor_framework();
#if WASM_ENABLE_GUI != 0
wgl_exit();
#endif
exit_connection_framework();
fail1:

View File

@ -0,0 +1,9 @@
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET X86_64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR)

View File

@ -4,6 +4,9 @@
*/
#include "wasm_app.h"
#include "wa-inc/connection.h"
#include "wa-inc/timer_wasm_app.h"
#include "wa-inc/request.h"
/* User global variable */
static int num = 0;
@ -44,7 +47,7 @@ void my_close_handler(request_t * request)
api_timer_cancel(g_timer);
api_close_connection(g_conn);
}
make_response_for_request(request, response);
set_response(response, DELETED_2_02, 0, NULL, 0);
api_response_send(response);

View File

@ -4,6 +4,8 @@
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
#include "wa-inc/timer_wasm_app.h"
int num = 0;

View File

@ -4,6 +4,7 @@
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
void over_heat_event_handler(request_t *request)
{

View File

@ -1,70 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <unistd.h>
#include "wasm_app.h"
static void btn_event_cb(wgl_obj_t btn, wgl_event_t event);
uint32_t count = 0;
char count_str[11] = { 0 };
wgl_obj_t hello_world_label;
wgl_obj_t count_label;
wgl_obj_t btn1;
wgl_obj_t label_count1;
int label_count1_value = 0;
char label_count1_str[11] = { 0 };
void timer1_update(user_timer_t timer1)
{
if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count / 100);
wgl_label_set_text(count_label, count_str);
}
++count;
}
void on_init()
{
char text[32] = {0};
hello_world_label = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL);
wgl_label_set_text(hello_world_label, "Hello world!");
wgl_label_get_text(hello_world_label, text, sizeof(text));
printf("Label text %d %s \n", wgl_label_get_text_length(hello_world_label), text);
wgl_obj_align(hello_world_label, (wgl_obj_t)NULL, WGL_ALIGN_IN_TOP_LEFT, 0, 0);
count_label = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL);
wgl_obj_align(count_label, (wgl_obj_t)NULL, WGL_ALIGN_IN_TOP_MID, 0, 0);
btn1 = wgl_btn_create((wgl_obj_t)NULL, (wgl_obj_t)NULL); /*Create a button on the currently loaded screen*/
wgl_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/
wgl_obj_align(btn1, (wgl_obj_t)NULL, WGL_ALIGN_CENTER, 0, 0); /*Align below the label*/
/*Create a label on the button*/
wgl_obj_t btn_label = wgl_label_create(btn1, (wgl_obj_t)NULL);
wgl_label_set_text(btn_label, "Click ++");
label_count1 = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL);
wgl_label_set_text(label_count1, "0");
wgl_obj_align(label_count1, (wgl_obj_t)NULL, WGL_ALIGN_IN_BOTTOM_MID, 0, 0);
/* set up a timer */
user_timer_t timer;
timer = api_timer_create(10, true, false, timer1_update);
api_timer_restart(timer, 10);
}
static void btn_event_cb(wgl_obj_t btn, wgl_event_t event)
{
if(event == WGL_EVENT_RELEASED) {
label_count1_value++;
snprintf(label_count1_str, sizeof(label_count1_str),
"%d", label_count1_value);
wgl_label_set_text(label_count1, label_count1_str);
}
}

View File

@ -1,74 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <unistd.h>
#include "wasm_app.h"
#include "lvgl.h"
extern char g_widget_text[];
static void btn_event_cb(lv_obj_t *btn, lv_event_t event);
uint32_t count = 0;
char count_str[11] = { 0 };
lv_obj_t *hello_world_label;
lv_obj_t *count_label;
lv_obj_t *btn1;
lv_obj_t *label_count1;
int label_count1_value = 100;
char label_count1_str[11] = { 0 };
void timer1_update(user_timer_t timer1)
{
if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count / 100);
lv_label_set_text(count_label, count_str);
}
++count;
}
void on_init()
{
char *text;
hello_world_label = lv_label_create(NULL, NULL);
lv_label_set_text(hello_world_label, "Hello world!");
text = lv_label_get_text(hello_world_label);
printf("Label text %lu %s \n", strlen(text), text);
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
count_label = lv_label_create(NULL, NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
btn1 = lv_btn_create(NULL, NULL); /*Create a button on the currently loaded screen*/
lv_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/
/*Create a label on the button*/
lv_obj_t *btn_label = lv_label_create(btn1, NULL);
lv_label_set_text(btn_label, "Click --");
label_count1 = lv_label_create(NULL, NULL);
lv_label_set_text(label_count1, "100");
lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
/* set up a timer */
user_timer_t timer;
timer = api_timer_create(10, true, false, timer1_update);
api_timer_restart(timer, 10);
}
static void btn_event_cb(lv_obj_t *btn, lv_event_t event)
{
if(event == LV_EVENT_RELEASED) {
label_count1_value--;
snprintf(label_count1_str, sizeof(label_count1_str),
"%d", label_count1_value);
lv_label_set_text(label_count1, label_count1_str);
if (label_count1_value == 0)
label_count1_value = 100;
}
}

View File

@ -4,6 +4,7 @@
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
static void url1_request_handler(request_t *request)
{

View File

@ -4,6 +4,7 @@
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
static void my_response_handler(response_t *response, void *user_data)
{

View File

@ -4,6 +4,7 @@
*/
#include "wasm_app.h"
#include "wa-inc/sensor.h"
static sensor_t sensor = NULL;

View File

@ -4,6 +4,7 @@
*/
#include "wasm_app.h"
#include "wa-inc/timer_wasm_app.h"
/* User global variable */
static int num = 0;