diff options
Diffstat (limited to 'lib/chibios/os')
1950 files changed, 2949354 insertions, 0 deletions
diff --git a/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.c b/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.c new file mode 100644 index 000000000..9bd63da8f --- /dev/null +++ b/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.c | |||
@@ -0,0 +1,558 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014, | ||
3 | 2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio. | ||
4 | |||
5 | This file is part of ChibiOS. | ||
6 | |||
7 | ChibiOS is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation version 3 of the License. | ||
10 | |||
11 | ChibiOS is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | /* | ||
20 | Concepts and parts of this file have been contributed by Andre R. | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file cmsis_os.c | ||
25 | * @brief CMSIS RTOS module code. | ||
26 | * | ||
27 | * @addtogroup CMSIS_OS | ||
28 | * @{ | ||
29 | */ | ||
30 | |||
31 | #include "cmsis_os.h" | ||
32 | #include <string.h> | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Module local definitions. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /*===========================================================================*/ | ||
39 | /* Module exported variables. */ | ||
40 | /*===========================================================================*/ | ||
41 | |||
42 | int32_t cmsis_os_started; | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Module local types. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* Module local variables. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | static memory_pool_t sempool; | ||
53 | static semaphore_t semaphores[CMSIS_CFG_NUM_SEMAPHORES]; | ||
54 | |||
55 | static memory_pool_t timpool; | ||
56 | static struct os_timer_cb timers[CMSIS_CFG_NUM_TIMERS]; | ||
57 | |||
58 | /*===========================================================================*/ | ||
59 | /* Module local functions. */ | ||
60 | /*===========================================================================*/ | ||
61 | |||
62 | /** | ||
63 | * @brief Virtual timers common callback. | ||
64 | */ | ||
65 | static void timer_cb(void const *arg) { | ||
66 | |||
67 | osTimerId timer_id = (osTimerId)arg; | ||
68 | timer_id->ptimer(timer_id->argument); | ||
69 | if (timer_id->type == osTimerPeriodic) { | ||
70 | chSysLockFromISR(); | ||
71 | chVTDoSetI(&timer_id->vt, TIME_MS2I(timer_id->millisec), | ||
72 | (vtfunc_t)timer_cb, timer_id); | ||
73 | chSysUnlockFromISR(); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | /*===========================================================================*/ | ||
78 | /* Module exported functions. */ | ||
79 | /*===========================================================================*/ | ||
80 | |||
81 | /** | ||
82 | * @brief Kernel initialization. | ||
83 | */ | ||
84 | osStatus osKernelInitialize(void) { | ||
85 | |||
86 | cmsis_os_started = 0; | ||
87 | |||
88 | chSysInit(); | ||
89 | chThdSetPriority(HIGHPRIO); | ||
90 | |||
91 | chPoolObjectInit(&sempool, sizeof(semaphore_t), chCoreAllocAlignedI); | ||
92 | chPoolLoadArray(&sempool, semaphores, CMSIS_CFG_NUM_SEMAPHORES); | ||
93 | |||
94 | chPoolObjectInit(&timpool, sizeof(struct os_timer_cb), chCoreAllocAlignedI); | ||
95 | chPoolLoadArray(&timpool, timers, CMSIS_CFG_NUM_TIMERS); | ||
96 | |||
97 | return osOK; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * @brief Kernel start. | ||
102 | */ | ||
103 | osStatus osKernelStart(void) { | ||
104 | |||
105 | cmsis_os_started = 1; | ||
106 | |||
107 | chThdSetPriority(NORMALPRIO); | ||
108 | |||
109 | return osOK; | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * @brief Creates a thread. | ||
114 | */ | ||
115 | osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *argument) { | ||
116 | size_t size; | ||
117 | |||
118 | size = thread_def->stacksize == 0 ? CMSIS_CFG_DEFAULT_STACK : | ||
119 | thread_def->stacksize; | ||
120 | return (osThreadId)chThdCreateFromHeap(0, | ||
121 | THD_WORKING_AREA_SIZE(size), | ||
122 | thread_def->name, | ||
123 | NORMALPRIO+thread_def->tpriority, | ||
124 | (tfunc_t)thread_def->pthread, | ||
125 | argument); | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * @brief Thread termination. | ||
130 | * @note The thread is not really terminated but asked to terminate which | ||
131 | * is not compliant. | ||
132 | */ | ||
133 | osStatus osThreadTerminate(osThreadId thread_id) { | ||
134 | |||
135 | if (thread_id == osThreadGetId()) { | ||
136 | /* Note, no memory will be recovered unless a cleaner thread is | ||
137 | implemented using the registry.*/ | ||
138 | chThdExit(0); | ||
139 | } | ||
140 | chThdTerminate(thread_id); | ||
141 | chThdWait((thread_t *)thread_id); | ||
142 | |||
143 | return osOK; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * @brief Change thread priority. | ||
148 | * @note This can interfere with the priority inheritance mechanism. | ||
149 | */ | ||
150 | osStatus osThreadSetPriority(osThreadId thread_id, osPriority newprio) { | ||
151 | thread_t * tp = (thread_t *)thread_id; | ||
152 | |||
153 | chSysLock(); | ||
154 | |||
155 | /* Changing priority.*/ | ||
156 | #if CH_CFG_USE_MUTEXES | ||
157 | if ((tp->hdr.pqueue.prio == tp->realprio) || | ||
158 | ((tprio_t)newprio > tp->hdr.pqueue.prio)) | ||
159 | tp->hdr.pqueue.prio = (tprio_t)newprio; | ||
160 | tp->realprio = (tprio_t)newprio; | ||
161 | #else | ||
162 | tp->hdr.pqueue.prio = (tprio_t)newprio; | ||
163 | #endif | ||
164 | |||
165 | /* The following states need priority queues reordering.*/ | ||
166 | switch (tp->state) { | ||
167 | #if CH_CFG_USE_MUTEXES | \ | ||
168 | CH_CFG_USE_CONDVARS | \ | ||
169 | (CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \ | ||
170 | (CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY) | ||
171 | #if CH_CFG_USE_MUTEXES | ||
172 | case CH_STATE_WTMTX: | ||
173 | #endif | ||
174 | #if CH_CFG_USE_CONDVARS | ||
175 | case CH_STATE_WTCOND: | ||
176 | #endif | ||
177 | #if CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY | ||
178 | case CH_STATE_WTSEM: | ||
179 | #endif | ||
180 | #if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY | ||
181 | case CH_STATE_SNDMSGQ: | ||
182 | #endif | ||
183 | /* Re-enqueues tp with its new priority on the queue.*/ | ||
184 | ch_sch_prio_insert(ch_queue_dequeue(&tp->hdr.queue), | ||
185 | (ch_queue_t *)tp->u.wtobjp); | ||
186 | break; | ||
187 | #endif | ||
188 | case CH_STATE_READY: | ||
189 | #if CH_DBG_ENABLE_ASSERTS | ||
190 | /* Prevents an assertion in chSchReadyI().*/ | ||
191 | tp->state = CH_STATE_CURRENT; | ||
192 | #endif | ||
193 | /* Re-enqueues tp with its new priority on the ready list.*/ | ||
194 | chSchReadyI((thread_t *)ch_queue_dequeue(&tp->hdr.queue)); | ||
195 | break; | ||
196 | } | ||
197 | |||
198 | /* Rescheduling.*/ | ||
199 | chSchRescheduleS(); | ||
200 | |||
201 | chSysUnlock(); | ||
202 | |||
203 | return osOK; | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * @brief Create a timer. | ||
208 | */ | ||
209 | osTimerId osTimerCreate(const osTimerDef_t *timer_def, | ||
210 | os_timer_type type, | ||
211 | void *argument) { | ||
212 | |||
213 | osTimerId timer = chPoolAlloc(&timpool); | ||
214 | chVTObjectInit(&timer->vt); | ||
215 | timer->ptimer = timer_def->ptimer; | ||
216 | timer->type = type; | ||
217 | timer->argument = argument; | ||
218 | return timer; | ||
219 | } | ||
220 | |||
221 | /** | ||
222 | * @brief Start a timer. | ||
223 | */ | ||
224 | osStatus osTimerStart(osTimerId timer_id, uint32_t millisec) { | ||
225 | |||
226 | if ((millisec == 0) || (millisec == osWaitForever)) | ||
227 | return osErrorValue; | ||
228 | |||
229 | timer_id->millisec = millisec; | ||
230 | chVTSet(&timer_id->vt, TIME_MS2I(millisec), (vtfunc_t)timer_cb, timer_id); | ||
231 | |||
232 | return osOK; | ||
233 | } | ||
234 | |||
235 | /** | ||
236 | * @brief Stop a timer. | ||
237 | */ | ||
238 | osStatus osTimerStop(osTimerId timer_id) { | ||
239 | |||
240 | chVTReset(&timer_id->vt); | ||
241 | |||
242 | return osOK; | ||
243 | } | ||
244 | |||
245 | /** | ||
246 | * @brief Delete a timer. | ||
247 | */ | ||
248 | osStatus osTimerDelete(osTimerId timer_id) { | ||
249 | |||
250 | chVTReset(&timer_id->vt); | ||
251 | chPoolFree(&timpool, (void *)timer_id); | ||
252 | |||
253 | return osOK; | ||
254 | } | ||
255 | |||
256 | /** | ||
257 | * @brief Send signals. | ||
258 | */ | ||
259 | int32_t osSignalSet(osThreadId thread_id, int32_t signals) { | ||
260 | int32_t oldsignals; | ||
261 | |||
262 | syssts_t sts = chSysGetStatusAndLockX(); | ||
263 | oldsignals = (int32_t)thread_id->epending; | ||
264 | chEvtSignalI((thread_t *)thread_id, (eventmask_t)signals); | ||
265 | chSysRestoreStatusX(sts); | ||
266 | |||
267 | return oldsignals; | ||
268 | } | ||
269 | |||
270 | /** | ||
271 | * @brief Clear signals. | ||
272 | */ | ||
273 | int32_t osSignalClear(osThreadId thread_id, int32_t signals) { | ||
274 | eventmask_t m; | ||
275 | |||
276 | chSysLock(); | ||
277 | |||
278 | m = thread_id->epending & (eventmask_t)signals; | ||
279 | thread_id->epending &= ~(eventmask_t)signals; | ||
280 | |||
281 | chSysUnlock(); | ||
282 | |||
283 | return (int32_t)m; | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * @brief Wait for signals. | ||
288 | */ | ||
289 | osEvent osSignalWait(int32_t signals, uint32_t millisec) { | ||
290 | osEvent event; | ||
291 | sysinterval_t timeout = (millisec == osWaitForever ? | ||
292 | TIME_INFINITE : (millisec == 0 ? TIME_IMMEDIATE : | ||
293 | TIME_MS2I(millisec))); | ||
294 | |||
295 | if (signals == 0) | ||
296 | event.value.signals = (uint32_t)chEvtWaitAnyTimeout(ALL_EVENTS, timeout); | ||
297 | else | ||
298 | event.value.signals = (uint32_t)chEvtWaitAllTimeout((eventmask_t)signals, | ||
299 | timeout); | ||
300 | |||
301 | /* Type of event.*/ | ||
302 | if (event.value.signals == 0) | ||
303 | event.status = osEventTimeout; | ||
304 | else | ||
305 | event.status = osEventSignal; | ||
306 | |||
307 | return event; | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * @brief Create a semaphore. | ||
312 | * @note @p semaphore_def is not used. | ||
313 | * @note Can involve memory allocation. | ||
314 | */ | ||
315 | osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, | ||
316 | int32_t count) { | ||
317 | |||
318 | (void)semaphore_def; | ||
319 | |||
320 | semaphore_t *sem = chPoolAlloc(&sempool); | ||
321 | chSemObjectInit(sem, (cnt_t)count); | ||
322 | return sem; | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * @brief Wait on a semaphore. | ||
327 | */ | ||
328 | int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec) { | ||
329 | sysinterval_t timeout = (millisec == osWaitForever ? | ||
330 | TIME_INFINITE : (millisec == 0 ? TIME_IMMEDIATE : | ||
331 | TIME_MS2I(millisec))); | ||
332 | |||
333 | msg_t msg = chSemWaitTimeout((semaphore_t *)semaphore_id, timeout); | ||
334 | switch (msg) { | ||
335 | case MSG_OK: | ||
336 | return osOK; | ||
337 | case MSG_TIMEOUT: | ||
338 | return osErrorTimeoutResource; | ||
339 | } | ||
340 | return osErrorResource; | ||
341 | } | ||
342 | |||
343 | /** | ||
344 | * @brief Release a semaphore. | ||
345 | */ | ||
346 | osStatus osSemaphoreRelease(osSemaphoreId semaphore_id) { | ||
347 | |||
348 | syssts_t sts = chSysGetStatusAndLockX(); | ||
349 | chSemSignalI((semaphore_t *)semaphore_id); | ||
350 | chSysRestoreStatusX(sts); | ||
351 | |||
352 | return osOK; | ||
353 | } | ||
354 | |||
355 | /** | ||
356 | * @brief Deletes a semaphore. | ||
357 | * @note After deletion there could be references in the system to a | ||
358 | * non-existent semaphore. | ||
359 | */ | ||
360 | osStatus osSemaphoreDelete(osSemaphoreId semaphore_id) { | ||
361 | |||
362 | chSemReset((semaphore_t *)semaphore_id, 0); | ||
363 | chPoolFree(&sempool, (void *)semaphore_id); | ||
364 | |||
365 | return osOK; | ||
366 | } | ||
367 | |||
368 | /** | ||
369 | * @brief Create a mutex. | ||
370 | * @note @p mutex_def is not used. | ||
371 | * @note Can involve memory allocation. | ||
372 | */ | ||
373 | osMutexId osMutexCreate(const osMutexDef_t *mutex_def) { | ||
374 | |||
375 | (void)mutex_def; | ||
376 | |||
377 | binary_semaphore_t *mtx = chPoolAlloc(&sempool); | ||
378 | chBSemObjectInit(mtx, false); | ||
379 | return mtx; | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * @brief Wait on a mutex. | ||
384 | */ | ||
385 | osStatus osMutexWait(osMutexId mutex_id, uint32_t millisec) { | ||
386 | sysinterval_t timeout = (millisec == osWaitForever ? | ||
387 | TIME_INFINITE : (millisec == 0 ? TIME_IMMEDIATE : | ||
388 | TIME_MS2I(millisec))); | ||
389 | |||
390 | msg_t msg = chBSemWaitTimeout((binary_semaphore_t *)mutex_id, timeout); | ||
391 | switch (msg) { | ||
392 | case MSG_OK: | ||
393 | return osOK; | ||
394 | case MSG_TIMEOUT: | ||
395 | return osErrorTimeoutResource; | ||
396 | } | ||
397 | return osErrorResource; | ||
398 | } | ||
399 | |||
400 | /** | ||
401 | * @brief Release a mutex. | ||
402 | */ | ||
403 | osStatus osMutexRelease(osMutexId mutex_id) { | ||
404 | |||
405 | syssts_t sts = chSysGetStatusAndLockX(); | ||
406 | chBSemSignalI((binary_semaphore_t *)mutex_id); | ||
407 | chSysRestoreStatusX(sts); | ||
408 | |||
409 | return osOK; | ||
410 | } | ||
411 | |||
412 | /** | ||
413 | * @brief Deletes a mutex. | ||
414 | * @note After deletion there could be references in the system to a | ||
415 | * non-existent semaphore. | ||
416 | */ | ||
417 | osStatus osMutexDelete(osMutexId mutex_id) { | ||
418 | |||
419 | chSemReset((semaphore_t *)mutex_id, 0); | ||
420 | chPoolFree(&sempool, (void *)mutex_id); | ||
421 | |||
422 | return osOK; | ||
423 | } | ||
424 | |||
425 | /** | ||
426 | * @brief Create a memory pool. | ||
427 | * @note The pool is not really created because it is allocated statically, | ||
428 | * this function just re-initializes it. | ||
429 | */ | ||
430 | osPoolId osPoolCreate(const osPoolDef_t *pool_def) { | ||
431 | |||
432 | chPoolObjectInit(pool_def->pool, (size_t)pool_def->item_sz, NULL); | ||
433 | chPoolLoadArray(pool_def->pool, pool_def->items, (size_t)pool_def->pool_sz); | ||
434 | |||
435 | return (osPoolId)pool_def->pool; | ||
436 | } | ||
437 | |||
438 | /** | ||
439 | * @brief Allocate an object. | ||
440 | */ | ||
441 | void *osPoolAlloc(osPoolId pool_id) { | ||
442 | void *object; | ||
443 | |||
444 | syssts_t sts = chSysGetStatusAndLockX(); | ||
445 | object = chPoolAllocI((memory_pool_t *)pool_id); | ||
446 | chSysRestoreStatusX(sts); | ||
447 | |||
448 | return object; | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * @brief Allocate an object clearing it. | ||
453 | */ | ||
454 | void *osPoolCAlloc(osPoolId pool_id) { | ||
455 | void *object; | ||
456 | |||
457 | object = chPoolAllocI((memory_pool_t *)pool_id); | ||
458 | memset(object, 0, pool_id->object_size); | ||
459 | return object; | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * @brief Free an object. | ||
464 | */ | ||
465 | osStatus osPoolFree(osPoolId pool_id, void *block) { | ||
466 | |||
467 | syssts_t sts = chSysGetStatusAndLockX(); | ||
468 | chPoolFreeI((memory_pool_t *)pool_id, block); | ||
469 | chSysRestoreStatusX(sts); | ||
470 | |||
471 | return osOK; | ||
472 | } | ||
473 | |||
474 | /** | ||
475 | * @brief Create a message queue. | ||
476 | * @note The queue is not really created because it is allocated statically, | ||
477 | * this function just re-initializes it. | ||
478 | */ | ||
479 | osMessageQId osMessageCreate(const osMessageQDef_t *queue_def, | ||
480 | osThreadId thread_id) { | ||
481 | |||
482 | /* Ignoring this parameter for now.*/ | ||
483 | (void)thread_id; | ||
484 | |||
485 | if (queue_def->item_sz > sizeof (msg_t)) | ||
486 | return NULL; | ||
487 | |||
488 | chMBObjectInit(queue_def->mailbox, | ||
489 | queue_def->items, | ||
490 | (size_t)queue_def->queue_sz); | ||
491 | |||
492 | return (osMessageQId) queue_def->mailbox; | ||
493 | } | ||
494 | |||
495 | /** | ||
496 | * @brief Put a message in the queue. | ||
497 | */ | ||
498 | osStatus osMessagePut(osMessageQId queue_id, | ||
499 | uint32_t info, | ||
500 | uint32_t millisec) { | ||
501 | msg_t msg; | ||
502 | sysinterval_t timeout = (millisec == osWaitForever ? | ||
503 | TIME_INFINITE : (millisec == 0 ? TIME_IMMEDIATE : | ||
504 | TIME_MS2I(millisec))); | ||
505 | |||
506 | if (port_is_isr_context()) { | ||
507 | |||
508 | /* Waiting makes no sense in ISRs so any value except "immediate" | ||
509 | makes no sense.*/ | ||
510 | if (millisec != 0) | ||
511 | return osErrorValue; | ||
512 | |||
513 | chSysLockFromISR(); | ||
514 | msg = chMBPostI((mailbox_t *)queue_id, (msg_t)info); | ||
515 | chSysUnlockFromISR(); | ||
516 | } | ||
517 | else | ||
518 | msg = chMBPostTimeout((mailbox_t *)queue_id, (msg_t)info, timeout); | ||
519 | |||
520 | return msg == MSG_OK ? osOK : osEventTimeout; | ||
521 | } | ||
522 | |||
523 | /** | ||
524 | * @brief Get a message from the queue. | ||
525 | */ | ||
526 | osEvent osMessageGet(osMessageQId queue_id, | ||
527 | uint32_t millisec) { | ||
528 | msg_t msg; | ||
529 | osEvent event; | ||
530 | sysinterval_t timeout = (millisec == osWaitForever ? | ||
531 | TIME_INFINITE : (millisec == 0 ? TIME_IMMEDIATE : | ||
532 | TIME_MS2I(millisec))); | ||
533 | |||
534 | event.def.message_id = queue_id; | ||
535 | |||
536 | if (port_is_isr_context()) { | ||
537 | |||
538 | /* Waiting makes no sense in ISRs so any value except "immediate" | ||
539 | makes no sense.*/ | ||
540 | if (millisec != 0) { | ||
541 | event.status = osErrorValue; | ||
542 | return event; | ||
543 | } | ||
544 | |||
545 | chSysLockFromISR(); | ||
546 | msg = chMBFetchI((mailbox_t *)queue_id, (msg_t*)&event.value.v); | ||
547 | chSysUnlockFromISR(); | ||
548 | } | ||
549 | else { | ||
550 | msg = chMBFetchTimeout((mailbox_t *)queue_id, (msg_t*)&event.value.v, timeout); | ||
551 | } | ||
552 | |||
553 | /* Returned event type.*/ | ||
554 | event.status = msg == MSG_OK ? osEventMessage : osEventTimeout; | ||
555 | return event; | ||
556 | } | ||
557 | |||
558 | /** @} */ | ||
diff --git a/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.h b/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.h new file mode 100644 index 000000000..dafe3e398 --- /dev/null +++ b/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.h | |||
@@ -0,0 +1,522 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014, | ||
3 | 2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio. | ||
4 | |||
5 | This file is part of ChibiOS. | ||
6 | |||
7 | ChibiOS is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation version 3 of the License. | ||
10 | |||
11 | ChibiOS is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | /* | ||
20 | Concepts and parts of this file have been contributed by Andre R. | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file cmsis_os.h | ||
25 | * @brief CMSIS RTOS module macros and structures. | ||
26 | * | ||
27 | * @addtogroup CMSIS_OS | ||
28 | * @{ | ||
29 | */ | ||
30 | |||
31 | #ifndef CMSIS_OS_H | ||
32 | #define CMSIS_OS_H | ||
33 | |||
34 | #include "ch.h" | ||
35 | |||
36 | /*===========================================================================*/ | ||
37 | /* Module constants. */ | ||
38 | /*===========================================================================*/ | ||
39 | |||
40 | /** | ||
41 | * @brief API version. | ||
42 | */ | ||
43 | #define osCMSIS 0x10002 | ||
44 | |||
45 | /** | ||
46 | * @brief Kernel version. | ||
47 | */ | ||
48 | #define osKernelSystemId "KERNEL V1.00" | ||
49 | |||
50 | /** | ||
51 | * @brief ChibiOS/RT version encoded for CMSIS. | ||
52 | */ | ||
53 | #define osCMSIS_KERNEL ((CH_KERNEL_MAJOR << 16) | \ | ||
54 | (CH_KERNEL_MINOR << 8) | \ | ||
55 | (CH_KERNEL_PATCH)) | ||
56 | |||
57 | /** | ||
58 | * @name CMSIS Capabilities | ||
59 | * @{ | ||
60 | */ | ||
61 | #define osFeature_MainThread 1 | ||
62 | #define osFeature_Pool 1 | ||
63 | #define osFeature_MailQ 0 | ||
64 | #define osFeature_MessageQ 1 | ||
65 | #define osFeature_Signals 24 | ||
66 | #define osFeature_Semaphore ((1U << 31) - 1U) | ||
67 | #define osFeature_Wait 0 | ||
68 | #define osFeature_SysTick 1 | ||
69 | /**< @} */ | ||
70 | |||
71 | /** | ||
72 | * @brief Wait forever specification for timeouts. | ||
73 | */ | ||
74 | #define osWaitForever ((uint32_t)-1) | ||
75 | |||
76 | /** | ||
77 | * @brief System tick frequency. | ||
78 | */ | ||
79 | #define osKernelSysTickFrequency CH_CFG_ST_FREQUENCY | ||
80 | |||
81 | /*===========================================================================*/ | ||
82 | /* Module pre-compile time settings. */ | ||
83 | /*===========================================================================*/ | ||
84 | |||
85 | /** | ||
86 | * @brief Number of pre-allocated static semaphores/mutexes. | ||
87 | */ | ||
88 | #if !defined(CMSIS_CFG_DEFAULT_STACK) | ||
89 | #define CMSIS_CFG_DEFAULT_STACK 256 | ||
90 | #endif | ||
91 | |||
92 | /** | ||
93 | * @brief Number of pre-allocated static semaphores/mutexes. | ||
94 | */ | ||
95 | #if !defined(CMSIS_CFG_NUM_SEMAPHORES) | ||
96 | #define CMSIS_CFG_NUM_SEMAPHORES 4 | ||
97 | #endif | ||
98 | |||
99 | /** | ||
100 | * @brief Number of pre-allocated static timers. | ||
101 | */ | ||
102 | #if !defined(CMSIS_CFG_NUM_TIMERS) | ||
103 | #define CMSIS_CFG_NUM_TIMERS 4 | ||
104 | #endif | ||
105 | |||
106 | /*===========================================================================*/ | ||
107 | /* Derived constants and error checks. */ | ||
108 | /*===========================================================================*/ | ||
109 | |||
110 | #if !CH_CFG_USE_MEMPOOLS | ||
111 | #error "CMSIS RTOS requires CH_CFG_USE_MEMPOOLS" | ||
112 | #endif | ||
113 | |||
114 | #if !CH_CFG_USE_EVENTS | ||
115 | #error "CMSIS RTOS requires CH_CFG_USE_EVENTS" | ||
116 | #endif | ||
117 | |||
118 | #if !CH_CFG_USE_EVENTS_TIMEOUT | ||
119 | #error "CMSIS RTOS requires CH_CFG_USE_EVENTS_TIMEOUT" | ||
120 | #endif | ||
121 | |||
122 | #if !CH_CFG_USE_SEMAPHORES | ||
123 | #error "CMSIS RTOS requires CH_CFG_USE_SEMAPHORES" | ||
124 | #endif | ||
125 | |||
126 | #if !CH_CFG_USE_DYNAMIC | ||
127 | #error "CMSIS RTOS requires CH_CFG_USE_DYNAMIC" | ||
128 | #endif | ||
129 | |||
130 | /*===========================================================================*/ | ||
131 | /* Module data structures and types. */ | ||
132 | /*===========================================================================*/ | ||
133 | |||
134 | /** | ||
135 | * @brief Type of priority levels. | ||
136 | */ | ||
137 | typedef enum { | ||
138 | osPriorityIdle = -3, | ||
139 | osPriorityLow = -2, | ||
140 | osPriorityBelowNormal = -1, | ||
141 | osPriorityNormal = 0, | ||
142 | osPriorityAboveNormal = +1, | ||
143 | osPriorityHigh = +2, | ||
144 | osPriorityRealtime = +3, | ||
145 | osPriorityError = 0x84 | ||
146 | } osPriority; | ||
147 | |||
148 | /** | ||
149 | * @brief Type of error codes. | ||
150 | */ | ||
151 | typedef enum { | ||
152 | osOK = 0, | ||
153 | osEventSignal = 0x08, | ||
154 | osEventMessage = 0x10, | ||
155 | osEventMail = 0x20, | ||
156 | osEventTimeout = 0x40, | ||
157 | osErrorParameter = 0x80, | ||
158 | osErrorResource = 0x81, | ||
159 | osErrorTimeoutResource = 0xC1, | ||
160 | osErrorISR = 0x82, | ||
161 | osErrorISRRecursive = 0x83, | ||
162 | osErrorPriority = 0x84, | ||
163 | osErrorNoMemory = 0x85, | ||
164 | osErrorValue = 0x86, | ||
165 | osErrorOS = 0xFF, | ||
166 | os_status_reserved = 0x7FFFFFFF | ||
167 | } osStatus; | ||
168 | |||
169 | /** | ||
170 | * @brief Type of a timer mode. | ||
171 | */ | ||
172 | typedef enum { | ||
173 | osTimerOnce = 0, | ||
174 | osTimerPeriodic = 1 | ||
175 | } os_timer_type; | ||
176 | |||
177 | /** | ||
178 | * @brief Type of thread functions. | ||
179 | */ | ||
180 | typedef void (*os_pthread) (void const *argument); | ||
181 | |||
182 | /** | ||
183 | * @brief Type of timer callback. | ||
184 | */ | ||
185 | typedef void (*os_ptimer) (void const *argument); | ||
186 | |||
187 | /** | ||
188 | * @brief Type of pointer to thread control block. | ||
189 | */ | ||
190 | typedef thread_t *osThreadId; | ||
191 | |||
192 | /** | ||
193 | * @brief Type of pointer to timer control block. | ||
194 | */ | ||
195 | typedef struct os_timer_cb { | ||
196 | virtual_timer_t vt; | ||
197 | os_timer_type type; | ||
198 | os_ptimer ptimer; | ||
199 | void *argument; | ||
200 | uint32_t millisec; | ||
201 | } *osTimerId; | ||
202 | |||
203 | /** | ||
204 | * @brief Type of pointer to mutex control block. | ||
205 | */ | ||
206 | typedef binary_semaphore_t *osMutexId; | ||
207 | |||
208 | /** | ||
209 | * @brief Type of pointer to semaphore control block. | ||
210 | */ | ||
211 | typedef semaphore_t *osSemaphoreId; | ||
212 | |||
213 | /** | ||
214 | * @brief Type of pointer to memory pool control block. | ||
215 | */ | ||
216 | typedef memory_pool_t *osPoolId; | ||
217 | |||
218 | /** | ||
219 | * @brief Type of pointer to message queue control block. | ||
220 | */ | ||
221 | typedef struct mailbox *osMessageQId; | ||
222 | |||
223 | /** | ||
224 | * @brief Type of an event. | ||
225 | */ | ||
226 | typedef struct { | ||
227 | osStatus status; | ||
228 | union { | ||
229 | uint32_t v; | ||
230 | void *p; | ||
231 | int32_t signals; | ||
232 | } value; | ||
233 | union { | ||
234 | /* osMailQId mail_id;*/ | ||
235 | osMessageQId message_id; | ||
236 | } def; | ||
237 | } osEvent; | ||
238 | |||
239 | /** | ||
240 | * @brief Type of a thread definition block. | ||
241 | */ | ||
242 | typedef struct os_thread_def { | ||
243 | os_pthread pthread; | ||
244 | osPriority tpriority; | ||
245 | uint32_t stacksize; | ||
246 | const char *name; | ||
247 | } osThreadDef_t; | ||
248 | |||
249 | /** | ||
250 | * @brief Type of a timer definition block. | ||
251 | */ | ||
252 | typedef struct os_timer_def { | ||
253 | os_ptimer ptimer; | ||
254 | } osTimerDef_t; | ||
255 | |||
256 | /** | ||
257 | * @brief Type of a mutex definition block. | ||
258 | */ | ||
259 | typedef struct os_mutex_def { | ||
260 | uint32_t dummy; | ||
261 | } osMutexDef_t; | ||
262 | |||
263 | /** | ||
264 | * @brief Type of a semaphore definition block. | ||
265 | */ | ||
266 | typedef struct os_semaphore_def { | ||
267 | uint32_t dummy; | ||
268 | } osSemaphoreDef_t; | ||
269 | |||
270 | /** | ||
271 | * @brief Type of a memory pool definition block. | ||
272 | */ | ||
273 | typedef struct os_pool_def { | ||
274 | uint32_t pool_sz; | ||
275 | uint32_t item_sz; | ||
276 | memory_pool_t *pool; | ||
277 | void *items; | ||
278 | } osPoolDef_t; | ||
279 | |||
280 | /** | ||
281 | * @brief Type of a message queue definition block. | ||
282 | */ | ||
283 | typedef struct os_messageQ_def { | ||
284 | uint32_t queue_sz; | ||
285 | uint32_t item_sz; | ||
286 | mailbox_t *mailbox; | ||
287 | void *items; | ||
288 | } osMessageQDef_t; | ||
289 | |||
290 | /*===========================================================================*/ | ||
291 | /* Module macros. */ | ||
292 | /*===========================================================================*/ | ||
293 | |||
294 | /** | ||
295 | * @brief Convert a microseconds value to a RTOS kernel system timer value. | ||
296 | */ | ||
297 | #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * \ | ||
298 | (osKernelSysTickFrequency)) / \ | ||
299 | 1000000) | ||
300 | |||
301 | /** | ||
302 | * @brief Create a Thread definition. | ||
303 | */ | ||
304 | #if defined(osObjectsExternal) | ||
305 | #define osThreadDef(thd, priority, stacksz, name) \ | ||
306 | extern const osThreadDef_t os_thread_def_##thd | ||
307 | #else | ||
308 | #define osThreadDef(thd, priority, stacksz, name) \ | ||
309 | const osThreadDef_t os_thread_def_##thd = { \ | ||
310 | (thd), \ | ||
311 | (priority), \ | ||
312 | (stacksz), \ | ||
313 | (name) \ | ||
314 | } | ||
315 | #endif | ||
316 | |||
317 | /** | ||
318 | * @brief Access a Thread definition. | ||
319 | */ | ||
320 | #define osThread(name) &os_thread_def_##name | ||
321 | |||
322 | /** | ||
323 | * @brief Define a Timer object. | ||
324 | */ | ||
325 | #if defined(osObjectsExternal) | ||
326 | #define osTimerDef(name, function) \ | ||
327 | extern const osTimerDef_t os_timer_def_##name | ||
328 | #else | ||
329 | #define osTimerDef(name, function) \ | ||
330 | const osTimerDef_t os_timer_def_##name = { \ | ||
331 | (function) \ | ||
332 | } | ||
333 | #endif | ||
334 | |||
335 | /** | ||
336 | * @brief Access a Timer definition. | ||
337 | */ | ||
338 | #define osTimer(name) &os_timer_def_##name | ||
339 | |||
340 | /** | ||
341 | * @brief Define a Mutex. | ||
342 | */ | ||
343 | #if defined(osObjectsExternal) | ||
344 | #define osMutexDef(name) extern const osMutexDef_t os_mutex_def_##name | ||
345 | #else | ||
346 | #define osMutexDef(name) const osMutexDef_t os_mutex_def_##name = {0} | ||
347 | #endif | ||
348 | |||
349 | /** | ||
350 | * @brief Access a Mutex definition. | ||
351 | */ | ||
352 | #define osMutex(name) &os_mutex_def_##name | ||
353 | |||
354 | /** | ||
355 | * @brief Define a Semaphore. | ||
356 | */ | ||
357 | #if defined(osObjectsExternal) | ||
358 | #define osSemaphoreDef(name) \ | ||
359 | extern const osSemaphoreDef_t os_semaphore_def_##name | ||
360 | #else // define the object | ||
361 | #define osSemaphoreDef(name) \ | ||
362 | const osSemaphoreDef_t os_semaphore_def_##name = {0} | ||
363 | #endif | ||
364 | |||
365 | /** | ||
366 | * @brief Access a Semaphore definition. | ||
367 | */ | ||
368 | #define osSemaphore(name) &os_semaphore_def_##name | ||
369 | |||
370 | /** | ||
371 | * @brief Define a Memory Pool. | ||
372 | */ | ||
373 | #if defined(osObjectsExternal) | ||
374 | #define osPoolDef(name, no, type) \ | ||
375 | extern const osPoolDef_t os_pool_def_##name | ||
376 | #else | ||
377 | #define osPoolDef(name, no, type) \ | ||
378 | static const type os_pool_buf_##name[no]; \ | ||
379 | static memory_pool_t os_pool_obj_##name; \ | ||
380 | const osPoolDef_t os_pool_def_##name = { \ | ||
381 | (no), \ | ||
382 | sizeof (type), \ | ||
383 | (void *)&os_pool_obj_##name, \ | ||
384 | (void *)&os_pool_buf_##name[0] \ | ||
385 | } | ||
386 | #endif | ||
387 | |||
388 | /** | ||
389 | * @brief Access a Memory Pool definition. | ||
390 | */ | ||
391 | #define osPool(name) &os_pool_def_##name | ||
392 | |||
393 | /** | ||
394 | * @brief Define a Message Queue. | ||
395 | */ | ||
396 | #if defined(osObjectsExternal) | ||
397 | #define osMessageQDef(name, queue_sz, type) \ | ||
398 | extern const osMessageQDef_t os_messageQ_def_##name | ||
399 | #else | ||
400 | #define osMessageQDef(name, queue_sz, type) \ | ||
401 | static const msg_t os_messageQ_buf_##name[queue_sz]; \ | ||
402 | static mailbox_t os_messageQ_obj_##name; \ | ||
403 | const osMessageQDef_t os_messageQ_def_##name = { \ | ||
404 | (queue_sz), \ | ||
405 | sizeof (type), \ | ||
406 | (void *)&os_messageQ_obj_##name, \ | ||
407 | (void *)&os_messageQ_buf_##name[0] \ | ||
408 | } | ||
409 | #endif | ||
410 | |||
411 | /** | ||
412 | * @brief Access a Message Queue definition. | ||
413 | */ | ||
414 | #define osMessageQ(name) &os_messageQ_def_##name | ||
415 | |||
416 | /*===========================================================================*/ | ||
417 | /* External declarations. */ | ||
418 | /*===========================================================================*/ | ||
419 | |||
420 | extern int32_t cmsis_os_started; | ||
421 | |||
422 | #ifdef __cplusplus | ||
423 | extern "C" { | ||
424 | #endif | ||
425 | osStatus osKernelInitialize(void); | ||
426 | osStatus osKernelStart(void); | ||
427 | osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *argument); | ||
428 | osStatus osThreadTerminate(osThreadId thread_id); | ||
429 | osStatus osThreadSetPriority(osThreadId thread_id, osPriority newprio); | ||
430 | /*osEvent osWait(uint32_t millisec);*/ | ||
431 | osTimerId osTimerCreate(const osTimerDef_t *timer_def, | ||
432 | os_timer_type type, | ||
433 | void *argument); | ||
434 | osStatus osTimerStart(osTimerId timer_id, uint32_t millisec); | ||
435 | osStatus osTimerStop(osTimerId timer_id); | ||
436 | osStatus osTimerDelete(osTimerId timer_id); | ||
437 | int32_t osSignalSet(osThreadId thread_id, int32_t signals); | ||
438 | int32_t osSignalClear(osThreadId thread_id, int32_t signals); | ||
439 | osEvent osSignalWait(int32_t signals, uint32_t millisec); | ||
440 | osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, | ||
441 | int32_t count); | ||
442 | int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec); | ||
443 | osStatus osSemaphoreRelease(osSemaphoreId semaphore_id); | ||
444 | osStatus osSemaphoreDelete(osSemaphoreId semaphore_id); | ||
445 | osMutexId osMutexCreate(const osMutexDef_t *mutex_def); | ||
446 | osStatus osMutexWait(osMutexId mutex_id, uint32_t millisec); | ||
447 | osStatus osMutexRelease(osMutexId mutex_id); | ||
448 | osStatus osMutexDelete(osMutexId mutex_id); | ||
449 | osPoolId osPoolCreate(const osPoolDef_t *pool_def); | ||
450 | void *osPoolAlloc(osPoolId pool_id); | ||
451 | void *osPoolCAlloc(osPoolId pool_id); | ||
452 | osStatus osPoolFree(osPoolId pool_id, void *block); | ||
453 | osMessageQId osMessageCreate(const osMessageQDef_t *queue_def, | ||
454 | osThreadId thread_id); | ||
455 | osStatus osMessagePut(osMessageQId queue_id, | ||
456 | uint32_t info, | ||
457 | uint32_t millisec); | ||
458 | osEvent osMessageGet(osMessageQId queue_id, | ||
459 | uint32_t millisec); | ||
460 | #ifdef __cplusplus | ||
461 | } | ||
462 | #endif | ||
463 | |||
464 | /*===========================================================================*/ | ||
465 | /* Module inline functions. */ | ||
466 | /*===========================================================================*/ | ||
467 | |||
468 | /** | ||
469 | * @brief To be or not to be. | ||
470 | */ | ||
471 | static inline int32_t osKernelRunning(void) { | ||
472 | |||
473 | return cmsis_os_started; | ||
474 | } | ||
475 | |||
476 | /** | ||
477 | * @brief System ticks since start. | ||
478 | */ | ||
479 | static inline uint32_t osKernelSysTick(void) { | ||
480 | |||
481 | return (uint32_t)chVTGetSystemTimeX(); | ||
482 | } | ||
483 | |||
484 | /** | ||
485 | * @brief Returns the current thread. | ||
486 | */ | ||
487 | static inline osThreadId osThreadGetId(void) { | ||
488 | |||
489 | return (osThreadId)chThdGetSelfX(); | ||
490 | } | ||
491 | |||
492 | /** | ||
493 | * @brief Thread time slice yield. | ||
494 | */ | ||
495 | static inline osStatus osThreadYield(void) { | ||
496 | |||
497 | chThdYield(); | ||
498 | |||
499 | return osOK; | ||
500 | } | ||
501 | |||
502 | /** | ||
503 | * @brief Returns priority of a thread. | ||
504 | */ | ||
505 | static inline osPriority osThreadGetPriority(osThreadId thread_id) { | ||
506 | |||
507 | return (osPriority)(NORMALPRIO - thread_id->hdr.pqueue.prio); | ||
508 | } | ||
509 | |||
510 | /** | ||
511 | * @brief Thread delay in milliseconds. | ||
512 | */ | ||
513 | static inline osStatus osDelay(uint32_t millisec) { | ||
514 | |||
515 | chThdSleepMilliseconds(millisec); | ||
516 | |||
517 | return osOK; | ||
518 | } | ||
519 | |||
520 | #endif /* CMSIS_OS_H */ | ||
521 | |||
522 | /** @} */ | ||
diff --git a/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.mk b/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.mk new file mode 100644 index 000000000..343f6df40 --- /dev/null +++ b/lib/chibios/os/common/abstractions/cmsis_os/cmsis_os.mk | |||
@@ -0,0 +1,8 @@ | |||
1 | # List of the ChibiOS/RT CMSIS RTOS wrapper. | ||
2 | CMSISRTOSSRC = ${CHIBIOS}/os/common/abstractions/cmsis_os/cmsis_os.c | ||
3 | |||
4 | CMSISRTOSINC = ${CHIBIOS}/os/common/abstractions/cmsis_os | ||
5 | |||
6 | # Shared variables | ||
7 | ALLCSRC += $(CMSISRTOSSRC) | ||
8 | ALLINC += $(CMSISRTOSINC) | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/cfe_osal.mk b/lib/chibios/os/common/abstractions/nasa_cfe/osal/cfe_osal.mk new file mode 100644 index 000000000..c0add1c26 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/cfe_osal.mk | |||
@@ -0,0 +1,8 @@ | |||
1 | # NASA CFE OSAL files. | ||
2 | CFEOSALSRC = $(CHIBIOS)/os/common/abstractions/nasa_cfe/osal/src/osapi.c | ||
3 | |||
4 | CFEOSALINC = $(CHIBIOS)/os/common/abstractions/nasa_cfe/osal/include | ||
5 | |||
6 | # Shared variables | ||
7 | ALLCSRC += $(CFEOSALSRC) | ||
8 | ALLINC += $(CFEOSALINC) | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/common_types.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/common_types.h new file mode 100644 index 000000000..100a9c72e --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/common_types.h | |||
@@ -0,0 +1,267 @@ | |||
1 | /*--------------------------------------------------------------------------- | ||
2 | ** | ||
3 | ** Filename: | ||
4 | ** $Id: common_types.h 1.9 2014/01/14 16:28:32GMT-05:00 acudmore Exp $ | ||
5 | ** | ||
6 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
7 | ** administrator of the National Aeronautics Space Administration. | ||
8 | ** All rights reserved. This software was created at NASAs Goddard | ||
9 | ** Space Flight Center pursuant to government contracts. | ||
10 | ** | ||
11 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
12 | ** distributed and modified only pursuant to the terms of that agreement. | ||
13 | ** | ||
14 | ** Purpose: | ||
15 | ** Unit specification for common types. | ||
16 | ** | ||
17 | ** Design Notes: | ||
18 | ** Assumes make file has defined processor family | ||
19 | ** | ||
20 | ** References: | ||
21 | ** Flight Software Branch C Coding Standard Version 1.0a | ||
22 | ** | ||
23 | ** | ||
24 | ** Notes: | ||
25 | ** | ||
26 | ** | ||
27 | ** $Date: 2014/01/14 16:28:32GMT-05:00 $ | ||
28 | ** $Revision: 1.9 $ | ||
29 | ** $Log: common_types.h $ | ||
30 | ** Revision 1.9 2014/01/14 16:28:32GMT-05:00 acudmore | ||
31 | ** Fixed typo in macro for x86-64 | ||
32 | ** Revision 1.8 2013/08/09 13:58:04GMT-05:00 acudmore | ||
33 | ** Added int64 type, added support for ARM arch, added 64 bit x86 arch, added arch check for GCC arch macros, added check for proper data type sizes | ||
34 | ** Revision 1.7 2013/07/25 10:01:29GMT-05:00 acudmore | ||
35 | ** Added C++ support | ||
36 | ** Revision 1.6 2012/04/11 09:19:03GMT-05:00 acudmore | ||
37 | ** added OS_USED attribute | ||
38 | ** Revision 1.5 2010/02/18 16:43:29EST acudmore | ||
39 | ** Added SPARC processor section | ||
40 | ** Removed special characters from comments that cause problems with some tools. | ||
41 | ** Revision 1.4 2010/02/18 16:41:39EST acudmore | ||
42 | ** Added a block of defines for GCC specific pragmas and extensions. | ||
43 | ** Removed RTEMS boolean related ifdefs | ||
44 | ** moved OS_PACK into the GCC specific block | ||
45 | ** Revision 1.3 2010/02/01 12:31:17EST acudmore | ||
46 | ** Added uint64 type | ||
47 | ** Revision 1.2 2009/07/07 16:30:05EDT acudmore | ||
48 | ** Removed conditinal comp. around boolean for m68k. | ||
49 | ** This will need to be done for all RTEMS targets | ||
50 | ** Revision 1.1 2009/06/02 10:04:58EDT acudmore | ||
51 | ** Initial revision | ||
52 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
53 | ** Revision 1.1 2008/04/20 22:35:58EDT ruperera | ||
54 | ** Initial revision | ||
55 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/inc/project.pj | ||
56 | ** Revision 1.1 2007/10/16 16:14:49EDT apcudmore | ||
57 | ** Initial revision | ||
58 | ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/inc/project.pj | ||
59 | ** Revision 1.2 2006/06/08 14:28:32EDT David Kobe (dlkobe) | ||
60 | ** Added NASA Open Source Legal Statement | ||
61 | ** Revision 1.1 2005/06/09 09:57:51GMT-05:00 rperera | ||
62 | ** Initial revision | ||
63 | ** Member added to project d:/mksdata/MKS-CFE-REPOSITORY/cfe-core/inc/project.pj | ||
64 | ** Revision 1.6 2005/03/24 19:20:52 rmcgraw | ||
65 | ** Wrapped the boolean defintion for all three processors with #ifndef _USING_RTEMS_INCLUDES_ | ||
66 | ** | ||
67 | ** Revision 1.5 2005/03/10 16:59:08 acudmore | ||
68 | ** removed boolean prefix to TRUE and FALSE defintion to avoid vxWorks conflict. | ||
69 | ** | ||
70 | ** Revision 1.4 2005/03/07 20:23:34 acudmore | ||
71 | ** removed duplicate boolean definition | ||
72 | ** | ||
73 | ** Revision 1.3 2005/03/07 20:05:17 acudmore | ||
74 | ** updated with __PPC__ macro that gnu compiler uses | ||
75 | ** | ||
76 | ** Revision 1.2 2005/03/04 16:02:44 acudmore | ||
77 | ** added coldfire architecture | ||
78 | ** | ||
79 | ** Revision 1.1 2005/03/04 15:58:45 acudmore | ||
80 | ** Added common_types.h | ||
81 | ** | ||
82 | ** | ||
83 | ** | ||
84 | **-------------------------------------------------------------------------*/ | ||
85 | |||
86 | #ifndef _common_types_ | ||
87 | #define _common_types_ | ||
88 | |||
89 | #ifdef __cplusplus | ||
90 | extern "C" { | ||
91 | #endif | ||
92 | |||
93 | /* | ||
94 | ** Includes | ||
95 | */ | ||
96 | |||
97 | /* | ||
98 | ** Macro Definitions | ||
99 | */ | ||
100 | |||
101 | /* | ||
102 | ** Condition = TRUE is ok, Condition = FALSE is error | ||
103 | */ | ||
104 | #define CompileTimeAssert(Condition, Message) typedef char Message[(Condition) ? 1 : -1] | ||
105 | |||
106 | |||
107 | /* | ||
108 | ** Define compiler specific macros | ||
109 | ** The __extension__ compiler pragma is required | ||
110 | ** for the uint64 type using GCC with the ANSI C90 standard. | ||
111 | ** Other macros can go in here as needed, for example alignment | ||
112 | ** pragmas. | ||
113 | */ | ||
114 | #if defined (__GNUC__) | ||
115 | #define _EXTENSION_ __extension__ | ||
116 | #define OS_PACK __attribute__ ((packed)) | ||
117 | #define OS_ALIGN(n) __attribute__((aligned(n))) | ||
118 | #define OS_USED __attribute__((used)) | ||
119 | #else | ||
120 | #define _EXTENSION_ | ||
121 | #define OS_PACK | ||
122 | #define OS_ALIGN(n) | ||
123 | #define OS_USED | ||
124 | #endif | ||
125 | |||
126 | #if defined(_ix86_) || defined (__i386__) | ||
127 | /* ----------------------- Intel x86 processor family -------------------------*/ | ||
128 | /* Little endian */ | ||
129 | #undef _STRUCT_HIGH_BIT_FIRST_ | ||
130 | #define _STRUCT_LOW_BIT_FIRST_ | ||
131 | |||
132 | typedef unsigned char boolean; | ||
133 | typedef signed char int8; | ||
134 | typedef short int int16; | ||
135 | typedef long int int32; | ||
136 | _EXTENSION_ typedef long long int int64; | ||
137 | typedef unsigned char uint8; | ||
138 | typedef unsigned short int uint16; | ||
139 | typedef unsigned long int uint32; | ||
140 | _EXTENSION_ typedef unsigned long long int uint64; | ||
141 | |||
142 | typedef unsigned long int cpuaddr; | ||
143 | |||
144 | #elif defined (_ix64_) || defined (__x86_64__) | ||
145 | /* ----------------------- Intel/AMD x64 processor family -------------------------*/ | ||
146 | /* Little endian */ | ||
147 | #undef _STRUCT_HIGH_BIT_FIRST_ | ||
148 | #define _STRUCT_LOW_BIT_FIRST_ | ||
149 | |||
150 | typedef unsigned char boolean; | ||
151 | typedef signed char int8; | ||
152 | typedef short int int16; | ||
153 | typedef int int32; | ||
154 | typedef long int int64; | ||
155 | typedef unsigned char uint8; | ||
156 | typedef unsigned short int uint16; | ||
157 | typedef unsigned int uint32; | ||
158 | typedef unsigned long int uint64; | ||
159 | |||
160 | typedef unsigned long int cpuaddr; | ||
161 | |||
162 | #elif defined(__PPC__) || defined (__ppc__) | ||
163 | /* ----------------------- Motorola Power PC family ---------------------------*/ | ||
164 | /* The PPC can be programmed to be big or little endian, we assume native */ | ||
165 | /* Big endian */ | ||
166 | #define _STRUCT_HIGH_BIT_FIRST_ | ||
167 | #undef _STRUCT_LOW_BIT_FIRST_ | ||
168 | |||
169 | typedef unsigned char boolean; | ||
170 | typedef signed char int8; | ||
171 | typedef short int int16; | ||
172 | typedef long int int32; | ||
173 | _EXTENSION_ typedef long long int int64; | ||
174 | typedef unsigned char uint8; | ||
175 | typedef unsigned short int uint16; | ||
176 | typedef unsigned long int uint32; | ||
177 | _EXTENSION_ typedef unsigned long long int uint64; | ||
178 | |||
179 | typedef unsigned long int cpuaddr; | ||
180 | |||
181 | #elif defined(_m68k_) || defined(__m68k__) | ||
182 | /* ----------------------- Motorola m68k/Coldfire family ---------------------------*/ | ||
183 | /* Big endian */ | ||
184 | #define _STRUCT_HIGH_BIT_FIRST_ | ||
185 | #undef _STRUCT_LOW_BIT_FIRST_ | ||
186 | |||
187 | typedef unsigned char boolean; | ||
188 | typedef signed char int8; | ||
189 | typedef short int int16; | ||
190 | typedef long int int32; | ||
191 | _EXTENSION_ typedef long long int int64; | ||
192 | typedef unsigned char uint8; | ||
193 | typedef unsigned short int uint16; | ||
194 | typedef unsigned long int uint32; | ||
195 | _EXTENSION_ typedef unsigned long long int uint64; | ||
196 | |||
197 | typedef unsigned long int cpuaddr; | ||
198 | |||
199 | #elif defined (__ARM__) || defined(__arm__) | ||
200 | /* ----------------------- ARM processor family -------------------------*/ | ||
201 | /* Little endian */ | ||
202 | #undef _STRUCT_HIGH_BIT_FIRST_ | ||
203 | #define _STRUCT_LOW_BIT_FIRST_ | ||
204 | |||
205 | typedef unsigned char boolean; | ||
206 | typedef signed char int8; | ||
207 | typedef short int int16; | ||
208 | typedef long int int32; | ||
209 | _EXTENSION_ typedef long long int int64; | ||
210 | typedef unsigned char uint8; | ||
211 | typedef unsigned short int uint16; | ||
212 | typedef unsigned long int uint32; | ||
213 | _EXTENSION_ typedef unsigned long long int uint64; | ||
214 | |||
215 | typedef unsigned long int cpuaddr; | ||
216 | |||
217 | #elif defined(__SPARC__) || defined (_sparc_) | ||
218 | /* ----------------------- SPARC/LEON family ---------------------------*/ | ||
219 | /* SPARC Big endian */ | ||
220 | #define _STRUCT_HIGH_BIT_FIRST_ | ||
221 | #undef _STRUCT_LOW_BIT_FIRST_ | ||
222 | |||
223 | typedef unsigned char boolean; | ||
224 | typedef signed char int8; | ||
225 | typedef short int int16; | ||
226 | typedef long int int32; | ||
227 | _EXTENSION_ typedef long long int int64; | ||
228 | typedef unsigned char uint8; | ||
229 | typedef unsigned short int uint16; | ||
230 | typedef unsigned long int uint32; | ||
231 | _EXTENSION_ typedef unsigned long long int uint64; | ||
232 | |||
233 | typedef unsigned long int cpuaddr; | ||
234 | |||
235 | #else /* not any of the above */ | ||
236 | #error undefined processor | ||
237 | #endif /* processor types */ | ||
238 | |||
239 | #ifndef NULL /* pointer to nothing */ | ||
240 | #define NULL ((void *) 0) | ||
241 | #endif | ||
242 | |||
243 | #ifndef TRUE /* Boolean true */ | ||
244 | #define TRUE (1) | ||
245 | #endif | ||
246 | |||
247 | #ifndef FALSE /* Boolean false */ | ||
248 | #define FALSE (0) | ||
249 | #endif | ||
250 | |||
251 | /* | ||
252 | ** Check Sizes | ||
253 | */ | ||
254 | CompileTimeAssert(sizeof(uint8)==1, TypeUint8WrongSize); | ||
255 | CompileTimeAssert(sizeof(uint16)==2, TypeUint16WrongSize); | ||
256 | CompileTimeAssert(sizeof(uint32)==4, TypeUint32WrongSize); | ||
257 | CompileTimeAssert(sizeof(uint64)==8, TypeUint64WrongSize); | ||
258 | CompileTimeAssert(sizeof(int8)==1, Typeint8WrongSize); | ||
259 | CompileTimeAssert(sizeof(int16)==2, Typeint16WrongSize); | ||
260 | CompileTimeAssert(sizeof(int32)==4, Typeint32WrongSize); | ||
261 | CompileTimeAssert(sizeof(int64)==8, Typeint64WrongSize); | ||
262 | |||
263 | #ifdef __cplusplus | ||
264 | } | ||
265 | #endif | ||
266 | |||
267 | #endif /* _common_types_ */ | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-core.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-core.h new file mode 100644 index 000000000..8c9b13a78 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-core.h | |||
@@ -0,0 +1,274 @@ | |||
1 | /* | ||
2 | ** File: osapi-os-core.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Ezra Yeheksli -Code 582/Raytheon | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variables declarations | ||
15 | ** for the OS Abstraction Layer, Core OS module | ||
16 | ** | ||
17 | ** $Revision: 1.8 $ | ||
18 | ** | ||
19 | ** $Date: 2013/07/25 10:02:00GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi-os-core.h $ | ||
22 | ** Revision 1.8 2013/07/25 10:02:00GMT-05:00 acudmore | ||
23 | ** removed circular include "osapi.h" | ||
24 | ** Revision 1.7 2012/04/11 09:30:48GMT-05:00 acudmore | ||
25 | ** Added OS_printf_enable and OS_printf_disable | ||
26 | ** Revision 1.6 2010/11/12 12:00:17EST acudmore | ||
27 | ** replaced copyright character with (c) and added open source notice where needed. | ||
28 | ** Revision 1.5 2010/11/10 15:33:14EST acudmore | ||
29 | ** Updated IntAttachHandler prototype | ||
30 | ** Revision 1.4 2010/03/08 12:06:28EST acudmore | ||
31 | ** added function pointer type to get rid of warnings | ||
32 | ** Revision 1.3 2010/02/01 12:37:15EST acudmore | ||
33 | ** added return code to OS API init | ||
34 | ** Revision 1.2 2009/08/04 10:49:09EDT acudmore | ||
35 | ** | ||
36 | */ | ||
37 | |||
38 | #ifndef _osapi_core_ | ||
39 | #define _osapi_core_ | ||
40 | |||
41 | #include <stdarg.h> /* for va_list */ | ||
42 | |||
43 | /*difines constants for OS_BinSemCreate for state of semaphore */ | ||
44 | #define OS_SEM_FULL 1 | ||
45 | #define OS_SEM_EMPTY 0 | ||
46 | |||
47 | /* #define for enabling floating point operations on a task*/ | ||
48 | #define OS_FP_ENABLED 1 | ||
49 | |||
50 | /* tables for the properties of objects */ | ||
51 | |||
52 | /*tasks */ | ||
53 | typedef struct | ||
54 | { | ||
55 | char name [OS_MAX_API_NAME]; | ||
56 | uint32 creator; | ||
57 | uint32 stack_size; | ||
58 | uint32 priority; | ||
59 | uint32 OStask_id; | ||
60 | }OS_task_prop_t; | ||
61 | |||
62 | /* queues */ | ||
63 | typedef struct | ||
64 | { | ||
65 | char name [OS_MAX_API_NAME]; | ||
66 | uint32 creator; | ||
67 | }OS_queue_prop_t; | ||
68 | |||
69 | /* Binary Semaphores */ | ||
70 | typedef struct | ||
71 | { | ||
72 | char name [OS_MAX_API_NAME]; | ||
73 | uint32 creator; | ||
74 | int32 value; | ||
75 | }OS_bin_sem_prop_t; | ||
76 | |||
77 | /* Counting Semaphores */ | ||
78 | typedef struct | ||
79 | { | ||
80 | char name [OS_MAX_API_NAME]; | ||
81 | uint32 creator; | ||
82 | int32 value; | ||
83 | }OS_count_sem_prop_t; | ||
84 | |||
85 | /* Mutexes */ | ||
86 | typedef struct | ||
87 | { | ||
88 | char name [OS_MAX_API_NAME]; | ||
89 | uint32 creator; | ||
90 | }OS_mut_sem_prop_t; | ||
91 | |||
92 | |||
93 | /* struct for OS_GetLocalTime() */ | ||
94 | |||
95 | typedef struct | ||
96 | { | ||
97 | uint32 seconds; | ||
98 | uint32 microsecs; | ||
99 | }OS_time_t; | ||
100 | |||
101 | /* heap info */ | ||
102 | typedef struct | ||
103 | { | ||
104 | uint32 free_bytes; | ||
105 | uint32 free_blocks; | ||
106 | uint32 largest_free_block; | ||
107 | }OS_heap_prop_t; | ||
108 | |||
109 | |||
110 | /* This typedef is for the OS_GetErrorName function, to ensure | ||
111 | * everyone is making an array of the same length */ | ||
112 | |||
113 | typedef char os_err_name_t[35]; | ||
114 | |||
115 | /* | ||
116 | ** These typedefs are for the task entry point | ||
117 | */ | ||
118 | typedef void osal_task; | ||
119 | typedef osal_task ((*osal_task_entry)(void)); | ||
120 | |||
121 | /* | ||
122 | ** Exported Functions | ||
123 | */ | ||
124 | |||
125 | /* | ||
126 | ** Initialization of API | ||
127 | */ | ||
128 | int32 OS_API_Init (void); | ||
129 | |||
130 | |||
131 | /* | ||
132 | ** Task API | ||
133 | */ | ||
134 | |||
135 | int32 OS_TaskCreate (uint32 *task_id, const char *task_name, | ||
136 | osal_task_entry function_pointer, | ||
137 | const uint32 *stack_pointer, | ||
138 | uint32 stack_size, | ||
139 | uint32 priority, uint32 flags); | ||
140 | |||
141 | int32 OS_TaskDelete (uint32 task_id); | ||
142 | void OS_TaskExit (void); | ||
143 | int32 OS_TaskInstallDeleteHandler(void *function_pointer); | ||
144 | int32 OS_TaskDelay (uint32 millisecond); | ||
145 | int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority); | ||
146 | int32 OS_TaskRegister (void); | ||
147 | uint32 OS_TaskGetId (void); | ||
148 | int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name); | ||
149 | int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop); | ||
150 | |||
151 | /* | ||
152 | ** Message Queue API | ||
153 | */ | ||
154 | |||
155 | /* | ||
156 | ** Queue Create now has the Queue ID returned to the caller. | ||
157 | */ | ||
158 | int32 OS_QueueCreate (uint32 *queue_id, const char *queue_name, | ||
159 | uint32 queue_depth, uint32 data_size, uint32 flags); | ||
160 | int32 OS_QueueDelete (uint32 queue_id); | ||
161 | int32 OS_QueueGet (uint32 queue_id, void *data, uint32 size, | ||
162 | uint32 *size_copied, int32 timeout); | ||
163 | int32 OS_QueuePut (uint32 queue_id, void *data, uint32 size, | ||
164 | uint32 flags); | ||
165 | int32 OS_QueueGetIdByName (uint32 *queue_id, const char *queue_name); | ||
166 | int32 OS_QueueGetInfo (uint32 queue_id, OS_queue_prop_t *queue_prop); | ||
167 | |||
168 | /* | ||
169 | ** Semaphore API | ||
170 | */ | ||
171 | |||
172 | int32 OS_BinSemCreate (uint32 *sem_id, const char *sem_name, | ||
173 | uint32 sem_initial_value, uint32 options); | ||
174 | int32 OS_BinSemFlush (uint32 sem_id); | ||
175 | int32 OS_BinSemGive (uint32 sem_id); | ||
176 | int32 OS_BinSemTake (uint32 sem_id); | ||
177 | int32 OS_BinSemTimedWait (uint32 sem_id, uint32 msecs); | ||
178 | int32 OS_BinSemDelete (uint32 sem_id); | ||
179 | int32 OS_BinSemGetIdByName (uint32 *sem_id, const char *sem_name); | ||
180 | int32 OS_BinSemGetInfo (uint32 sem_id, OS_bin_sem_prop_t *bin_prop); | ||
181 | |||
182 | int32 OS_CountSemCreate (uint32 *sem_id, const char *sem_name, | ||
183 | uint32 sem_initial_value, uint32 options); | ||
184 | int32 OS_CountSemGive (uint32 sem_id); | ||
185 | int32 OS_CountSemTake (uint32 sem_id); | ||
186 | int32 OS_CountSemTimedWait (uint32 sem_id, uint32 msecs); | ||
187 | int32 OS_CountSemDelete (uint32 sem_id); | ||
188 | int32 OS_CountSemGetIdByName (uint32 *sem_id, const char *sem_name); | ||
189 | int32 OS_CountSemGetInfo (uint32 sem_id, OS_count_sem_prop_t *count_prop); | ||
190 | |||
191 | /* | ||
192 | ** Mutex API | ||
193 | */ | ||
194 | |||
195 | int32 OS_MutSemCreate (uint32 *sem_id, const char *sem_name, uint32 options); | ||
196 | int32 OS_MutSemGive (uint32 sem_id); | ||
197 | int32 OS_MutSemTake (uint32 sem_id); | ||
198 | int32 OS_MutSemDelete (uint32 sem_id); | ||
199 | int32 OS_MutSemGetIdByName (uint32 *sem_id, const char *sem_name); | ||
200 | int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop); | ||
201 | |||
202 | /* | ||
203 | ** OS Time/Tick related API | ||
204 | */ | ||
205 | |||
206 | int32 OS_Milli2Ticks (uint32 milli_seconds); | ||
207 | int32 OS_Tick2Micros (void); | ||
208 | int32 OS_GetLocalTime (OS_time_t *time_struct); | ||
209 | int32 OS_SetLocalTime (OS_time_t *time_struct); | ||
210 | |||
211 | /* | ||
212 | ** Exception API | ||
213 | */ | ||
214 | |||
215 | int32 OS_ExcAttachHandler (uint32 ExceptionNumber, | ||
216 | void (*ExceptionHandler)(uint32, uint32 *,uint32), | ||
217 | int32 parameter); | ||
218 | int32 OS_ExcEnable (int32 ExceptionNumber); | ||
219 | int32 OS_ExcDisable (int32 ExceptionNumber); | ||
220 | |||
221 | /* | ||
222 | ** Floating Point Unit API | ||
223 | */ | ||
224 | |||
225 | int32 OS_FPUExcAttachHandler (uint32 ExceptionNumber, void * ExceptionHandler , | ||
226 | int32 parameter); | ||
227 | int32 OS_FPUExcEnable (int32 ExceptionNumber); | ||
228 | int32 OS_FPUExcDisable (int32 ExceptionNumber); | ||
229 | int32 OS_FPUExcSetMask (uint32 mask); | ||
230 | int32 OS_FPUExcGetMask (uint32 *mask); | ||
231 | |||
232 | /* | ||
233 | ** Interrupt API | ||
234 | */ | ||
235 | int32 OS_IntAttachHandler (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter); | ||
236 | int32 OS_IntUnlock (int32 IntLevel); | ||
237 | int32 OS_IntLock (void); | ||
238 | |||
239 | int32 OS_IntEnable (int32 Level); | ||
240 | int32 OS_IntDisable (int32 Level); | ||
241 | |||
242 | int32 OS_IntSetMask (uint32 mask); | ||
243 | int32 OS_IntGetMask (uint32 *mask); | ||
244 | int32 OS_IntAck (int32 InterruptNumber); | ||
245 | |||
246 | /* | ||
247 | ** Shared memory API | ||
248 | */ | ||
249 | int32 OS_ShMemInit (void); | ||
250 | int32 OS_ShMemCreate (uint32 *Id, uint32 NBytes, char* SegName); | ||
251 | int32 OS_ShMemSemTake (uint32 Id); | ||
252 | int32 OS_ShMemSemGive (uint32 Id); | ||
253 | int32 OS_ShMemAttach (uint32 * Address, uint32 Id); | ||
254 | int32 OS_ShMemGetIdByName (uint32 *ShMemId, const char *SegName ); | ||
255 | |||
256 | /* | ||
257 | ** Heap API | ||
258 | */ | ||
259 | int32 OS_HeapGetInfo (OS_heap_prop_t *heap_prop); | ||
260 | |||
261 | /* | ||
262 | ** API for useful debugging function | ||
263 | */ | ||
264 | int32 OS_GetErrorName (int32 error_num, os_err_name_t* err_name); | ||
265 | |||
266 | |||
267 | /* | ||
268 | ** Abstraction for printf statements | ||
269 | */ | ||
270 | void OS_printf( const char *string, ...); | ||
271 | void OS_printf_disable(void); | ||
272 | void OS_printf_enable(void); | ||
273 | |||
274 | #endif | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-custom.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-custom.h new file mode 100644 index 000000000..15a308848 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-custom.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file osapi-os-custom.h | ||
19 | * @brief Custom OSAPI extensions header. | ||
20 | * | ||
21 | * @addtogroup osapi-custom | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef OSAPI_CUSTOM_H | ||
26 | #define OSAPI_CUSTOM_H | ||
27 | |||
28 | /*===========================================================================*/ | ||
29 | /* Module constants. */ | ||
30 | /*===========================================================================*/ | ||
31 | |||
32 | /*===========================================================================*/ | ||
33 | /* Module pre-compile time settings. */ | ||
34 | /*===========================================================================*/ | ||
35 | |||
36 | /*===========================================================================*/ | ||
37 | /* Derived constants and error checks. */ | ||
38 | /*===========================================================================*/ | ||
39 | |||
40 | /*===========================================================================*/ | ||
41 | /* Module data structures and types. */ | ||
42 | /*===========================================================================*/ | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Module macros. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* External declarations. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | #ifdef __cplusplus | ||
53 | extern "C" { | ||
54 | #endif | ||
55 | void OS_set_printf(int (*printf)(const char *fmt, ...)); | ||
56 | boolean OS_TaskDeleteCheck(void); | ||
57 | int32 OS_TaskWait(uint32 task_id); | ||
58 | #ifdef __cplusplus | ||
59 | } | ||
60 | #endif | ||
61 | |||
62 | /*===========================================================================*/ | ||
63 | /* Module inline functions. */ | ||
64 | /*===========================================================================*/ | ||
65 | |||
66 | #endif /* OSAPI_CUSTOM_H */ | ||
67 | |||
68 | /** @} */ | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-filesys.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-filesys.h new file mode 100644 index 000000000..c46800341 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-filesys.h | |||
@@ -0,0 +1,419 @@ | |||
1 | /* | ||
2 | ** File: osapi-os-filesys.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Alan Cudmore Code 582 | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variables declarations | ||
15 | ** for the OS Abstraction Layer, File System module | ||
16 | ** | ||
17 | ** $Revision: 1.11 $ | ||
18 | ** | ||
19 | ** $Date: 2013/12/16 12:57:41GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi-os-filesys.h $ | ||
22 | ** Revision 1.11 2013/12/16 12:57:41GMT-05:00 acudmore | ||
23 | ** Added macros for Volume name length and physical device name length | ||
24 | ** Revision 1.10 2013/07/29 12:05:48GMT-05:00 acudmore | ||
25 | ** Added define for device and volume name length | ||
26 | ** Revision 1.9 2013/07/25 14:31:21GMT-05:00 acudmore | ||
27 | ** Added prototype and datatype for OS_GetFsInfo | ||
28 | ** Revision 1.8 2011/12/05 12:04:21GMT-05:00 acudmore | ||
29 | ** Added OS_rewinddir API | ||
30 | ** Revision 1.7 2011/04/05 16:01:12EDT acudmore | ||
31 | ** Added OS_CloseFileByName and OS_CloseAllFiles | ||
32 | ** Revision 1.6 2010/11/15 11:04:38EST acudmore | ||
33 | ** Added OS_FileOpenCheck function. | ||
34 | ** Revision 1.5 2010/11/12 12:00:18EST acudmore | ||
35 | ** replaced copyright character with (c) and added open source notice where needed. | ||
36 | ** Revision 1.4 2010/02/01 12:28:57EST acudmore | ||
37 | ** Added OS_fsBytesFree API | ||
38 | ** Revision 1.3 2010/01/25 14:44:26EST acudmore | ||
39 | ** renamed "new" variable to avoid C++ reserved name conflict. | ||
40 | ** Revision 1.2 2009/07/14 15:16:05EDT acudmore | ||
41 | ** Added OS_TranslatePath to the API | ||
42 | ** Revision 1.1 2008/04/20 22:36:01EDT ruperera | ||
43 | ** Initial revision | ||
44 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
45 | ** Revision 1.1 2007/10/16 16:14:52EDT apcudmore | ||
46 | ** Initial revision | ||
47 | ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
48 | ** Revision 1.1 2007/08/24 13:43:24EDT apcudmore | ||
49 | ** Initial revision | ||
50 | ** Member added to project d:/mksdata/MKS-CFE-PROJECT/fsw/cfe-core/os/inc/project.pj | ||
51 | ** Revision 1.17 2007/06/07 09:59:14EDT njyanchik | ||
52 | ** I replaced the second OS_cp definition with OS_mv | ||
53 | ** Revision 1.16 2007/06/05 16:25:33EDT apcudmore | ||
54 | ** Increased Number of volume table entries from 10 to 14. | ||
55 | ** Added 2 extra EEPROM disk mappings to RAD750 Volume table + 2 spares | ||
56 | ** Added 4 spares to every other volume table. | ||
57 | ** Revision 1.15 2007/05/25 09:17:56EDT njyanchik | ||
58 | ** I added the rmfs call to the OSAL and updated the unit test stubs to match | ||
59 | ** Revision 1.14 2007/03/21 10:15:29EST njyanchik | ||
60 | ** I mistakenly put the wrong length in for the path in the OS_FDTableEntry structure, and I added | ||
61 | ** some code that will set and out of range file descriptors .IsValid flag to false in OS_FDGetInfo | ||
62 | ** Revision 1.13 2007/03/06 11:52:46EST njyanchik | ||
63 | ** This change goes with the previous CP, I forgot to include it | ||
64 | ** Revision 1.12 2007/02/28 14:57:45EST njyanchik | ||
65 | ** The updates for supporting copying and moving files are now supported | ||
66 | ** Revision 1.11 2007/02/27 15:22:11EST njyanchik | ||
67 | ** This CP has the initial import of the new file descripor table mechanism | ||
68 | ** Revision 1.10 2006/12/20 10:27:09EST njyanchik | ||
69 | ** This change package incorporates all the changes necessary for the addition | ||
70 | ** of a new API to get the real physical drive undernieth a mount point | ||
71 | ** Revision 1.9 2006/11/14 14:44:28GMT-05:00 njyanchik | ||
72 | ** Checks were added to the OS fs calls that look at the return of a function that | ||
73 | ** changes the name of paths from abstracted to local path names. | ||
74 | ** Revision 1.8 2006/10/30 16:12:19GMT-05:00 apcudmore | ||
75 | ** Updated Compact flash and RAM device names for vxWorks 6.2 changes. | ||
76 | ** Revision 1.7 2006/10/25 11:31:18EDT njyanchik | ||
77 | ** This CP incorporates changes to every bsp_voltab.c file. I increased the number | ||
78 | ** entries in the volume table to 10. I also changed the #define in the os_filesys.h | ||
79 | ** file for the number of entries to match. | ||
80 | ** | ||
81 | ** This update also includes adding the prototype for OS_initfs in os_filesys.h | ||
82 | ** Revision 1.6 2006/09/26 09:03:46GMT-05:00 njyanchik | ||
83 | ** Contains the initial import of the ES Shell commands interface | ||
84 | ** Revision 1.5 2006/07/25 15:37:52EDT njyanchik | ||
85 | ** It turns out the both the FS app and the OSAL were incorrect where file descriptors are | ||
86 | ** concerned. the file descriptors should be int32 across the board. | ||
87 | ** Revision 1.4 2006/01/20 11:56:18EST njyanchik | ||
88 | ** Fixed header file information to match api document | ||
89 | ** Revision 1.26 2005/07/12 17:13:56 nyanchik | ||
90 | ** Moved the Volume table to a bsp table in the arch directories. | ||
91 | ** | ||
92 | ** Revision 1.2 2005/07/11 16:26:57EDT apcudmore | ||
93 | ** OSAPI 2.0 integration | ||
94 | ** Revision 1.25 2005/07/06 16:11:17 nyanchik | ||
95 | ** *** empty log message *** | ||
96 | ** | ||
97 | ** Revision 1.24 2005/07/05 18:34:55 nyanchik | ||
98 | ** fixed issues found in code walkthrogh. Also removed the OS_Info* functions that are going in the BSP | ||
99 | ** | ||
100 | ** Revision 1.23 2005/06/17 19:46:34 nyanchik | ||
101 | ** added new file system style to linux and rtems. | ||
102 | ** | ||
103 | ** Revision 1.22 2005/06/15 16:43:48 nyanchik | ||
104 | ** added extra parenthesis for the .h file # defines | ||
105 | ** | ||
106 | ** Revision 1.21 2005/06/06 14:17:42 nyanchik | ||
107 | ** added headers to osapi-os-core.h and osapi-os-filesys.h | ||
108 | ** | ||
109 | ** Revision 1.20 2005/06/02 18:04:24 nyanchik | ||
110 | ** *** empty log message *** | ||
111 | ** | ||
112 | ** Revision 1.1 2005/03/15 18:26:32 nyanchik | ||
113 | ** *** empty log message *** | ||
114 | ** | ||
115 | ** | ||
116 | ** Date Written: | ||
117 | ** | ||
118 | ** | ||
119 | */ | ||
120 | |||
121 | #ifndef _osapi_filesys_ | ||
122 | #define _osapi_filesys_ | ||
123 | #include <stdio.h> | ||
124 | #include <stdlib.h> | ||
125 | #include <dirent.h> | ||
126 | #include <sys/stat.h> | ||
127 | |||
128 | #define OS_READ_ONLY 0 | ||
129 | #define OS_WRITE_ONLY 1 | ||
130 | #define OS_READ_WRITE 2 | ||
131 | |||
132 | #define OS_SEEK_SET 0 | ||
133 | #define OS_SEEK_CUR 1 | ||
134 | #define OS_SEEK_END 2 | ||
135 | |||
136 | #define OS_CHK_ONLY 0 | ||
137 | #define OS_REPAIR 1 | ||
138 | |||
139 | #define FS_BASED 0 | ||
140 | #define RAM_DISK 1 | ||
141 | #define EEPROM_DISK 2 | ||
142 | #define ATA_DISK 3 | ||
143 | |||
144 | |||
145 | /* | ||
146 | ** Number of entries in the internal volume table | ||
147 | */ | ||
148 | #define NUM_TABLE_ENTRIES 14 | ||
149 | |||
150 | /* | ||
151 | ** Length of a Device and Volume name | ||
152 | */ | ||
153 | #define OS_FS_DEV_NAME_LEN 32 | ||
154 | #define OS_FS_PHYS_NAME_LEN 64 | ||
155 | #define OS_FS_VOL_NAME_LEN 32 | ||
156 | |||
157 | |||
158 | /* | ||
159 | ** Defines for File System Calls | ||
160 | */ | ||
161 | #define OS_FS_SUCCESS 0 | ||
162 | #define OS_FS_ERROR (-1) | ||
163 | #define OS_FS_ERR_INVALID_POINTER (-2) | ||
164 | #define OS_FS_ERR_PATH_TOO_LONG (-3) | ||
165 | #define OS_FS_ERR_NAME_TOO_LONG (-4) | ||
166 | #define OS_FS_UNIMPLEMENTED (-5) | ||
167 | #define OS_FS_ERR_DRIVE_NOT_CREATED (-6) | ||
168 | #define OS_FS_ERR_DEVICE_NOT_FREE (-7) | ||
169 | #define OS_FS_ERR_PATH_INVALID (-8) | ||
170 | #define OS_FS_ERR_NO_FREE_FDS (-9) | ||
171 | #define OS_FS_ERR_INVALID_FD (-10) | ||
172 | |||
173 | /* This typedef is for the OS_FS_GetErrorName function, to ensure | ||
174 | * everyone is making an array of the same length */ | ||
175 | |||
176 | typedef char os_fs_err_name_t[35]; | ||
177 | |||
178 | |||
179 | /* | ||
180 | ** Internal structure of the OS volume table for | ||
181 | ** mounted file systems and path translation | ||
182 | */ | ||
183 | typedef struct | ||
184 | { | ||
185 | char DeviceName [OS_FS_DEV_NAME_LEN]; | ||
186 | char PhysDevName [OS_FS_PHYS_NAME_LEN]; | ||
187 | uint32 VolumeType; | ||
188 | uint8 VolatileFlag; | ||
189 | uint8 FreeFlag; | ||
190 | uint8 IsMounted; | ||
191 | char VolumeName [OS_FS_VOL_NAME_LEN]; | ||
192 | char MountPoint [OS_MAX_PATH_LEN]; | ||
193 | uint32 BlockSize; | ||
194 | |||
195 | }OS_VolumeInfo_t; | ||
196 | |||
197 | typedef struct | ||
198 | { | ||
199 | int32 OSfd; /* The underlying OS's file descriptor */ | ||
200 | char Path[OS_MAX_PATH_LEN]; /* The path of the file opened */ | ||
201 | uint32 User; /* The task id of the task who opened the file*/ | ||
202 | uint8 IsValid; /* Whether or not this entry is valid */ | ||
203 | }OS_FDTableEntry; | ||
204 | |||
205 | typedef struct | ||
206 | { | ||
207 | uint32 MaxFds; /* Total number of file descriptors */ | ||
208 | uint32 FreeFds; /* Total number that are free */ | ||
209 | uint32 MaxVolumes; /* Maximum number of volumes */ | ||
210 | uint32 FreeVolumes; /* Total number of volumes free */ | ||
211 | } os_fsinfo_t; | ||
212 | |||
213 | /* modified to posix calls, since all of the | ||
214 | * applicable OSes use the posix calls */ | ||
215 | |||
216 | typedef struct stat os_fstat_t; | ||