forked from Open-CMSIS-Pack/cmsis-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
277 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "interface.h" // Interface API | ||
#include "cmsis_os2.h" // ARM::CMSIS:RTOS2:Keil RTX5 | ||
|
||
static osStatus_t Status; | ||
|
||
static osThreadId_t ThreadAdd_Id; | ||
static osThreadId_t ThreadMul_Id; | ||
|
||
static const osThreadAttr_t ThreadAttr = { | ||
.tz_module = 1U, | ||
}; | ||
|
||
void AddThread (void *argument); | ||
void MulThread (void *argument); | ||
|
||
extern volatile int valueA; | ||
extern volatile int valueB; | ||
|
||
volatile int valueA; | ||
volatile int valueB; | ||
|
||
|
||
static int Addition (int val1, int val2) { | ||
return (val1 + val2); | ||
} | ||
|
||
__attribute__((noreturn)) | ||
void AddThread (void *argument) { | ||
(void)argument; | ||
|
||
for (;;) { | ||
valueA = function_1 (valueA); | ||
valueA = function_2 (Addition, valueA, 2); | ||
osDelay(2U); | ||
} | ||
} | ||
|
||
static int Multiply (int val1, int val2) { | ||
uint32_t flags; | ||
|
||
flags = osThreadFlagsWait (1U, osFlagsWaitAny, osWaitForever); | ||
if (flags == 1U) { | ||
return (val1*val2); | ||
} | ||
else { | ||
return (0); | ||
} | ||
} | ||
|
||
|
||
__attribute__((noreturn)) | ||
void MulThread (void *argument) { | ||
(void)argument; | ||
|
||
for (;;) { | ||
valueB = function_1 (valueB); | ||
valueB = function_2 (Multiply, valueB, 2); | ||
} | ||
} | ||
|
||
|
||
int main (void) { | ||
Status = osKernelInitialize(); | ||
|
||
ThreadAdd_Id = osThreadNew(AddThread, NULL, &ThreadAttr); | ||
ThreadMul_Id = osThreadNew(MulThread, NULL, &ThreadAttr); | ||
|
||
Status = osKernelStart(); | ||
|
||
for(;;); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json | ||
|
||
project: | ||
misc: | ||
- for-compiler: AC6 | ||
C: [-fshort-enums, -fshort-wchar] | ||
add-path: | ||
- $OutDir(Secure)$ | ||
components: | ||
- component: C Startup | ||
- component: CMSIS CORE | ||
- component: Keil RTX5 Library_NS | ||
groups: | ||
- group: Non-secure Code | ||
files: | ||
- file: main_ns.c | ||
- file: $Source(Secure)$/interface.h | ||
- file: $Output(Secure)$_CMSE_Lib.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <arm_cmse.h> | ||
|
||
#include "interface.h" | ||
|
||
/* typedef for non-secure callback functions */ | ||
typedef funcptr funcptr_NS __attribute__((cmse_nonsecure_call)); | ||
|
||
/* Non-secure callable (entry) function */ | ||
int function_1(int x) __attribute__((cmse_nonsecure_entry)) { | ||
return x+5; | ||
} | ||
|
||
/* Non-secure callable (entry) function, calling a non-secure callback function */ | ||
int function_2(funcptr callback, int x, int y) __attribute__((cmse_nonsecure_entry)) { | ||
funcptr_NS callback_NS; // non-secure callback function pointer | ||
int res; | ||
|
||
/* return function pointer with cleared LSB */ | ||
callback_NS = (funcptr_NS)cmse_nsfptr_create(callback); | ||
res = callback_NS (x, y); | ||
|
||
return (res*10); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// function pointer | ||
typedef int(*funcptr)(int,int); | ||
|
||
/* Non-secure callable functions */ | ||
extern int function_1(int x); | ||
extern int function_2(funcptr callback, int x, int y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Use CMSE intrinsics */ | ||
#include <arm_cmse.h> | ||
|
||
#include "RTE_Components.h" | ||
#include CMSIS_device_header | ||
|
||
#ifndef START_NS | ||
#define START_NS (0x200000U) | ||
#endif | ||
|
||
typedef void (*funcptr) (void) __attribute__((cmse_nonsecure_call)); | ||
|
||
int main(void) { | ||
funcptr ResetHandler; | ||
|
||
__TZ_set_MSP_NS(*((uint32_t *)(START_NS))); | ||
ResetHandler = (funcptr)(*((uint32_t *)((START_NS) + 4U))); | ||
ResetHandler(); | ||
|
||
while (1) { | ||
__NOP(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json | ||
|
||
project: | ||
processor: | ||
trustzone: secure | ||
components: | ||
- component: C Startup | ||
- component: CMSIS CORE | ||
groups: | ||
- group: Secure Code | ||
files: | ||
- file: main_s.c | ||
- group: CMSE | ||
files: | ||
- file: interface.c | ||
- file: interface.h | ||
- file: tz_context.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "RTE_Components.h" | ||
#include CMSIS_device_header | ||
#include "tz_context.h" | ||
|
||
__attribute__((cmse_nonsecure_entry)) | ||
uint32_t TZ_InitContextSystem_S(void) { | ||
return 1U; | ||
} | ||
|
||
__attribute__((cmse_nonsecure_entry)) | ||
TZ_MemoryId_t TZ_AllocModuleContext_S(TZ_ModuleId_t module) { | ||
(void)module; | ||
return 1U; | ||
} | ||
|
||
__attribute__((cmse_nonsecure_entry)) | ||
uint32_t TZ_FreeModuleContext_S(TZ_MemoryId_t id) { | ||
(void)id; | ||
return 1U; | ||
} | ||
|
||
|
||
__attribute__((cmse_nonsecure_entry)) | ||
uint32_t TZ_LoadContext_S(TZ_MemoryId_t id) { | ||
(void)id; | ||
return 2U; | ||
} | ||
|
||
__attribute__((cmse_nonsecure_entry)) | ||
uint32_t TZ_StoreContext_S(TZ_MemoryId_t id) { | ||
(void)id; | ||
return 2U; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json | ||
|
||
solution: | ||
target-types: | ||
- type: CM33 | ||
device: ARMCM33_DSP_FP_TZ | ||
- type: CM35P | ||
device: ARMCM35P_DSP_FP_TZ | ||
|
||
build-types: | ||
- type: Debug | ||
compiler: AC6 | ||
misc: | ||
- for-compiler: AC6 | ||
C: | ||
- -O1 | ||
- -g | ||
- type: Release | ||
compiler: AC6 | ||
misc: | ||
- for-compiler: AC6 | ||
C: | ||
- -O3 | ||
|
||
projects: | ||
- project: ./securecode/secure.cproject.yml | ||
- project: ./nonsecurecode/nonsecure.cproject.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "RTE_Components.h" | ||
#include CMSIS_device_header | ||
|
||
int main(void) { | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
project: | ||
|
||
components: | ||
- component: ARM::CMSIS:CORE | ||
- component: ARM::Device:Startup&C Startup | ||
|
||
groups: | ||
- group: Source | ||
files: | ||
- file: ./ma in.c | ||
- group: Header | ||
files: | ||
- file: ./tes t/tes t.h | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#define TES_T 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
solution: | ||
created-for: [email protected] | ||
cdefault: | ||
|
||
packs: | ||
- pack: ARM::Cortex_DFP | ||
- pack: ARM::CMSIS | ||
|
||
target-types: | ||
- type: ARMCM0 | ||
device: ARMCM0 | ||
|
||
build-types: | ||
- type: AC6 | ||
compiler: AC6 | ||
|
||
- type: GCC | ||
compiler: GCC | ||
misc: | ||
- Library: | ||
- -lm | ||
- -lc | ||
|
||
# - type: IAR | ||
# compiler: IAR | ||
|
||
- type: CLANG | ||
compiler: CLANG | ||
|
||
projects: | ||
- project: ./project/project.cproject.yml |