Go to the documentation of this file.
40 #if !defined(FALSE) || defined(__DOXYGEN__)
44 #if !defined(TRUE) || defined(__DOXYGEN__)
48 #define OSAL_SUCCESS false
49 #define OSAL_FAILED true
56 #define MSG_OK (msg_t)0
57 #define MSG_TIMEOUT (msg_t)-1
58 #define MSG_RESET (msg_t)-2
65 #define TIME_IMMEDIATE ((sysinterval_t)0)
66 #define TIME_INFINITE ((sysinterval_t)-1)
73 #define OSAL_ST_MODE_NONE 0
74 #define OSAL_ST_MODE_PERIODIC 1
75 #define OSAL_ST_MODE_FREERUNNING 2
85 #define OSAL_ST_RESOLUTION 32
90 #define OSAL_ST_FREQUENCY 1000
95 #define OSAL_ST_MODE OSAL_ST_MODE_PERIODIC
106 #define OSAL_IRQ_PRIORITY_LEVELS 16U
112 #define OSAL_IRQ_MAXIMUM_PRIORITY 0U
122 #if !defined(OSAL_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
123 #define OSAL_DBG_ENABLE_ASSERTS FALSE
129 #if !defined(OSAL_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
130 #define OSAL_DBG_ENABLE_CHECKS FALSE
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"
143 #if (OSAL_ST_RESOLUTION != 16) && (OSAL_ST_RESOLUTION != 32)
144 #error "invalid OSAL_ST_RESOLUTION, must be 16 or 32"
264 #define osalDbgAssert(c, remark) do { \
266 if (OSAL_DBG_ENABLE_ASSERTS != FALSE) { \
269 osalSysHalt(__func__); \
284 #define osalDbgCheck(c) do { \
286 if (OSAL_DBG_ENABLE_CHECKS != FALSE) { \
289 osalSysHalt(__func__); \
298 #define osalDbgCheckClassI()
304 #define osalDbgCheckClassS()
314 #define OSAL_IRQ_IS_VALID_PRIORITY(n) \
315 (((n) >= OSAL_IRQ_MAXIMUM_PRIORITY) && ((n) < OSAL_IRQ_PRIORITY_LEVELS))
321 #define OSAL_IRQ_PROLOGUE()
327 #define OSAL_IRQ_EPILOGUE()
335 #define OSAL_IRQ_HANDLER(id) void id(void)
355 #define OSAL_S2I(secs) \
356 ((sysinterval_t)((time_conv_t)(secs) * (time_conv_t)OSAL_ST_FREQUENCY))
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))
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))
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)
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)
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)
464 #define OSAL_S2RTC(freq, sec) ((freq) * (sec))
478 #define OSAL_MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec))
492 #define OSAL_US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec))
509 #define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
522 #define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
535 #define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
uint32_t eventflags_t
Type of an event flags mask.
void osalThreadSleep(sysinterval_t time)
Suspends the invoking thread for the specified time.
uint64_t time_conv_t
Type of time conversion variable.
void osalSysHalt(const char *reason)
System halt with error message.
msg_t osalThreadSuspendS(thread_reference_t *trp)
Sends the current thread sleeping and sets a reference variable.
uint64_t systime_t
Type of system time.
void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the queue.
static sysinterval_t osalTimeDiffX(systime_t start, systime_t end)
Subtracts two system times returning an interval.
static void osalSysDisable(void)
Disables interrupts globally.
static void osalSysLockFromISR(void)
Enters a critical zone from ISR context.
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
void osalOsTimerHandlerI(void)
System timer handler.
static void osalEventObjectInit(event_source_t *esp)
Initializes an event source object.
uint32_t systime_t
Type of system time counter.
static syssts_t osalSysGetStatusAndLockX(void)
Returns the execution status and enters a critical zone.
void osalMutexLock(mutex_t *mp)
Locks the specified mutex.
void osalOsRescheduleS(void)
Checks if a reschedule is required and performs it.
int32_t msg_t
Type of a message.
Structure representing a thread.
void osalSysPolledDelayX(rtcnt_t cycles)
Polled delay.
void osalEventBroadcastFlags(event_source_t *esp, eventflags_t flags)
Add flags to an event source object.
void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags)
Add flags to an event source object.
uint32_t syssts_t
Type of a system status word.
static systime_t osalTimeAddX(systime_t systime, sysinterval_t interval)
Adds an interval to a system time returning a system time.
volatile eventflags_t flags
Stored event flags.
static bool osalTimeIsInRangeX(systime_t time, systime_t start, systime_t end)
Checks if the specified time is within the specified time window.
void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the queue, if any.
void osalThreadSleepS(sysinterval_t time)
Suspends the invoking thread for the specified time.
void(* eventcallback_t)(event_source_t *esp)
Type of an event source callback.
uint32_t rtcnt_t
Type of realtime counter.
void osalInit(void)
OSAL module initialization.
msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread.
#define osalDbgCheck(c)
Function parameters check.
static void osalSysRestoreStatusX(syssts_t sts)
Restores the specified execution status and leaves a critical zone.
msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
Sends the current thread sleeping and sets a reference variable.
void * thread_reference_t
Type of a thread reference.
void osalEventSetCallback(event_source_t *esp, eventcallback_t cb, void *param)
Event callback setup.
static void osalSysUnlockFromISR(void)
Leaves a critical zone from ISR context.
uint32_t sysinterval_t
Type of system time interval.
uint64_t sysinterval_t
Type of time interval.
systime_t osalOsGetSystemTimeX(void)
Current system time.
static void osalSysLock(void)
Enters a critical zone from thread context.
void osalThreadResumeS(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
eventcallback_t cb
Event source callback.
const char * osal_halt_msg
Pointer to a halt error message.
void osalThreadResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
uint32_t mutex_t
Type of a mutex.
struct ch_threads_queue threads_queue_t
Type of a threads queue.
void * param
User defined field.
void osalMutexUnlock(mutex_t *mp)
Unlocks the specified mutex.
static void osalSysEnable(void)
Enables interrupts globally.
static void osalMutexObjectInit(mutex_t *mp)
Initializes s mutex_t object.
static void osalThreadQueueObjectInit(threads_queue_t *tqp)
Initializes a threads queue object.