summaryrefslogtreecommitdiff
path: root/firmware/app
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/app')
-rw-r--r--firmware/app/Android.mk18
-rw-r--r--firmware/app/app.mk304
-rw-r--r--firmware/app/chre/Android.mk (renamed from firmware/app/external.app/Makefile)11
-rw-r--r--firmware/app/chre/chre.mk32
-rw-r--r--firmware/app/chre/chre_test0.app/Android.mk30
-rw-r--r--firmware/app/chre/chre_test0.app/Makefile41
-rw-r--r--firmware/app/chre/chre_test0.app/main.c107
-rw-r--r--firmware/app/chre/chre_test1.app/Android.mk31
-rw-r--r--firmware/app/chre/chre_test1.app/Makefile38
-rw-r--r--firmware/app/chre/chre_test1.app/main.cpp120
-rw-r--r--firmware/app/chre/common/Android.mk30
-rw-r--r--firmware/app/chre/common/chre_app.c89
-rw-r--r--firmware/app/chre/common/chre_app_syscalls.c145
-rw-r--r--firmware/app/common.mk38
-rw-r--r--firmware/app/test0.app/Android.mk30
-rw-r--r--firmware/app/test0.app/Makefile26
-rw-r--r--firmware/app/test0.app/test_app0.c2
-rw-r--r--firmware/app/test1.app/Android.mk30
-rw-r--r--firmware/app/test1.app/Makefile28
19 files changed, 1094 insertions, 56 deletions
diff --git a/firmware/app/Android.mk b/firmware/app/Android.mk
new file mode 100644
index 00000000..e6bbbc1e
--- /dev/null
+++ b/firmware/app/Android.mk
@@ -0,0 +1,18 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+subdirs := test0.app test1.app chre
+include $(call all-named-subdir-makefiles,$(subdirs))
diff --git a/firmware/app/app.mk b/firmware/app/app.mk
new file mode 100644
index 00000000..47c8de2e
--- /dev/null
+++ b/firmware/app/app.mk
@@ -0,0 +1,304 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+#
+# NanoApp C/C++ Makefile Utils
+#
+################################################################################
+
+# Configuration ################################################################
+
+# Toolchain Prefix
+ifndef CROSS_COMPILE
+ $(error Please set the environment variable CROSS_COMPILE to the complete \
+ path to the toolchain directory plus the binary prefix, e.g. export \
+ CROSS_COMPILE=~/bin/gcc-arm-none-eabi-4_8-2014q3/bin/arm-none-eabi-)
+endif
+
+PREFIX = $(CROSS_COMPILE)
+TOOLCHAIN_DIR = $(shell dirname `which $(CROSS_COMPILE)gcc`)/..
+
+# NANOHUB_DIR is relative to CWD (which is always APP Makefile dir)
+
+NANOAPP_POSTPROCESS := $(NANOHUB_DIR)/../util/nanoapp_postprocess/nanoapp_postprocess
+NANOAPP_SIGN := $(NANOHUB_DIR)/../util/nanoapp_sign/nanoapp_sign
+
+# TOP_RELPATH is ANDROID_TOP relative to NANOHUB_DIR
+TOP_RELPATH := ../../../..
+TOP_ABSPATH := $(realpath $(NANOHUB_DIR)/$(TOP_RELPATH))
+
+# for local variants there is always a path; for out-of-tree variants there may be
+# - a $(VARIANT) soft link under firmware/variant subdir, or
+# - VARIANT_PATH is found as vendor/<vendor_name>/<variant_name>/nanohub, or
+# - explicitly provided in VARIANT_CONFIG_PATH (path, where <variant>_conf.mk is located)
+#
+ifeq ($(VARIANT_CONFIG_PATH),)
+ variant_conf := $(wildcard $(TOP_ABSPATH)/vendor/*/*/nanohub/$(VARIANT)_conf.mk)
+ ifeq ($(words $(variant_conf)),1)
+ VARIANT_CONFIG_PATH := $(patsubst $(TOP_ABSPATH)/%/$(VARIANT)_conf.mk,%,$(variant_conf))
+ else
+ VARIANT_CONFIG_PATH := device/google/contexthub/firmware/variant/$(VARIANT)
+ endif
+endif
+
+include $(TOP_ABSPATH)/$(VARIANT_CONFIG_PATH)/$(VARIANT)_conf.mk
+
+# $(VARIANT)_conf.mk defines VARIANT_PATH, PLATFORM, CHIP, CPU, VARIANT
+# VARIANT_PATH from $(VARIANT)_conf.mk is ANDROID_TOP relative
+
+# change VARIANT_PATH to become CWD-relative
+VARIANT_PATH := $(NANOHUB_DIR)/$(TOP_RELPATH)/$(VARIANT_PATH)
+
+# all output goes here
+ifndef OUT
+OUT:=out/nanohub/$(VARIANT)/app/$(BIN)
+else
+ifneq ($(filter $(TOP_ABSPATH)/out/target/product/%,$(OUT)),)
+# this looks like Android OUT env var; update it
+IMAGE_TARGET_OUT:=$(OUT)/vendor/firmware/$(BIN).napp
+OUT:=$(OUT)/nanohub/$(VARIANT)/app/$(BIN)
+endif
+endif
+
+################################################################################
+#
+# Nanoapp Libc/Libm Utils
+#
+################################################################################
+
+include $(NANOHUB_DIR)/lib/lib.mk
+
+# Tools ########################################################################
+
+AS := $(PREFIX)gcc
+CC := $(PREFIX)gcc
+CXX := $(PREFIX)g++
+OBJCOPY := $(PREFIX)objcopy
+OBJDUMP := $(PREFIX)objdump
+
+# Assembly Flags ###############################################################
+
+AS_FLAGS +=
+
+# C++ Flags ####################################################################
+
+CXX_CFLAGS += -std=c++11
+CXX_CFLAGS += -fno-exceptions
+CXX_CFLAGS += -fno-rtti
+
+# C Flags ######################################################################
+
+C_CFLAGS +=
+
+# Common Flags #################################################################
+
+# Defines
+CFLAGS += -DAPP_ID=$(APP_ID)
+CFLAGS += -DAPP_VERSION=$(APP_VERSION)
+CFLAGS += -D__NANOHUB__
+
+# Optimization/debug
+CFLAGS += -Os
+CFLAGS += -g
+
+# Include paths
+CFLAGS += -I$(NANOHUB_DIR)/os/inc
+CFLAGS += -I$(NANOHUB_DIR)/os/platform/$(PLATFORM)/inc
+CFLAGS += -I$(NANOHUB_DIR)/os/cpu/$(CPU)/inc
+CFLAGS += -I$(VARIANT_PATH)/inc
+CFLAGS += -I$(NANOHUB_DIR)/../lib/include
+
+# Warnings/error configuration.
+CFLAGS += -Wall
+CFLAGS += -Werror
+CFLAGS += -Wmissing-declarations
+CFLAGS += -Wlogical-op
+CFLAGS += -Waddress
+CFLAGS += -Wempty-body
+CFLAGS += -Wpointer-arith
+CFLAGS += -Wenum-compare
+CFLAGS += -Wdouble-promotion
+CFLAGS += -Wshadow
+CFLAGS += -Wno-attributes
+
+# Produce position independent code.
+CFLAGS += -fpic
+CFLAGS += -mno-pic-data-is-text-relative
+CFLAGS += -msingle-pic-base
+CFLAGS += -mpic-register=r9
+
+# Code generation options for Cortex-M4F
+CFLAGS += -mthumb
+CFLAGS += -mcpu=cortex-m4
+CFLAGS += -march=armv7e-m
+CFLAGS += -mfloat-abi=softfp
+CFLAGS += -mfpu=fpv4-sp-d16
+CFLAGS += -mno-thumb-interwork
+CFLAGS += -ffast-math
+CFLAGS += -fsingle-precision-constant
+
+# Platform defines
+CFLAGS += -DARM
+CFLAGS += -DUSE_NANOHUB_FLOAT_RUNTIME
+CFLAGS += -DARM_MATH_CM4
+CFLAGS += -D__FPU_PRESENT
+
+# Miscellaneous
+CFLAGS += -fno-strict-aliasing
+CFLAGS += -fshort-double
+CFLAGS += -fvisibility=hidden
+CFLAGS += -fno-unwind-tables
+CFLAGS += -fstack-reuse=all
+CFLAGS += -ffunction-sections
+CFLAGS += -fdata-sections
+
+# Linker Configuration #########################################################
+
+LD := $(PREFIX)g++
+
+LDFLAGS := -T $(NANOHUB_DIR)/os/platform/$(PLATFORM)/lkr/app.lkr
+LDFLAGS += -nostartfiles
+LDFLAGS += -Wl,--gc-sections
+LDFLAGS += -Wl,-Map,$(OUT)/$(BIN).map
+LDFLAGS += -Wl,--cref
+STATIC_LIBS += -lgcc
+ifeq ($(BIN_MODE),static)
+LDFLAGS += -Bstatic
+LDFLAGS += -Wl,--emit-relocs
+else
+LDFLAGS += -Bdynamic
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -Wl,--no-allow-shlib-undefined
+endif
+
+# Build Rules ##################################################################
+
+AS_SRCS := $(filter %.S, $(SRCS))
+C_SRCS := $(filter %.c, $(SRCS))
+CXX_SRCS := $(filter %.cc, $(SRCS))
+CPP_SRCS := $(filter %.cpp, $(SRCS))
+
+OBJS := $(patsubst %.S, $(OUT)/%.o, $(AS_SRCS))
+OBJS += $(patsubst %.c, $(OUT)/%.o, $(C_SRCS))
+OBJS += $(patsubst %.cc, $(OUT)/%.o, $(CXX_SRCS))
+OBJS += $(patsubst %.cpp, $(OUT)/%.o, $(CPP_SRCS))
+
+UNSIGNED_BIN := $(BIN).unsigned.napp
+
+NANOHUB_KEY_PATH := $(NANOHUB_DIR)/os/platform/$(PLATFORM)/misc
+
+.PHONY: all clean sync
+all: $(OUT)/$(BIN).S $(OUT)/$(BIN).napp $(IMAGE_TARGET_OUT)
+
+$(OUT)/$(BIN).napp : $(OUT)/$(UNSIGNED_BIN) $(NANOAPP_SIGN)
+ @mkdir -p $(dir $@)
+ $(NANOAPP_SIGN) -e $(NANOHUB_KEY_PATH)/debug.privkey \
+ -m $(NANOHUB_KEY_PATH)/debug.pubkey -s $< $@
+ifdef IMAGE_TARGET_OUT
+$(IMAGE_TARGET_OUT): $(OUT)/$(BIN).napp
+ @mkdir -p $(dir $@)
+ cp $< $(IMAGE_TARGET_OUT)
+endif
+
+ifeq ($(BIN_MODE),static)
+$(OUT)/$(UNSIGNED_BIN) : $(OUT)/$(BIN).elf $(NANOAPP_POSTPROCESS)
+ @mkdir -p $(dir $@)
+ $(NANOAPP_POSTPROCESS) -s -a $(APP_ID) -v $(BIN_POSTPROCESS_ARGS) $< $@
+else
+$(OUT)/$(UNSIGNED_BIN) : $(OUT)/$(BIN).bin $(NANOAPP_POSTPROCESS)
+ @mkdir -p $(dir $@)
+ $(NANOAPP_POSTPROCESS) -a $(APP_ID) -v $(BIN_POSTPROCESS_ARGS) $< $@
+
+$(OUT)/$(BIN).bin : $(OUT)/$(BIN).elf
+ @mkdir -p $(dir $@)
+ $(OBJCOPY) -j.relocs -j.flash -j.data -j.dynsym -O binary $< $@
+endif
+
+$(OUT)/$(BIN).S : $(OUT)/$(BIN).elf
+ @mkdir -p $(dir $@)
+ $(OBJDUMP) $< -DS > $@
+
+$(OUT)/$(BIN).elf : $(OBJS)
+ @mkdir -p $(dir $@)
+ $(LD) $(CFLAGS) $(CXX_FLAGS) $(LDFLAGS) $(OBJS) $(STATIC_LIBS) -o $@
+
+$(OUT)/%.o : %.S
+ @mkdir -p $(dir $@)
+ $(AS) $(AS_FLAGS) $(CFLAGS) -c $< -o $@
+
+$(OUT)/%.o : %.c
+ @mkdir -p $(dir $@)
+ $(CC) $(C_CFLAGS) $(CFLAGS) -c $< -o $@
+
+$(OUT)/%.o : %.cc
+ @mkdir -p $(dir $@)
+ $(CXX) $(CXX_CFLAGS) $(CFLAGS) -c $< -o $@
+
+$(OUT)/%.o : %.cpp
+ @mkdir -p $(dir $@)
+ $(CXX) $(CXX_CFLAGS) $(CFLAGS) -c $< -o $@
+
+# Automatic dependency resolution ##############################################
+
+DEPS_AS = $(OUT)/deps_as
+DEPS_C = $(OUT)/deps_c
+DEPS_CXX = $(OUT)/deps_cxx
+
+$(DEPS_AS) : $(AS_SRCS)
+ @mkdir -p $(dir $@)
+ $(AS) $(AS_CFLAGS) $(CFLAGS) -MM $^ > $@
+
+$(DEPS_C) : $(C_SRCS)
+ @mkdir -p $(dir $@)
+ $(CC) $(C_CFLAGS) $(CFLAGS) -MM $^ > $@
+
+$(DEPS_CXX) : $(CXX_SRCS) $(CPP_SRCS)
+ @mkdir -p $(dir $@)
+ $(CXX) $(CXX_CFLAGS) $(CFLAGS) -MM $^ > $@
+
+NOAUTODEPTARGETS = clean
+
+ifeq ($(words $(findstring $(MAKECMDGOALS), $(NOAUTODEPTARGETS))), 0)
+
+ifneq ($(AS_SRCS), )
+-include $(DEPS_AS)
+endif
+
+ifneq ($(C_SRCS), )
+-include $(DEPS_C)
+endif
+
+ifneq ($(CXX_SRCS)$(CPP_SRCS),)
+-include $(DEPS_CXX)
+endif
+
+endif
+
+$(NANOAPP_POSTPROCESS): $(wildcard $(dir $(NANOAPP_POSTPROCESS))/*.c* $(dir $(NANOAPP_POSTPROCESS))/*.h)
+ echo DEPS [$@]: $^
+ make -C $(dir $@)
+
+$(NANOAPP_SIGN): $(wildcard $(dir $(NANOAPP_SIGN))/*.c* $(dir $(NANOAPP_SIGN))/*.h)
+ echo DEPS [$@]: $^
+ make -C $(dir $@)
+
+# Clean targets ################################################################
+
+clean :
+ rm -rf $(OUT)
+
+sync: $(OUT)/$(BIN).napp
+ adb push $< /vendor/firmware/$(BIN).napp
diff --git a/firmware/app/external.app/Makefile b/firmware/app/chre/Android.mk
index 7b3ae790..54d18ee0 100644
--- a/firmware/app/external.app/Makefile
+++ b/firmware/app/chre/Android.mk
@@ -14,13 +14,6 @@
# limitations under the License.
#
-#makefile for all extrernal appspop app
-
-EXTRA_FLAGS ?=
-
-ifneq ($(EXTERNAL_APP_BUILD),)
- SELF_MKFILE := $(EXTERNAL_APP_MAKEFILE)
- APP_ID := $(EXTERNAL_APP_ID)
- include app/common.mk
-endif
+LOCAL_PATH := $(call my-dir)
+include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/firmware/app/chre/chre.mk b/firmware/app/chre/chre.mk
new file mode 100644
index 00000000..a1476771
--- /dev/null
+++ b/firmware/app/chre/chre.mk
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+#
+# NanoApp C/C++ Makefile Utils
+#
+################################################################################
+
+SRCS += $(NANOHUB_DIR)/app/chre/common/chre_app.c
+SRCS += $(NANOHUB_DIR)/app/chre/common/chre_app_syscalls.c
+CFLAGS += -I$(NANOHUB_DIR)/../inc
+
+include $(NANOHUB_DIR)/firmware_conf.mk
+
+CFLAGS += $(COMMON_FLAGS)
+
+BIN_POSTPROCESS_ARGS := -f 0x10
+
+include $(NANOHUB_DIR)/app/app.mk
diff --git a/firmware/app/chre/chre_test0.app/Android.mk b/firmware/app/chre/chre_test0.app/Android.mk
new file mode 100644
index 00000000..4e265c20
--- /dev/null
+++ b/firmware/app/chre/chre_test0.app/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := chre_test0
+LOCAL_MODULE_TAGS := optional
+
+# Googl + T + 0x9000
+LOCAL_NANO_APP_ID := 476f6f676c549000
+LOCAL_NANO_APP_VERSION := 0
+
+LOCAL_SRC_FILES := main.c
+
+include $(BUILD_NANOHUB_APP_CHRE_EXECUTABLE)
diff --git a/firmware/app/chre/chre_test0.app/Makefile b/firmware/app/chre/chre_test0.app/Makefile
new file mode 100644
index 00000000..135fe517
--- /dev/null
+++ b/firmware/app/chre/chre_test0.app/Makefile
@@ -0,0 +1,41 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+################################################################################
+#
+# test NanoApp Makefile
+#
+################################################################################
+
+
+SRCS := main.c
+BIN := chre_test0
+APP_ID := 476f6f676c549000
+APP_VERSION := 0
+
+# Nanohub relative path
+NANOHUB_DIR := ../../..
+
+# Device configuration #########################################################
+
+# select device variant for this app
+# if there is no path of the form $(NANOHUB_DIR)/variant/$(VARIANT), the
+# VARIANT_PATH variable must be set to ANDROID_TOP-relative valid path containing VARIANT subtree
+
+TARGET_PRODUCT ?= nucleo
+VARIANT := $(TARGET_PRODUCT)
+
+include $(NANOHUB_DIR)/app/chre/chre.mk
diff --git a/firmware/app/chre/chre_test0.app/main.c b/firmware/app/chre/chre_test0.app/main.c
new file mode 100644
index 00000000..acdba524
--- /dev/null
+++ b/firmware/app/chre/chre_test0.app/main.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <chre.h>
+
+#define CHRE_APP_TAG "CHRE App 0: "
+
+/* chre.h does not define printf format attribute for chreLog() */
+void chreLog(enum chreLogLevel level, const char *str, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
+
+#define EVT_LOCAL_SETUP CHRE_EVENT_FIRST_USER_VALUE
+
+struct MyTimer {
+ uint32_t timerId;
+};
+
+struct ExtMsg
+{
+ uint8_t msg;
+ uint32_t val;
+} __attribute__((packed));
+
+static const uint64_t kOneSecond = UINT64_C(1000000000); // in nanoseconds
+
+static uint32_t mMyTid;
+static uint64_t mMyAppId;
+static int cnt;
+static struct MyTimer mTimer;
+
+static void nanoappFreeEvent(uint16_t eventType, void *data)
+{
+ chreLog(CHRE_LOG_INFO, CHRE_APP_TAG "event callback invoked: eventType=%04" PRIX16
+ "; data=%p\n", eventType, data);
+}
+
+// Default implementation for message free
+static void nanoappFreeMessage(void *msg, size_t size)
+{
+ chreLog(CHRE_LOG_INFO, CHRE_APP_TAG "message callback invoked: msg=%p; size=%08zu\n",
+ msg, size);
+ chreHeapFree(msg);
+}
+
+bool nanoappStart(void)
+{
+ mMyAppId = chreGetAppId();
+ mMyTid = chreGetInstanceId();
+ cnt = 3;
+ chreSendEvent(EVT_LOCAL_SETUP, (void*)0x87654321, nanoappFreeEvent, mMyTid);
+ chreLog(CHRE_LOG_INFO, CHRE_APP_TAG "init\n");
+ return true;
+}
+
+void nanoappEnd(void)
+{
+}
+
+void nanoappHandleEvent(uint32_t srcTid, uint16_t evtType, const void* evtData)
+{
+ switch (evtType) {
+ case EVT_LOCAL_SETUP:
+ mTimer.timerId = chreTimerSet(kOneSecond, &mTimer, false);
+ chreLog(CHRE_LOG_INFO, CHRE_APP_TAG "started with tid %04" PRIX32
+ " timerid %" PRIu32
+ "\n", mMyTid, mTimer.timerId);
+ break;
+ case CHRE_EVENT_TIMER:
+ {
+ const struct MyTimer *t = (const struct MyTimer *)evtData;
+ struct ExtMsg *extMsg = chreHeapAlloc(sizeof(*extMsg));
+
+ chreLog(CHRE_LOG_INFO, CHRE_APP_TAG "received timer %" PRIu32
+ " (TIME: %" PRIu64
+ ") cnt: %d\n", t->timerId, chreGetTime(), cnt);
+ extMsg->msg = 0x01;
+ extMsg->val = cnt;
+ chreSendMessageToHost(extMsg, sizeof(*extMsg), 0, nanoappFreeMessage);
+ if (cnt-- <= 0)
+ chreTimerCancel(t->timerId);
+ break;
+ }
+ case CHRE_EVENT_MESSAGE_FROM_HOST:
+ {
+ const struct chreMessageFromHostData *msg = (const struct chreMessageFromHostData *)evtData;
+ const uint8_t *data = (const uint8_t *)msg->message;
+ const size_t size = msg->messageSize;
+ chreLog(CHRE_LOG_INFO, CHRE_APP_TAG "message=%p; code=%d; size=%zu\n",
+ data, (data && size) ? data[0] : 0, size);
+ break;
+ }
+ }
+}
diff --git a/firmware/app/chre/chre_test1.app/Android.mk b/firmware/app/chre/chre_test1.app/Android.mk
new file mode 100644
index 00000000..f5a303c8
--- /dev/null
+++ b/firmware/app/chre/chre_test1.app/Android.mk
@@ -0,0 +1,31 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := chre_test1
+LOCAL_MODULE_TAGS := optional
+
+# Googl + T + 0x9001
+LOCAL_NANO_APP_ID := 476f6f676c549001
+LOCAL_NANO_APP_VERSION := 0
+
+LOCAL_SRC_FILES := \
+ main.cpp \
+
+include $(BUILD_NANOHUB_APP_CHRE_EXECUTABLE)
diff --git a/firmware/app/chre/chre_test1.app/Makefile b/firmware/app/chre/chre_test1.app/Makefile
new file mode 100644
index 00000000..6e6390c7
--- /dev/null
+++ b/firmware/app/chre/chre_test1.app/Makefile
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+################################################################################
+#
+# test NanoApp Makefile
+#
+################################################################################
+
+
+SRCS := main.cpp
+BIN := chre_test1
+APP_ID := 476f6f676c549001
+APP_VERSION := 0
+
+# Nanohub relative path
+NANOHUB_DIR := ../../..
+
+# Device configuration #########################################################
+
+# select device variant for this app
+TARGET_PRODUCT ?= nucleo
+VARIANT := $(TARGET_PRODUCT)
+
+include $(NANOHUB_DIR)/app/chre/chre.mk
diff --git a/firmware/app/chre/chre_test1.app/main.cpp b/firmware/app/chre/chre_test1.app/main.cpp
new file mode 100644
index 00000000..22a33ce6
--- /dev/null
+++ b/firmware/app/chre/chre_test1.app/main.cpp
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <chre.h>
+
+#define APP_LABEL "CHRE App 1: "
+
+/* chre.h does not define printf format attribute for chreLog() */
+void chreLog(enum chreLogLevel level, const char *str, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
+
+#define EVT_LOCAL_SETUP CHRE_EVENT_FIRST_USER_VALUE
+
+struct MyTimer {
+ uint32_t timerId;
+};
+
+struct ExtMsg
+{
+ uint8_t msg;
+ uint32_t val;
+} __attribute__((packed));
+
+static const uint64_t kOneSecond = UINT64_C(1000000000); // in nanoseconds
+
+static uint32_t mMyTid;
+static uint64_t mMyAppId;
+static int cnt;
+static struct MyTimer mTimer;
+
+// Default implementation for message free
+static void nanoappFreeMessage(void *msg, size_t size)
+{
+ chreHeapFree(msg);
+}
+
+bool nanoappStart(void)
+{
+ mMyAppId = chreGetAppId();
+ mMyTid = chreGetInstanceId();
+ cnt = 3;
+ chreSendEvent(EVT_LOCAL_SETUP, NULL, NULL, mMyTid);
+ chreLog(CHRE_LOG_INFO, APP_LABEL "init");
+ return true;
+}
+
+void nanoappEnd(void)
+{
+ chreLog(CHRE_LOG_INFO, APP_LABEL "terminating");
+}
+
+class A {
+ int *p;
+public:
+ A(int _x) {
+ p = new int[1];
+ if (p != nullptr)
+ *p = _x;
+ chreLog(CHRE_LOG_INFO, APP_LABEL "A::A(int): *p=%d", p != nullptr ? *p : 0);
+ }
+ ~A() {
+ chreLog(CHRE_LOG_INFO, APP_LABEL "A::~A(): *p=%d", p != nullptr ? *p : 0);
+ delete p;
+ p = nullptr;
+ }
+};
+
+static A global_with_ctor_dtor(1); // test the behavior of global static constructors/destructors
+
+void nanoappHandleEvent(uint32_t srcTid, uint16_t evtType, const void* evtData)
+{
+ static A local_static_with_ctor_dtor(2); // test the behavior of local static constructors/destructors
+
+ switch (evtType) {
+ case EVT_LOCAL_SETUP:
+ mTimer.timerId = chreTimerSet(kOneSecond, &mTimer, false);
+ chreLog(CHRE_LOG_INFO, APP_LABEL "started with tid %04" PRIX32
+ " timerid %" PRIu32
+ "\n", mMyTid, mTimer.timerId);
+ break;
+ case CHRE_EVENT_TIMER:
+ {
+ const struct MyTimer *t = (const struct MyTimer *)evtData;
+ auto extMsg = new ExtMsg;
+
+ chreLog(CHRE_LOG_INFO, APP_LABEL "received timer %" PRIu32
+ " (TIME: %" PRIu64
+ ") cnt: %d\n", t->timerId, chreGetTime(), cnt);
+ extMsg->msg = 0x01;
+ extMsg->val = cnt;
+ chreSendMessageToHost(extMsg, sizeof(*extMsg), 0, nanoappFreeMessage);
+ if (cnt-- <= 0)
+ chreTimerCancel(t->timerId);
+ break;
+ }
+ case CHRE_EVENT_MESSAGE_FROM_HOST:
+ {
+ const struct chreMessageFromHostData *msg = (const struct chreMessageFromHostData *)evtData;
+ const uint8_t *data = (const uint8_t *)msg->message;
+ const size_t size = msg->messageSize;
+ chreLog(CHRE_LOG_INFO, APP_LABEL "message=%p; code=%d; size=%zu",
+ data, (data && size) ? data[0] : 0, size);
+ break;
+ }
+ }
+}
diff --git a/firmware/app/chre/common/Android.mk b/firmware/app/chre/common/Android.mk
new file mode 100644
index 00000000..9a05b034
--- /dev/null
+++ b/firmware/app/chre/common/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := libnanochre
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+ chre_app.c \
+ chre_app_syscalls.c \
+
+LOCAL_STATIC_LIBRARIES += libnanolibc
+
+include $(BUILD_NANOHUB_APP_STATIC_LIBRARY)
diff --git a/firmware/app/chre/common/chre_app.c b/firmware/app/chre/common/chre_app.c
new file mode 100644
index 00000000..d12941a8
--- /dev/null
+++ b/firmware/app/chre/common/chre_app.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <eventnums.h>
+#include <seos.h>
+#include <timer.h>
+#include <toolchain.h>
+#include <crt_priv.h>
+
+#include <chre.h>
+
+/*
+ * Common CHRE App support code
+ */
+
+static bool chreappStart(uint32_t tid)
+{
+ __crt_init();
+ return nanoappStart();
+}
+
+static void chreappEnd(void)
+{
+ nanoappEnd();
+ __crt_exit();
+}
+
+static void chreappHandle(uint32_t eventTypeAndTid, const void *eventData)
+{
+ uint16_t evt = eventTypeAndTid;
+ uint16_t srcTid = eventTypeAndTid >> 16;
+ const void *data = eventData;
+
+ union EventLocalData {
+ struct chreMessageFromHostData msg;
+ } u;
+
+ switch(evt) {
+ case EVT_APP_TIMER:
+ evt = CHRE_EVENT_TIMER;
+ data = ((struct TimerEvent *)eventData)->data;
+ break;
+ case EVT_APP_FROM_HOST:
+ evt = CHRE_EVENT_MESSAGE_FROM_HOST;
+ data = &u.msg;
+ u.msg.message = (uint8_t*)eventData + 1;
+ u.msg.reservedMessageType = 0;
+ u.msg.messageSize = *(uint8_t*)eventData;
+ break;
+ case EVT_APP_FROM_HOST_CHRE:
+ {
+ const struct NanohubMsgChreHdr *hdr = eventData;
+ evt = CHRE_EVENT_MESSAGE_FROM_HOST;
+ data = &u.msg;
+ u.msg.message = hdr + 1;
+ u.msg.reservedMessageType = hdr->appEvent;
+ u.msg.messageSize = hdr->size;
+ break;
+ }
+ default:
+ // ignore any other system events; OS may send them to any app
+ if (evt < EVT_NO_FIRST_USER_EVENT)
+ return;
+ }
+ nanoappHandleEvent(srcTid, evt, data);
+}
+
+// Collect entry points
+const struct AppFuncs SET_EXTERNAL_APP_ATTRIBUTES(used, section (".app_init"),visibility("default")) _mAppFuncs = {
+ .init = chreappStart,
+ .end = chreappEnd,
+ .handle = chreappHandle,
+};
+
+// declare version for compatibility with current runtime
+const uint32_t SET_EXTERNAL_APP_VERSION(used, section (".app_version"), visibility("default")) _mAppVer = 0;
diff --git a/firmware/app/chre/common/chre_app_syscalls.c b/firmware/app/chre/common/chre_app_syscalls.c
new file mode 100644
index 00000000..666bdaed
--- /dev/null
+++ b/firmware/app/chre/common/chre_app_syscalls.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdarg.h>
+
+#include <gpio.h>
+#include <osApi.h>
+#include <sensors.h>
+#include <seos.h>
+#include <util.h>
+
+/* CHRE syscalls */
+#include <chre.h>
+#include <chreApi.h>
+#include <syscall.h>
+#include <syscall_defs.h>
+
+#define SYSCALL_CHRE_API(name) \
+ SYSCALL_NO(SYSCALL_DOMAIN_CHRE, SYSCALL_CHRE_MAIN, SYSCALL_CHRE_MAIN_API, SYSCALL_CHRE_MAIN_API_ ## name)
+
+uint64_t chreGetAppId(void)
+{
+ uint64_t appId = 0;
+ (void)syscallDo1P(SYSCALL_CHRE_API(GET_APP_ID), &appId);
+ return appId;
+}
+
+uint32_t chreGetInstanceId(void)
+{
+ return syscallDo0P(SYSCALL_CHRE_API(GET_INST_ID));
+}
+
+uint64_t chreGetTime(void) {
+ uint64_t time_ns = 0;
+ (void)syscallDo1P(SYSCALL_CHRE_API(GET_TIME), &time_ns);
+ return time_ns;
+}
+
+void chreLog(enum chreLogLevel level, const char *str, ...)
+{
+ va_list vl;
+
+ va_start(vl, str);
+ (void)syscallDo3P(SYSCALL_CHRE_API(LOG), level, str, VA_LIST_TO_INTEGER(vl));
+ va_end(vl);
+}
+
+uint32_t chreTimerSet(uint64_t duration, const void* cookie, bool oneShot)
+{
+ uint32_t dur_lo = duration;
+ uint32_t dur_hi = duration >> 32;
+ return syscallDo4P(SYSCALL_CHRE_API(TIMER_SET), dur_lo, dur_hi, cookie, oneShot);
+}
+
+bool chreTimerCancel(uint32_t timerId)
+{
+ return syscallDo1P(SYSCALL_CHRE_API(TIMER_CANCEL), timerId);
+}
+
+void chreAbort(uint32_t abortCode)
+{
+ (void)syscallDo1P(SYSCALL_CHRE_API(ABORT), abortCode);
+}
+
+void* chreHeapAlloc(uint32_t bytes)
+{
+ return (void *)syscallDo1P(SYSCALL_CHRE_API(HEAP_ALLOC), bytes);
+}
+
+void chreHeapFree(void* ptr)
+{
+ (void)syscallDo1P(SYSCALL_CHRE_API(HEAP_FREE), ptr);
+}
+
+bool chreSensorFindDefault(uint8_t sensorType, uint32_t *handle)
+{
+ return syscallDo2P(SYSCALL_CHRE_API(SENSOR_FIND_DEFAULT), sensorType, handle);
+}
+
+bool chreGetSensorInfo(uint32_t sensorHandle, struct chreSensorInfo *info)
+{
+ return syscallDo2P(SYSCALL_CHRE_API(SENSOR_GET_INFO), sensorHandle, info);
+}
+
+bool chreGetSensorSamplingStatus(uint32_t sensorHandle,
+ struct chreSensorSamplingStatus *status)
+{
+ return syscallDo2P(SYSCALL_CHRE_API(SENSOR_GET_STATUS), sensorHandle, status);
+}
+
+bool chreSensorConfigure(uint32_t sensorHandle,
+ enum chreSensorConfigureMode mode,
+ uint64_t interval, uint64_t latency)
+{
+ uint32_t interval_lo = interval;
+ uint32_t interval_hi = interval >> 32;
+ uint32_t latency_lo = latency;
+ uint32_t latency_hi = latency >> 32;
+ return syscallDo6P(SYSCALL_CHRE_API(SENSOR_CONFIG), sensorHandle, mode,
+ interval_lo, interval_hi, latency_lo, latency_hi);
+}
+
+bool chreSendEvent(uint16_t eventType, void *eventData,
+ chreEventCompleteFunction *freeCallback,
+ uint32_t targetInstanceId)
+{
+ return syscallDo4P(SYSCALL_CHRE_API(SEND_EVENT), eventType, eventData, freeCallback, targetInstanceId);
+}
+
+bool chreSendMessageToHost(void *message, uint32_t messageSize,
+ uint32_t reservedMessageType,
+ chreMessageFreeFunction *freeCallback)
+{
+ return syscallDo4P(SYSCALL_CHRE_API(SEND_MSG), message, messageSize, reservedMessageType, freeCallback);
+}
+
+uint32_t chreGetApiVersion(void)
+{
+ return syscallDo0P(SYSCALL_CHRE_API(GET_OS_API_VERSION));
+}
+
+uint32_t chreGetVersion(void)
+{
+ return syscallDo0P(SYSCALL_CHRE_API(GET_OS_VERSION));
+}
+
+uint64_t chreGetPlatformId(void)
+{
+ uint64_t plat = 0;
+ (void)syscallDo1P(SYSCALL_CHRE_API(GET_PLATFORM_ID), &plat);
+ return plat;
+}
diff --git a/firmware/app/common.mk b/firmware/app/common.mk
deleted file mode 100644
index 81a96240..00000000
--- a/firmware/app/common.mk
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-SELF_DIR := $(SELF_MKFILE:Makefile=)
-SELF_FILES := $(wildcard $(SELF_DIR)*.c)
-APP_NM := $(SELF_DIR)app
-CLEANFILES := $(CLEANFILES) $(APP_NM).elf $(APP_NM).bin
-DELIVERABLES := $(DELIVERABLES) $(APP_NM).napp
-APP_ELF := $(APP_NM).elf
-APP_BIN := $(APP_NM).bin
-APP_APP := $(APP_NM).napp
-APPFLAGS += $(EXTRA_FLAGS) -Wall -Werror
-
-define APPRULE
-$(APP_APP): $(APP_BIN)
- nanoapp_postprocess -v -a $(APP_ID) $(APP_BIN) $(APP_APP)
-
-$(APP_BIN): $(APP_ELF)
- $(OBJCOPY) -j.relocs -j.flash -j.data -j.dynsym -O binary $(APP_ELF) $(APP_BIN)
-
-$(APP_ELF): $(SELF_FILES) symlinks
- $(GCC) -o $(APP_ELF) $(FLAGS) $(APPFLAGS) -fvisibility=hidden $(SELF_FILES)
-endef
-
-$(eval $(APPRULE))
diff --git a/firmware/app/test0.app/Android.mk b/firmware/app/test0.app/Android.mk
new file mode 100644
index 00000000..3e7d6493
--- /dev/null
+++ b/firmware/app/test0.app/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := test0
+LOCAL_MODULE_TAGS := optional
+
+# Googl + T + 0x8000
+LOCAL_NANO_APP_ID := 476f6f676c548000
+LOCAL_NANO_APP_VERSION := 0
+
+LOCAL_SRC_FILES := test_app0.c
+
+include $(BUILD_NANOHUB_APP_EXECUTABLE)
diff --git a/firmware/app/test0.app/Makefile b/firmware/app/test0.app/Makefile
index 0303b64e..0747921d 100644
--- a/firmware/app/test0.app/Makefile
+++ b/firmware/app/test0.app/Makefile
@@ -14,10 +14,28 @@
# limitations under the License.
#
-#makefile for test0 app
+################################################################################
+#
+# test NanoApp Makefile
+#
+################################################################################
-SELF_MKFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
-# Googl + T + 0x8000
+
+SRCS := test_app0.c
+BIN := test0
APP_ID := 476f6f676c548000
+APP_VERSION := 0
+
+# Nanohub relative path
+NANOHUB_DIR := ../..
+
+# Device configuration #########################################################
+
+# select device variant for this app
+# if there is no path of the form $(NANOHUB_DIR)/variant/$(VARIANT), the
+# VARIANT_PATH variable must be set to ANDROID_TOP-relative valid path containing VARIANT subtree
+
+TARGET_PRODUCT ?= nucleo
+VARIANT := $(TARGET_PRODUCT)
-include app/common.mk
+include $(NANOHUB_DIR)/app/app.mk
diff --git a/firmware/app/test0.app/test_app0.c b/firmware/app/test0.app/test_app0.c
index 9ea84179..1c02d159 100644
--- a/firmware/app/test0.app/test_app0.c
+++ b/firmware/app/test0.app/test_app0.c
@@ -58,7 +58,7 @@ static void handle_event(uint32_t evtType, const void* evtData)
te = evtData;
eOsLog(LOG_INFO, "App 0 received timer %u callback: %d (TIM: %lld, RTC: %lld, SENSOR: %lld, HOST: %lld)\n", te->timerId, *(int *)te->data, eOsTimGetTime(), eOsRtcGetTime(), eOsSensorGetTime(), eOsHostGetTime());
extMsg = eOsHeapAlloc(sizeof(*extMsg));
- extMsg->hdr.appId = APP_ID_MAKE(APP_ID_VENDOR_GOOGLE, 0x548000);
+ extMsg->hdr.appId = APP_ID_MAKE(NANOHUB_VENDOR_GOOGLE, 0x548000);
extMsg->hdr.dataLen = 5;
extMsg->msg = 0x01;
extMsg->val = *(int *)te->data;
diff --git a/firmware/app/test1.app/Android.mk b/firmware/app/test1.app/Android.mk
new file mode 100644
index 00000000..7d04e3c6
--- /dev/null
+++ b/firmware/app/test1.app/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_NANO_VARS)
+
+LOCAL_MODULE := test1
+LOCAL_MODULE_TAGS := optional
+
+# Googl + T + 0x8000
+LOCAL_NANO_APP_ID := 476f6f676c548001
+LOCAL_NANO_APP_VERSION := 0
+
+LOCAL_SRC_FILES := test_app1.c
+
+include $(BUILD_NANOHUB_APP_EXECUTABLE)
diff --git a/firmware/app/test1.app/Makefile b/firmware/app/test1.app/Makefile
index 8cade3f9..b7e224e4 100644
--- a/firmware/app/test1.app/Makefile
+++ b/firmware/app/test1.app/Makefile
@@ -14,10 +14,30 @@
# limitations under the License.
#
-#makefile for test1 app
+################################################################################
+#
+# test1 NanoApp Makefile
+#
+################################################################################
+
+# Device configuration #########################################################
+
+SRCS := test_app1.c
+BIN := test1
-SELF_MKFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
-# Googl + T + 0x8001
APP_ID := 476f6f676c548001
+APP_VERSION := 0
+
+# Nanohub relative path
+NANOHUB_DIR := ../..
+
+# Device configuration #########################################################
+
+# select device variant for this app
+# if there is no path of the form $(NANOHUB_DIR)/variant/$(VARIANT), the
+# VARIANT_PATH variable must be set to ANDROID_TOP-relative valid path containing VARIANT subtree
+
+TARGET_PRODUCT ?= nucleo
+VARIANT := $(TARGET_PRODUCT)
-include app/common.mk
+include $(NANOHUB_DIR)/app/app.mk