Skip to content

Commit 5fcc961

Browse files
author
Cruz Monrreal
authored
Merge pull request #6486 from deepikabhavnani/thread_class_tz
Thread class tz
2 parents 11b6a4e + 48002ff commit 5fcc961

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

rtos/Thread.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ extern "C" void thread_terminate_hook(osThreadId_t id)
4343

4444
namespace rtos {
4545

46-
void Thread::constructor(osPriority priority,
46+
#ifndef MBED_TZ_DEFAULT_ACCESS
47+
#define MBED_TZ_DEFAULT_ACCESS 0
48+
#endif
49+
50+
void Thread::constructor(uint32_t tz_module, osPriority priority,
4751
uint32_t stack_size, unsigned char *stack_mem, const char *name) {
4852

4953
const uintptr_t unaligned_mem = reinterpret_cast<uintptr_t>(stack_mem);
@@ -60,11 +64,17 @@ void Thread::constructor(osPriority priority,
6064
_attr.stack_size = aligned_size;
6165
_attr.name = name ? name : "application_unnamed_thread";
6266
_attr.stack_mem = reinterpret_cast<uint32_t*>(aligned_mem);
67+
_attr.tz_module = tz_module;
68+
}
69+
70+
void Thread::constructor(osPriority priority,
71+
uint32_t stack_size, unsigned char *stack_mem, const char *name) {
72+
constructor(MBED_TZ_DEFAULT_ACCESS, priority, stack_size, stack_mem, name);
6373
}
6474

6575
void Thread::constructor(Callback<void()> task,
6676
osPriority priority, uint32_t stack_size, unsigned char *stack_mem, const char *name) {
67-
constructor(priority, stack_size, stack_mem, name);
77+
constructor(MBED_TZ_DEFAULT_ACCESS, priority, stack_size, stack_mem, name);
6878

6979
switch (start(task)) {
7080
case osErrorResource:

rtos/Thread.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ namespace rtos {
7272
* Memory considerations: The thread control structures will be created on current thread's stack, both for the mbed OS
7373
* and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
7474
* Additionally the stack memory for this thread will be allocated on the heap, if it wasn't supplied to the constructor.
75+
*
76+
* @note
77+
* MBED_TZ_DEFAULT_ACCESS (default:0) flag can be used to change the default access of all user threads in non-secure mode.
78+
* MBED_TZ_DEFAULT_ACCESS set to 1, means all non-secure user threads have access to call secure functions.
79+
* MBED_TZ_DEFAULT_ACCESS set to 0, means none of the non-secure user thread have access to call secure functions,
80+
* to give access to particular thread used overloaded constructor with `tz_module` as argument during thread creation.
81+
*
82+
* MBED_TZ_DEFAULT_ACCESS is target specific define, should be set in targets.json file for Cortex-M23/M33 devices.
7583
*/
84+
7685
class Thread : private mbed::NonCopyable<Thread> {
7786
public:
7887
/** Allocate a new thread without starting execution
@@ -81,14 +90,36 @@ class Thread : private mbed::NonCopyable<Thread> {
8190
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
8291
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
8392
93+
@note Default value of tz_module will be MBED_TZ_DEFAULT_ACCESS
8494
@note You cannot call this function from ISR context.
8595
*/
96+
8697
Thread(osPriority priority=osPriorityNormal,
8798
uint32_t stack_size=OS_STACK_SIZE,
8899
unsigned char *stack_mem=NULL, const char *name=NULL) {
89100
constructor(priority, stack_size, stack_mem, name);
90101
}
91102

103+
/** Allocate a new thread without starting execution
104+
@param tz_module trustzone thread identifier (osThreadAttr_t::tz_module)
105+
Context of RTOS threads in non-secure state must be saved when calling secure functions.
106+
tz_module ID is used to allocate context memory for threads, and it can be safely set to zero for
107+
threads not using secure calls at all. See "TrustZone RTOS Context Management" for more details.
108+
@param priority initial priority of the thread function. (default: osPriorityNormal).
109+
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
110+
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
111+
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
112+
113+
@note You cannot call this function from ISR context.
114+
*/
115+
116+
Thread(uint32_t tz_module, osPriority priority=osPriorityNormal,
117+
uint32_t stack_size=OS_STACK_SIZE,
118+
unsigned char *stack_mem=NULL, const char *name=NULL) {
119+
constructor(tz_module, priority, stack_size, stack_mem, name);
120+
}
121+
122+
92123
/** Create a new thread, and start it executing the specified function.
93124
@param task function to be executed by this thread.
94125
@param priority initial priority of the thread function. (default: osPriorityNormal).
@@ -433,6 +464,11 @@ class Thread : private mbed::NonCopyable<Thread> {
433464
uint32_t stack_size=OS_STACK_SIZE,
434465
unsigned char *stack_mem=NULL,
435466
const char *name=NULL);
467+
void constructor(uint32_t tz_module,
468+
osPriority priority=osPriorityNormal,
469+
uint32_t stack_size=OS_STACK_SIZE,
470+
unsigned char *stack_mem=NULL,
471+
const char *name=NULL);
436472
static void _thunk(void * thread_ptr);
437473

438474
mbed::Callback<void()> _task;

0 commit comments

Comments
 (0)