aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/osal/nil/osal.h114
-rw-r--r--os/hal/osal/rt/osal.h60
-rw-r--r--os/hal/templates/osal/osal.h114
3 files changed, 188 insertions, 100 deletions
diff --git a/os/hal/osal/nil/osal.h b/os/hal/osal/nil/osal.h
index 9a8d16d12..6a69a371d 100644
--- a/os/hal/osal/nil/osal.h
+++ b/os/hal/osal/nil/osal.h
@@ -51,8 +51,8 @@
#define TRUE (!FALSE)
#endif
-#define OSAL_SUCCESS FALSE
-#define OSAL_FAILED TRUE
+#define OSAL_SUCCESS false
+#define OSAL_FAILED true
/** @} */
#if 0
@@ -60,9 +60,9 @@
* @name Messages
* @{
*/
-#define MSG_OK RDY_OK
-#define MSG_RESET RDY_RESET
-#define MSG_TIMEOUT RDY_TIMEOUT
+#define MSG_OK (msg_t)0
+#define MSG_TIMEOUT (msg_t)-1
+#define MSG_RESET (msg_t)-2
/** @} */
#endif
@@ -71,8 +71,8 @@
* @name Special time constants
* @{
*/
-#define TIME_IMMEDIATE ((systime_t)0)
-#define TIME_INFINITE ((systime_t)-1)
+#define TIME_IMMEDIATE ((sysinterval_t)0)
+#define TIME_INFINITE ((sysinterval_t)-1)
/** @} */
#endif
@@ -162,6 +162,13 @@ typedef uint32_t systime_t;
#if 0
/**
+ * @brief Type of system time counter.
+ */
+typedef uint32_t sysinterval_t;
+#endif
+
+#if 0
+/**
* @brief Type of realtime counter.
*/
typedef uint32_t rtcnt_t;
@@ -174,6 +181,13 @@ typedef uint32_t rtcnt_t;
typedef thread_t * thread_reference_t;
#endif
+#if 0
+/**
+ * @brief Type of an event flags mask.
+ */
+typedef uint32_t eventflags_t;
+#endif
+
/**
* @brief Type of an event flags object.
* @note The content of this structure is not part of the API and should
@@ -189,14 +203,7 @@ typedef struct event_source event_source_t;
* @note This type is not part of the OSAL API and is provided
* exclusively as an example and for convenience.
*/
-typedef void (*eventcallback_t)(event_source_t *p);
-
-#if 0
-/**
- * @brief Type of an event flags mask.
- */
-typedef uint32_t eventflags_t;
-#endif
+typedef void (*eventcallback_t)(event_source_t *esp);
/**
* @brief Events source object.
@@ -219,7 +226,6 @@ struct event_source {
*/
typedef semaphore_t mutex_t;
-
#if 0
/**
* @brief Type of a thread queue.
@@ -319,36 +325,36 @@ typedef struct {
* @details Converts from seconds to system ticks number.
* @note The result is rounded upward to the next tick boundary.
*
- * @param[in] sec number of seconds
+ * @param[in] secs number of seconds
* @return The number of ticks.
*
* @api
*/
-#define OSAL_S2ST(sec) S2ST(sec)
+#define OSAL_S2I(secs) TIME_S2I(secs)
/**
* @brief Milliseconds to system ticks.
* @details Converts from milliseconds to system ticks number.
* @note The result is rounded upward to the next tick boundary.
*
- * @param[in] msec number of milliseconds
+ * @param[in] msecs number of milliseconds
* @return The number of ticks.
*
* @api
*/
-#define OSAL_MS2ST(msec) MS2ST(msec)
+#define OSAL_MS2I(msecs) TIME_MS2I(msecs)
/**
* @brief Microseconds to system ticks.
* @details Converts from microseconds to system ticks number.
* @note The result is rounded upward to the next tick boundary.
*
- * @param[in] usec number of microseconds
+ * @param[in] usecs number of microseconds
* @return The number of ticks.
*
* @api
*/
-#define OSAL_US2ST(usec) US2ST(usec)
+#define OSAL_US2I(usecs) TIME_US2I(usecs)
/** @} */
/**
@@ -407,11 +413,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
- * @param[in] sec time in seconds, must be different from zero
+ * @param[in] secs time in seconds, must be different from zero
*
* @api
*/
-#define osalThreadSleepSeconds(sec) osalThreadSleep(OSAL_S2ST(sec))
+#define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
/**
* @brief Delays the invoking thread for the specified number of
@@ -420,11 +426,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
- * @param[in] msec time in milliseconds, must be different from zero
+ * @param[in] msecs time in milliseconds, must be different from zero
*
* @api
*/
-#define osalThreadSleepMilliseconds(msec) osalThreadSleep(OSAL_MS2ST(msec))
+#define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
/**
* @brief Delays the invoking thread for the specified number of
@@ -433,11 +439,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
- * @param[in] usec time in microseconds, must be different from zero
+ * @param[in] usecs time in microseconds, must be different from zero
*
* @api
*/
-#define osalThreadSleepMicroseconds(usec) osalThreadSleep(OSAL_US2ST(usec))
+#define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
/** @} */
/*===========================================================================*/
@@ -634,6 +640,35 @@ static inline systime_t osalOsGetSystemTimeX(void) {
}
/**
+ * @brief Adds an interval to a system time returning a system time.
+ *
+ * @param[in] systime base system time
+ * @param[in] interval interval to be added
+ * @return The new system time.
+ *
+ * @xclass
+ */
+static inline systime_t osalTimeAddX(systime_t systime,
+ sysinterval_t interval) {
+
+ return chTimeAddX(systime, interval);
+}
+
+/**
+ * @brief Subtracts two system times returning an interval.
+ *
+ * @param[in] start first system time
+ * @param[in] end second system time
+ * @return The interval representing the time difference.
+ *
+ * @xclass
+ */
+static inline sysinterval_t osalTimeDiffX(systime_t start, systime_t end) {
+
+ return chTimeDiffX(start, end);
+}
+
+/**
* @brief Checks if the specified time is within the specified time window.
* @note When start==end then the function returns always true because the
* whole time range is specified.
@@ -647,11 +682,11 @@ static inline systime_t osalOsGetSystemTimeX(void) {
*
* @xclass
*/
-static inline bool osalOsIsTimeWithinX(systime_t time,
- systime_t start,
- systime_t end) {
+static inline bool osalTimeIsInRangeX(systime_t time,
+ systime_t start,
+ systime_t end) {
- return chVTIsTimeWithinX(time, start, end);
+ return chTimeIsInRangeX(time, start, end);
}
/**
@@ -666,7 +701,7 @@ static inline bool osalOsIsTimeWithinX(systime_t time,
*
* @sclass
*/
-static inline void osalThreadSleepS(systime_t time) {
+static inline void osalThreadSleepS(sysinterval_t time) {
chThdSleepS(time);
}
@@ -683,7 +718,7 @@ static inline void osalThreadSleepS(systime_t time) {
*
* @api
*/
-static inline void osalThreadSleep(systime_t time) {
+static inline void osalThreadSleep(sysinterval_t time) {
chThdSleep(time);
}
@@ -723,7 +758,7 @@ static inline msg_t osalThreadSuspendS(thread_reference_t *trp) {
* @sclass
*/
static inline msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp,
- systime_t timeout) {
+ sysinterval_t timeout) {
return chThdSuspendTimeoutS(trp, timeout);
}
@@ -795,7 +830,7 @@ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
* @sclass
*/
static inline msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp,
- systime_t time) {
+ sysinterval_t time) {
return chThdEnqueueTimeoutS(tqp, time);
}
@@ -827,9 +862,9 @@ static inline void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg) {
}
/**
- * @brief Initializes an event flags object.
+ * @brief Initializes an event source object.
*
- * @param[out] esp pointer to the event flags object
+ * @param[out] esp pointer to the event source object
*
* @init
*/
@@ -837,7 +872,7 @@ static inline void osalEventObjectInit(event_source_t *esp) {
osalDbgCheck(esp != NULL);
- esp->flags = 0;
+ esp->flags = (eventflags_t)0;
esp->cb = NULL;
esp->param = NULL;
}
@@ -878,6 +913,7 @@ static inline void osalEventBroadcastFlags(event_source_t *esp,
esp->flags |= flags;
if (esp->cb != NULL) {
esp->cb(esp);
+ }
chSysUnlock();
}
diff --git a/os/hal/osal/rt/osal.h b/os/hal/osal/rt/osal.h
index c81edef4f..b8151c15c 100644
--- a/os/hal/osal/rt/osal.h
+++ b/os/hal/osal/rt/osal.h
@@ -47,8 +47,8 @@
#define TRUE (!FALSE)
#endif
-#define OSAL_SUCCESS FALSE
-#define OSAL_FAILED TRUE
+#define OSAL_SUCCESS false
+#define OSAL_FAILED true
/** @} */
#if 0
@@ -56,9 +56,9 @@
* @name Messages
* @{
*/
-#define MSG_OK RDY_OK
-#define MSG_RESET RDY_RESET
-#define MSG_TIMEOUT RDY_TIMEOUT
+#define MSG_OK (msg_t)0
+#define MSG_TIMEOUT (msg_t)-1
+#define MSG_RESET (msg_t)-2
/** @} */
#endif
@@ -176,7 +176,7 @@ typedef thread_t * thread_reference_t;
typedef uint32_t eventflags_t;
#endif
-#if !CH_CFG_USE_EVENTS
+#if (CH_CFG_USE_EVENTS == FALSE) || defined(__DOXYGEN__)
/**
* @brief Type of an event flags object.
* @note The content of this structure is not part of the API and should
@@ -185,12 +185,29 @@ typedef uint32_t eventflags_t;
* @note Retrieval and clearing of the flags are not defined in this
* API and are implementation-dependent.
*/
-typedef struct {
+typedef struct event_source event_source_t;
+
+/**
+ * @brief Type of an event source callback.
+ * @note This type is not part of the OSAL API and is provided
+ * exclusively as an example and for convenience.
+ */
+typedef void (*eventcallback_t)(event_source_t *esp);
+
+/**
+ * @brief Events source object.
+ * @note The content of this structure is not part of the API and should
+ * not be relied upon. Implementers may define this structure in
+ * an entirely different way.
+ * @note Retrieval and clearing of the flags are not defined in this
+ * API and are implementation-dependent.
+ */
+struct event_source {
volatile eventflags_t flags; /**< @brief Stored event flags. */
eventcallback_t cb; /**< @brief Event source callback. */
void *param; /**< @brief User defined field. */
-} event_source_t;
-#endif
+};
+#endif /* CH_CFG_USE_EVENTS == FALSE */
/**
* @brief Type of a mutex.
@@ -221,13 +238,6 @@ typedef struct {
/* Module macros. */
/*===========================================================================*/
-/* Temporary names provided for ChibiOS 2.x compatibility.*/
-#define osalQueueInit osalThreadQueueObjectInit
-#define osalQueueWakeupAllI osalThreadDequeueAllI
-#define osalQueueWakeupOneI osalThreadDequeueNextI
-#define osalQueueGoSleepTimeoutS osalThreadEnqueueTimeoutS
-#define osalEventInit osalEventObjectInit
-
/**
* @name Debug related macros
* @{
@@ -575,7 +585,7 @@ static inline void osalSysRestoreStatusX(syssts_t sts) {
*
* @xclass
*/
-#if PORT_SUPPORTS_RT || defined(__DOXYGEN__)
+#if (PORT_SUPPORTS_RT == TRUE) || defined(__DOXYGEN__)
static inline void osalSysPolledDelayX(rtcnt_t cycles) {
chSysPolledDelayX(cycles);
@@ -722,7 +732,7 @@ static inline void osalThreadSleep(sysinterval_t delay) {
*/
static inline msg_t osalThreadSuspendS(thread_reference_t *trp) {
- return chThdSuspendS(trp);
+ return chThdSuspendTimeoutS(trp, TIME_INFINITE);
}
/**
@@ -847,11 +857,11 @@ static inline void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg) {
chThdDequeueAllI(tqp, msg);
}
-#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
+#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Initializes an event flags object.
+ * @brief Initializes an event source object.
*
- * @param[out] esp pointer to the event flags object
+ * @param[out] esp pointer to the event source object
*
* @init
*/
@@ -864,13 +874,13 @@ static inline void osalEventObjectInit(osal_event_source_t *esp) {
osalDbgCheck(esp != NULL);
- esp->flags = 0;
+ esp->flags = (eventflags_t)0;
esp->cb = NULL;
esp->param = NULL;
}
#endif
-#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
+#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
/**
* @brief Add flags to an event source object.
*
@@ -897,7 +907,7 @@ static inline void osalEventBroadcastFlagsI(event_source_t *esp,
}
#endif
-#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
+#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
/**
* @brief Add flags to an event source object.
*
@@ -925,7 +935,7 @@ static inline void osalEventBroadcastFlags(event_source_t *esp,
}
#endif
-#if !CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
+#if (CH_CFG_USE_EVENTS == FALSE) || defined(__DOXYGEN__)
/**
* @brief Event callback setup.
* @note The callback is invoked from ISR context and can
diff --git a/os/hal/templates/osal/osal.h b/os/hal/templates/osal/osal.h
index 166cc3983..e6a4ddc7d 100644
--- a/os/hal/templates/osal/osal.h
+++ b/os/hal/templates/osal/osal.h
@@ -42,7 +42,7 @@
#endif
#if !defined(TRUE) || defined(__DOXYGEN__)
-#define TRUE 1
+#define TRUE (!FALSE)
#endif
#define OSAL_SUCCESS false
@@ -54,8 +54,8 @@
* @{
*/
#define MSG_OK (msg_t)0
-#define MSG_RESET (msg_t)-1
-#define MSG_TIMEOUT (msg_t)-2
+#define MSG_TIMEOUT (msg_t)-1
+#define MSG_RESET (msg_t)-2
/** @} */
@@ -63,8 +63,8 @@
* @name Special time constants
* @{
*/
-#define TIME_IMMEDIATE ((systime_t)0)
-#define TIME_INFINITE ((systime_t)-1)
+#define TIME_IMMEDIATE ((sysinterval_t)0)
+#define TIME_INFINITE ((sysinterval_t)-1)
/** @} */
/**
@@ -135,6 +135,16 @@
/* Derived constants and error checks. */
/*===========================================================================*/
+#if !(OSAL_ST_MODE == OSAL_ST_MODE_NONE) && \
+ !(OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) && \
+ !(OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING)
+#error "invalid OSAL_ST_MODE setting in osal.h"
+#endif
+
+#if (OSAL_ST_RESOLUTION != 16) && (OSAL_ST_RESOLUTION != 32)
+#error "invalid OSAL_ST_RESOLUTION, must be 16 or 32"
+#endif
+
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
@@ -155,6 +165,11 @@ typedef int32_t msg_t;
typedef uint32_t systime_t;
/**
+ * @brief Type of system time counter.
+ */
+typedef uint32_t sysinterval_t;
+
+/**
* @brief Type of realtime counter.
*/
typedef uint32_t rtcnt_t;
@@ -165,6 +180,11 @@ typedef uint32_t rtcnt_t;
typedef void * thread_reference_t;
/**
+ * @brief Type of an event flags mask.
+ */
+typedef uint32_t eventflags_t;
+
+/**
* @brief Type of an event flags object.
* @note The content of this structure is not part of the API and should
* not be relied upon. Implementers may define this structure in
@@ -182,11 +202,6 @@ typedef struct event_source event_source_t;
typedef void (*eventcallback_t)(event_source_t *esp);
/**
- * @brief Type of an event flags mask.
- */
-typedef uint32_t eventflags_t;
-
-/**
* @brief Events source object.
* @note The content of this structure is not part of the API and should
* not be relied upon. Implementers may define this structure in
@@ -250,7 +265,6 @@ typedef struct {
} \
} while (false)
-
/**
* @brief Function parameters check.
* @details If the condition check fails then the OSAL panics and halts.
@@ -271,7 +285,6 @@ typedef struct {
} \
} while (false)
-
/**
* @brief I-Class state check.
* @note Implementation is optional.
@@ -325,26 +338,26 @@ typedef struct {
* @details Converts from seconds to system ticks number.
* @note The result is rounded upward to the next tick boundary.
*
- * @param[in] sec number of seconds
+ * @param[in] secs number of seconds
* @return The number of ticks.
*
* @api
*/
-#define OSAL_S2ST(sec) \
- ((systime_t)((uint32_t)(sec) * (uint32_t)OSAL_ST_FREQUENCY))
+#define OSAL_S2I(secs) \
+ ((systime_t)((uint32_t)(secs) * (uint32_t)OSAL_ST_FREQUENCY))
/**
* @brief Milliseconds to system ticks.
* @details Converts from milliseconds to system ticks number.
* @note The result is rounded upward to the next tick boundary.
*
- * @param[in] msec number of milliseconds
+ * @param[in] msecs number of milliseconds
* @return The number of ticks.
*
* @api
*/
-#define OSAL_MS2ST(msec) \
- ((systime_t)((((((uint32_t)(msec)) * \
+#define OSAL_MS2I(msecs) \
+ ((systime_t)((((((uint32_t)(msecs)) * \
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL))
/**
@@ -352,13 +365,13 @@ typedef struct {
* @details Converts from microseconds to system ticks number.
* @note The result is rounded upward to the next tick boundary.
*
- * @param[in] usec number of microseconds
+ * @param[in] usecs number of microseconds
* @return The number of ticks.
*
* @api
*/
-#define OSAL_US2ST(usec) \
- ((systime_t)((((((uint32_t)(usec)) * \
+#define OSAL_US2I(usecs) \
+ ((systime_t)((((((uint32_t)(usecs)) * \
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL))
/** @} */
@@ -418,11 +431,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
- * @param[in] sec time in seconds, must be different from zero
+ * @param[in] secs time in seconds, must be different from zero
*
* @api
*/
-#define osalThreadSleepSeconds(sec) osalThreadSleep(OSAL_S2ST(sec))
+#define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
/**
* @brief Delays the invoking thread for the specified number of
@@ -431,11 +444,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
- * @param[in] msec time in milliseconds, must be different from zero
+ * @param[in] msecs time in milliseconds, must be different from zero
*
* @api
*/
-#define osalThreadSleepMilliseconds(msec) osalThreadSleep(OSAL_MS2ST(msec))
+#define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
/**
* @brief Delays the invoking thread for the specified number of
@@ -444,11 +457,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
- * @param[in] usec time in microseconds, must be different from zero
+ * @param[in] usecs time in microseconds, must be different from zero
*
* @api
*/
-#define osalThreadSleepMicroseconds(usec) osalThreadSleep(OSAL_US2ST(usec))
+#define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
/** @} */
/*===========================================================================*/
@@ -466,13 +479,13 @@ extern "C" {
void osalOsTimerHandlerI(void);
void osalOsRescheduleS(void);
systime_t osalOsGetSystemTimeX(void);
- void osalThreadSleepS(systime_t time);
- void osalThreadSleep(systime_t time);
+ void osalThreadSleepS(sysinterval_t time);
+ void osalThreadSleep(sysinterval_t time);
msg_t osalThreadSuspendS(thread_reference_t *trp);
- msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, systime_t timeout);
+ msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout);
void osalThreadResumeI(thread_reference_t *trp, msg_t msg);
void osalThreadResumeS(thread_reference_t *trp, msg_t msg);
- msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout);
+ msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout);
void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg);
void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg);
void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags);
@@ -581,6 +594,35 @@ static inline void osalSysRestoreStatusX(syssts_t sts) {
}
/**
+ * @brief Adds an interval to a system time returning a system time.
+ *
+ * @param[in] systime base system time
+ * @param[in] interval interval to be added
+ * @return The new system time.
+ *
+ * @xclass
+ */
+static inline systime_t osalTimeAddX(systime_t systime,
+ sysinterval_t interval) {
+
+ return systime + (systime_t)interval;
+}
+
+/**
+ * @brief Subtracts two system times returning an interval.
+ *
+ * @param[in] start first system time
+ * @param[in] end second system time
+ * @return The interval representing the time difference.
+ *
+ * @xclass
+ */
+static inline sysinterval_t osalTimeDiffX(systime_t start, systime_t end) {
+
+ return (sysinterval_t)((systime_t)(end - start));
+}
+
+/**
* @brief Checks if the specified time is within the specified time window.
* @note When start==end then the function returns always true because the
* whole time range is specified.
@@ -594,9 +636,9 @@ static inline void osalSysRestoreStatusX(syssts_t sts) {
*
* @xclass
*/
-static inline bool osalOsIsTimeWithinX(systime_t time,
- systime_t start,
- systime_t end) {
+static inline bool osalTimeIsInRangeX(systime_t time,
+ systime_t start,
+ systime_t end) {
return (bool)((time - start) < (end - start));
}
@@ -614,9 +656,9 @@ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
}
/**
- * @brief Initializes an event flags object.
+ * @brief Initializes an event source object.
*
- * @param[out] esp pointer to the event flags object
+ * @param[out] esp pointer to the event source object
*
* @init
*/