OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #if defined(FLETCH_TARGET_OS_CMSIS) | 5 #if defined(DARTINO_TARGET_OS_CMSIS) |
6 | 6 |
7 #include "src/vm/thread.h" // NOLINT we don't include thread_posix.h. | 7 #include "src/vm/thread.h" // NOLINT we don't include thread_posix.h. |
8 | 8 |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include "src/shared/platform.h" | 12 #include "src/shared/platform.h" |
13 | 13 |
14 #include "src/shared/utils.h" | 14 #include "src/shared/utils.h" |
15 | 15 |
16 namespace fletch { | 16 namespace dartino { |
17 | 17 |
18 static const int kNumberOfFletchThreads = 8; | 18 static const int kNumberOfDartinoThreads = 8; |
19 static const int kFletchStackSize = 4096; | 19 static const int kDartinoStackSize = 4096; |
20 static const int kFletchStackSizeInWords = kFletchStackSize / sizeof(uint32_t); | 20 static const int kDartinoStackSizeInWords = |
| 21 kDartinoStackSize / sizeof(uint32_t); |
21 | 22 |
22 static osThreadDef_t cmsis_thread_pool[kNumberOfFletchThreads]; | 23 static osThreadDef_t cmsis_thread_pool[kNumberOfDartinoThreads]; |
23 static char cmsis_thread_no = 0; | 24 static char cmsis_thread_no = 0; |
24 #ifdef CMSIS_OS_RTX | 25 #ifdef CMSIS_OS_RTX |
25 static uint32_t cmsis_stack[kNumberOfFletchThreads][kFletchStackSizeInWords]; | 26 static uint32_t cmsis_stack[kNumberOfDartinoThreads][kDartinoStackSizeInWords]; |
26 #endif | 27 #endif |
27 | 28 |
28 static const char* base_name = "cmsis_thread_"; | 29 static const char* base_name = "cmsis_thread_"; |
29 | 30 |
30 void Thread::SetProcess(Process* process) { | 31 void Thread::SetProcess(Process* process) { |
31 // Unused since tick sample is not available on cmsis. | 32 // Unused since tick sample is not available on cmsis. |
32 } | 33 } |
33 | 34 |
34 Process* Thread::GetProcess() { | 35 Process* Thread::GetProcess() { |
35 // Unused since tick sample is not available on cmsis. | 36 // Unused since tick sample is not available on cmsis. |
(...skipping 14 matching lines...) Expand all Loading... |
50 | 51 |
51 void Thread::TeardownOSSignals() { | 52 void Thread::TeardownOSSignals() { |
52 // Platform doesn't have signals. | 53 // Platform doesn't have signals. |
53 } | 54 } |
54 | 55 |
55 ThreadIdentifier Thread::Run(RunSignature run, void* data) { | 56 ThreadIdentifier Thread::Run(RunSignature run, void* data) { |
56 char* name = reinterpret_cast<char*>(malloc(strlen(base_name) + 5)); | 57 char* name = reinterpret_cast<char*>(malloc(strlen(base_name) + 5)); |
57 | 58 |
58 snprintf(name, strlen(base_name) + 5, "cmsis_thread%d", cmsis_thread_no); | 59 snprintf(name, strlen(base_name) + 5, "cmsis_thread%d", cmsis_thread_no); |
59 int thread_no = cmsis_thread_no++; | 60 int thread_no = cmsis_thread_no++; |
60 ASSERT(thread_no < kNumberOfFletchThreads); | 61 ASSERT(thread_no < kNumberOfDartinoThreads); |
61 osThreadDef_t* threadDef = &(cmsis_thread_pool[thread_no]); | 62 osThreadDef_t* threadDef = &(cmsis_thread_pool[thread_no]); |
62 threadDef->pthread = reinterpret_cast<void (*)(const void*)>(run); | 63 threadDef->pthread = reinterpret_cast<void (*)(const void*)>(run); |
63 threadDef->tpriority = osPriorityNormal; | 64 threadDef->tpriority = osPriorityNormal; |
64 threadDef->stacksize = kFletchStackSize; | 65 threadDef->stacksize = kDartinoStackSize; |
65 threadDef->name = const_cast<char*>(name); | 66 threadDef->name = const_cast<char*>(name); |
66 #ifdef CMSIS_OS_RTX | 67 #ifdef CMSIS_OS_RTX |
67 threadDef->stack_pointer = cmsis_stack[thread_no]; | 68 threadDef->stack_pointer = cmsis_stack[thread_no]; |
68 #endif | 69 #endif |
69 | 70 |
70 osThreadId thread = osThreadCreate(threadDef, data); | 71 osThreadId thread = osThreadCreate(threadDef, data); |
71 | 72 |
72 if (thread == NULL) { | 73 if (thread == NULL) { |
73 FATAL("osThreadCreate failed\n"); | 74 FATAL("osThreadCreate failed\n"); |
74 } | 75 } |
75 return ThreadIdentifier(thread); | 76 return ThreadIdentifier(thread); |
76 } | 77 } |
77 | 78 |
78 } // namespace fletch | 79 } // namespace dartino |
79 | 80 |
80 #endif // defined(FLETCH_TARGET_OS_CMSIS) | 81 #endif // defined(DARTINO_TARGET_OS_CMSIS) |
OLD | NEW |