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 66 #define TIME_IMMEDIATE ((sysinterval_t)0) 67 #define TIME_INFINITE ((sysinterval_t)-1) 74 #define OSAL_ST_MODE_NONE 0 75 #define OSAL_ST_MODE_PERIODIC 1 76 #define OSAL_ST_MODE_FREERUNNING 2 86 #define OSAL_ST_RESOLUTION 32 91 #define OSAL_ST_FREQUENCY 1000 96 #define OSAL_ST_MODE OSAL_ST_MODE_PERIODIC 107 #define OSAL_IRQ_PRIORITY_LEVELS 16U 113 #define OSAL_IRQ_MAXIMUM_PRIORITY 0U 123 #if !defined(OSAL_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__) 124 #define OSAL_DBG_ENABLE_ASSERTS FALSE 130 #if !defined(OSAL_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__) 131 #define OSAL_DBG_ENABLE_CHECKS FALSE 138 #if !(OSAL_ST_MODE == OSAL_ST_MODE_NONE) && \ 139 !(OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) && \ 140 !(OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) 141 #error "invalid OSAL_ST_MODE setting in osal.h" 144 #if (OSAL_ST_RESOLUTION != 16) && (OSAL_ST_RESOLUTION != 32) 145 #error "invalid OSAL_ST_RESOLUTION, must be 16 or 32" 258 #define osalDbgAssert(c, remark) do { \ 260 if (OSAL_DBG_ENABLE_ASSERTS != FALSE) { \ 263 osalSysHalt(__func__); \ 278 #define osalDbgCheck(c) do { \ 280 if (OSAL_DBG_ENABLE_CHECKS != FALSE) { \ 283 osalSysHalt(__func__); \ 292 #define osalDbgCheckClassI() 298 #define osalDbgCheckClassS() 308 #define OSAL_IRQ_IS_VALID_PRIORITY(n) \ 309 (((n) >= OSAL_IRQ_MAXIMUM_PRIORITY) && ((n) < OSAL_IRQ_PRIORITY_LEVELS)) 315 #define OSAL_IRQ_PROLOGUE() 321 #define OSAL_IRQ_EPILOGUE() 329 #define OSAL_IRQ_HANDLER(id) void id(void) 346 #define OSAL_S2I(secs) \ 347 ((sysinterval_t)((uint32_t)(secs) * (uint32_t)OSAL_ST_FREQUENCY)) 359 #define OSAL_MS2I(msecs) \ 360 ((sysinterval_t)((((((uint32_t)(msecs)) * \ 361 ((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL)) 373 #define OSAL_US2I(usecs) \ 374 ((sysinterval_t)((((((uint32_t)(usecs)) * \ 375 ((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL)) 393 #define OSAL_S2RTC(freq, sec) ((freq) * (sec)) 407 #define OSAL_MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec)) 421 #define OSAL_US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec)) 438 #define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs)) 451 #define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs)) 464 #define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs)) 643 return (
bool)((time - start) < (end - start));
static void osalMutexObjectInit(mutex_t *mp)
Initializes s mutex_t object.
uint32_t eventflags_t
Type of an event flags mask.
msg_t osalThreadSuspendS(thread_reference_t *trp)
Sends the current thread sleeping and sets a reference variable.
void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the queue.
void osalThreadSleep(sysinterval_t time)
Suspends the invoking thread for the specified time.
void osalSysHalt(const char *reason)
System halt with error message.
static sysinterval_t osalTimeDiffX(systime_t start, systime_t end)
Subtracts two system times returning an interval.
void osalOsTimerHandlerI(void)
System timer handler.
static void osalSysDisable(void)
Disables interrupts globally.
static void osalSysLockFromISR(void)
Enters a critical zone from ISR context.
void osalMutexLock(mutex_t *mp)
Locks the specified mutex.
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
void osalOsRescheduleS(void)
Checks if a reschedule is required and performs it.
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 osalSysPolledDelayX(rtcnt_t cycles)
Polled delay.
int32_t msg_t
Type of a message.
void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags)
Add flags to an event source object.
void osalEventBroadcastFlags(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 bool osalTimeIsInRangeX(systime_t time, systime_t start, systime_t end)
Checks if the specified time is within the specified time window.
void osalThreadSleepS(sysinterval_t time)
Suspends the invoking thread for the specified time.
static systime_t osalTimeAddX(systime_t systime, sysinterval_t interval)
Adds an interval to a system time returning a system time.
void(* eventcallback_t)(event_source_t *esp)
Type of an event source callback.
uint32_t rtcnt_t
Type of realtime counter.
#define osalDbgCheck(c)
Function parameters check.
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.
volatile eventflags_t flags
Stored event flags.
uint32_t sysinterval_t
Type of system time interval.
systime_t osalOsGetSystemTimeX(void)
Current system time.
void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the queue, if any.
void osalInit(void)
OSAL module initialization.
msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread.
static void osalSysRestoreStatusX(syssts_t sts)
Restores the specified execution status and leaves a critical zone.
void * param
User defined field.
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 osalThreadResumeS(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
static void osalSysLock(void)
Enters a critical zone from thread context.
const char * osal_halt_msg
Pointer to a halt error message.
eventcallback_t cb
Event source callback.
void osalMutexUnlock(mutex_t *mp)
Unlocks the specified mutex.
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.
static void osalSysEnable(void)
Enables interrupts globally.
static void osalThreadQueueObjectInit(threads_queue_t *tqp)
Initializes a threads queue object.