SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
example.cpp File Reference

TrustZone blinky, Non-Secure side (RP2350, Cortex-M33). More...

#include <stk.h>
#include <sync/stk_sync.h>
#include <time/stk_time.h>
#include <arch/arm/cortex-m/stk_arch_arm-tz.h>
#include "example.h"
#include "pico/unique_id.h"
Include dependency graph for blinky-trustzone-ns/example.cpp:

Go to the source code of this file.

Classes

class  MyTask< _AccessMode >

Functions

void NSC_OnExitNs (void)
uint32_t NSC_GetKey (uint8_t key[], uint32_t size)
void NSC_GetBoardUID (pico_unique_board_id_t *id_out)
void NSC_bsp_Led_SwitchOnExclusive (bsp::Led::Id led)
void runtime_init_clocks (void)
void pico_get_unique_board_id (pico_unique_board_id_t *id_out)
void RunExample ()

Variables

static constexpr size_t TASK_STACK_SIZE = 256U
static const uint32_t FLAGS_ALL []
static stk::sync::EventFlags g_TaskFlags (FLAGS_ALL[LED_RED])
static stk::Ticks g_Timeline = 0

Detailed Description

TrustZone blinky, Non-Secure side (RP2350, Cortex-M33).

Definition in file blinky-trustzone-ns/example.cpp.

Function Documentation

◆ NSC_bsp_Led_SwitchOnExclusive()

void NSC_bsp_Led_SwitchOnExclusive ( bsp::Led::Id led)
Examples
blinky-trustzone-ns/example.cpp, blinky-trustzone-sc/example.cpp, blinky_mpu-trustzone-ns/example.cpp, and blinky_mpu-trustzone-sc/example.cpp.

Definition at line 115 of file blinky-trustzone-sc/example.cpp.

116{
117 // You can call hardware directly now, because execution is happening in a
118 // Secure world and Non-Secure task is Privileged.
120 {
122 }
123 else
124 {
125 // If Non-Secure task is not Privileged - direct hw calls are not possible, let Secure
126 // Privileged task handle all hw calls for such calling contexts.
127 s_HwCmdQueue.Write({ .id = HwCommand::CMD_LED_ON, led });
128 }
129}
bool IsPrivilegedContext()
Check if caller context is Privileged.
static void SwitchOnExclusive(Id led)
Definition led.h:48
static sync::PipeT< HwCommand, 4 > s_HwCmdQueue

References __stk_tz_nsc_entry, HwCommand::CMD_LED_ON, stk::hw::IsPrivilegedContext(), s_HwCmdQueue, and bsp::Led::SwitchOnExclusive().

Referenced by MyTask< _AccessMode >::Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NSC_GetBoardUID()

void NSC_GetBoardUID ( pico_unique_board_id_t * id_out)
Examples
blinky-trustzone-ns/example.cpp, blinky-trustzone-sc/example.cpp, blinky_mpu-trustzone-ns/example.cpp, and blinky_mpu-trustzone-sc/example.cpp.

Definition at line 87 of file blinky-trustzone-sc/example.cpp.

88{
90}
void pico_get_unique_board_id(pico_unique_board_id_t *id_out)

References __stk_tz_nsc_entry, and pico_get_unique_board_id().

Referenced by pico_get_unique_board_id().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NSC_GetKey()

uint32_t NSC_GetKey ( uint8_t key[],
uint32_t size )
Examples
blinky-trustzone-ns/example.cpp, blinky-trustzone-sc/example.cpp, blinky_mpu-trustzone-ns/example.cpp, and blinky_mpu-trustzone-sc/example.cpp.

Definition at line 93 of file blinky-trustzone-sc/example.cpp.

94{
95 uint32_t result = 0;
96
97 // Verify the entire buffer lies in Non-Secure memory and is writable
98 if (cmse_check_address_range(key, size, CMSE_NONSECURE | CMSE_MPU_READWRITE) != nullptr)
99 {
100 if (size == 4)
101 {
102 key[0] = 1;
103 key[1] = 2;
104 key[2] = 3;
105 key[3] = 4;
106
107 result = 4;
108 }
109 }
110
111 return result;
112}

References __stk_tz_nsc_entry.

Referenced by RunExample().

Here is the caller graph for this function:

◆ NSC_OnExitNs()

void NSC_OnExitNs ( void )
Examples
blinky-trustzone-ns/example.cpp, blinky-trustzone-sc/example.cpp, blinky_mpu-trustzone-ns/example.cpp, and blinky_mpu-trustzone-sc/example.cpp.

Definition at line 79 of file blinky-trustzone-sc/example.cpp.

80{
81 // Jump back to the point right before BLXNS happened,
82 // passing '1' as the return value for setjmp.
83 longjmp(s_NsExitEnv, 1);
84}
static jmp_buf s_NsExitEnv

References __stk_tz_nsc_entry, and s_NsExitEnv.

Referenced by RunExample().

Here is the caller graph for this function:

◆ pico_get_unique_board_id()

void pico_get_unique_board_id ( pico_unique_board_id_t * id_out)
Examples
blinky-trustzone-ns/example.cpp, blinky-trustzone-sc/example.cpp, blinky_mpu-trustzone-ns/example.cpp, and blinky_mpu-trustzone-sc/example.cpp.

Definition at line 51 of file blinky-trustzone-ns/example.cpp.

52{
53 // you can get Id via NSC call, if needed for a Non-Secure side of the binary
54 //*id_out = pico_unique_board_id_t{};
55
56 NSC_GetBoardUID(id_out);
57}
void NSC_GetBoardUID(pico_unique_board_id_t *id_out)

References NSC_GetBoardUID().

Referenced by NSC_GetBoardUID().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RunExample()

void RunExample ( void )
Examples
/tls/example.cpp, blinky-trustzone-ns/example.cpp, blinky-trustzone-sc/example.cpp, blinky/example.cpp, blinky_c-pthread/example.c, blinky_c/example.c, blinky_fp/example.cpp, blinky_mc/example.cpp, blinky_mpu-hard/example.cpp, blinky_mpu-trustzone-ns/example.cpp, blinky_mpu-trustzone-sc/example.cpp, blinky_mpu/example.cpp, blinky_mpu_armv8/example.cpp, blinky_swrr/example.cpp, blinky_time-slice/example.cpp, critical_section/example.cpp, debounce/example.cpp, hrt/example.cpp, httpd/example.cpp, httpd_tls/example.cpp, low_power/example.cpp, low_power_c/example.c, once/example.cpp, secure_task/example.cpp, sleep/example.cpp, sync/example.cpp, sync_c/example.c, timer/example.cpp, and timer_c/example.c.

Definition at line 129 of file blinky-trustzone-ns/example.cpp.

130{
131 using namespace stk;
132
133 uint8_t key[4] = {0};
134 NSC_GetKey(key, 4);
135
136 // Note: using ACCESS_PRIVILEGED as Cortex-M3+ may not allow writing to GPIO from a less secure user thread.
137 static MyTask<ACCESS_USER> task1(LED_RED);
138 static MyTask<ACCESS_USER> task2(LED_ORANGE);
139 static MyTask<ACCESS_USER> task3(LED_GREEN); // you can set to ACCESS_PRIVILEGED too, see NSC_bsp_Led_SwitchOnExclusive on secure side, but for smooth performance on RP2350 let background thread handle GPIO
140 static MyTask<ACCESS_USER> task4(LED_BLUE);
141
142 static tz::nsec::Kernel kernel;
143
144 kernel.Initialize(0);
145
146 // Register threads (tasks).
147 kernel.AddTask(&task1);
148 kernel.AddTask(&task2);
149 kernel.AddTask(&task3);
150 kernel.AddTask(&task4);
151
152 // Start scheduler (it will start threads added by AddTask), execution in main() will be blocked on this line.
153 kernel.Start();
154
155 // Return back to Secure binary. Note: kernel.Start() will exit only if Secure side initialized Kernel instance
156 // with KERNEL_DYNAMIC mode and when all tasks exited on both sides.
157 NSC_OnExitNs();
158}
@ LED_ORANGE
Definition led.h:18
@ LED_GREEN
Definition led.h:17
@ LED_BLUE
Definition led.h:20
@ LED_RED
Definition led.h:19
Namespace of STK package.
void NSC_OnExitNs(void)
uint32_t NSC_GetKey(uint8_t key[], uint32_t size)

References LED_BLUE, LED_GREEN, LED_ORANGE, LED_RED, NSC_GetKey(), and NSC_OnExitNs().

Here is the call graph for this function:

◆ runtime_init_clocks()

void runtime_init_clocks ( void )
Examples
blinky-trustzone-ns/example.cpp, and blinky_mpu-trustzone-ns/example.cpp.

Definition at line 46 of file blinky-trustzone-ns/example.cpp.

47{
48 // clocks are initialized on Secure side of the binary
49}

Variable Documentation

◆ FLAGS_ALL

◆ g_TaskFlags

◆ g_Timeline

◆ TASK_STACK_SIZE

size_t TASK_STACK_SIZE = 256U
staticconstexpr

Definition at line 64 of file blinky-trustzone-ns/example.cpp.