Still work in progress.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5996 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
gdisirio 2013-07-19 13:17:42 +00:00
parent 84e044f176
commit d58064a533
16 changed files with 567 additions and 304 deletions

View File

@ -53,14 +53,34 @@
#if CH_USE_SEMAPHORES || defined(__DOXYGEN__) #if CH_USE_SEMAPHORES || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
/** /**
* @extends Semaphore * @extends semaphore_t
* *
* @brief Binary semaphore type. * @brief Binary semaphore type.
*/ */
typedef struct { typedef struct {
Semaphore bs_sem; semaphore_t bs_sem;
} BinarySemaphore; } binary_semaphore_t;
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/** /**
* @brief Data part of a static semaphore initializer. * @brief Data part of a static semaphore initializer.
@ -82,16 +102,20 @@ typedef struct {
* @param[in] taken the semaphore initial state * @param[in] taken the semaphore initial state
*/ */
#define BSEMAPHORE_DECL(name, taken) \ #define BSEMAPHORE_DECL(name, taken) \
BinarySemaphore name = _BSEMAPHORE_DATA(name, taken) binary_semaphore_t name = _BSEMAPHORE_DATA(name, taken)
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
/**
* @name Macro Functions
* @{
*/
/** /**
* @brief Initializes a binary semaphore. * @brief Initializes a binary semaphore.
* *
* @param[out] bsp pointer to a @p BinarySemaphore structure * @param[out] bsp pointer to a @p binary_semaphore_t structure
* @param[in] taken initial state of the binary semaphore: * @param[in] taken initial state of the binary semaphore:
* - @a FALSE, the initial state is not taken. * - @a FALSE, the initial state is not taken.
* - @a TRUE, the initial state is taken. * - @a TRUE, the initial state is taken.
@ -99,12 +123,15 @@ typedef struct {
* *
* @init * @init
*/ */
#define chBSemInit(bsp, taken) chSemInit(&(bsp)->bs_sem, (taken) ? 0 : 1) static inline void chBSemInit(binary_semaphore_t *bsp, bool taken) {
chSemInit(&bsp->bs_sem, taken ? 0 : 1);
}
/** /**
* @brief Wait operation on the binary semaphore. * @brief Wait operation on the binary semaphore.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the semaphore. * released from the semaphore.
* @retval RDY_OK if the binary semaphore has been successfully taken. * @retval RDY_OK if the binary semaphore has been successfully taken.
@ -113,12 +140,15 @@ typedef struct {
* *
* @api * @api
*/ */
#define chBSemWait(bsp) chSemWait(&(bsp)->bs_sem) static inline msg_t chBSemWait(binary_semaphore_t *bsp) {
return chSemWait(&bsp->bs_sem);
}
/** /**
* @brief Wait operation on the binary semaphore. * @brief Wait operation on the binary semaphore.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the semaphore. * released from the semaphore.
* @retval RDY_OK if the binary semaphore has been successfully taken. * @retval RDY_OK if the binary semaphore has been successfully taken.
@ -127,33 +157,17 @@ typedef struct {
* *
* @sclass * @sclass
*/ */
#define chBSemWaitS(bsp) chSemWaitS(&(bsp)->bs_sem) static inline msg_t chBSemWaitS(binary_semaphore_t *bsp) {
chDbgCheckClassS();
return chSemWaitS(&bsp->bs_sem);
}
/** /**
* @brief Wait operation on the binary semaphore. * @brief Wait operation on the binary semaphore.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* @return A message specifying how the invoking thread has been
* released from the semaphore.
* @retval RDY_OK if the binary semaphore has been successfully taken.
* @retval RDY_RESET if the binary semaphore has been reset using
* @p bsemReset().
* @retval RDY_TIMEOUT if the binary semaphore has not been signaled or reset
* within the specified timeout.
*
* @api
*/
#define chBSemWaitTimeout(bsp, time) chSemWaitTimeout(&(bsp)->bs_sem, (time))
/**
* @brief Wait operation on the binary semaphore.
*
* @param[in] bsp pointer to a @p BinarySemaphore structure
* @param[in] time the number of ticks before the operation timeouts, * @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed: * the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_IMMEDIATE immediate timeout.
@ -169,23 +183,38 @@ typedef struct {
* *
* @sclass * @sclass
*/ */
#define chBSemWaitTimeoutS(bsp, time) chSemWaitTimeoutS(&(bsp)->bs_sem, (time)) static inline msg_t chBSemWaitTimeoutS(binary_semaphore_t *bsp,
systime_t time) {
chDbgCheckClassS();
return chSemWaitTimeoutS(&bsp->bs_sem, time);
}
/** /**
* @brief Reset operation on the binary semaphore. * @brief Wait operation on the binary semaphore.
* @note The released threads can recognize they were waked up by a reset
* rather than a signal because the @p bsemWait() will return
* @p RDY_RESET instead of @p RDY_OK.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* @param[in] taken new state of the binary semaphore * @param[in] time the number of ticks before the operation timeouts,
* - @a FALSE, the new state is not taken. * the following special values are allowed:
* - @a TRUE, the new state is taken. * - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* . * .
* @return A message specifying how the invoking thread has been
* released from the semaphore.
* @retval RDY_OK if the binary semaphore has been successfully taken.
* @retval RDY_RESET if the binary semaphore has been reset using
* @p bsemReset().
* @retval RDY_TIMEOUT if the binary semaphore has not been signaled or reset
* within the specified timeout.
* *
* @api * @api
*/ */
#define chBSemReset(bsp, taken) chSemReset(&(bsp)->bs_sem, (taken) ? 0 : 1) static inline msg_t chBSemWaitTimeout(binary_semaphore_t *bsp,
systime_t time) {
return chSemWaitTimeout(&bsp->bs_sem, time);
}
/** /**
* @brief Reset operation on the binary semaphore. * @brief Reset operation on the binary semaphore.
@ -194,7 +223,7 @@ typedef struct {
* @p RDY_RESET instead of @p RDY_OK. * @p RDY_RESET instead of @p RDY_OK.
* @note This function does not reschedule. * @note This function does not reschedule.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* @param[in] taken new state of the binary semaphore * @param[in] taken new state of the binary semaphore
* - @a FALSE, the new state is not taken. * - @a FALSE, the new state is not taken.
* - @a TRUE, the new state is taken. * - @a TRUE, the new state is taken.
@ -202,47 +231,79 @@ typedef struct {
* *
* @iclass * @iclass
*/ */
#define chBSemResetI(bsp, taken) chSemResetI(&(bsp)->bs_sem, (taken) ? 0 : 1) static inline void chBSemResetI(binary_semaphore_t *bsp, bool taken) {
chDbgCheckClassI();
chSemResetI(&bsp->bs_sem, taken ? 0 : 1);
}
/** /**
* @brief Performs a signal operation on a binary semaphore. * @brief Reset operation on the binary semaphore.
* @note The released threads can recognize they were waked up by a reset
* rather than a signal because the @p bsemWait() will return
* @p RDY_RESET instead of @p RDY_OK.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* @param[in] taken new state of the binary semaphore
* - @a FALSE, the new state is not taken.
* - @a TRUE, the new state is taken.
* .
* *
* @api * @api
*/ */
#define chBSemSignal(bsp) { \ static inline void chBSemReset(binary_semaphore_t *bsp, bool taken) {
chSysLock(); \
chBSemSignalI((bsp)); \ chSemReset(&bsp->bs_sem, taken ? 0 : 1);
chSchRescheduleS(); \
chSysUnlock(); \
} }
/** /**
* @brief Performs a signal operation on a binary semaphore. * @brief Performs a signal operation on a binary semaphore.
* @note This function does not reschedule. * @note This function does not reschedule.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* *
* @iclass * @iclass
*/ */
#define chBSemSignalI(bsp) { \ static inline void chBSemSignalI(binary_semaphore_t *bsp) {
if ((bsp)->bs_sem.s_cnt < 1) \
chSemSignalI(&(bsp)->bs_sem); \ chDbgCheckClassI();
if (bsp->bs_sem.s_cnt < 1)
chSemSignalI(&bsp->bs_sem);
}
/**
* @brief Performs a signal operation on a binary semaphore.
*
* @param[in] bsp pointer to a @p binary_semaphore_t structure
*
* @api
*/
static inline void chBSemSignal(binary_semaphore_t *bsp) {
chSysLock();
chBSemSignalI(bsp);
chSchRescheduleS();
chSysUnlock();
} }
/** /**
* @brief Returns the binary semaphore current state. * @brief Returns the binary semaphore current state.
* *
* @param[in] bsp pointer to a @p BinarySemaphore structure * @param[in] bsp pointer to a @p binary_semaphore_t structure
* @return The binary semaphore current state. * @return The binary semaphore current state.
* @retval FALSE if the binary semaphore is not taken. * @retval FALSE if the binary semaphore is not taken.
* @retval TRUE if the binary semaphore is taken. * @retval TRUE if the binary semaphore is taken.
* *
* @iclass * @iclass
*/ */
#define chBSemGetStateI(bsp) ((bsp)->bs_sem.s_cnt > 0 ? FALSE : TRUE) static inline bool chBSemGetStateI(binary_semaphore_t *bsp) {
/** @} */
chDbgCheckClassI();
return bsp->bs_sem.s_cnt > 0 ? FALSE : TRUE;
}
#endif /* CH_USE_SEMAPHORES */ #endif /* CH_USE_SEMAPHORES */

View File

@ -34,37 +34,37 @@
#if CH_USE_CONDVARS || defined(__DOXYGEN__) #if CH_USE_CONDVARS || defined(__DOXYGEN__)
/* /*===========================================================================*/
* Module dependencies check. /* Module constants. */
*/ /*===========================================================================*/
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
#if !CH_USE_MUTEXES #if !CH_USE_MUTEXES
#error "CH_USE_CONDVARS requires CH_USE_MUTEXES" #error "CH_USE_CONDVARS requires CH_USE_MUTEXES"
#endif #endif
/** /*===========================================================================*/
* @brief CondVar structure. /* Module data structures and types. */
*/ /*===========================================================================*/
typedef struct CondVar {
threads_queue_t c_queue; /**< @brief CondVar threads queue.*/
} CondVar;
#ifdef __cplusplus /**
extern "C" { * @brief condition_variable_t structure.
#endif */
void chCondInit(CondVar *cp); typedef struct condition_variable {
void chCondSignal(CondVar *cp); threads_queue_t c_queue; /**< @brief Condition variable
void chCondSignalI(CondVar *cp); threads queue. */
void chCondBroadcast(CondVar *cp); } condition_variable_t;
void chCondBroadcastI(CondVar *cp);
msg_t chCondWait(CondVar *cp); /*===========================================================================*/
msg_t chCondWaitS(CondVar *cp); /* Module macros. */
#if CH_USE_CONDVARS_TIMEOUT /*===========================================================================*/
msg_t chCondWaitTimeout(CondVar *cp, systime_t time);
msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time);
#endif
#ifdef __cplusplus
}
#endif
/** /**
* @brief Data part of a static condition variable initializer. * @brief Data part of a static condition variable initializer.
@ -82,7 +82,33 @@ extern "C" {
* *
* @param[in] name the name of the condition variable * @param[in] name the name of the condition variable
*/ */
#define CONDVAR_DECL(name) CondVar name = _CONDVAR_DATA(name) #define CONDVAR_DECL(name) condition_variable_t name = _CONDVAR_DATA(name)
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
void chCondInit(condition_variable_t *cp);
void chCondSignal(condition_variable_t *cp);
void chCondSignalI(condition_variable_t *cp);
void chCondBroadcast(condition_variable_t *cp);
void chCondBroadcastI(condition_variable_t *cp);
msg_t chCondWait(condition_variable_t *cp);
msg_t chCondWaitS(condition_variable_t *cp);
#if CH_USE_CONDVARS_TIMEOUT
msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time);
msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time);
#endif
#ifdef __cplusplus
}
#endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
#endif /* CH_USE_CONDVARS */ #endif /* CH_USE_CONDVARS */

View File

@ -31,6 +31,18 @@
#if CH_USE_DYNAMIC || defined(__DOXYGEN__) #if CH_USE_DYNAMIC || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/* /*
* Module dependencies check. * Module dependencies check.
*/ */
@ -41,6 +53,18 @@
#error "CH_USE_DYNAMIC requires CH_USE_HEAP and/or CH_USE_MEMPOOLS" #error "CH_USE_DYNAMIC requires CH_USE_HEAP and/or CH_USE_MEMPOOLS"
#endif #endif
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
/* /*
* Dynamic threads APIs. * Dynamic threads APIs.
*/ */
@ -61,6 +85,10 @@ extern "C" {
} }
#endif #endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
#endif /* CH_USE_DYNAMIC */ #endif /* CH_USE_DYNAMIC */
#endif /* _CHDYNAMIC_H_ */ #endif /* _CHDYNAMIC_H_ */

View File

@ -34,6 +34,22 @@
#if CH_USE_EVENTS || defined(__DOXYGEN__) #if CH_USE_EVENTS || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
typedef struct EventListener EventListener; typedef struct EventListener EventListener;
/** /**
@ -66,6 +82,20 @@ typedef struct EventSource {
*/ */
typedef void (*evhandler_t)(eventid_t); typedef void (*evhandler_t)(eventid_t);
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/**
* @brief All events allowed mask.
*/
#define ALL_EVENTS ((eventmask_t)-1)
/**
* @brief Returns an event mask from an event identifier.
*/
#define EVENT_MASK(eid) ((eventmask_t)(1 << (eid)))
/** /**
* @brief Data part of a static event source initializer. * @brief Data part of a static event source initializer.
* @details This macro should be used when statically initializing an event * @details This macro should be used when statically initializing an event
@ -83,84 +113,9 @@ typedef void (*evhandler_t)(eventid_t);
*/ */
#define EVENTSOURCE_DECL(name) EventSource name = _EVENTSOURCE_DATA(name) #define EVENTSOURCE_DECL(name) EventSource name = _EVENTSOURCE_DATA(name)
/** /*===========================================================================*/
* @brief All events allowed mask. /* External declarations. */
*/ /*===========================================================================*/
#define ALL_EVENTS ((eventmask_t)-1)
/**
* @brief Returns an event mask from an event identifier.
*/
#define EVENT_MASK(eid) ((eventmask_t)(1 << (eid)))
/**
* @name Macro Functions
* @{
*/
/**
* @brief Registers an Event Listener on an Event Source.
* @note Multiple Event Listeners can use the same event identifier, the
* listener will share the callback function.
*
* @param[in] esp pointer to the @p EventSource structure
* @param[out] elp pointer to the @p EventListener structure
* @param[in] eid numeric identifier assigned to the Event Listener. The
* identifier is used as index for the event callback
* function.
* The value must range between zero and the size, in bit,
* of the @p eventid_t type minus one.
*
* @api
*/
#define chEvtRegister(esp, elp, eid) \
chEvtRegisterMask(esp, elp, EVENT_MASK(eid))
/**
* @brief Initializes an Event Source.
* @note This function can be invoked before the kernel is initialized
* because it just prepares a @p EventSource structure.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @init
*/
#define chEvtInit(esp) \
((esp)->es_next = (EventListener *)(void *)(esp))
/**
* @brief Verifies if there is at least one @p EventListener registered.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @iclass
*/
#define chEvtIsListeningI(esp) \
((void *)(esp) != (void *)(esp)->es_next)
/**
* @brief Signals all the Event Listeners registered on the specified Event
* Source.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @api
*/
#define chEvtBroadcast(esp) chEvtBroadcastFlags(esp, 0)
/**
* @brief Signals all the Event Listeners registered on the specified Event
* Source.
* @post This function does not reschedule so a call to a rescheduling
* function must be performed before unlocking the kernel. Note that
* interrupt handlers always reschedule on exit so an explicit
* reschedule must not be performed in ISRs.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @iclass
*/
#define chEvtBroadcastI(esp) chEvtBroadcastFlagsI(esp, 0)
/** @} */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -198,6 +153,88 @@ extern "C" {
#define chEvtWaitAll(mask) chEvtWaitAllTimeout(mask, TIME_INFINITE) #define chEvtWaitAll(mask) chEvtWaitAllTimeout(mask, TIME_INFINITE)
#endif #endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
/**
* @brief Initializes an Event Source.
* @note This function can be invoked before the kernel is initialized
* because it just prepares a @p EventSource structure.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @init
*/
static inline void chEvtInit(EventSource *esp) {
esp->es_next = (EventListener *)(void *)esp;
}
/**
* @brief Registers an Event Listener on an Event Source.
* @note Multiple Event Listeners can use the same event identifier, the
* listener will share the callback function.
*
* @param[in] esp pointer to the @p EventSource structure
* @param[out] elp pointer to the @p EventListener structure
* @param[in] eid numeric identifier assigned to the Event Listener. The
* identifier is used as index for the event callback
* function.
* The value must range between zero and the size, in bit,
* of the @p eventid_t type minus one.
*
* @api
*/
static inline void chEvtRegister(EventSource *esp,
EventListener *elp,
eventid_t eid) {
chEvtRegisterMask(esp, elp, EVENT_MASK(eid));
}
/**
* @brief Verifies if there is at least one @p EventListener registered.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @iclass
*/
static inline bool chEvtIsListeningI(EventSource *esp) {
return (bool)((void *)esp != (void *)esp->es_next);
}
/**
* @brief Signals all the Event Listeners registered on the specified Event
* Source.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @api
*/
static inline void chEvtBroadcast(EventSource *esp) {
chEvtBroadcastFlags(esp, 0);
}
/**
* @brief Signals all the Event Listeners registered on the specified Event
* Source.
* @post This function does not reschedule so a call to a rescheduling
* function must be performed before unlocking the kernel. Note that
* interrupt handlers always reschedule on exit so an explicit
* reschedule must not be performed in ISRs.
*
* @param[in] esp pointer to the @p EventSource structure
*
* @iclass
*/
static inline void chEvtBroadcastI(EventSource *esp) {
chEvtBroadcastFlagsI(esp, 0);
}
#endif /* CH_USE_EVENTS */ #endif /* CH_USE_EVENTS */
#endif /* _CHEVENTS_H_ */ #endif /* _CHEVENTS_H_ */

View File

@ -48,10 +48,10 @@ typedef struct {
after the buffer. */ after the buffer. */
msg_t *mb_wrptr; /**< @brief Write pointer. */ msg_t *mb_wrptr; /**< @brief Write pointer. */
msg_t *mb_rdptr; /**< @brief Read pointer. */ msg_t *mb_rdptr; /**< @brief Read pointer. */
Semaphore mb_fullsem; /**< @brief Full counter semaphore_t mb_fullsem; /**< @brief Full counter
@p Semaphore. */ @p semaphore_t. */
Semaphore mb_emptysem; /**< @brief Empty counter semaphore_t mb_emptysem; /**< @brief Empty counter
@p Semaphore. */ @p semaphore_t. */
} Mailbox; } Mailbox;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -31,34 +31,34 @@
#if CH_USE_SEMAPHORES || defined(__DOXYGEN__) #if CH_USE_SEMAPHORES || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
/** /**
* @brief Semaphore structure. * @brief Semaphore structure.
*/ */
typedef struct Semaphore { typedef struct semaphore {
threads_queue_t s_queue; /**< @brief Queue of the threads sleeping threads_queue_t s_queue; /**< @brief Queue of the threads sleeping
on this semaphore. */ on this semaphore. */
cnt_t s_cnt; /**< @brief The semaphore counter. */ cnt_t s_cnt; /**< @brief The semaphore counter. */
} Semaphore; } semaphore_t;
#ifdef __cplusplus /*===========================================================================*/
extern "C" { /* Module macros. */
#endif /*===========================================================================*/
void chSemInit(Semaphore *sp, cnt_t n);
void chSemReset(Semaphore *sp, cnt_t n);
void chSemResetI(Semaphore *sp, cnt_t n);
msg_t chSemWait(Semaphore *sp);
msg_t chSemWaitS(Semaphore *sp);
msg_t chSemWaitTimeout(Semaphore *sp, systime_t time);
msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time);
void chSemSignal(Semaphore *sp);
void chSemSignalI(Semaphore *sp);
void chSemAddCounterI(Semaphore *sp, cnt_t n);
#if CH_USE_SEMSW
msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw);
#endif
#ifdef __cplusplus
}
#endif
/** /**
* @brief Data part of a static semaphore initializer. * @brief Data part of a static semaphore initializer.
@ -80,19 +80,48 @@ extern "C" {
* @param[in] n the counter initial value, this value must be * @param[in] n the counter initial value, this value must be
* non-negative * non-negative
*/ */
#define SEMAPHORE_DECL(name, n) Semaphore name = _SEMAPHORE_DATA(name, n) #define SEMAPHORE_DECL(name, n) semaphore_t name = _SEMAPHORE_DATA(name, n)
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
void chSemInit(semaphore_t *sp, cnt_t n);
void chSemReset(semaphore_t *sp, cnt_t n);
void chSemResetI(semaphore_t *sp, cnt_t n);
msg_t chSemWait(semaphore_t *sp);
msg_t chSemWaitS(semaphore_t *sp);
msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time);
msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time);
void chSemSignal(semaphore_t *sp);
void chSemSignalI(semaphore_t *sp);
void chSemAddCounterI(semaphore_t *sp, cnt_t n);
#if CH_USE_SEMSW
msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw);
#endif
#ifdef __cplusplus
}
#endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
/**
* @name Macro Functions
* @{
*/
/** /**
* @brief Decreases the semaphore counter. * @brief Decreases the semaphore counter.
* @details This macro can be used when the counter is known to be positive. * @details This macro can be used when the counter is known to be positive.
* *
* @iclass * @iclass
*/ */
#define chSemFastWaitI(sp) ((sp)->s_cnt--) static inline void chSemFastWaitI(semaphore_t *sp) {
chDbgCheckClassI();
sp->s_cnt--;
}
/** /**
* @brief Increases the semaphore counter. * @brief Increases the semaphore counter.
@ -101,15 +130,24 @@ extern "C" {
* *
* @iclass * @iclass
*/ */
#define chSemFastSignalI(sp) ((sp)->s_cnt++) static inline void chSemFastSignalI(semaphore_t *sp) {
chDbgCheckClassI();
sp->s_cnt++;
}
/** /**
* @brief Returns the semaphore counter current value. * @brief Returns the semaphore counter current value.
* *
* @iclass * @iclass
*/ */
#define chSemGetCounterI(sp) ((sp)->s_cnt) static inline cnt_t chSemGetCounterI(semaphore_t *sp) {
/** @} */
chDbgCheckClassI();
return sp->s_cnt;
}
#endif /* CH_USE_SEMAPHORES */ #endif /* CH_USE_SEMAPHORES */

View File

@ -53,7 +53,7 @@ typedef void (*vtfunc_t)(void *);
/** /**
* @brief Virtual Timer structure type. * @brief Virtual Timer structure type.
*/ */
typedef struct VirtualTimer VirtualTimer; typedef struct virtual_timer virtual_timer_t;
/** /**
* @brief Virtual timers list header. * @brief Virtual timers list header.
@ -62,22 +62,22 @@ typedef struct VirtualTimer VirtualTimer;
* timer is often used in the code. * timer is often used in the code.
*/ */
typedef struct { typedef struct {
VirtualTimer *vt_next; /**< @brief Next timer in the delta virtual_timer_t *vt_next; /**< @brief Next timer in the delta
list. */ list. */
VirtualTimer *vt_prev; /**< @brief Last timer in the delta virtual_timer_t *vt_prev; /**< @brief Last timer in the delta
list. */ list. */
systime_t vt_time; /**< @brief Must be initialized to -1. */ systime_t vt_time; /**< @brief Must be initialized to -1. */
volatile systime_t vt_systime; /**< @brief System Time counter. */ volatile systime_t vt_systime; /**< @brief System Time counter. */
} VTList; } virtual_timers_list_t;
/** /**
* @extends VTList * @extends virtual_timers_list_t
* *
* @brief Virtual Timer descriptor structure. * @brief Virtual Timer descriptor structure.
*/ */
struct VirtualTimer { struct virtual_timer {
VirtualTimer *vt_next; /**< @brief Next timer in the list. */ virtual_timer_t *vt_next; /**< @brief Next timer in the list. */
VirtualTimer *vt_prev; /**< @brief Previous timer in the list. */ virtual_timer_t *vt_prev; /**< @brief Previous timer in the list. */
systime_t vt_time; /**< @brief Time delta before timeout. */ systime_t vt_time; /**< @brief Time delta before timeout. */
vtfunc_t vt_func; /**< @brief Timer callback function vtfunc_t vt_func; /**< @brief Timer callback function
pointer. */ pointer. */
@ -137,7 +137,7 @@ struct VirtualTimer {
/* External declarations. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/
extern VTList vtlist; extern virtual_timers_list_t vtlist;
/* /*
* Virtual Timers APIs. * Virtual Timers APIs.
@ -147,9 +147,9 @@ extern "C" {
#endif #endif
void _vt_init(void); void _vt_init(void);
bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end); bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end);
void chVTDoSetI(VirtualTimer *vtp, systime_t delay, void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
vtfunc_t vtfunc, void *par); vtfunc_t vtfunc, void *par);
void chVTDoResetI(VirtualTimer *vtp); void chVTDoResetI(virtual_timer_t *vtp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -159,17 +159,17 @@ extern "C" {
/*===========================================================================*/ /*===========================================================================*/
/** /**
* @brief Initializes a @p VirtualTimer object. * @brief Initializes a @p virtual_timer_t object.
* @note Initializing a timer object is not strictly required because * @note Initializing a timer object is not strictly required because
* the function @p chVTSetI() initializes the object too. This * the function @p chVTSetI() initializes the object too. This
* function is only useful if you need to perform a @p chVTIsArmed() * function is only useful if you need to perform a @p chVTIsArmed()
* check before calling @p chVTSetI(). * check before calling @p chVTSetI().
* *
* @param[out] vtp the @p VirtualTimer structure pointer * @param[out] vtp the @p virtual_timer_t structure pointer
* *
* @init * @init
*/ */
static inline void chVTObjectInit(VirtualTimer *vtp) { static inline void chVTObjectInit(virtual_timer_t *vtp) {
vtp->vt_func = NULL; vtp->vt_func = NULL;
} }
@ -251,12 +251,12 @@ static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) {
* @pre The timer must have been initialized using @p chVTObjectInit() * @pre The timer must have been initialized using @p chVTObjectInit()
* or @p chVTSetI() (or @p chVTSetI() variants). * or @p chVTSetI() (or @p chVTSetI() variants).
* *
* @param[in] vtp the @p VirtualTimer structure pointer * @param[in] vtp the @p virtual_timer_t structure pointer
* @return true if the timer is armed. * @return true if the timer is armed.
* *
* @iclass * @iclass
*/ */
static inline bool chVTIsArmedI(VirtualTimer *vtp) { static inline bool chVTIsArmedI(virtual_timer_t *vtp) {
chDbgCheckClassI(); chDbgCheckClassI();
@ -267,11 +267,11 @@ static inline bool chVTIsArmedI(VirtualTimer *vtp) {
* @brief Disables a Virtual Timer. * @brief Disables a Virtual Timer.
* @note The timer is first checked and disabled only if armed. * @note The timer is first checked and disabled only if armed.
* *
* @param[in] vtp the @p VirtualTimer structure pointer * @param[in] vtp the @p virtual_timer_t structure pointer
* *
* @iclass * @iclass
*/ */
static inline void chVTResetI(VirtualTimer *vtp) { static inline void chVTResetI(virtual_timer_t *vtp) {
if (chVTIsArmedI(vtp)) if (chVTIsArmedI(vtp))
chVTDoResetI(vtp); chVTDoResetI(vtp);
@ -281,11 +281,11 @@ static inline void chVTResetI(VirtualTimer *vtp) {
* @brief Disables a Virtual Timer. * @brief Disables a Virtual Timer.
* @note The timer is first checked and disabled only if armed. * @note The timer is first checked and disabled only if armed.
* *
* @param[in] vtp the @p VirtualTimer structure pointer * @param[in] vtp the @p virtual_timer_t structure pointer
* *
* @api * @api
*/ */
static inline void chVTReset(VirtualTimer *vtp) { static inline void chVTReset(virtual_timer_t *vtp) {
chSysLock(); chSysLock();
chVTResetI(vtp); chVTResetI(vtp);
@ -297,7 +297,7 @@ static inline void chVTReset(VirtualTimer *vtp) {
* @details If the virtual timer was already enabled then it is re-enabled * @details If the virtual timer was already enabled then it is re-enabled
* using the new parameters. * using the new parameters.
* *
* @param[in] vtp the @p VirtualTimer structure pointer * @param[in] vtp the @p virtual_timer_t structure pointer
* @param[in] delay the number of ticks before the operation timeouts. * @param[in] delay the number of ticks before the operation timeouts.
* @param[in] vtfunc the timer callback function. After invoking the * @param[in] vtfunc the timer callback function. After invoking the
* callback the timer is disabled and the structure can * callback the timer is disabled and the structure can
@ -307,7 +307,7 @@ static inline void chVTReset(VirtualTimer *vtp) {
* *
* @iclass * @iclass
*/ */
static inline void chVTSetI(VirtualTimer *vtp, systime_t delay, static inline void chVTSetI(virtual_timer_t *vtp, systime_t delay,
vtfunc_t vtfunc, void *par) { vtfunc_t vtfunc, void *par) {
chVTResetI(vtp); chVTResetI(vtp);
@ -319,7 +319,7 @@ static inline void chVTSetI(VirtualTimer *vtp, systime_t delay,
* @details If the virtual timer was already enabled then it is re-enabled * @details If the virtual timer was already enabled then it is re-enabled
* using the new parameters. * using the new parameters.
* *
* @param[in] vtp the @p VirtualTimer structure pointer * @param[in] vtp the @p virtual_timer_t structure pointer
* @param[in] delay the number of ticks before the operation timeouts. * @param[in] delay the number of ticks before the operation timeouts.
* @param[in] vtfunc the timer callback function. After invoking the * @param[in] vtfunc the timer callback function. After invoking the
* callback the timer is disabled and the structure can * callback the timer is disabled and the structure can
@ -329,7 +329,7 @@ static inline void chVTSetI(VirtualTimer *vtp, systime_t delay,
* *
* @api * @api
*/ */
static inline void chVTSet(VirtualTimer *vtp, systime_t delay, static inline void chVTSet(virtual_timer_t *vtp, systime_t delay,
vtfunc_t vtfunc, void *par) { vtfunc_t vtfunc, void *par) {
chSysLock(); chSysLock();
@ -351,8 +351,8 @@ static inline void chVTDoTickI(void) {
chDbgCheckClassI(); chDbgCheckClassI();
vtlist.vt_systime++; vtlist.vt_systime++;
if (&vtlist != (VTList *)vtlist.vt_next) { if (&vtlist != (virtual_timers_list_t *)vtlist.vt_next) {
VirtualTimer *vtp; virtual_timer_t *vtp;
--vtlist.vt_next->vt_time; --vtlist.vt_next->vt_time;
while (!(vtp = vtlist.vt_next)->vt_time) { while (!(vtp = vtlist.vt_next)->vt_time) {

View File

@ -25,14 +25,14 @@
* @file chcond.c * @file chcond.c
* @brief Condition Variables code. * @brief Condition Variables code.
* *
* @addtogroup condvars Condition Variables * @addtogroup condition variables Condition Variables
* @details This module implements the Condition Variables mechanism. Condition * @details This module implements the Condition Variables mechanism. Condition
* variables are an extensions to the Mutex subsystem and cannot * variables are an extensions to the mutex subsystem and cannot
* work alone. * work alone.
* <h2>Operation mode</h2> * <h2>Operation mode</h2>
* The condition variable is a synchronization object meant to be * The condition variable is a synchronization object meant to be
* used inside a zone protected by a @p Mutex. Mutexes and CondVars * used inside a zone protected by a mutex. Mutexes and condition
* together can implement a Monitor construct. * variables together can implement a Monitor construct.
* @pre In order to use the condition variable APIs the @p CH_USE_CONDVARS * @pre In order to use the condition variable APIs the @p CH_USE_CONDVARS
* option must be enabled in @p chconf.h. * option must be enabled in @p chconf.h.
* @{ * @{
@ -40,16 +40,40 @@
#include "ch.h" #include "ch.h"
#if (CH_USE_CONDVARS && CH_USE_MUTEXES) || defined(__DOXYGEN__) #if CH_USE_CONDVARS || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local types. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/** /**
* @brief Initializes s @p CondVar structure. * @brief Initializes s @p condition_variable_t structure.
* *
* @param[out] cp pointer to a @p CondVar structure * @param[out] cp pointer to a @p condition_variable_t structure
* *
* @init * @init
*/ */
void chCondInit(CondVar *cp) { void chCondInit(condition_variable_t *cp) {
chDbgCheck(cp != NULL, "chCondInit"); chDbgCheck(cp != NULL, "chCondInit");
@ -59,11 +83,11 @@ void chCondInit(CondVar *cp) {
/** /**
* @brief Signals one thread that is waiting on the condition variable. * @brief Signals one thread that is waiting on the condition variable.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* *
* @api * @api
*/ */
void chCondSignal(CondVar *cp) { void chCondSignal(condition_variable_t *cp) {
chDbgCheck(cp != NULL, "chCondSignal"); chDbgCheck(cp != NULL, "chCondSignal");
@ -80,11 +104,11 @@ void chCondSignal(CondVar *cp) {
* interrupt handlers always reschedule on exit so an explicit * interrupt handlers always reschedule on exit so an explicit
* reschedule must not be performed in ISRs. * reschedule must not be performed in ISRs.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* *
* @iclass * @iclass
*/ */
void chCondSignalI(CondVar *cp) { void chCondSignalI(condition_variable_t *cp) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(cp != NULL, "chCondSignalI"); chDbgCheck(cp != NULL, "chCondSignalI");
@ -96,11 +120,11 @@ void chCondSignalI(CondVar *cp) {
/** /**
* @brief Signals all threads that are waiting on the condition variable. * @brief Signals all threads that are waiting on the condition variable.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* *
* @api * @api
*/ */
void chCondBroadcast(CondVar *cp) { void chCondBroadcast(condition_variable_t *cp) {
chSysLock(); chSysLock();
chCondBroadcastI(cp); chCondBroadcastI(cp);
@ -115,11 +139,11 @@ void chCondBroadcast(CondVar *cp) {
* interrupt handlers always reschedule on exit so an explicit * interrupt handlers always reschedule on exit so an explicit
* reschedule must not be performed in ISRs. * reschedule must not be performed in ISRs.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* *
* @iclass * @iclass
*/ */
void chCondBroadcastI(CondVar *cp) { void chCondBroadcastI(condition_variable_t *cp) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(cp != NULL, "chCondBroadcastI"); chDbgCheck(cp != NULL, "chCondBroadcastI");
@ -138,17 +162,17 @@ void chCondBroadcastI(CondVar *cp) {
* is performed atomically. * is performed atomically.
* @pre The invoking thread <b>must</b> have at least one owned mutex. * @pre The invoking thread <b>must</b> have at least one owned mutex.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the condition variable. * released from the condition variable.
* @retval RDY_OK if the condvar has been signaled using * @retval RDY_OK if the condition variable has been signaled using
* @p chCondSignal(). * @p chCondSignal().
* @retval RDY_RESET if the condvar has been signaled using * @retval RDY_RESET if the condition variable has been signaled using
* @p chCondBroadcast(). * @p chCondBroadcast().
* *
* @api * @api
*/ */
msg_t chCondWait(CondVar *cp) { msg_t chCondWait(condition_variable_t *cp) {
msg_t msg; msg_t msg;
chSysLock(); chSysLock();
@ -164,17 +188,17 @@ msg_t chCondWait(CondVar *cp) {
* is performed atomically. * is performed atomically.
* @pre The invoking thread <b>must</b> have at least one owned mutex. * @pre The invoking thread <b>must</b> have at least one owned mutex.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the condition variable. * released from the condition variable.
* @retval RDY_OK if the condvar has been signaled using * @retval RDY_OK if the condition variable has been signaled using
* @p chCondSignal(). * @p chCondSignal().
* @retval RDY_RESET if the condvar has been signaled using * @retval RDY_RESET if the condition variable has been signaled using
* @p chCondBroadcast(). * @p chCondBroadcast().
* *
* @sclass * @sclass
*/ */
msg_t chCondWaitS(CondVar *cp) { msg_t chCondWaitS(condition_variable_t *cp) {
thread_t *ctp = currp; thread_t *ctp = currp;
Mutex *mp; Mutex *mp;
msg_t msg; msg_t msg;
@ -206,7 +230,7 @@ msg_t chCondWaitS(CondVar *cp) {
* @post Exiting the function because a timeout does not re-acquire the * @post Exiting the function because a timeout does not re-acquire the
* mutex, the mutex ownership is lost. * mutex, the mutex ownership is lost.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* @param[in] time the number of ticks before the operation timeouts, the * @param[in] time the number of ticks before the operation timeouts, the
* special values are handled as follow: * special values are handled as follow:
* - @a TIME_INFINITE no timeout. * - @a TIME_INFINITE no timeout.
@ -214,16 +238,16 @@ msg_t chCondWaitS(CondVar *cp) {
* . * .
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the condition variable. * released from the condition variable.
* @retval RDY_OK if the condvar has been signaled using * @retval RDY_OK if the condition variable has been signaled using
* @p chCondSignal(). * @p chCondSignal().
* @retval RDY_RESET if the condvar has been signaled using * @retval RDY_RESET if the condition variable has been signaled using
* @p chCondBroadcast(). * @p chCondBroadcast().
* @retval RDY_TIMEOUT if the condvar has not been signaled within the * @retval RDY_TIMEOUT if the condition variable has not been signaled within
* specified timeout. * the specified timeout.
* *
* @api * @api
*/ */
msg_t chCondWaitTimeout(CondVar *cp, systime_t time) { msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) {
msg_t msg; msg_t msg;
chSysLock(); chSysLock();
@ -243,7 +267,7 @@ msg_t chCondWaitTimeout(CondVar *cp, systime_t time) {
* @post Exiting the function because a timeout does not re-acquire the * @post Exiting the function because a timeout does not re-acquire the
* mutex, the mutex ownership is lost. * mutex, the mutex ownership is lost.
* *
* @param[in] cp pointer to the @p CondVar structure * @param[in] cp pointer to the @p condition_variable_t structure
* @param[in] time the number of ticks before the operation timeouts, the * @param[in] time the number of ticks before the operation timeouts, the
* special values are handled as follow: * special values are handled as follow:
* - @a TIME_INFINITE no timeout. * - @a TIME_INFINITE no timeout.
@ -251,16 +275,16 @@ msg_t chCondWaitTimeout(CondVar *cp, systime_t time) {
* . * .
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the condition variable. * released from the condition variable.
* @retval RDY_OK if the condvar has been signaled using * @retval RDY_OK if the condition variable has been signaled using
* @p chCondSignal(). * @p chCondSignal().
* @retval RDY_RESET if the condvar has been signaled using * @retval RDY_RESET if the condition variable has been signaled using
* @p chCondBroadcast(). * @p chCondBroadcast().
* @retval RDY_TIMEOUT if the condvar has not been signaled within the * @retval RDY_TIMEOUT if the condition variable has not been signaled within
* specified timeout. * the specified timeout.
* *
* @sclass * @sclass
*/ */
msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time) { msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) {
Mutex *mp; Mutex *mp;
msg_t msg; msg_t msg;
@ -280,6 +304,6 @@ msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time) {
} }
#endif /* CH_USE_CONDVARS_TIMEOUT */ #endif /* CH_USE_CONDVARS_TIMEOUT */
#endif /* CH_USE_CONDVARS && CH_USE_MUTEXES */ #endif /* CH_USE_CONDVARS */
/** @} */ /** @} */

View File

@ -31,6 +31,30 @@
#if CH_USE_DYNAMIC || defined(__DOXYGEN__) #if CH_USE_DYNAMIC || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local types. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/** /**
* @brief Adds a reference to a thread object. * @brief Adds a reference to a thread object.
* @pre The configuration option @p CH_USE_DYNAMIC must be enabled in order * @pre The configuration option @p CH_USE_DYNAMIC must be enabled in order

View File

@ -61,6 +61,31 @@
#include "ch.h" #include "ch.h"
#if CH_USE_EVENTS || defined(__DOXYGEN__) #if CH_USE_EVENTS || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local types. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/** /**
* @brief Registers an Event Listener on an Event Source. * @brief Registers an Event Listener on an Event Source.
* @details Once a thread has registered as listener on an event source it * @details Once a thread has registered as listener on an event source it

View File

@ -153,7 +153,7 @@ static void wakeup(void *p) {
(CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT)
#if CH_USE_SEMAPHORES #if CH_USE_SEMAPHORES
case THD_STATE_WTSEM: case THD_STATE_WTSEM:
chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp);
/* Falls into, intentional. */ /* Falls into, intentional. */
#endif #endif
#if CH_USE_QUEUES #if CH_USE_QUEUES
@ -197,7 +197,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
chDbgCheckClassS(); chDbgCheckClassS();
if (TIME_INFINITE != time) { if (TIME_INFINITE != time) {
VirtualTimer vt; virtual_timer_t vt;
chVTDoSetI(&vt, time, wakeup, currp); chVTDoSetI(&vt, time, wakeup, currp);
chSchGoSleepS(newstate); chSchGoSleepS(newstate);

View File

@ -70,13 +70,13 @@
/** /**
* @brief Initializes a semaphore with the specified counter value. * @brief Initializes a semaphore with the specified counter value.
* *
* @param[out] sp pointer to a @p Semaphore structure * @param[out] sp pointer to a @p semaphore_t structure
* @param[in] n initial value of the semaphore counter. Must be * @param[in] n initial value of the semaphore counter. Must be
* non-negative. * non-negative.
* *
* @init * @init
*/ */
void chSemInit(Semaphore *sp, cnt_t n) { void chSemInit(semaphore_t *sp, cnt_t n) {
chDbgCheck((sp != NULL) && (n >= 0), "chSemInit"); chDbgCheck((sp != NULL) && (n >= 0), "chSemInit");
@ -93,13 +93,13 @@ void chSemInit(Semaphore *sp, cnt_t n) {
* rather than a signal because the @p chSemWait() will return * rather than a signal because the @p chSemWait() will return
* @p RDY_RESET instead of @p RDY_OK. * @p RDY_RESET instead of @p RDY_OK.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* @param[in] n the new value of the semaphore counter. The value must * @param[in] n the new value of the semaphore counter. The value must
* be non-negative. * be non-negative.
* *
* @api * @api
*/ */
void chSemReset(Semaphore *sp, cnt_t n) { void chSemReset(semaphore_t *sp, cnt_t n) {
chSysLock(); chSysLock();
chSemResetI(sp, n); chSemResetI(sp, n);
@ -120,13 +120,13 @@ void chSemReset(Semaphore *sp, cnt_t n) {
* rather than a signal because the @p chSemWait() will return * rather than a signal because the @p chSemWait() will return
* @p RDY_RESET instead of @p RDY_OK. * @p RDY_RESET instead of @p RDY_OK.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* @param[in] n the new value of the semaphore counter. The value must * @param[in] n the new value of the semaphore counter. The value must
* be non-negative. * be non-negative.
* *
* @iclass * @iclass
*/ */
void chSemResetI(Semaphore *sp, cnt_t n) { void chSemResetI(semaphore_t *sp, cnt_t n) {
cnt_t cnt; cnt_t cnt;
chDbgCheckClassI(); chDbgCheckClassI();
@ -145,7 +145,7 @@ void chSemResetI(Semaphore *sp, cnt_t n) {
/** /**
* @brief Performs a wait operation on a semaphore. * @brief Performs a wait operation on a semaphore.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the semaphore. * released from the semaphore.
* @retval RDY_OK if the thread has not stopped on the semaphore or the * @retval RDY_OK if the thread has not stopped on the semaphore or the
@ -154,7 +154,7 @@ void chSemResetI(Semaphore *sp, cnt_t n) {
* *
* @api * @api
*/ */
msg_t chSemWait(Semaphore *sp) { msg_t chSemWait(semaphore_t *sp) {
msg_t msg; msg_t msg;
chSysLock(); chSysLock();
@ -166,7 +166,7 @@ msg_t chSemWait(Semaphore *sp) {
/** /**
* @brief Performs a wait operation on a semaphore. * @brief Performs a wait operation on a semaphore.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the semaphore. * released from the semaphore.
* @retval RDY_OK if the thread has not stopped on the semaphore or the * @retval RDY_OK if the thread has not stopped on the semaphore or the
@ -175,7 +175,7 @@ msg_t chSemWait(Semaphore *sp) {
* *
* @sclass * @sclass
*/ */
msg_t chSemWaitS(Semaphore *sp) { msg_t chSemWaitS(semaphore_t *sp) {
chDbgCheckClassS(); chDbgCheckClassS();
chDbgCheck(sp != NULL, "chSemWaitS"); chDbgCheck(sp != NULL, "chSemWaitS");
@ -196,7 +196,7 @@ msg_t chSemWaitS(Semaphore *sp) {
/** /**
* @brief Performs a wait operation on a semaphore with timeout specification. * @brief Performs a wait operation on a semaphore with timeout specification.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* @param[in] time the number of ticks before the operation timeouts, * @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed: * the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_IMMEDIATE immediate timeout.
@ -212,7 +212,7 @@ msg_t chSemWaitS(Semaphore *sp) {
* *
* @api * @api
*/ */
msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) { msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) {
msg_t msg; msg_t msg;
chSysLock(); chSysLock();
@ -224,7 +224,7 @@ msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) {
/** /**
* @brief Performs a wait operation on a semaphore with timeout specification. * @brief Performs a wait operation on a semaphore with timeout specification.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* @param[in] time the number of ticks before the operation timeouts, * @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed: * the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_IMMEDIATE immediate timeout.
@ -240,7 +240,7 @@ msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) {
* *
* @sclass * @sclass
*/ */
msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
chDbgCheckClassS(); chDbgCheckClassS();
chDbgCheck(sp != NULL, "chSemWaitTimeoutS"); chDbgCheck(sp != NULL, "chSemWaitTimeoutS");
@ -264,11 +264,11 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) {
/** /**
* @brief Performs a signal operation on a semaphore. * @brief Performs a signal operation on a semaphore.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* *
* @api * @api
*/ */
void chSemSignal(Semaphore *sp) { void chSemSignal(semaphore_t *sp) {
chDbgCheck(sp != NULL, "chSemSignal"); chDbgCheck(sp != NULL, "chSemSignal");
chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) ||
@ -289,11 +289,11 @@ void chSemSignal(Semaphore *sp) {
* interrupt handlers always reschedule on exit so an explicit * interrupt handlers always reschedule on exit so an explicit
* reschedule must not be performed in ISRs. * reschedule must not be performed in ISRs.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* *
* @iclass * @iclass
*/ */
void chSemSignalI(Semaphore *sp) { void chSemSignalI(semaphore_t *sp) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(sp != NULL, "chSemSignalI"); chDbgCheck(sp != NULL, "chSemSignalI");
@ -318,13 +318,13 @@ void chSemSignalI(Semaphore *sp) {
* interrupt handlers always reschedule on exit so an explicit * interrupt handlers always reschedule on exit so an explicit
* reschedule must not be performed in ISRs. * reschedule must not be performed in ISRs.
* *
* @param[in] sp pointer to a @p Semaphore structure * @param[in] sp pointer to a @p semaphore_t structure
* @param[in] n value to be added to the semaphore counter. The value * @param[in] n value to be added to the semaphore counter. The value
* must be positive. * must be positive.
* *
* @iclass * @iclass
*/ */
void chSemAddCounterI(Semaphore *sp, cnt_t n) { void chSemAddCounterI(semaphore_t *sp, cnt_t n) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck((sp != NULL) && (n > 0), "chSemAddCounterI"); chDbgCheck((sp != NULL) && (n > 0), "chSemAddCounterI");
@ -346,8 +346,8 @@ void chSemAddCounterI(Semaphore *sp, cnt_t n) {
* @pre The configuration option @p CH_USE_SEMSW must be enabled in order * @pre The configuration option @p CH_USE_SEMSW must be enabled in order
* to use this function. * to use this function.
* *
* @param[in] sps pointer to a @p Semaphore structure to be signaled * @param[in] sps pointer to a @p semaphore_t structure to be signaled
* @param[in] spw pointer to a @p Semaphore structure to wait on * @param[in] spw pointer to a @p semaphore_t structure to wait on
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the semaphore. * released from the semaphore.
* @retval RDY_OK if the thread has not stopped on the semaphore or the * @retval RDY_OK if the thread has not stopped on the semaphore or the
@ -356,7 +356,7 @@ void chSemAddCounterI(Semaphore *sp, cnt_t n) {
* *
* @api * @api
*/ */
msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) {
msg_t msg; msg_t msg;
chDbgCheck((sps != NULL) && (spw != NULL), "chSemSignalWait"); chDbgCheck((sps != NULL) && (spw != NULL), "chSemSignalWait");

View File

@ -40,7 +40,7 @@
/** /**
* @brief Virtual timers delta list header. * @brief Virtual timers delta list header.
*/ */
VTList vtlist; virtual_timers_list_t vtlist;
/*===========================================================================*/ /*===========================================================================*/
/* Module local types. */ /* Module local types. */
@ -99,7 +99,7 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) {
* @pre The timer must not be already armed before calling this function. * @pre The timer must not be already armed before calling this function.
* @note The callback function is invoked from interrupt context. * @note The callback function is invoked from interrupt context.
* *
* @param[out] vtp the @p VirtualTimer structure pointer * @param[out] vtp the @p virtual_timer_t structure pointer
* @param[in] delay the number of ticks before the operation timeouts, the * @param[in] delay the number of ticks before the operation timeouts, the
* special values are handled as follow: * special values are handled as follow:
* - @a TIME_INFINITE is allowed but interpreted as a * - @a TIME_INFINITE is allowed but interpreted as a
@ -114,9 +114,9 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) {
* *
* @iclass * @iclass
*/ */
void chVTDoSetI(VirtualTimer *vtp, systime_t delay, void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
vtfunc_t vtfunc, void *par) { vtfunc_t vtfunc, void *par) {
VirtualTimer *p; virtual_timer_t *p;
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE), chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE),
@ -141,11 +141,11 @@ void chVTDoSetI(VirtualTimer *vtp, systime_t delay,
* @brief Disables a Virtual Timer. * @brief Disables a Virtual Timer.
* @pre The timer must be in armed state before calling this function. * @pre The timer must be in armed state before calling this function.
* *
* @param[in] vtp the @p VirtualTimer structure pointer * @param[in] vtp the @p virtual_timer_t structure pointer
* *
* @iclass * @iclass
*/ */
void chVTDoResetI(VirtualTimer *vtp) { void chVTDoResetI(virtual_timer_t *vtp) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(vtp != NULL, "chVTDoResetI"); chDbgCheck(vtp != NULL, "chVTDoResetI");

View File

@ -257,7 +257,7 @@ systime_t test_wait_tick(void) {
*/ */
bool_t test_timer_done; bool_t test_timer_done;
static VirtualTimer vt; static virtual_timer_t vt;
static void tmr(void *p) { static void tmr(void *p) {
(void)p; (void)p;

View File

@ -56,7 +56,7 @@
* @brief Kernel Benchmarks header file * @brief Kernel Benchmarks header file
*/ */
static Semaphore sem1; static semaphore_t sem1;
#if CH_USE_MUTEXES || defined(__DOXYGEN__) #if CH_USE_MUTEXES || defined(__DOXYGEN__)
static Mutex mtx1; static Mutex mtx1;
#endif #endif
@ -500,7 +500,7 @@ ROMCONST struct testcase testbmk9 = {
static void tmo(void *param) {(void)param;} static void tmo(void *param) {(void)param;}
static void bmk10_execute(void) { static void bmk10_execute(void) {
static VirtualTimer vt1, vt2; static virtual_timer_t vt1, vt2;
uint32_t n = 0; uint32_t n = 0;
test_wait_tick(); test_wait_tick();
@ -633,7 +633,7 @@ ROMCONST struct testcase testbmk12 = {
static void bmk13_execute(void) { static void bmk13_execute(void) {
test_print("--- System: "); test_print("--- System: ");
test_printn(sizeof(ready_list_t) + sizeof(VTList) + test_printn(sizeof(ready_list_t) + sizeof(virtual_timers_list_t) +
PORT_IDLE_THREAD_STACK_SIZE + PORT_IDLE_THREAD_STACK_SIZE +
(sizeof(thread_t) + sizeof(struct intctx) + (sizeof(thread_t) + sizeof(struct intctx) +
sizeof(struct extctx) + sizeof(struct extctx) +
@ -643,10 +643,10 @@ static void bmk13_execute(void) {
test_printn(sizeof(thread_t)); test_printn(sizeof(thread_t));
test_println(" bytes"); test_println(" bytes");
test_print("--- Timer : "); test_print("--- Timer : ");
test_printn(sizeof(VirtualTimer)); test_printn(sizeof(virtual_timer_t));
test_println(" bytes"); test_println(" bytes");
test_print("--- Semaph: "); test_print("--- Semaph: ");
test_printn(sizeof(Semaphore)); test_printn(sizeof(semaphore_t));
test_println(" bytes"); test_println(" bytes");
#if CH_USE_EVENTS || defined(__DOXYGEN__) #if CH_USE_EVENTS || defined(__DOXYGEN__)
test_print("--- EventS: "); test_print("--- EventS: ");
@ -663,7 +663,7 @@ static void bmk13_execute(void) {
#endif #endif
#if CH_USE_CONDVARS || defined(__DOXYGEN__) #if CH_USE_CONDVARS || defined(__DOXYGEN__)
test_print("--- CondV.: "); test_print("--- CondV.: ");
test_printn(sizeof(CondVar)); test_printn(sizeof(condition_variable_t));
test_println(" bytes"); test_println(" bytes");
#endif #endif
#if CH_USE_QUEUES || defined(__DOXYGEN__) #if CH_USE_QUEUES || defined(__DOXYGEN__)

View File

@ -244,12 +244,12 @@ ROMCONST struct testcase testsem3 = {
*/ */
static msg_t thread4(void *p) { static msg_t thread4(void *p) {
chBSemSignal((BinarySemaphore *)p); chBSemSignal((binary_semaphore_t *)p);
return 0; return 0;
} }
static void sem4_execute(void) { static void sem4_execute(void) {
BinarySemaphore bsem; binary_semaphore_t bsem;
/* Creates a taken binary semaphore.*/ /* Creates a taken binary semaphore.*/
chBSemInit(&bsem, TRUE); chBSemInit(&bsem, TRUE);