Updated OS-less osal for Cortex-M.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10948 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
d37c7dbd2d
commit
47b464519d
|
@ -99,8 +99,8 @@ include $(CHIBIOS)/os/hal/osal/os-less/ARMCMx/osal.mk
|
|||
#include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
|
||||
# Other files (optional).
|
||||
#include $(CHIBIOS)/test/lib/test.mk
|
||||
include $(CHIBIOS)/test/rt/rt_test.mk
|
||||
include $(CHIBIOS)/test/oslib/oslib_test.mk
|
||||
#include $(CHIBIOS)/test/rt/rt_test.mk
|
||||
#include $(CHIBIOS)/test/oslib/oslib_test.mk
|
||||
|
||||
# Define linker script file here
|
||||
LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld
|
||||
|
|
|
@ -66,7 +66,7 @@ void vtInit(void) {
|
|||
|
||||
/* Virtual Timers initialization.*/
|
||||
vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist;
|
||||
vtlist.vt_time = (systime_t)-1;
|
||||
vtlist.vt_delta = (sysinterval_t)-1;
|
||||
vtlist.vt_systime = 0;
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,8 @@ void vtDoTickI(void) {
|
|||
if (&vtlist != (virtual_timers_list_t *)vtlist.vt_next) {
|
||||
virtual_timer_t *vtp;
|
||||
|
||||
--vtlist.vt_next->vt_time;
|
||||
while (!(vtp = vtlist.vt_next)->vt_time) {
|
||||
--vtlist.vt_next->vt_delta;
|
||||
while (!(vtp = vtlist.vt_next)->vt_delta) {
|
||||
vtfunc_t fn = vtp->vt_func;
|
||||
vtp->vt_func = (vtfunc_t)NULL;
|
||||
vtp->vt_next->vt_prev = (void *)&vtlist;
|
||||
|
@ -115,7 +115,7 @@ void vtDoTickI(void) {
|
|||
* @note The associated function is invoked from interrupt context.
|
||||
*
|
||||
* @param[out] vtp the @p virtual_timer_t structure pointer
|
||||
* @param[in] time the number of ticks before the operation timeouts, the
|
||||
* @param[in] timeout the number of ticks before the operation timeouts, the
|
||||
* special values are handled as follow:
|
||||
* - @a TIME_INFINITE is allowed but interpreted as a
|
||||
* normal time specification.
|
||||
|
@ -129,23 +129,23 @@ void vtDoTickI(void) {
|
|||
*
|
||||
* @iclass
|
||||
*/
|
||||
void vtSetI(virtual_timer_t *vtp, systime_t time,
|
||||
void vtSetI(virtual_timer_t *vtp, sysinterval_t timeout,
|
||||
vtfunc_t vtfunc, void *par) {
|
||||
virtual_timer_t *p;
|
||||
|
||||
vtp->vt_par = par;
|
||||
vtp->vt_func = vtfunc;
|
||||
p = vtlist.vt_next;
|
||||
while (p->vt_time < time) {
|
||||
time -= p->vt_time;
|
||||
while (p->vt_delta < timeout) {
|
||||
timeout -= p->vt_delta;
|
||||
p = p->vt_next;
|
||||
}
|
||||
|
||||
vtp->vt_prev = (vtp->vt_next = p)->vt_prev;
|
||||
vtp->vt_prev->vt_next = p->vt_prev = vtp;
|
||||
vtp->vt_time = time;
|
||||
vtp->vt_delta = timeout;
|
||||
if (p != (void *)&vtlist)
|
||||
p->vt_time -= time;
|
||||
p->vt_delta -= timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,7 +159,7 @@ void vtSetI(virtual_timer_t *vtp, systime_t time,
|
|||
void vtResetI(virtual_timer_t *vtp) {
|
||||
|
||||
if (vtp->vt_next != (void *)&vtlist)
|
||||
vtp->vt_next->vt_time += vtp->vt_time;
|
||||
vtp->vt_next->vt_delta += vtp->vt_delta;
|
||||
vtp->vt_prev->vt_next = vtp->vt_next;
|
||||
vtp->vt_next->vt_prev = vtp->vt_prev;
|
||||
vtp->vt_func = (vtfunc_t)NULL;
|
||||
|
|
|
@ -29,14 +29,6 @@
|
|||
/* Module constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Special time constants
|
||||
* @{
|
||||
*/
|
||||
#define TIME_IMMEDIATE ((systime_t)0)
|
||||
#define TIME_INFINITE ((systime_t)-1)
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
@ -73,7 +65,7 @@ typedef struct {
|
|||
list. */
|
||||
virtual_timer_t *vt_prev; /**< @brief Last timer in the timers
|
||||
list. */
|
||||
systime_t vt_time; /**< @brief Must be initialized to -1. */
|
||||
sysinterval_t vt_delta; /**< @brief Must be initialized to -1. */
|
||||
volatile systime_t vt_systime; /**< @brief System Time counter. */
|
||||
} virtual_timers_list_t;
|
||||
|
||||
|
@ -90,7 +82,7 @@ struct virtual_timer {
|
|||
list. */
|
||||
virtual_timer_t *vt_prev; /**< @brief Previous timer in the timers
|
||||
list. */
|
||||
systime_t vt_time; /**< @brief Time delta before timeout. */
|
||||
sysinterval_t vt_delta; /**< @brief Time delta before timeout. */
|
||||
vtfunc_t vt_func; /**< @brief Timer callback function
|
||||
pointer. */
|
||||
void *vt_par; /**< @brief Timer callback function
|
||||
|
@ -115,7 +107,7 @@ extern "C" {
|
|||
void vtInit(void);
|
||||
bool vtIsArmedI(virtual_timer_t *vtp);
|
||||
void vtDoTickI(void);
|
||||
void vtSetI(virtual_timer_t *vtp, systime_t time,
|
||||
void vtSetI(virtual_timer_t *vtp, sysinterval_t timeout,
|
||||
vtfunc_t vtfunc, void *par);
|
||||
void vtResetI(virtual_timer_t *vtp);
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#endif
|
||||
|
||||
#if !defined(TRUE) || defined(__DOXYGEN__)
|
||||
#define TRUE 1
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
#define OSAL_SUCCESS false
|
||||
|
@ -67,8 +67,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)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -176,6 +176,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.
|
||||
*/
|
||||
|
@ -196,6 +201,11 @@ typedef struct {
|
|||
*/
|
||||
typedef thread_t * 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
|
||||
|
@ -213,11 +223,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
|
||||
|
@ -282,7 +287,6 @@ typedef struct {
|
|||
} \
|
||||
} while (false)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function parameters check.
|
||||
* @details If the condition check fails then the OSAL panics and halts.
|
||||
|
@ -303,7 +307,6 @@ typedef struct {
|
|||
} \
|
||||
} while (false)
|
||||
|
||||
|
||||
/**
|
||||
* @brief I-Class state check.
|
||||
* @note Implementation is optional.
|
||||
|
@ -357,41 +360,41 @@ 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)) * \
|
||||
((uint32_t)OSAL_ST_FREQUENCY) + 999UL) / 1000UL))
|
||||
#define OSAL_MS2I(msecs) \
|
||||
((systime_t)((((((uint32_t)(msecs)) * \
|
||||
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL))
|
||||
|
||||
/**
|
||||
* @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) \
|
||||
((systime_t)((((uint32_t)(usec)) * \
|
||||
((uint32_t)OSAL_ST_FREQUENCY) + 999999UL) / 1000000UL))
|
||||
#define OSAL_US2I(usecs) \
|
||||
((systime_t)((((((uint32_t)(usecs)) * \
|
||||
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -450,11 +453,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
|
||||
|
@ -463,11 +466,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
|
||||
|
@ -476,11 +479,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))
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -498,13 +501,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);
|
||||
|
@ -595,11 +598,6 @@ static inline void osalSysLockFromISR(void) {
|
|||
*/
|
||||
static inline void osalSysUnlockFromISR(void) {
|
||||
|
||||
#if CORTEX_MODEL == 0
|
||||
__enable_irq();
|
||||
#else
|
||||
__set_BASEPRI(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -650,6 +648,35 @@ static inline void osalSysRestoreStatusX(syssts_t sts) {
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
@ -664,9 +691,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));
|
||||
}
|
||||
|
@ -681,14 +708,12 @@ static inline bool osalOsIsTimeWithinX(systime_t time,
|
|||
static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
|
||||
|
||||
osalDbgCheck(tqp != NULL);
|
||||
|
||||
(void)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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue