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))
msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread.
void osalSysHalt(const char *reason)
System halt with error message.
static void osalSysLock(void)
Enters a critical zone from thread context.
void osalEventSetCallback(event_source_t *esp, eventcallback_t cb, void *param)
Event callback setup.
uint32_t eventflags_t
Type of an event flags mask.
static void osalMutexObjectInit(mutex_t *mp)
Initializes a mutex_t object.
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
static systime_t osalTimeAddX(systime_t systime, sysinterval_t interval)
Adds an interval to a system time returning a system time.
static void osalSysEnable(void)
Enables interrupts globally.
const char * osal_halt_msg
Pointer to a halt error message.
void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the queue.
struct event_source event_source_t
Type of an event flags object.
uint32_t rtcnt_t
Type of realtime counter.
static void osalSysLockFromISR(void)
Enters a critical zone from ISR context.
static void osalThreadQueueObjectInit(threads_queue_t *tqp)
Initializes a threads queue object.
int32_t msg_t
Type of a message.
uint32_t sysinterval_t
Type of system time interval.
msg_t osalThreadSuspendS(thread_reference_t *trp)
Sends the current thread sleeping and sets a reference variable.
void(* eventcallback_t)(event_source_t *esp)
Type of an event source callback.
void osalThreadResumeS(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
void * thread_reference_t
Type of a thread reference.
void osalOsRescheduleS(void)
Checks if a reschedule is required and performs it.
void osalThreadSleep(sysinterval_t time)
Suspends the invoking thread for the specified time.
static void osalSysDisable(void)
Disables interrupts globally.
void osalMutexLock(mutex_t *mp)
Locks the specified mutex.
void osalOsTimerHandlerI(void)
System timer handler.
void osalThreadResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
static bool osalTimeIsInRangeX(systime_t time, systime_t start, systime_t end)
Checks if the specified time is within the specified time window.
uint32_t mutex_t
Type of a mutex.
void osalInit(void)
OSAL module initialization.
static sysinterval_t osalTimeDiffX(systime_t start, systime_t end)
Subtracts two system times returning an interval.
void osalThreadSleepS(sysinterval_t time)
Suspends the invoking thread for the specified time.
void osalEventBroadcastFlags(event_source_t *esp, eventflags_t flags)
Add flags to an event source object.
uint64_t time_conv_t
Type of time conversion variable.
static syssts_t osalSysGetStatusAndLockX(void)
Returns the execution status and enters a critical zone.
static void osalSysUnlockFromISR(void)
Leaves a critical zone from ISR context.
systime_t osalOsGetSystemTimeX(void)
Current system time.
static void osalEventObjectInit(event_source_t *esp)
Initializes an event source object.
static void osalSysRestoreStatusX(syssts_t sts)
Restores the specified execution status and leaves a critical zone.
uint32_t syssts_t
Type of a system status word.
void osalMutexUnlock(mutex_t *mp)
Unlocks the specified mutex.
msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
Sends the current thread sleeping and sets a reference variable.
#define osalDbgCheck(c)
Function parameters check.
uint32_t systime_t
Type of system time counter.
void osalSysPolledDelayX(rtcnt_t cycles)
Polled delay.
void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the queue, if any.
void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags)
Add flags to an event source object.
void * param
User defined field.
eventcallback_t cb
Event source callback.
volatile eventflags_t flags
Stored event flags.