From a6c8b39631ee9c09b9170493867c91bb619c7f36 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Mon, 14 Mar 2022 19:47:25 +0900 Subject: [PATCH 1/5] Fix local compile flag was ignored issue Fixed by saving local flags once and adding them later. --- resources/makefiles/application.mk | 6 ++++++ resources/makefiles/worker.mk | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/resources/makefiles/application.mk b/resources/makefiles/application.mk index 0d6b340..f891eb2 100644 --- a/resources/makefiles/application.mk +++ b/resources/makefiles/application.mk @@ -40,6 +40,10 @@ # THIS FILE IS AUTO GENERATED. DO NOT MODIFY # ############################################################################ +# Local flags +LOCAL_CFLAGS := $(CFLAGS) +LOCAL_CXXFLAGS := $(CXXFLAGS) + ifeq ($(SDK_VERSION_MAJ),1) # SDK 1.x.x series -include $(TOPDIR)/Make.defs @@ -83,7 +87,9 @@ CSRCS += $(filter-out $(MAINSRC),$(wildcard *.c) $(wildcard */*.c)) CXXSRCS += $(wildcard *.cpp) $(wildcard */*.cpp) $(wildcard *.cxx) $(wildcard */*.cxx) CFLAGS += $(foreach inc,$(wildcard ../*/include),-I$(inc)) +CFLAGS += $(LOCAL_CFLAGS) CXXFLAGS += $(foreach inc,$(wildcard ../*/include),-I$(inc)) +CXXFLAGS += $(LOCAL_CXXFLAGS) PROGNAME = $(APPNAME)$(EXEEXT) diff --git a/resources/makefiles/worker.mk b/resources/makefiles/worker.mk index df17b18..34c60a8 100644 --- a/resources/makefiles/worker.mk +++ b/resources/makefiles/worker.mk @@ -1,4 +1,12 @@ +############################################################################ +# THIS FILE IS AUTO GENERATED. DO NOT MODIFY # +############################################################################ + # SPRESENSE_IDE_VERSION := 1.1.0 + +# Local flags +LOCAL_CELFFLAGS := $(CELFFLAGS) + -include $(TOPDIR)/Make.defs -include $(SDKDIR)/Make.defs @@ -17,6 +25,7 @@ DBG = $(APPDIR)/$(WORKER_FOLDER_NAME)/$(WORKER_NAME).debug CELFFLAGS += -Og CELFFLAGS += -I$(APPDIR) CELFFLAGS += -I$(WORKER_DIR) +CELFFLAGS += $(LOCAL_CELFFLAGS) CSRCS += $(wildcard *.c) $(wildcard */*.c) From eb91f2362f7ba9d5d7b6dbf71f5b368b3e4c2449 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 15 Mar 2022 18:39:54 +0900 Subject: [PATCH 2/5] settings.ts: Create .vscode/include directory when project created The '.vscode/include' is a neccessary directory for using a Spresense VSCode IDE. So, create it in first time after creating project workspace. --- src/settings.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/settings.ts b/src/settings.ts index fc8cedb..acc4da2 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -80,11 +80,17 @@ function win32ToPosixPath(win32Path: string): string { function createVscode(newFolderPath: string) { let vscodePath = path.join(newFolderPath, '.vscode'); + let includePath = path.join(vscodePath, 'include'); if (!fs.existsSync(vscodePath) || !fs.statSync(vscodePath).isDirectory()) { /* If .vscode does not exist, create it */ fs.mkdirSync(vscodePath); } + + if (!fs.existsSync(includePath) || !fs.statSync(includePath).isDirectory()) { + /* If .vscode/include does not exist, create it */ + fs.mkdirSync(includePath); + } } function getFirstFolder(): vscode.WorkspaceFolder | undefined { From 6889a1a8ad9400afde425e7a77197af788d22d31 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Wed, 16 Mar 2022 16:54:58 +0900 Subject: [PATCH 3/5] Separate application template for SDK1.x and SDK2.x After SDK2.x, some code rule was changed. Separate template file between SDK1.x and SDK2.x for adapt it. --- resources/ver1/appfiles/Make.defs | 2 + resources/ver1/appfiles/Makefile | 30 ++++ resources/ver1/appfiles/main.c | 7 + resources/ver1/workerfiles/app/Make.defs | 2 + resources/ver1/workerfiles/app/Makefile | 30 ++++ resources/ver1/workerfiles/app/main.c | 161 +++++++++++++++++++++ resources/ver1/workerfiles/worker/.worker | 1 + resources/ver1/workerfiles/worker/Makefile | 12 ++ resources/ver1/workerfiles/worker/header.h | 7 + resources/ver1/workerfiles/worker/worker.c | 77 ++++++++++ resources/ver2/appfiles/Make.defs | 2 + resources/ver2/appfiles/Makefile | 30 ++++ resources/ver2/appfiles/main.c | 7 + resources/ver2/workerfiles/app/Make.defs | 2 + resources/ver2/workerfiles/app/Makefile | 30 ++++ resources/ver2/workerfiles/app/main.c | 161 +++++++++++++++++++++ resources/ver2/workerfiles/worker/.worker | 1 + resources/ver2/workerfiles/worker/Makefile | 12 ++ resources/ver2/workerfiles/worker/header.h | 7 + resources/ver2/workerfiles/worker/worker.c | 77 ++++++++++ src/common.ts | 67 +++++++-- 21 files changed, 712 insertions(+), 13 deletions(-) create mode 100644 resources/ver1/appfiles/Make.defs create mode 100644 resources/ver1/appfiles/Makefile create mode 100644 resources/ver1/appfiles/main.c create mode 100644 resources/ver1/workerfiles/app/Make.defs create mode 100644 resources/ver1/workerfiles/app/Makefile create mode 100644 resources/ver1/workerfiles/app/main.c create mode 100644 resources/ver1/workerfiles/worker/.worker create mode 100644 resources/ver1/workerfiles/worker/Makefile create mode 100644 resources/ver1/workerfiles/worker/header.h create mode 100644 resources/ver1/workerfiles/worker/worker.c create mode 100644 resources/ver2/appfiles/Make.defs create mode 100644 resources/ver2/appfiles/Makefile create mode 100644 resources/ver2/appfiles/main.c create mode 100644 resources/ver2/workerfiles/app/Make.defs create mode 100644 resources/ver2/workerfiles/app/Makefile create mode 100644 resources/ver2/workerfiles/app/main.c create mode 100644 resources/ver2/workerfiles/worker/.worker create mode 100644 resources/ver2/workerfiles/worker/Makefile create mode 100644 resources/ver2/workerfiles/worker/header.h create mode 100644 resources/ver2/workerfiles/worker/worker.c diff --git a/resources/ver1/appfiles/Make.defs b/resources/ver1/appfiles/Make.defs new file mode 100644 index 0000000..58d57cc --- /dev/null +++ b/resources/ver1/appfiles/Make.defs @@ -0,0 +1,2 @@ +CONFIGURED_APPS += __app_name__ + diff --git a/resources/ver1/appfiles/Makefile b/resources/ver1/appfiles/Makefile new file mode 100644 index 0000000..9b72590 --- /dev/null +++ b/resources/ver1/appfiles/Makefile @@ -0,0 +1,30 @@ +# Application makefile + +# Command name (Public function 'int _main(void)' required) +APPNAME = + +# Application execute priority (Range: 0 ~ 255, Default: 100) +PRIORITY = + +# Application stack memory size (Default: 2048) +STACKSIZE = + +# Main source code +MAINSRC = + +# Additional C source files (*.c) +CSRCS = + +# Additional C++ source files (*.cxx) +CXXSRCS = + +# Additional assembler source files (*.S) +ASRCS = + +# C compiler flags +CFLAGS = + +# C++ compiler flags +CXXFLAGS = + +include $(SPRESENSE_HOME)/.vscode/application.mk diff --git a/resources/ver1/appfiles/main.c b/resources/ver1/appfiles/main.c new file mode 100644 index 0000000..5990410 --- /dev/null +++ b/resources/ver1/appfiles/main.c @@ -0,0 +1,7 @@ +#include +#include + +int __app_name___main(int argc, char *argv[]) +{ + return 0; +} diff --git a/resources/ver1/workerfiles/app/Make.defs b/resources/ver1/workerfiles/app/Make.defs new file mode 100644 index 0000000..58d57cc --- /dev/null +++ b/resources/ver1/workerfiles/app/Make.defs @@ -0,0 +1,2 @@ +CONFIGURED_APPS += __app_name__ + diff --git a/resources/ver1/workerfiles/app/Makefile b/resources/ver1/workerfiles/app/Makefile new file mode 100644 index 0000000..9b72590 --- /dev/null +++ b/resources/ver1/workerfiles/app/Makefile @@ -0,0 +1,30 @@ +# Application makefile + +# Command name (Public function 'int _main(void)' required) +APPNAME = + +# Application execute priority (Range: 0 ~ 255, Default: 100) +PRIORITY = + +# Application stack memory size (Default: 2048) +STACKSIZE = + +# Main source code +MAINSRC = + +# Additional C source files (*.c) +CSRCS = + +# Additional C++ source files (*.cxx) +CXXSRCS = + +# Additional assembler source files (*.S) +ASRCS = + +# C compiler flags +CFLAGS = + +# C++ compiler flags +CXXFLAGS = + +include $(SPRESENSE_HOME)/.vscode/application.mk diff --git a/resources/ver1/workerfiles/app/main.c b/resources/ver1/workerfiles/app/main.c new file mode 100644 index 0000000..2abfe43 --- /dev/null +++ b/resources/ver1/workerfiles/app/main.c @@ -0,0 +1,161 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +/* Include worker header */ +#include "__worker_name__.h" + +/* Worker ELF path */ +#define WORKER_FILE "/mnt/spif/__worker_name__" + +#define message(format, ...) printf(format, ##__VA_ARGS__) +#define err(format, ...) fprintf(stderr, format, ##__VA_ARGS__) + +int __app_name___main(int argc, char *argv[]) +{ + mptask_t mptask; + mpmutex_t mutex; + mpshm_t shm; + mpmq_t mq; + uint32_t msgdata; + int data = 0x1234; + int ret, wret; + char *buf; + + /* Initialize MP task */ + + ret = mptask_init(&mptask, WORKER_FILE); + if (ret != 0) + { + err("mptask_init() failure. %d\n", ret); + return ret; + } + + ret = mptask_assign(&mptask); + if (ret != 0) + { + err("mptask_assign() failure. %d\n", ret); + return ret; + } + + /* Initialize MP mutex and bind it to MP task */ + + ret = mpmutex_init(&mutex, __WORKER_NAME__KEY_MUTEX); + if (ret < 0) + { + err("mpmutex_init() failure. %d\n", ret); + return ret; + } + ret = mptask_bindobj(&mptask, &mutex); + if (ret < 0) + { + err("mptask_bindobj(mutex) failure. %d\n", ret); + return ret; + } + + /* Initialize MP message queue with assigned CPU ID, and bind it to MP task */ + + ret = mpmq_init(&mq, __WORKER_NAME__KEY_MQ, mptask_getcpuid(&mptask)); + if (ret < 0) + { + err("mpmq_init() failure. %d\n", ret); + return ret; + } + ret = mptask_bindobj(&mptask, &mq); + if (ret < 0) + { + err("mptask_bindobj(mq) failure. %d\n", ret); + return ret; + } + + /* Initialize MP shared memory and bind it to MP task */ + + ret = mpshm_init(&shm, __WORKER_NAME__KEY_SHM, 1024); + if (ret < 0) + { + err("mpshm_init() failure. %d\n", ret); + return ret; + } + ret = mptask_bindobj(&mptask, &shm); + if (ret < 0) + { + err("mptask_binobj(shm) failure. %d\n", ret); + return ret; + } + + /* Map shared memory to virtual space */ + + buf = mpshm_attach(&shm, 0); + if (!buf) + { + err("mpshm_attach() failure.\n"); + return ret; + } + message("attached at %08x\n", (uintptr_t)buf); + memset(buf, 0, 1024); + + /* Run worker */ + + ret = mptask_exec(&mptask); + if (ret < 0) + { + err("mptask_exec() failure. %d\n", ret); + return ret; + } + + /* Send command to worker */ + ret = mpmq_send(&mq, MSG_ID___WORKER_NAME__, (uint32_t) &data); + if (ret < 0) + { + err("mpmq_send() failure. %d\n", ret); + return ret; + } + + /* Wait for worker message */ + + ret = mpmq_receive(&mq, &msgdata); + if (ret < 0) + { + err("mpmq_recieve() failure. %d\n", ret); + return ret; + } + message("Worker response: ID = %d, data = %x\n", + ret, *((int *)msgdata)); + + /* Show worker copied data */ + + /* Lock mutex for synchronize with worker after it's started */ + + mpmutex_lock(&mutex); + + message("Worker said: %s\n", buf); + + mpmutex_unlock(&mutex); + + /* Destroy worker */ + + wret = -1; + ret = mptask_destroy(&mptask, false, &wret); + if (ret < 0) + { + err("mptask_destroy() failure. %d\n", ret); + return ret; + } + + message("Worker exit status = %d\n", wret); + + /* Finalize all of MP objects */ + + mpshm_detach(&shm); + mpshm_destroy(&shm); + mpmutex_destroy(&mutex); + mpmq_destroy(&mq); + + return 0; +} diff --git a/resources/ver1/workerfiles/worker/.worker b/resources/ver1/workerfiles/worker/.worker new file mode 100644 index 0000000..f221e9b --- /dev/null +++ b/resources/ver1/workerfiles/worker/.worker @@ -0,0 +1 @@ +NAME=__app_name__ diff --git a/resources/ver1/workerfiles/worker/Makefile b/resources/ver1/workerfiles/worker/Makefile new file mode 100644 index 0000000..32b36cf --- /dev/null +++ b/resources/ver1/workerfiles/worker/Makefile @@ -0,0 +1,12 @@ +# Worker makefile + +# Additional C source files (*.c) +CSRCS = + +# Additional assembler source files (*.S) +ASRCS = + +# C compiler flags +CELFFLAGS = + +include $(SPRESENSE_HOME)/.vscode/worker.mk diff --git a/resources/ver1/workerfiles/worker/header.h b/resources/ver1/workerfiles/worker/header.h new file mode 100644 index 0000000..279ff26 --- /dev/null +++ b/resources/ver1/workerfiles/worker/header.h @@ -0,0 +1,7 @@ +/* MP object keys. Must be synchronized with supervisor. */ + +#define __APP_NAME__KEY_SHM 1 +#define __APP_NAME__KEY_MQ 2 +#define __APP_NAME__KEY_MUTEX 3 + +#define MSG_ID___APP_NAME__ 1 diff --git a/resources/ver1/workerfiles/worker/worker.c b/resources/ver1/workerfiles/worker/worker.c new file mode 100644 index 0000000..5af4b52 --- /dev/null +++ b/resources/ver1/workerfiles/worker/worker.c @@ -0,0 +1,77 @@ +#include + +#include +#include +#include +#include + +#include "asmp.h" +#include "include/__app_name__.h" + +#define ASSERT(cond) if (!(cond)) wk_abort() + +static const char helloworld[] = "Hello, ASMP World!"; + +static char *strcopy(char *dest, const char *src) +{ + char *d = dest; + while (*src) *d++ = *src++; + *d = '\0'; + + return dest; +} + +int main(void) +{ + mpmutex_t mutex; + mpshm_t shm; + mpmq_t mq; + uint32_t msgdata; + char *buf; + int ret; + + /* Initialize MP Mutex */ + + ret = mpmutex_init(&mutex, __APP_NAME__KEY_MUTEX); + ASSERT(ret == 0); + + /* Initialize MP message queue, + * On the worker side, 3rd argument is ignored. + */ + + ret = mpmq_init(&mq, __APP_NAME__KEY_MQ, 0); + ASSERT(ret == 0); + + /* Initialize MP shared memory */ + + ret = mpshm_init(&shm, __APP_NAME__KEY_SHM, 1024); + ASSERT(ret == 0); + + /* Map shared memory to virtual space */ + + buf = (char *)mpshm_attach(&shm, 0); + ASSERT(buf); + + /* Receive message from supervisor */ + + ret = mpmq_receive(&mq, &msgdata); + ASSERT(ret == MSG_ID___APP_NAME__); + + /* Copy hello message to shared memory */ + + mpmutex_lock(&mutex); + strcopy(buf, helloworld); + mpmutex_unlock(&mutex); + + /* Free virtual space */ + + mpshm_detach(&shm); + + /* Send done message to supervisor */ + + ret = mpmq_send(&mq, MSG_ID___APP_NAME__, msgdata); + ASSERT(ret == 0); + + return 0; +} + diff --git a/resources/ver2/appfiles/Make.defs b/resources/ver2/appfiles/Make.defs new file mode 100644 index 0000000..58d57cc --- /dev/null +++ b/resources/ver2/appfiles/Make.defs @@ -0,0 +1,2 @@ +CONFIGURED_APPS += __app_name__ + diff --git a/resources/ver2/appfiles/Makefile b/resources/ver2/appfiles/Makefile new file mode 100644 index 0000000..9b72590 --- /dev/null +++ b/resources/ver2/appfiles/Makefile @@ -0,0 +1,30 @@ +# Application makefile + +# Command name (Public function 'int _main(void)' required) +APPNAME = + +# Application execute priority (Range: 0 ~ 255, Default: 100) +PRIORITY = + +# Application stack memory size (Default: 2048) +STACKSIZE = + +# Main source code +MAINSRC = + +# Additional C source files (*.c) +CSRCS = + +# Additional C++ source files (*.cxx) +CXXSRCS = + +# Additional assembler source files (*.S) +ASRCS = + +# C compiler flags +CFLAGS = + +# C++ compiler flags +CXXFLAGS = + +include $(SPRESENSE_HOME)/.vscode/application.mk diff --git a/resources/ver2/appfiles/main.c b/resources/ver2/appfiles/main.c new file mode 100644 index 0000000..6356ea6 --- /dev/null +++ b/resources/ver2/appfiles/main.c @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/resources/ver2/workerfiles/app/Make.defs b/resources/ver2/workerfiles/app/Make.defs new file mode 100644 index 0000000..58d57cc --- /dev/null +++ b/resources/ver2/workerfiles/app/Make.defs @@ -0,0 +1,2 @@ +CONFIGURED_APPS += __app_name__ + diff --git a/resources/ver2/workerfiles/app/Makefile b/resources/ver2/workerfiles/app/Makefile new file mode 100644 index 0000000..9b72590 --- /dev/null +++ b/resources/ver2/workerfiles/app/Makefile @@ -0,0 +1,30 @@ +# Application makefile + +# Command name (Public function 'int _main(void)' required) +APPNAME = + +# Application execute priority (Range: 0 ~ 255, Default: 100) +PRIORITY = + +# Application stack memory size (Default: 2048) +STACKSIZE = + +# Main source code +MAINSRC = + +# Additional C source files (*.c) +CSRCS = + +# Additional C++ source files (*.cxx) +CXXSRCS = + +# Additional assembler source files (*.S) +ASRCS = + +# C compiler flags +CFLAGS = + +# C++ compiler flags +CXXFLAGS = + +include $(SPRESENSE_HOME)/.vscode/application.mk diff --git a/resources/ver2/workerfiles/app/main.c b/resources/ver2/workerfiles/app/main.c new file mode 100644 index 0000000..b403eb5 --- /dev/null +++ b/resources/ver2/workerfiles/app/main.c @@ -0,0 +1,161 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +/* Include worker header */ +#include "__worker_name__.h" + +/* Worker ELF path */ +#define WORKER_FILE "/mnt/spif/__worker_name__" + +#define message(format, ...) printf(format, ##__VA_ARGS__) +#define err(format, ...) fprintf(stderr, format, ##__VA_ARGS__) + +int main(int argc, char *argv[]) +{ + mptask_t mptask; + mpmutex_t mutex; + mpshm_t shm; + mpmq_t mq; + uint32_t msgdata; + int data = 0x1234; + int ret, wret; + char *buf; + + /* Initialize MP task */ + + ret = mptask_init(&mptask, WORKER_FILE); + if (ret != 0) + { + err("mptask_init() failure. %d\n", ret); + return ret; + } + + ret = mptask_assign(&mptask); + if (ret != 0) + { + err("mptask_assign() failure. %d\n", ret); + return ret; + } + + /* Initialize MP mutex and bind it to MP task */ + + ret = mpmutex_init(&mutex, __WORKER_NAME__KEY_MUTEX); + if (ret < 0) + { + err("mpmutex_init() failure. %d\n", ret); + return ret; + } + ret = mptask_bindobj(&mptask, &mutex); + if (ret < 0) + { + err("mptask_bindobj(mutex) failure. %d\n", ret); + return ret; + } + + /* Initialize MP message queue with assigned CPU ID, and bind it to MP task */ + + ret = mpmq_init(&mq, __WORKER_NAME__KEY_MQ, mptask_getcpuid(&mptask)); + if (ret < 0) + { + err("mpmq_init() failure. %d\n", ret); + return ret; + } + ret = mptask_bindobj(&mptask, &mq); + if (ret < 0) + { + err("mptask_bindobj(mq) failure. %d\n", ret); + return ret; + } + + /* Initialize MP shared memory and bind it to MP task */ + + ret = mpshm_init(&shm, __WORKER_NAME__KEY_SHM, 1024); + if (ret < 0) + { + err("mpshm_init() failure. %d\n", ret); + return ret; + } + ret = mptask_bindobj(&mptask, &shm); + if (ret < 0) + { + err("mptask_binobj(shm) failure. %d\n", ret); + return ret; + } + + /* Map shared memory to virtual space */ + + buf = mpshm_attach(&shm, 0); + if (!buf) + { + err("mpshm_attach() failure.\n"); + return ret; + } + message("attached at %08x\n", (uintptr_t)buf); + memset(buf, 0, 1024); + + /* Run worker */ + + ret = mptask_exec(&mptask); + if (ret < 0) + { + err("mptask_exec() failure. %d\n", ret); + return ret; + } + + /* Send command to worker */ + ret = mpmq_send(&mq, MSG_ID___WORKER_NAME__, (uint32_t) &data); + if (ret < 0) + { + err("mpmq_send() failure. %d\n", ret); + return ret; + } + + /* Wait for worker message */ + + ret = mpmq_receive(&mq, &msgdata); + if (ret < 0) + { + err("mpmq_recieve() failure. %d\n", ret); + return ret; + } + message("Worker response: ID = %d, data = %x\n", + ret, *((int *)msgdata)); + + /* Show worker copied data */ + + /* Lock mutex for synchronize with worker after it's started */ + + mpmutex_lock(&mutex); + + message("Worker said: %s\n", buf); + + mpmutex_unlock(&mutex); + + /* Destroy worker */ + + wret = -1; + ret = mptask_destroy(&mptask, false, &wret); + if (ret < 0) + { + err("mptask_destroy() failure. %d\n", ret); + return ret; + } + + message("Worker exit status = %d\n", wret); + + /* Finalize all of MP objects */ + + mpshm_detach(&shm); + mpshm_destroy(&shm); + mpmutex_destroy(&mutex); + mpmq_destroy(&mq); + + return 0; +} diff --git a/resources/ver2/workerfiles/worker/.worker b/resources/ver2/workerfiles/worker/.worker new file mode 100644 index 0000000..f221e9b --- /dev/null +++ b/resources/ver2/workerfiles/worker/.worker @@ -0,0 +1 @@ +NAME=__app_name__ diff --git a/resources/ver2/workerfiles/worker/Makefile b/resources/ver2/workerfiles/worker/Makefile new file mode 100644 index 0000000..32b36cf --- /dev/null +++ b/resources/ver2/workerfiles/worker/Makefile @@ -0,0 +1,12 @@ +# Worker makefile + +# Additional C source files (*.c) +CSRCS = + +# Additional assembler source files (*.S) +ASRCS = + +# C compiler flags +CELFFLAGS = + +include $(SPRESENSE_HOME)/.vscode/worker.mk diff --git a/resources/ver2/workerfiles/worker/header.h b/resources/ver2/workerfiles/worker/header.h new file mode 100644 index 0000000..279ff26 --- /dev/null +++ b/resources/ver2/workerfiles/worker/header.h @@ -0,0 +1,7 @@ +/* MP object keys. Must be synchronized with supervisor. */ + +#define __APP_NAME__KEY_SHM 1 +#define __APP_NAME__KEY_MQ 2 +#define __APP_NAME__KEY_MUTEX 3 + +#define MSG_ID___APP_NAME__ 1 diff --git a/resources/ver2/workerfiles/worker/worker.c b/resources/ver2/workerfiles/worker/worker.c new file mode 100644 index 0000000..5af4b52 --- /dev/null +++ b/resources/ver2/workerfiles/worker/worker.c @@ -0,0 +1,77 @@ +#include + +#include +#include +#include +#include + +#include "asmp.h" +#include "include/__app_name__.h" + +#define ASSERT(cond) if (!(cond)) wk_abort() + +static const char helloworld[] = "Hello, ASMP World!"; + +static char *strcopy(char *dest, const char *src) +{ + char *d = dest; + while (*src) *d++ = *src++; + *d = '\0'; + + return dest; +} + +int main(void) +{ + mpmutex_t mutex; + mpshm_t shm; + mpmq_t mq; + uint32_t msgdata; + char *buf; + int ret; + + /* Initialize MP Mutex */ + + ret = mpmutex_init(&mutex, __APP_NAME__KEY_MUTEX); + ASSERT(ret == 0); + + /* Initialize MP message queue, + * On the worker side, 3rd argument is ignored. + */ + + ret = mpmq_init(&mq, __APP_NAME__KEY_MQ, 0); + ASSERT(ret == 0); + + /* Initialize MP shared memory */ + + ret = mpshm_init(&shm, __APP_NAME__KEY_SHM, 1024); + ASSERT(ret == 0); + + /* Map shared memory to virtual space */ + + buf = (char *)mpshm_attach(&shm, 0); + ASSERT(buf); + + /* Receive message from supervisor */ + + ret = mpmq_receive(&mq, &msgdata); + ASSERT(ret == MSG_ID___APP_NAME__); + + /* Copy hello message to shared memory */ + + mpmutex_lock(&mutex); + strcopy(buf, helloworld); + mpmutex_unlock(&mutex); + + /* Free virtual space */ + + mpshm_detach(&shm); + + /* Send done message to supervisor */ + + ret = mpmq_send(&mq, MSG_ID___APP_NAME__, msgdata); + ASSERT(ret == 0); + + return 0; +} + diff --git a/src/common.ts b/src/common.ts index 78cfc21..ba920a8 100644 --- a/src/common.ts +++ b/src/common.ts @@ -161,6 +161,26 @@ export function createFileByTemplate (srcFile: string, destFile: string, custom: }); } +/** + * Get template file root directory with SDK version + * + * This function get a root directory that contain a template files. + * + * @param resourcePath Path to resource directory + * @param folderPath Path to workspace folder + */ + +export function getTemplateRootPathWithVersion (resourcePath: string, folderPath: string): string { + let version: Version = getSdkVersionFromSpresenseConf(folderPath); + let subdir: string = "ver2"; + + if (version.major == 1) { + subdir = "ver1"; + } + + return path.join(resourcePath, subdir); +} + /** * Create new worker files with template * @@ -177,7 +197,7 @@ export function createFileByTemplate (srcFile: string, destFile: string, custom: */ export function createWorkerFiles (name: string, appname: string| undefined, folder: string, resourcePath: string) { - const tempPath = path.join(resourcePath, 'workerfiles', 'worker'); + const tempPath = path.join(getTemplateRootPathWithVersion(resourcePath, folder), 'workerfiles', 'worker'); const fileList = fs.readdirSync(tempPath); const destDir = path.join(folder, `${name}_worker`); const replaceRules = { @@ -235,7 +255,7 @@ export function createWorkerFiles (name: string, appname: string| undefined, fol */ export function createWorkerApplicationFiles (name: string, worker_name: string, folder: string, resourcePath: string) { - const tempPath = path.join(resourcePath, 'workerfiles', 'app'); + const tempPath = path.join(getTemplateRootPathWithVersion(resourcePath, folder), 'workerfiles', 'app'); const fileList = fs.readdirSync(tempPath); const destDir = path.join(folder, name); const replaceRules = { @@ -291,7 +311,7 @@ export function createWorkerApplicationFiles (name: string, worker_name: string, */ export function createApplicationFiles (name: string, folder: string, resourcePath: string) { - const tempPath = path.join(resourcePath, 'appfiles'); + const tempPath = path.join(getTemplateRootPathWithVersion(resourcePath, folder), 'appfiles'); const fileList = fs.readdirSync(tempPath); const destDir = path.join(folder, name); const replaceRules = { @@ -450,6 +470,34 @@ export function loadSpresenseConfFile(folderPath: string): {[key: string]: any} return jsonItem; } +/** + * Get Spresense SDK version from spresense_prj.json + * + * @param folderPath Path to project folder + * + * @returns Version information + */ + + export function getSdkVersionFromSpresenseConf(folderPath: string): Version { + const jsonItem = loadSpresenseConfFile(folderPath); + let ver : Version = { + major: 0, + minor: 0, + patch: 0, + str: UNKNOWN_SDK_VERSION + }; + + if (jsonItem) { + let pjVer = jsonItem['SdkVersion'].match(/SDK(\d+).(\d+).(\d+)/); + ver.major = parseInt(pjVer[1]); + ver.minor = parseInt(pjVer[2]); + ver.patch = parseInt(pjVer[3]); + ver.str = jsonItem['SdkVersion']; + } + + return ver; +} + /** * Check project folder compatibility. * @@ -461,22 +509,15 @@ export function loadSpresenseConfFile(folderPath: string): {[key: string]: any} export function checkSdkCompatibility(sdkVersion: Version, uri: vscode.Uri): boolean { let wsFolder = vscode.workspace.getWorkspaceFolder(uri); - let jsonItem: {[key: string]: any} | null; - let pjVer: any; + let verInPrj : Version; if (!wsFolder) { return false; } - jsonItem = loadSpresenseConfFile(wsFolder.uri.fsPath); - - if (!jsonItem) { - return false; - } - - pjVer = jsonItem['SdkVersion'].match(/SDK(\d+).(\d+).(\d+)/); + verInPrj = getSdkVersionFromSpresenseConf(wsFolder.uri.fsPath); - if (sdkVersion.major === parseInt(pjVer[1])) { + if (sdkVersion.major === verInPrj.major) { return true; } else { return false; From 455ca8dedd73079fff49138093fc3fb49ef2174d Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 31 Mar 2022 14:59:40 +0900 Subject: [PATCH 4/5] Update CHANGELOG.md for v1.3.200 release --- CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d1d19d..b99eec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,37 @@ # Change Log +# v1.3.200 + +(日本語の説明文は英語の後に記載しています。) + +## Summary + +* Feature improvements are available + +## Improved features + +* The following minor problems have been corrected. + + * Fix a problem in which some parameters were not reflected when Makefile was edited manually. + + * Fix an unintentional ".vscode/include not found" warning. + +------------------------ + +(Below is in Japanese) + +## 概要 + +* 機能改善を行いました。 + +## 改善された機能 + +* 下記の軽微な不具合を修正しました。 + + * Makefileを手動で編集した際に一部パラメータが反映されない問題を修正しました。 + + * ".vscode/includeが見つかりません" という意図しない警告が表示されないように修正しました。 + # v1.3.100 (日本語の説明文は英語の後に記載しています。) From 3e1d6ea2409d4c1fb07a2930ec90f4aa27b2567b Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 31 Mar 2022 15:03:27 +0900 Subject: [PATCH 5/5] Update version to v1.3.200 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ef7306..39b0db7 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publisher": "sony-spresense", "displayName": "Spresense VSCode IDE", "description": "Spresense Extension for VSCode", - "version": "1.3.100", + "version": "1.3.200", "license": "MIT", "author": { "name": "Sony Semiconductor Solutions"