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 #ifndef SRC_SHARED_PLATFORM_CMSIS_H_ | 5 #ifndef SRC_SHARED_PLATFORM_CMSIS_H_ |
6 #define SRC_SHARED_PLATFORM_CMSIS_H_ | 6 #define SRC_SHARED_PLATFORM_CMSIS_H_ |
7 | 7 |
8 #ifndef SRC_SHARED_PLATFORM_H_ | 8 #ifndef SRC_SHARED_PLATFORM_H_ |
9 #error Do not include platform_cmsis.h directly; use platform.h instead. | 9 #error Do not include platform_cmsis.h directly; use platform.h instead. |
10 #endif | 10 #endif |
11 | 11 |
12 #if defined(FLETCH_TARGET_OS_CMSIS) | 12 #if defined(DARTINO_TARGET_OS_CMSIS) |
13 | 13 |
14 #include <errno.h> | 14 #include <errno.h> |
15 #include <cmsis_os.h> | 15 #include <cmsis_os.h> |
16 | 16 |
17 #include "src/shared/globals.h" | 17 #include "src/shared/globals.h" |
18 | 18 |
19 #ifdef DEBUG | 19 #ifdef DEBUG |
20 #define LOG_STATUS_MESSAGE \ | 20 #define LOG_STATUS_MESSAGE \ |
21 char const *msg; \ | 21 char const *msg; \ |
22 switch (status) { \ | 22 switch (status) { \ |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 #define CHECK_AND_FAIL(expr) \ | 68 #define CHECK_AND_FAIL(expr) \ |
69 { \ | 69 { \ |
70 int status = expr; \ | 70 int status = expr; \ |
71 if (status != osOK) { \ | 71 if (status != osOK) { \ |
72 FATAL("System call failed.\n"); \ | 72 FATAL("System call failed.\n"); \ |
73 } \ | 73 } \ |
74 } | 74 } |
75 #endif | 75 #endif |
76 | 76 |
77 namespace fletch { | 77 namespace dartino { |
78 | 78 |
79 static const int kMutexSize = sizeof(int32_t) * 3; | 79 static const int kMutexSize = sizeof(int32_t) * 3; |
80 static const int kSemaphoreSize = sizeof(int32_t) * 2; | 80 static const int kSemaphoreSize = sizeof(int32_t) * 2; |
81 | 81 |
82 osMailQId GetFletchMailQ(); | 82 osMailQId GetDartinoMailQ(); |
83 | 83 |
84 struct CmsisMessage { | 84 struct CmsisMessage { |
85 uint32_t port_id; | 85 uint32_t port_id; |
86 int64 message; | 86 int64 message; |
87 }; | 87 }; |
88 | 88 |
89 int SendMessageCmsis(uint32_t port_id, int64_t message); | 89 int SendMessageCmsis(uint32_t port_id, int64_t message); |
90 | 90 |
91 // Forward declare [Platform::GetMicroseconds]. | 91 // Forward declare [Platform::GetMicroseconds]. |
92 namespace Platform { | 92 namespace Platform { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 WaitListEntry wait_entry; | 141 WaitListEntry wait_entry; |
142 AddToWaitList(&wait_entry); | 142 AddToWaitList(&wait_entry); |
143 CHECK_AND_FAIL(osMutexRelease(internal_)); | 143 CHECK_AND_FAIL(osMutexRelease(internal_)); |
144 CHECK_AND_RETURN(osMutexRelease(mutex_)); | 144 CHECK_AND_RETURN(osMutexRelease(mutex_)); |
145 #ifdef CMSIS_OS_RTX | 145 #ifdef CMSIS_OS_RTX |
146 int tokens = osSemaphoreWait(wait_entry.semaphore_, osWaitForever); | 146 int tokens = osSemaphoreWait(wait_entry.semaphore_, osWaitForever); |
147 ASSERT(tokens > 0); // There should have been at least one token. | 147 ASSERT(tokens > 0); // There should have been at least one token. |
148 #else | 148 #else |
149 // The implementation in STM32CubeF7 returns osOK if the | 149 // The implementation in STM32CubeF7 returns osOK if the |
150 // semaphore was acquired. | 150 // semaphore was acquired. |
151 // See https://github.com/dart-lang/fletch/issues/377. | 151 // See https://github.com/dart-lang/dartino/issues/377. |
152 CHECK_AND_FAIL(osSemaphoreWait(wait_entry.semaphore_, osWaitForever)); | 152 CHECK_AND_FAIL(osSemaphoreWait(wait_entry.semaphore_, osWaitForever)); |
153 #endif | 153 #endif |
154 CHECK_AND_RETURN(osMutexWait(mutex_, osWaitForever)); | 154 CHECK_AND_RETURN(osMutexWait(mutex_, osWaitForever)); |
155 return osOK; | 155 return osOK; |
156 } | 156 } |
157 | 157 |
158 bool Wait(uint64 microseconds) { | 158 bool Wait(uint64 microseconds) { |
159 bool success = true; | 159 bool success = true; |
160 CHECK_AND_FAIL(osMutexWait(internal_, osWaitForever)); | 160 CHECK_AND_FAIL(osMutexWait(internal_, osWaitForever)); |
161 WaitListEntry wait_entry; | 161 WaitListEntry wait_entry; |
162 AddToWaitList(&wait_entry); | 162 AddToWaitList(&wait_entry); |
163 CHECK_AND_FAIL(osMutexRelease(internal_)); | 163 CHECK_AND_FAIL(osMutexRelease(internal_)); |
164 CHECK_AND_FAIL(osMutexRelease(mutex_)); | 164 CHECK_AND_FAIL(osMutexRelease(mutex_)); |
165 #ifdef CMSIS_OS_RTX | 165 #ifdef CMSIS_OS_RTX |
166 int tokens = osSemaphoreWait(wait_entry.semaphore_, microseconds / 1000); | 166 int tokens = osSemaphoreWait(wait_entry.semaphore_, microseconds / 1000); |
167 success = (tokens == 0); | 167 success = (tokens == 0); |
168 #else | 168 #else |
169 // The implementation in STM32CubeF7 returns osOK if the | 169 // The implementation in STM32CubeF7 returns osOK if the |
170 // semaphore was acquired and osErrorOS if it was not. | 170 // semaphore was acquired and osErrorOS if it was not. |
171 // See https://github.com/dart-lang/fletch/issues/377. | 171 // See https://github.com/dart-lang/dartino/issues/377. |
172 int status = osSemaphoreWait(wait_entry.semaphore_, microseconds / 1000); | 172 int status = osSemaphoreWait(wait_entry.semaphore_, microseconds / 1000); |
173 success = (status == osOK); | 173 success = (status == osOK); |
174 #endif | 174 #endif |
175 CHECK_AND_RETURN(osMutexWait(mutex_, osWaitForever)); | 175 CHECK_AND_RETURN(osMutexWait(mutex_, osWaitForever)); |
176 return success; | 176 return success; |
177 } | 177 } |
178 | 178 |
179 bool WaitUntil(uint64 microseconds_since_epoch) { | 179 bool WaitUntil(uint64 microseconds_since_epoch) { |
180 uint64 us = microseconds_since_epoch - Platform::GetMicroseconds(); | 180 uint64 us = microseconds_since_epoch - Platform::GetMicroseconds(); |
181 return Wait(us); | 181 return Wait(us); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 osMutexDef(mutex_def_); | 262 osMutexDef(mutex_def_); |
263 osMutexId mutex_; | 263 osMutexId mutex_; |
264 osMutexDef(internal_def_); | 264 osMutexDef(internal_def_); |
265 osMutexId internal_; | 265 osMutexId internal_; |
266 | 266 |
267 WaitListEntry* first_waiting_; | 267 WaitListEntry* first_waiting_; |
268 WaitListEntry* last_waiting_; | 268 WaitListEntry* last_waiting_; |
269 }; | 269 }; |
270 | 270 |
271 } // namespace fletch | 271 } // namespace dartino |
272 | 272 |
273 #endif // defined(FLETCH_TARGET_OS_CMSIS) | 273 #endif // defined(DARTINO_TARGET_OS_CMSIS) |
274 | 274 |
275 #endif // SRC_SHARED_PLATFORM_CMSIS_H_ | 275 #endif // SRC_SHARED_PLATFORM_CMSIS_H_ |
OLD | NEW |