|
26 | 26 |
|
27 | 27 | namespace rtos {
|
28 | 28 |
|
29 |
| -Thread::Thread() { |
| 29 | +Thread::Thread(osPriority priority, |
| 30 | + uint32_t stack_size, unsigned char *stack_pointer) { |
30 | 31 | _tid = NULL;
|
| 32 | + _priority = priority; |
| 33 | + _stack_size = stack_size; |
| 34 | + _stack_pointer = stack_pointer; |
31 | 35 | }
|
32 | 36 |
|
33 | 37 | Thread::Thread(void (*task)(void const *argument), void *argument,
|
34 | 38 | osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
|
35 | 39 | _tid = NULL;
|
36 |
| - start(task, argument, priority, stack_size, stack_pointer); |
| 40 | + _priority = priority; |
| 41 | + _stack_size = stack_size; |
| 42 | + _stack_pointer = stack_pointer; |
| 43 | + start(task, argument); |
37 | 44 | }
|
38 | 45 |
|
39 |
| -osStatus Thread::start(void (*task)(void const *argument), void *argument, |
40 |
| - osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) { |
| 46 | +osStatus Thread::start(void (*task)(void const *argument), void *argument) { |
41 | 47 | if (_tid != NULL) {
|
42 | 48 | return osErrorParameter;
|
43 | 49 | }
|
44 | 50 |
|
45 | 51 | #ifdef __MBED_CMSIS_RTOS_CM
|
46 | 52 | _thread_def.pthread = task;
|
47 |
| - _thread_def.tpriority = priority; |
48 |
| - _thread_def.stacksize = stack_size; |
49 |
| - if (stack_pointer != NULL) { |
50 |
| - _thread_def.stack_pointer = (uint32_t*)stack_pointer; |
51 |
| - _dynamic_stack = false; |
| 53 | + _thread_def.tpriority = _priority; |
| 54 | + _thread_def.stacksize = _stack_size; |
| 55 | + if (_stack_pointer != NULL) { |
| 56 | + _thread_def.stack_pointer = (uint32_t*)_stack_pointer; |
52 | 57 | } else {
|
53 |
| - _thread_def.stack_pointer = new uint32_t[stack_size/sizeof(uint32_t)]; |
| 58 | + _thread_def.stack_pointer = new uint32_t[_stack_size/sizeof(uint32_t)]; |
54 | 59 | if (_thread_def.stack_pointer == NULL)
|
55 | 60 | error("Error allocating the stack memory\n");
|
56 |
| - _dynamic_stack = true; |
57 | 61 | }
|
58 | 62 |
|
59 | 63 | //Fill the stack with a magic word for maximum usage checking
|
60 |
| - for (uint32_t i = 0; i < (stack_size / sizeof(uint32_t)); i++) { |
| 64 | + for (uint32_t i = 0; i < (_stack_size / sizeof(uint32_t)); i++) { |
61 | 65 | _thread_def.stack_pointer[i] = 0xE25A2EA5;
|
62 | 66 | }
|
63 | 67 | #endif
|
@@ -191,7 +195,7 @@ void Thread::attach_idle_hook(void (*fptr)(void)) {
|
191 | 195 | Thread::~Thread() {
|
192 | 196 | terminate();
|
193 | 197 | #ifdef __MBED_CMSIS_RTOS_CM
|
194 |
| - if (_dynamic_stack) { |
| 198 | + if (_stack_pointer == NULL) { |
195 | 199 | delete[] (_thread_def.stack_pointer);
|
196 | 200 | }
|
197 | 201 | #endif
|
|
0 commit comments