ChibiOS  21.6.0
osal.h
Go to the documentation of this file.
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 osal.h
19  * @brief OSAL module header.
20  *
21  * @addtogroup OSAL
22  * @{
23  */
24 
25 #ifndef OSAL_H
26 #define OSAL_H
27 
28 #include <stddef.h>
29 #include <stdint.h>
30 #include <stdbool.h>
31 
32 /*===========================================================================*/
33 /* Module constants. */
34 /*===========================================================================*/
35 
36 /**
37  * @name Common constants
38  * @{
39  */
40 #if !defined(FALSE) || defined(__DOXYGEN__)
41 #define FALSE 0
42 #endif
43 
44 #if !defined(TRUE) || defined(__DOXYGEN__)
45 #define TRUE 1
46 #endif
47 
48 #define OSAL_SUCCESS false
49 #define OSAL_FAILED true
50 /** @} */
51 
52 /**
53  * @name Messages
54  * @{
55  */
56 #define MSG_OK (msg_t)0
57 #define MSG_TIMEOUT (msg_t)-1
58 #define MSG_RESET (msg_t)-2
59 /** @} */
60 
61 /**
62  * @name Special time constants
63  * @{
64  */
65 #define TIME_IMMEDIATE ((sysinterval_t)0)
66 #define TIME_INFINITE ((sysinterval_t)-1)
67 /** @} */
68 
69 /**
70  * @name Systick modes.
71  * @{
72  */
73 #define OSAL_ST_MODE_NONE 0
74 #define OSAL_ST_MODE_PERIODIC 1
75 #define OSAL_ST_MODE_FREERUNNING 2
76 /** @} */
77 
78 /**
79  * @name Systick parameters.
80  * @{
81  */
82 /**
83  * @brief Size in bits of the @p systick_t type.
84  */
85 #define OSAL_ST_RESOLUTION 32
86 
87 /**
88  * @brief Required systick frequency or resolution.
89  */
90 #define OSAL_ST_FREQUENCY 1000
91 
92 /**
93  * @brief Systick mode required by the underlying OS.
94  */
95 #define OSAL_ST_MODE OSAL_ST_MODE_PERIODIC
96 /** @} */
97 
98 /**
99  * @name IRQ-related constants
100  * @{
101  */
102 /**
103  * @brief Total priority levels.
104  * @brief Implementation not mandatory.
105  */
106 #define OSAL_IRQ_PRIORITY_LEVELS 16U
107 
108 /**
109  * @brief Highest IRQ priority for HAL drivers.
110  * @brief Implementation not mandatory.
111  */
112 #define OSAL_IRQ_MAXIMUM_PRIORITY 0U
113 /** @} */
114 
115 /*===========================================================================*/
116 /* Module pre-compile time settings. */
117 /*===========================================================================*/
118 
119 /**
120  * @brief Enables OSAL assertions.
121  */
122 #if !defined(OSAL_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
123 #define OSAL_DBG_ENABLE_ASSERTS FALSE
124 #endif
125 
126 /**
127  * @brief Enables OSAL functions parameters checks.
128  */
129 #if !defined(OSAL_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
130 #define OSAL_DBG_ENABLE_CHECKS FALSE
131 #endif
132 
133 /*===========================================================================*/
134 /* Derived constants and error checks. */
135 /*===========================================================================*/
136 
137 #if !(OSAL_ST_MODE == OSAL_ST_MODE_NONE) && \
138  !(OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) && \
139  !(OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING)
140 #error "invalid OSAL_ST_MODE setting in osal.h"
141 #endif
142 
143 #if (OSAL_ST_RESOLUTION != 16) && (OSAL_ST_RESOLUTION != 32)
144 #error "invalid OSAL_ST_RESOLUTION, must be 16 or 32"
145 #endif
146 
147 /*===========================================================================*/
148 /* Module data structures and types. */
149 /*===========================================================================*/
150 
151 /**
152  * @brief Type of a system status word.
153  */
154 typedef uint32_t syssts_t;
155 
156 /**
157  * @brief Type of a message.
158  */
159 typedef int32_t msg_t;
160 
161 /**
162  * @brief Type of system time counter.
163  */
164 typedef uint32_t systime_t;
165 
166 /**
167  * @brief Type of system time interval.
168  */
169 typedef uint32_t sysinterval_t;
170 
171 /**
172  * @brief Type of time conversion variable.
173  * @note This type must have double width than other time types, it is
174  * only used internally for conversions.
175  */
176 typedef uint64_t time_conv_t;
177 
178 /**
179  * @brief Type of realtime counter.
180  */
181 typedef uint32_t rtcnt_t;
182 
183 /**
184  * @brief Type of a thread reference.
185  */
186 typedef void * thread_reference_t;
187 
188 /**
189  * @brief Type of an event flags mask.
190  */
191 typedef uint32_t eventflags_t;
192 
193 /**
194  * @brief Type of an event flags object.
195  * @note The content of this structure is not part of the API and should
196  * not be relied upon. Implementers may define this structure in
197  * an entirely different way.
198  * @note Retrieval and clearing of the flags are not defined in this
199  * API and are implementation-dependent.
200  */
202 
203 /**
204  * @brief Type of an event source callback.
205  * @note This type is not part of the OSAL API and is provided
206  * exclusively as an example and for convenience.
207  */
208 typedef void (*eventcallback_t)(event_source_t *esp);
209 
210 /**
211  * @brief Events source object.
212  * @note The content of this structure is not part of the API and should
213  * not be relied upon. Implementers may define this structure in
214  * an entirely different way.
215  * @note Retrieval and clearing of the flags are not defined in this
216  * API and are implementation-dependent.
217  */
218 struct event_source {
219  volatile eventflags_t flags; /**< @brief Stored event flags. */
220  eventcallback_t cb; /**< @brief Event source callback. */
221  void *param; /**< @brief User defined field. */
222 };
223 
224 /**
225  * @brief Type of a mutex.
226  * @note If the OS does not support mutexes or there is no OS then them
227  * mechanism can be simulated.
228  */
229 typedef uint32_t mutex_t;
230 
231 /**
232  * @brief Type of a thread queue.
233  * @details A thread queue is a queue of sleeping threads, queued threads
234  * can be dequeued one at time or all together.
235  * @note If the OSAL is implemented on a bare metal machine without RTOS
236  * then the queue can be implemented as a single thread reference.
237  */
238 typedef struct {
241 
242 /*===========================================================================*/
243 /* Module macros. */
244 /*===========================================================================*/
245 
246 /**
247  * @name Debug related macros
248  * @{
249  */
250 /**
251  * @brief Condition assertion.
252  * @details If the condition check fails then the OSAL panics with a
253  * message and halts.
254  * @note The condition is tested only if the @p OSAL_ENABLE_ASSERTIONS
255  * switch is enabled.
256  * @note The remark string is not currently used except for putting a
257  * comment in the code about the assertion.
258  *
259  * @param[in] c the condition to be verified to be true
260  * @param[in] remark a remark string
261  *
262  * @api
263  */
264 #define osalDbgAssert(c, remark) do { \
265  /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
266  if (OSAL_DBG_ENABLE_ASSERTS != FALSE) { \
267  if (!(c)) { \
268  /*lint -restore*/ \
269  osalSysHalt(__func__); \
270  } \
271  } \
272 } while (false)
273 
274 /**
275  * @brief Function parameters check.
276  * @details If the condition check fails then the OSAL panics and halts.
277  * @note The condition is tested only if the @p OSAL_ENABLE_CHECKS switch
278  * is enabled.
279  *
280  * @param[in] c the condition to be verified to be true
281  *
282  * @api
283  */
284 #define osalDbgCheck(c) do { \
285  /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
286  if (OSAL_DBG_ENABLE_CHECKS != FALSE) { \
287  if (!(c)) { \
288  /*lint -restore*/ \
289  osalSysHalt(__func__); \
290  } \
291  } \
292 } while (false)
293 
294 /**
295  * @brief I-Class state check.
296  * @note Implementation is optional.
297  */
298 #define osalDbgCheckClassI()
299 
300 /**
301  * @brief S-Class state check.
302  * @note Implementation is optional.
303  */
304 #define osalDbgCheckClassS()
305 /** @} */
306 
307 /**
308  * @name IRQ service routines wrappers
309  * @{
310  */
311 /**
312  * @brief Priority level verification macro.
313  */
314 #define OSAL_IRQ_IS_VALID_PRIORITY(n) \
315  (((n) >= OSAL_IRQ_MAXIMUM_PRIORITY) && ((n) < OSAL_IRQ_PRIORITY_LEVELS))
316 
317 /**
318  * @brief IRQ prologue code.
319  * @details This macro must be inserted at the start of all IRQ handlers.
320  */
321 #define OSAL_IRQ_PROLOGUE()
322 
323 /**
324  * @brief IRQ epilogue code.
325  * @details This macro must be inserted at the end of all IRQ handlers.
326  */
327 #define OSAL_IRQ_EPILOGUE()
328 
329 /**
330  * @brief IRQ handler function declaration.
331  * @details This macro hides the details of an ISR function declaration.
332  *
333  * @param[in] id a vector name as defined in @p vectors.s
334  */
335 #define OSAL_IRQ_HANDLER(id) void id(void)
336 /** @} */
337 
338 /**
339  * @name Time conversion utilities
340  * @{
341  */
342 /**
343  * @brief Seconds to time interval.
344  * @details Converts from seconds to system ticks number.
345  * @note The result is rounded upward to the next tick boundary.
346  * @note Use of this macro for large values is not secure because
347  * integer overflows, make sure your value can be correctly
348  * converted.
349  *
350  * @param[in] secs number of seconds
351  * @return The number of ticks.
352  *
353  * @api
354  */
355 #define OSAL_S2I(secs) \
356  ((sysinterval_t)((time_conv_t)(secs) * (time_conv_t)OSAL_ST_FREQUENCY))
357 
358 /**
359  * @brief Milliseconds to time interval.
360  * @details Converts from milliseconds to system ticks number.
361  * @note The result is rounded upward to the next tick boundary.
362  * @note Use of this macro for large values is not secure because
363  * integer overflows, make sure your value can be correctly
364  * converted.
365  *
366  * @param[in] msecs number of milliseconds
367  * @return The number of ticks.
368  *
369  * @api
370  */
371 #define OSAL_MS2I(msecs) \
372  ((sysinterval_t)((((time_conv_t)(msecs) * \
373  (time_conv_t)OSAL_ST_FREQUENCY) + \
374  (time_conv_t)999) / (time_conv_t)1000))
375 
376 /**
377  * @brief Microseconds to time interval.
378  * @details Converts from microseconds to system ticks number.
379  * @note The result is rounded upward to the next tick boundary.
380  * @note Use of this macro for large values is not secure because
381  * integer overflows, make sure your value can be correctly
382  * converted.
383  *
384  * @param[in] usecs number of microseconds
385  * @return The number of ticks.
386  *
387  * @api
388  */
389 #define OSAL_US2I(usecs) \
390  ((sysinterval_t)((((time_conv_t)(usecs) * \
391  (time_conv_t)OSAL_ST_FREQUENCY) + \
392  (time_conv_t)999999) / (time_conv_t)1000000))
393 
394 /**
395  * @brief Time interval to seconds.
396  * @details Converts from system ticks number to seconds.
397  * @note The result is rounded up to the next second boundary.
398  * @note Use of this macro for large values is not secure because
399  * integer overflows, make sure your value can be correctly
400  * converted.
401  *
402  * @param[in] interval interval in ticks
403  * @return The number of seconds.
404  *
405  * @api
406  */
407 #define OSAL_I2S(interval) \
408  (time_secs_t)(((time_conv_t)(interval) + \
409  (time_conv_t)OSAL_ST_FREQUENCY - \
410  (time_conv_t)1) / (time_conv_t)OSAL_ST_FREQUENCY)
411 
412 /**
413  * @brief Time interval to milliseconds.
414  * @details Converts from system ticks number to milliseconds.
415  * @note The result is rounded up to the next millisecond boundary.
416  * @note Use of this macro for large values is not secure because
417  * integer overflows, make sure your value can be correctly
418  * converted.
419  *
420  * @param[in] interval interval in ticks
421  * @return The number of milliseconds.
422  *
423  * @api
424  */
425 #define OSAL_I2MS(interval) \
426  (time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000) + \
427  (time_conv_t)OSAL_ST_FREQUENCY - (time_conv_t)1) / \
428  (time_conv_t)OSAL_ST_FREQUENCY)
429 
430 /**
431  * @brief Time interval to microseconds.
432  * @details Converts from system ticks number to microseconds.
433  * @note The result is rounded up to the next microsecond boundary.
434  * @note Use of this macro for large values is not secure because
435  * integer overflows, make sure your value can be correctly
436  * converted.
437  *
438  * @param[in] interval interval in ticks
439  * @return The number of microseconds.
440  *
441  * @api
442  */
443 #define OSAL_I2US(interval) \
444  (time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000000) + \
445  (time_conv_t)OSAL_ST_FREQUENCY - (time_conv_t)1) / \
446  (time_conv_t)OSAL_ST_FREQUENCY)
447 /** @} */
448 
449 /**
450  * @name Time conversion utilities for the realtime counter
451  * @{
452  */
453 /**
454  * @brief Seconds to realtime counter.
455  * @details Converts from seconds to realtime counter cycles.
456  * @note The macro assumes that @p freq >= @p 1.
457  *
458  * @param[in] freq clock frequency, in Hz, of the realtime counter
459  * @param[in] sec number of seconds
460  * @return The number of cycles.
461  *
462  * @api
463  */
464 #define OSAL_S2RTC(freq, sec) ((freq) * (sec))
465 
466 /**
467  * @brief Milliseconds to realtime counter.
468  * @details Converts from milliseconds to realtime counter cycles.
469  * @note The result is rounded upward to the next millisecond boundary.
470  * @note The macro assumes that @p freq >= @p 1000.
471  *
472  * @param[in] freq clock frequency, in Hz, of the realtime counter
473  * @param[in] msec number of milliseconds
474  * @return The number of cycles.
475  *
476  * @api
477  */
478 #define OSAL_MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec))
479 
480 /**
481  * @brief Microseconds to realtime counter.
482  * @details Converts from microseconds to realtime counter cycles.
483  * @note The result is rounded upward to the next microsecond boundary.
484  * @note The macro assumes that @p freq >= @p 1000000.
485  *
486  * @param[in] freq clock frequency, in Hz, of the realtime counter
487  * @param[in] usec number of microseconds
488  * @return The number of cycles.
489  *
490  * @api
491  */
492 #define OSAL_US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec))
493 /** @} */
494 
495 /**
496  * @name Sleep macros using absolute time
497  * @{
498  */
499 /**
500  * @brief Delays the invoking thread for the specified number of seconds.
501  * @note The specified time is rounded up to a value allowed by the real
502  * system tick clock.
503  * @note The maximum specifiable value is implementation dependent.
504  *
505  * @param[in] secs time in seconds, must be different from zero
506  *
507  * @api
508  */
509 #define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
510 
511 /**
512  * @brief Delays the invoking thread for the specified number of
513  * milliseconds.
514  * @note The specified time is rounded up to a value allowed by the real
515  * system tick clock.
516  * @note The maximum specifiable value is implementation dependent.
517  *
518  * @param[in] msecs time in milliseconds, must be different from zero
519  *
520  * @api
521  */
522 #define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
523 
524 /**
525  * @brief Delays the invoking thread for the specified number of
526  * microseconds.
527  * @note The specified time is rounded up to a value allowed by the real
528  * system tick clock.
529  * @note The maximum specifiable value is implementation dependent.
530  *
531  * @param[in] usecs time in microseconds, must be different from zero
532  *
533  * @api
534  */
535 #define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
536 /** @} */
537 
538 /*===========================================================================*/
539 /* External declarations. */
540 /*===========================================================================*/
541 
542 extern const char *osal_halt_msg;
543 
544 #ifdef __cplusplus
545 extern "C" {
546 #endif
547  void osalInit(void);
548  void osalSysHalt(const char *reason);
549  void osalSysPolledDelayX(rtcnt_t cycles);
550  void osalOsTimerHandlerI(void);
551  void osalOsRescheduleS(void);
553  void osalThreadSleepS(sysinterval_t time);
554  void osalThreadSleep(sysinterval_t time);
565  eventcallback_t cb,
566  void *param);
567  void osalMutexLock(mutex_t *mp);
568  void osalMutexUnlock(mutex_t *mp);
569 #ifdef __cplusplus
570 }
571 #endif
572 
573 /*===========================================================================*/
574 /* Module inline functions. */
575 /*===========================================================================*/
576 
577 /**
578  * @brief Disables interrupts globally.
579  *
580  * @special
581  */
582 static inline void osalSysDisable(void) {
583 
584 }
585 
586 /**
587  * @brief Enables interrupts globally.
588  *
589  * @special
590  */
591 static inline void osalSysEnable(void) {
592 
593 }
594 
595 /**
596  * @brief Enters a critical zone from thread context.
597  * @note This function cannot be used for reentrant critical zones.
598  *
599  * @special
600  */
601 static inline void osalSysLock(void) {
602 
603 }
604 
605 /**
606  * @brief Leaves a critical zone from thread context.
607  * @note This function cannot be used for reentrant critical zones.
608  *
609  * @special
610  */
611 static inline void osalSysUnlock(void) {
612 
613 }
614 
615 /**
616  * @brief Enters a critical zone from ISR context.
617  * @note This function cannot be used for reentrant critical zones.
618  *
619  * @special
620  */
621 static inline void osalSysLockFromISR(void) {
622 
623 }
624 
625 /**
626  * @brief Leaves a critical zone from ISR context.
627  * @note This function cannot be used for reentrant critical zones.
628  *
629  * @special
630  */
631 static inline void osalSysUnlockFromISR(void) {
632 
633 }
634 
635 /**
636  * @brief Returns the execution status and enters a critical zone.
637  * @details This functions enters into a critical zone and can be called
638  * from any context. Because its flexibility it is less efficient
639  * than @p chSysLock() which is preferable when the calling context
640  * is known.
641  * @post The system is in a critical zone.
642  *
643  * @return The previous system status, the encoding of this
644  * status word is architecture-dependent and opaque.
645  *
646  * @xclass
647  */
648 static inline syssts_t osalSysGetStatusAndLockX(void) {
649 
650  return (syssts_t)0;
651 }
652 
653 /**
654  * @brief Restores the specified execution status and leaves a critical zone.
655  * @note A call to @p chSchRescheduleS() is automatically performed
656  * if exiting the critical zone and if not in ISR context.
657  *
658  * @param[in] sts the system status to be restored.
659  *
660  * @xclass
661  */
662 static inline void osalSysRestoreStatusX(syssts_t sts) {
663 
664  (void)sts;
665 }
666 
667 /**
668  * @brief Adds an interval to a system time returning a system time.
669  *
670  * @param[in] systime base system time
671  * @param[in] interval interval to be added
672  * @return The new system time.
673  *
674  * @xclass
675  */
676 static inline systime_t osalTimeAddX(systime_t systime,
677  sysinterval_t interval) {
678 
679  return systime + (systime_t)interval;
680 }
681 
682 /**
683  * @brief Subtracts two system times returning an interval.
684  *
685  * @param[in] start first system time
686  * @param[in] end second system time
687  * @return The interval representing the time difference.
688  *
689  * @xclass
690  */
691 static inline sysinterval_t osalTimeDiffX(systime_t start, systime_t end) {
692 
693  return (sysinterval_t)((systime_t)(end - start));
694 }
695 
696 /**
697  * @brief Checks if the specified time is within the specified time window.
698  * @note When start==end then the function returns always false because the
699  * time window has zero size.
700  * @note This function can be called from any context.
701  *
702  * @param[in] time the time to be verified
703  * @param[in] start the start of the time window (inclusive)
704  * @param[in] end the end of the time window (non inclusive)
705  * @retval true current time within the specified time window.
706  * @retval false current time not within the specified time window.
707  *
708  * @xclass
709  */
710 static inline bool osalTimeIsInRangeX(systime_t time,
711  systime_t start,
712  systime_t end) {
713 
714  return (bool)((systime_t)((systime_t)time - (systime_t)start) <
715  (systime_t)((systime_t)end - (systime_t)start));
716 }
717 
718 /**
719  * @brief Initializes a threads queue object.
720  *
721  * @param[out] tqp pointer to the threads queue object
722  *
723  * @init
724  */
725 static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
726 
727  osalDbgCheck(tqp != NULL);
728 }
729 
730 /**
731  * @brief Initializes an event source object.
732  *
733  * @param[out] esp pointer to the event source object
734  *
735  * @init
736  */
737 static inline void osalEventObjectInit(event_source_t *esp) {
738 
739  osalDbgCheck(esp != NULL);
740 
741  esp->flags = (eventflags_t)0;
742  esp->cb = NULL;
743  esp->param = NULL;
744 }
745 
746 /**
747  * @brief Initializes s @p mutex_t object.
748  *
749  * @param[out] mp pointer to the @p mutex_t object
750  *
751  * @init
752  */
753 static inline void osalMutexObjectInit(mutex_t *mp) {
754 
755  osalDbgCheck(mp != NULL);
756 
757  *mp = 0;
758 }
759 
760 #endif /* OSAL_H */
761 
762 /** @} */
eventflags_t
uint32_t eventflags_t
Type of an event flags mask.
Definition: osal.h:191
osalThreadSleep
void osalThreadSleep(sysinterval_t time)
Suspends the invoking thread for the specified time.
Definition: osal.c:170
time_conv_t
uint64_t time_conv_t
Type of time conversion variable.
Definition: osal.h:176
osalSysHalt
void osalSysHalt(const char *reason)
System halt with error message.
Definition: osal.c:77
osalThreadSuspendS
msg_t osalThreadSuspendS(thread_reference_t *trp)
Sends the current thread sleeping and sets a reference variable.
Definition: osal.c:185
systime_t
uint64_t systime_t
Type of system time.
Definition: chtime.h:107
osalThreadDequeueAllI
void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the queue.
Definition: osal.c:309
event_source
Event Source structure.
Definition: chevents.h:74
osalTimeDiffX
static sysinterval_t osalTimeDiffX(systime_t start, systime_t end)
Subtracts two system times returning an interval.
Definition: osal.h:691
osalSysDisable
static void osalSysDisable(void)
Disables interrupts globally.
Definition: osal.h:582
osalSysLockFromISR
static void osalSysLockFromISR(void)
Enters a critical zone from ISR context.
Definition: osal.h:621
eventflags_t
uint32_t eventflags_t
Definition: chearly.h:91
osalSysUnlock
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition: osal.h:611
osalOsTimerHandlerI
void osalOsTimerHandlerI(void)
System timer handler.
Definition: osal.c:105
osalEventObjectInit
static void osalEventObjectInit(event_source_t *esp)
Initializes an event source object.
Definition: osal.h:737
msg_t
int32_t msg_t
Definition: chearly.h:88
systime_t
uint32_t systime_t
Type of system time counter.
Definition: osal.h:164
osalSysGetStatusAndLockX
static syssts_t osalSysGetStatusAndLockX(void)
Returns the execution status and enters a critical zone.
Definition: osal.h:648
osalMutexLock
void osalMutexLock(mutex_t *mp)
Locks the specified mutex.
Definition: osal.c:384
osalOsRescheduleS
void osalOsRescheduleS(void)
Checks if a reschedule is required and performs it.
Definition: osal.c:119
msg_t
int32_t msg_t
Type of a message.
Definition: osal.h:159
ch_thread
Structure representing a thread.
Definition: chobjects.h:156
osalSysPolledDelayX
void osalSysPolledDelayX(rtcnt_t cycles)
Polled delay.
Definition: osal.c:94
osalEventBroadcastFlags
void osalEventBroadcastFlags(event_source_t *esp, eventflags_t flags)
Add flags to an event source object.
Definition: osal.c:341
syssts_t
port_syssts_t syssts_t
Definition: chearly.h:79
rtcnt_t
port_rtcnt_t rtcnt_t
Definition: chearly.h:77
osalEventBroadcastFlagsI
void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags)
Add flags to an event source object.
Definition: osal.c:323
syssts_t
uint32_t syssts_t
Type of a system status word.
Definition: osal.h:154
osalTimeAddX
static systime_t osalTimeAddX(systime_t systime, sysinterval_t interval)
Adds an interval to a system time returning a system time.
Definition: osal.h:676
event_source::flags
volatile eventflags_t flags
Stored event flags.
Definition: osal.h:219
threads_queue_t
Type of a thread queue.
Definition: osal.h:238
osalTimeIsInRangeX
static bool osalTimeIsInRangeX(systime_t time, systime_t start, systime_t end)
Checks if the specified time is within the specified time window.
Definition: osal.h:710
osalThreadDequeueNextI
void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the queue, if any.
Definition: osal.c:294
osalThreadSleepS
void osalThreadSleepS(sysinterval_t time)
Suspends the invoking thread for the specified time.
Definition: osal.c:153
eventcallback_t
void(* eventcallback_t)(event_source_t *esp)
Type of an event source callback.
Definition: osal.h:208
rtcnt_t
uint32_t rtcnt_t
Type of realtime counter.
Definition: osal.h:181
osalInit
void osalInit(void)
OSAL module initialization.
Definition: osal.c:63
osalThreadEnqueueTimeoutS
msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread.
Definition: osal.c:277
osalDbgCheck
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:284
osalSysRestoreStatusX
static void osalSysRestoreStatusX(syssts_t sts)
Restores the specified execution status and leaves a critical zone.
Definition: osal.h:662
osalThreadSuspendTimeoutS
msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
Sends the current thread sleeping and sets a reference variable.
Definition: osal.c:211
thread_reference_t
void * thread_reference_t
Type of a thread reference.
Definition: osal.h:186
osalEventSetCallback
void osalEventSetCallback(event_source_t *esp, eventcallback_t cb, void *param)
Event callback setup.
Definition: osal.c:365
osalSysUnlockFromISR
static void osalSysUnlockFromISR(void)
Leaves a critical zone from ISR context.
Definition: osal.h:631
ch_mutex
Mutex structure.
Definition: chmtx.h:57
sysinterval_t
uint32_t sysinterval_t
Type of system time interval.
Definition: osal.h:169
sysinterval_t
uint64_t sysinterval_t
Type of time interval.
Definition: chtime.h:119
osalOsGetSystemTimeX
systime_t osalOsGetSystemTimeX(void)
Current system time.
Definition: osal.c:136
osalSysLock
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition: osal.h:601
osalThreadResumeS
void osalThreadResumeS(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
Definition: osal.c:247
event_source::cb
eventcallback_t cb
Event source callback.
Definition: osal.h:220
osal_halt_msg
const char * osal_halt_msg
Pointer to a halt error message.
Definition: osal.c:40
osalThreadResumeI
void osalThreadResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
Definition: osal.c:230
mutex_t
uint32_t mutex_t
Type of a mutex.
Definition: osal.h:229
threads_queue_t
struct ch_threads_queue threads_queue_t
Type of a threads queue.
event_source::param
void * param
User defined field.
Definition: osal.h:221
osalMutexUnlock
void osalMutexUnlock(mutex_t *mp)
Unlocks the specified mutex.
Definition: osal.c:404
osalSysEnable
static void osalSysEnable(void)
Enables interrupts globally.
Definition: osal.h:591
osalMutexObjectInit
static void osalMutexObjectInit(mutex_t *mp)
Initializes s mutex_t object.
Definition: osal.h:753
osalThreadQueueObjectInit
static void osalThreadQueueObjectInit(threads_queue_t *tqp)
Initializes a threads queue object.
Definition: osal.h:725