From df2d84dee1c23320a85623b023132ac9f477bb64 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Tue, 10 Mar 2020 13:31:33 +0100 Subject: [PATCH] Add multi-application support --- .vscode/launch.json | 4 ++-- .vscode/tasks.json | 4 +++- Makefile | 16 ++++++++++------ src/application/blinky/main.c | 26 ++++++++++++++++++++++++++ src/{ => application/button}/main.c | 0 5 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/application/blinky/main.c rename src/{ => application/button}/main.c (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index b5735ad..8b09410 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "name": "Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/bin/nrf.elf", + "program": "${workspaceFolder}/bin/firmware.elf", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", @@ -36,7 +36,7 @@ }, { "description": "Load executable into debugger.", - "text": "file ${workspaceFolder}/bin/nrf.elf", + "text": "file ${workspaceFolder}/bin/firmware.elf", "ignoreFailures": false }, { diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 389c723..9350bf2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,6 +6,8 @@ "env": { "PLATFORM": "nrf52", // "PLATFORM": "posix", + // "APPLICATION": "blinky", + "APPLICATION": "button", }, }, "tasks": [ @@ -84,4 +86,4 @@ "panel": "shared", "clear": true, } -} \ No newline at end of file +} diff --git a/Makefile b/Makefile index 0757637..3356194 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,23 @@ .DEFAULT_GOAL := all -PLATFORM ?= posix +APPLICATION ?= button -TARGET_FILE ?= firmware.elf +PLATFORM ?= posix +TARGET_FILE ?= $(APPLICATION).elf CC = $(CROSS_COMPILE)gcc CPP = $(CROSS_COMPILE)cpp OBJCOPY = $(CROSS_COMPILE)objcopy SRC_DIR = src -OBJ_DIR = obj -BIN_DIR = bin +OBJ_DIR = obj/$(PLATFORM) +BIN_DIR = bin/$(PLATFORM) CPP_FLAGS += $(addprefix -I, $(INCLUDES)) C_SRCS = $(wildcard $(SRC_DIR)/*.c) C_SRCS += $(wildcard $(SRC_DIR)/platform/$(PLATFORM)/*.c) +C_SRCS += $(wildcard $(SRC_DIR)/application/$(APPLICATION)/*.c) C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS))) OBJS = $(NRF_A_OBJS) $(NRF_C_OBJS) $(C_OBJS) @@ -46,14 +48,16 @@ clean: rm -f $(OBJS) $(patsubst %.o,%.d,$(OBJS)) distclean: - rm -rf $(OBJ_DIR) $(BIN_DIR) + rm -rf bin obj $(TARGET): $(OBJS) $(THIS_MAKEFILE) @mkdir -p $(dir $@) $(CC) $(CC_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@ + ln -sf $(shell pwd)/$@ $(shell pwd)/bin/firmware.elf $(TARGET_HEX): $(TARGET) $(THIS_MAKEFILE) $(OBJCOPY) -O ihex $(TARGET) $(TARGET_HEX) + ln -sf $(shell pwd)/$@ $(shell pwd)/bin/firmware.hex $(OBJ_DIR)/%.d: $(SRC_DIR)/%.c @mkdir -p $(dir $@) @@ -63,6 +67,6 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) $(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@ -ifneq ($(MAKECMDGOALS),clean) +ifeq "$(findstring $(MAKECMDGOALS), clean distclean)" "" -include $(patsubst %.o,%.d,$(OBJS)) endif diff --git a/src/application/blinky/main.c b/src/application/blinky/main.c new file mode 100644 index 0000000..039c05e --- /dev/null +++ b/src/application/blinky/main.c @@ -0,0 +1,26 @@ +#include +#include +#include "nrf_delay.h" +#include "boards.h" +#include "platform/narf52/narf52_dk.h" + +#include "driver.h" + +int main(void) +{ + drv_open(&led_1); + drv_open(&led_2); + drv_open(&led_3); + drv_open(&led_4); + + while(true) { + for(unsigned int i = 0; i < UINT_MAX; i++) { + char x = 0x30 | (char)(1 & i); + drv_write(&led_1, &x, 1); + drv_write(&led_2, &x, 1); + drv_write(&led_3, &x, 1); + drv_write(&led_4, &x, 1); + nrf_delay_ms(500); + } + } +} diff --git a/src/main.c b/src/application/button/main.c similarity index 100% rename from src/main.c rename to src/application/button/main.c