Started renaming the types to follow the _t convention.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5988 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
3739568d89
commit
3b6423187e
|
@ -45,7 +45,7 @@
|
||||||
* @brief CondVar structure.
|
* @brief CondVar structure.
|
||||||
*/
|
*/
|
||||||
typedef struct CondVar {
|
typedef struct CondVar {
|
||||||
ThreadsQueue c_queue; /**< @brief CondVar threads queue.*/
|
threads_queue_t c_queue; /**< @brief CondVar threads queue.*/
|
||||||
} CondVar;
|
} CondVar;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -73,7 +73,7 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* @param[in] name the name of the condition variable
|
* @param[in] name the name of the condition variable
|
||||||
*/
|
*/
|
||||||
#define _CONDVAR_DATA(name) {_THREADSQUEUE_DATA(name.c_queue)}
|
#define _CONDVAR_DATA(name) {_threads_queue_t_DATA(name.c_queue)}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static condition variable initializer.
|
* @brief Static condition variable initializer.
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
*
|
*
|
||||||
* @param[in] name the name of the threads queue variable
|
* @param[in] name the name of the threads queue variable
|
||||||
*/
|
*/
|
||||||
#define _THREADSQUEUE_DATA(name) {(Thread *)&name, (Thread *)&name}
|
#define _threads_queue_t_DATA(name) {(Thread *)&name, (Thread *)&name}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static threads queue initializer.
|
* @brief Static threads queue initializer.
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
*
|
*
|
||||||
* @param[in] name the name of the threads queue variable
|
* @param[in] name the name of the threads queue variable
|
||||||
*/
|
*/
|
||||||
#define THREADSQUEUE_DECL(name) ThreadsQueue name = _THREADSQUEUE_DATA(name)
|
#define threads_queue_t_DECL(name) threads_queue_t name = _threads_queue_t_DATA(name)
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static inline void list_init(ThreadsList *tlp) {
|
static inline void list_init(threads_list_t *tlp) {
|
||||||
|
|
||||||
tlp->p_next = (Thread *)tlp;
|
tlp->p_next = (Thread *)tlp;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ static inline void list_init(ThreadsList *tlp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static inline bool_t list_isempty(ThreadsList *tlp) {
|
static inline bool_t list_isempty(threads_list_t *tlp) {
|
||||||
|
|
||||||
return (bool_t)(tlp->p_next == (Thread *)tlp);
|
return (bool_t)(tlp->p_next == (Thread *)tlp);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ static inline bool_t list_isempty(ThreadsList *tlp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static inline bool_t list_notempty(ThreadsList *tlp) {
|
static inline bool_t list_notempty(threads_list_t *tlp) {
|
||||||
|
|
||||||
return (bool_t)(tlp->p_next != (Thread *)tlp);
|
return (bool_t)(tlp->p_next != (Thread *)tlp);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ static inline bool_t list_notempty(ThreadsList *tlp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static inline void queue_init(ThreadsQueue *tqp) {
|
static inline void queue_init(threads_queue_t *tqp) {
|
||||||
|
|
||||||
tqp->p_next = tqp->p_prev = (Thread *)tqp;
|
tqp->p_next = tqp->p_prev = (Thread *)tqp;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ static inline void queue_init(ThreadsQueue *tqp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static inline bool_t queue_isempty(ThreadsQueue *tqp) {
|
static inline bool_t queue_isempty(threads_queue_t *tqp) {
|
||||||
|
|
||||||
return (bool_t)(tqp->p_next == (Thread *)tqp);
|
return (bool_t)(tqp->p_next == (Thread *)tqp);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ static inline bool_t queue_isempty(ThreadsQueue *tqp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static inline bool_t queue_notempty(ThreadsQueue *tqp) {
|
static inline bool_t queue_notempty(threads_queue_t *tqp) {
|
||||||
|
|
||||||
return (bool_t)(tqp->p_next != (Thread *)tqp);
|
return (bool_t)(tqp->p_next != (Thread *)tqp);
|
||||||
}
|
}
|
||||||
|
@ -138,20 +138,20 @@ static inline bool_t queue_notempty(ThreadsQueue *tqp) {
|
||||||
/* If the performance code path has been chosen then all the following
|
/* If the performance code path has been chosen then all the following
|
||||||
functions are inlined into the various kernel modules.*/
|
functions are inlined into the various kernel modules.*/
|
||||||
#if CH_OPTIMIZE_SPEED
|
#if CH_OPTIMIZE_SPEED
|
||||||
static inline void list_insert(Thread *tp, ThreadsList *tlp) {
|
static inline void list_insert(Thread *tp, threads_list_t *tlp) {
|
||||||
|
|
||||||
tp->p_next = tlp->p_next;
|
tp->p_next = tlp->p_next;
|
||||||
tlp->p_next = tp;
|
tlp->p_next = tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Thread *list_remove(ThreadsList *tlp) {
|
static inline Thread *list_remove(threads_list_t *tlp) {
|
||||||
|
|
||||||
Thread *tp = tlp->p_next;
|
Thread *tp = tlp->p_next;
|
||||||
tlp->p_next = tp->p_next;
|
tlp->p_next = tp->p_next;
|
||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void queue_prio_insert(Thread *tp, ThreadsQueue *tqp) {
|
static inline void queue_prio_insert(Thread *tp, threads_queue_t *tqp) {
|
||||||
|
|
||||||
Thread *cp = (Thread *)tqp;
|
Thread *cp = (Thread *)tqp;
|
||||||
do {
|
do {
|
||||||
|
@ -162,21 +162,21 @@ static inline void queue_prio_insert(Thread *tp, ThreadsQueue *tqp) {
|
||||||
tp->p_prev->p_next = cp->p_prev = tp;
|
tp->p_prev->p_next = cp->p_prev = tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void queue_insert(Thread *tp, ThreadsQueue *tqp) {
|
static inline void queue_insert(Thread *tp, threads_queue_t *tqp) {
|
||||||
|
|
||||||
tp->p_next = (Thread *)tqp;
|
tp->p_next = (Thread *)tqp;
|
||||||
tp->p_prev = tqp->p_prev;
|
tp->p_prev = tqp->p_prev;
|
||||||
tp->p_prev->p_next = tqp->p_prev = tp;
|
tp->p_prev->p_next = tqp->p_prev = tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Thread *queue_fifo_remove(ThreadsQueue *tqp) {
|
static inline Thread *queue_fifo_remove(threads_queue_t *tqp) {
|
||||||
Thread *tp = tqp->p_next;
|
Thread *tp = tqp->p_next;
|
||||||
|
|
||||||
(tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp;
|
(tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp;
|
||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Thread *queue_lifo_remove(ThreadsQueue *tqp) {
|
static inline Thread *queue_lifo_remove(threads_queue_t *tqp) {
|
||||||
Thread *tp = tqp->p_prev;
|
Thread *tp = tqp->p_prev;
|
||||||
|
|
||||||
(tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp;
|
(tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
* @brief Mutex structure.
|
* @brief Mutex structure.
|
||||||
*/
|
*/
|
||||||
typedef struct Mutex {
|
typedef struct Mutex {
|
||||||
ThreadsQueue m_queue; /**< @brief Queue of the threads sleeping
|
threads_queue_t m_queue; /**< @brief Queue of the threads sleeping
|
||||||
on this Mutex. */
|
on this Mutex. */
|
||||||
Thread *m_owner; /**< @brief Owner @p Thread pointer or
|
Thread *m_owner; /**< @brief Owner @p Thread pointer or
|
||||||
@p NULL. */
|
@p NULL. */
|
||||||
|
@ -65,7 +65,7 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* @param[in] name the name of the mutex variable
|
* @param[in] name the name of the mutex variable
|
||||||
*/
|
*/
|
||||||
#define _MUTEX_DATA(name) {_THREADSQUEUE_DATA(name.m_queue), NULL, NULL}
|
#define _MUTEX_DATA(name) {_threads_queue_t_DATA(name.m_queue), NULL, NULL}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static mutex initializer.
|
* @brief Static mutex initializer.
|
||||||
|
|
|
@ -60,7 +60,7 @@ typedef void (*qnotify_t)(GenericQueue *qp);
|
||||||
* @ref system_states) and is non-blocking.
|
* @ref system_states) and is non-blocking.
|
||||||
*/
|
*/
|
||||||
struct GenericQueue {
|
struct GenericQueue {
|
||||||
ThreadsQueue q_waiting; /**< @brief Queue of waiting threads. */
|
threads_queue_t q_waiting; /**< @brief Queue of waiting threads. */
|
||||||
size_t q_counter; /**< @brief Resources counter. */
|
size_t q_counter; /**< @brief Resources counter. */
|
||||||
uint8_t *q_buffer; /**< @brief Pointer to the queue buffer.*/
|
uint8_t *q_buffer; /**< @brief Pointer to the queue buffer.*/
|
||||||
uint8_t *q_top; /**< @brief Pointer to the first location
|
uint8_t *q_top; /**< @brief Pointer to the first location
|
||||||
|
@ -200,7 +200,7 @@ typedef GenericQueue InputQueue;
|
||||||
* @param[in] link application defined pointer
|
* @param[in] link application defined pointer
|
||||||
*/
|
*/
|
||||||
#define _INPUTQUEUE_DATA(name, buffer, size, inotify, link) { \
|
#define _INPUTQUEUE_DATA(name, buffer, size, inotify, link) { \
|
||||||
_THREADSQUEUE_DATA(name), \
|
_threads_queue_t_DATA(name), \
|
||||||
0, \
|
0, \
|
||||||
(uint8_t *)(buffer), \
|
(uint8_t *)(buffer), \
|
||||||
(uint8_t *)(buffer) + (size), \
|
(uint8_t *)(buffer) + (size), \
|
||||||
|
@ -317,7 +317,7 @@ typedef GenericQueue OutputQueue;
|
||||||
* @param[in] link application defined pointer
|
* @param[in] link application defined pointer
|
||||||
*/
|
*/
|
||||||
#define _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link) { \
|
#define _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link) { \
|
||||||
_THREADSQUEUE_DATA(name), \
|
_threads_queue_t_DATA(name), \
|
||||||
(size), \
|
(size), \
|
||||||
(uint8_t *)(buffer), \
|
(uint8_t *)(buffer), \
|
||||||
(uint8_t *)(buffer) + (size), \
|
(uint8_t *)(buffer) + (size), \
|
||||||
|
|
|
@ -79,13 +79,13 @@
|
||||||
#define firstprio(rlp) ((rlp)->p_next->p_prio)
|
#define firstprio(rlp) ((rlp)->p_next->p_prio)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ThreadsQueue
|
* @extends threads_queue_t
|
||||||
*
|
*
|
||||||
* @brief Ready list header.
|
* @brief Ready list header.
|
||||||
*/
|
*/
|
||||||
#if !defined(PORT_OPTIMIZED_READYLIST_STRUCT) || defined(__DOXYGEN__)
|
#if !defined(PORT_OPTIMIZED_READYLIST_STRUCT) || defined(__DOXYGEN__)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ThreadsQueue r_queue; /**< @brief Threads queue. */
|
threads_queue_t r_queue; /**< @brief Threads queue. */
|
||||||
tprio_t r_prio; /**< @brief This field must be
|
tprio_t r_prio; /**< @brief This field must be
|
||||||
initialized to zero. */
|
initialized to zero. */
|
||||||
struct context r_ctx; /**< @brief Not used, present because
|
struct context r_ctx; /**< @brief Not used, present because
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
* @brief Semaphore structure.
|
* @brief Semaphore structure.
|
||||||
*/
|
*/
|
||||||
typedef struct Semaphore {
|
typedef struct Semaphore {
|
||||||
ThreadsQueue 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;
|
||||||
|
@ -69,7 +69,7 @@ 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_DATA(name, n) {_THREADSQUEUE_DATA(name.s_queue), n}
|
#define _SEMAPHORE_DATA(name, n) {_threads_queue_t_DATA(name.s_queue), n}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static semaphore initializer.
|
* @brief Static semaphore initializer.
|
||||||
|
|
|
@ -104,20 +104,20 @@ typedef struct Mutex Mutex;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
Thread *p_next; /**< @brief Next in the list/queue. */
|
Thread *p_next; /**< @brief Next in the list/queue. */
|
||||||
} ThreadsList;
|
} threads_list_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ThreadsList
|
* @extends threads_list_t
|
||||||
*
|
*
|
||||||
* @brief Generic threads bidirectional linked list header and element.
|
* @brief Generic threads bidirectional linked list header and element.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Thread *p_next; /**< @brief Next in the list/queue. */
|
Thread *p_next; /**< @brief Next in the list/queue. */
|
||||||
Thread *p_prev; /**< @brief Previous in the queue. */
|
Thread *p_prev; /**< @brief Previous in the queue. */
|
||||||
} ThreadsQueue;
|
} threads_queue_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ThreadsQueue
|
* @extends threads_queue_t
|
||||||
*
|
*
|
||||||
* @brief Structure representing a thread.
|
* @brief Structure representing a thread.
|
||||||
* @note Not all the listed fields are always needed, by switching off some
|
* @note Not all the listed fields are always needed, by switching off some
|
||||||
|
@ -126,9 +126,9 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
struct Thread {
|
struct Thread {
|
||||||
Thread *p_next; /**< @brief Next in the list/queue. */
|
Thread *p_next; /**< @brief Next in the list/queue. */
|
||||||
/* End of the fields shared with the ThreadsList structure. */
|
/* End of the fields shared with the threads_list_t structure.*/
|
||||||
Thread *p_prev; /**< @brief Previous in the queue. */
|
Thread *p_prev; /**< @brief Previous in the queue. */
|
||||||
/* End of the fields shared with the ThreadsQueue structure. */
|
/* End of the fields shared with the threads_queue_t structure.*/
|
||||||
tprio_t p_prio; /**< @brief Thread priority. */
|
tprio_t p_prio; /**< @brief Thread priority. */
|
||||||
struct context p_ctx; /**< @brief Processor context. */
|
struct context p_ctx; /**< @brief Processor context. */
|
||||||
#if CH_USE_REGISTRY || defined(__DOXYGEN__)
|
#if CH_USE_REGISTRY || defined(__DOXYGEN__)
|
||||||
|
@ -215,13 +215,13 @@ struct Thread {
|
||||||
/**
|
/**
|
||||||
* @brief Termination waiting list.
|
* @brief Termination waiting list.
|
||||||
*/
|
*/
|
||||||
ThreadsList p_waiting;
|
threads_list_t p_waiting;
|
||||||
#endif
|
#endif
|
||||||
#if CH_USE_MESSAGES || defined(__DOXYGEN__)
|
#if CH_USE_MESSAGES || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Messages queue.
|
* @brief Messages queue.
|
||||||
*/
|
*/
|
||||||
ThreadsQueue p_msgqueue;
|
threads_queue_t p_msgqueue;
|
||||||
/**
|
/**
|
||||||
* @brief Thread message.
|
* @brief Thread message.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -62,9 +62,12 @@ 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 list. */
|
VirtualTimer *vt_next; /**< @brief Next timer in the delta
|
||||||
VirtualTimer *vt_prev; /**< @brief Last timer in the list. */
|
list. */
|
||||||
volatile systime_t vt_time; /**< @brief Current system time. */
|
VirtualTimer *vt_prev; /**< @brief Last timer in the delta
|
||||||
|
list. */
|
||||||
|
systime_t vt_time; /**< @brief Must be initialized to -1. */
|
||||||
|
volatile systime_t vt_systime; /**< @brief System Time counter. */
|
||||||
} VTList;
|
} VTList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +78,7 @@ typedef struct {
|
||||||
struct VirtualTimer {
|
struct VirtualTimer {
|
||||||
VirtualTimer *vt_next; /**< @brief Next timer in the list. */
|
VirtualTimer *vt_next; /**< @brief Next timer in the list. */
|
||||||
VirtualTimer *vt_prev; /**< @brief Previous timer in the list. */
|
VirtualTimer *vt_prev; /**< @brief Previous timer in the list. */
|
||||||
systime_t vt_time; /**< @brief Absolute time. */
|
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. */
|
||||||
void *vt_par; /**< @brief Timer callback function
|
void *vt_par; /**< @brief Timer callback function
|
||||||
|
@ -144,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 chVTSetAbsoluteI(VirtualTimer *vtp, systime_t time,
|
void chVTDoSetI(VirtualTimer *vtp, systime_t delay,
|
||||||
vtfunc_t vtfunc, void *par);
|
vtfunc_t vtfunc, void *par);
|
||||||
void chVTResetI(VirtualTimer *vtp);
|
void chVTDoResetI(VirtualTimer *vtp);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -155,6 +158,22 @@ extern "C" {
|
||||||
/* Module inline functions. */
|
/* Module inline functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes a @p VirtualTimer object.
|
||||||
|
* @note Initializing a timer object is not strictly required because
|
||||||
|
* the function @p chVTSetI() initializes the object too. This
|
||||||
|
* function is only useful if you need to perform a @p chVTIsArmed()
|
||||||
|
* check before calling @p chVTSetI().
|
||||||
|
*
|
||||||
|
* @param[out] vtp the @p VirtualTimer structure pointer
|
||||||
|
*
|
||||||
|
* @init
|
||||||
|
*/
|
||||||
|
static inline void chVTObjectInit(VirtualTimer *vtp) {
|
||||||
|
|
||||||
|
vtp->vt_func = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Current system time.
|
* @brief Current system time.
|
||||||
* @details Returns the number of system ticks since the @p chSysInit()
|
* @details Returns the number of system ticks since the @p chSysInit()
|
||||||
|
@ -227,22 +246,6 @@ static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) {
|
||||||
return chVTIsTimeWithin(chVTGetSystemTime(), start, end);
|
return chVTIsTimeWithin(chVTGetSystemTime(), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initializes a @p VirtualTimer object.
|
|
||||||
* @note Initializing a timer object is not strictly required because
|
|
||||||
* the function @p chVTSetI() initializes the object too. This
|
|
||||||
* function is only useful if you need to perform a @p chVTIsArmed()
|
|
||||||
* check before calling @p chVTSetI().
|
|
||||||
*
|
|
||||||
* @param[out] vtp the @p VirtualTimer structure pointer
|
|
||||||
*
|
|
||||||
* @init
|
|
||||||
*/
|
|
||||||
static inline void chVTObjectInit(VirtualTimer *vtp) {
|
|
||||||
|
|
||||||
vtp->vt_func = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns @p true if the specified timer is armed.
|
* @brief Returns @p true if the specified timer is armed.
|
||||||
* @pre The timer must have been initialized using @p chVTObjectInit()
|
* @pre The timer must have been initialized using @p chVTObjectInit()
|
||||||
|
@ -260,62 +263,18 @@ static inline bool chVTIsArmedI(VirtualTimer *vtp) {
|
||||||
return (bool)(vtp->vt_func != NULL);
|
return (bool)(vtp->vt_func != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Enables a virtual timer.
|
|
||||||
*
|
|
||||||
* @param[out] vtp the @p VirtualTimer structure pointer
|
|
||||||
* @param[in] delay the number of ticks before the operation timeouts.
|
|
||||||
* @param[in] vtfunc the timer callback function. After invoking the
|
|
||||||
* callback the timer is disabled and the structure can
|
|
||||||
* be disposed or reused.
|
|
||||||
* @param[in] par a parameter that will be passed to the callback
|
|
||||||
* function
|
|
||||||
*
|
|
||||||
* @iclass
|
|
||||||
*/
|
|
||||||
static inline void chVTSetI(VirtualTimer *vtp, systime_t delay,
|
|
||||||
vtfunc_t vtfunc, void *par) {
|
|
||||||
|
|
||||||
chVTSetAbsoluteI(vtp, chVTGetSystemTimeI() + delay, vtfunc, par);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Enables a virtual timer.
|
|
||||||
*
|
|
||||||
* @param[out] vtp the @p VirtualTimer structure pointer
|
|
||||||
* @param[in] delay the number of ticks before the operation timeouts.
|
|
||||||
* @param[in] vtfunc the timer callback function. After invoking the
|
|
||||||
* callback the timer is disabled and the structure can
|
|
||||||
* be disposed or reused.
|
|
||||||
* @param[in] par a parameter that will be passed to the callback
|
|
||||||
* function
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
static inline void chVTSet(VirtualTimer *vtp, systime_t delay,
|
|
||||||
vtfunc_t vtfunc, void *par) {
|
|
||||||
|
|
||||||
chSysLock();
|
|
||||||
chVTSetI(vtp, delay, vtfunc, par);
|
|
||||||
chSysUnlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disables a Virtual Timer.
|
* @brief Disables a Virtual Timer.
|
||||||
* @pre The timer must be in armed state before calling this function.
|
* @note The timer is first checked and disabled only if armed.
|
||||||
*
|
*
|
||||||
* @param[in] vtp the @p VirtualTimer structure pointer
|
* @param[in] vtp the @p VirtualTimer structure pointer
|
||||||
*
|
*
|
||||||
* @iclass
|
* @iclass
|
||||||
*/
|
*/
|
||||||
static inline void chVTDoResetI(VirtualTimer *vtp) {
|
static inline void chVTResetI(VirtualTimer *vtp) {
|
||||||
|
|
||||||
chDbgCheckClassI();
|
if (chVTIsArmedI(vtp))
|
||||||
chDbgCheck(vtp != NULL, "chVTDoResetI");
|
chVTDoResetI(vtp);
|
||||||
|
|
||||||
vtp->vt_prev->vt_next = vtp->vt_next;
|
|
||||||
vtp->vt_next->vt_prev = vtp->vt_prev;
|
|
||||||
vtp->vt_func = (vtfunc_t)NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -333,6 +292,51 @@ static inline void chVTReset(VirtualTimer *vtp) {
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables a virtual timer.
|
||||||
|
* @details If the virtual timer was already enabled then it is re-enabled
|
||||||
|
* using the new parameters.
|
||||||
|
*
|
||||||
|
* @param[in] vtp the @p VirtualTimer structure pointer
|
||||||
|
* @param[in] delay the number of ticks before the operation timeouts.
|
||||||
|
* @param[in] vtfunc the timer callback function. After invoking the
|
||||||
|
* callback the timer is disabled and the structure can
|
||||||
|
* be disposed or reused.
|
||||||
|
* @param[in] par a parameter that will be passed to the callback
|
||||||
|
* function
|
||||||
|
*
|
||||||
|
* @iclass
|
||||||
|
*/
|
||||||
|
static inline void chVTSetI(VirtualTimer *vtp, systime_t delay,
|
||||||
|
vtfunc_t vtfunc, void *par) {
|
||||||
|
|
||||||
|
chVTResetI(vtp);
|
||||||
|
chVTDoSetI(vtp, delay, vtfunc, par);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables a virtual timer.
|
||||||
|
* @details If the virtual timer was already enabled then it is re-enabled
|
||||||
|
* using the new parameters.
|
||||||
|
*
|
||||||
|
* @param[in] vtp the @p VirtualTimer structure pointer
|
||||||
|
* @param[in] delay the number of ticks before the operation timeouts.
|
||||||
|
* @param[in] vtfunc the timer callback function. After invoking the
|
||||||
|
* callback the timer is disabled and the structure can
|
||||||
|
* be disposed or reused.
|
||||||
|
* @param[in] par a parameter that will be passed to the callback
|
||||||
|
* function
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
static inline void chVTSet(VirtualTimer *vtp, systime_t delay,
|
||||||
|
vtfunc_t vtfunc, void *par) {
|
||||||
|
|
||||||
|
chSysLock();
|
||||||
|
chVTSetI(vtp, delay, vtfunc, par);
|
||||||
|
chSysUnlock();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Virtual timers ticker.
|
* @brief Virtual timers ticker.
|
||||||
* @note The system lock is released before entering the callback and
|
* @note The system lock is released before entering the callback and
|
||||||
|
@ -343,17 +347,19 @@ static inline void chVTReset(VirtualTimer *vtp) {
|
||||||
* @iclass
|
* @iclass
|
||||||
*/
|
*/
|
||||||
static inline void chVTDoTickI(void) {
|
static inline void chVTDoTickI(void) {
|
||||||
systime_t systime = ++vtlist.vt_time;
|
|
||||||
|
|
||||||
chDbgCheckClassI();
|
chDbgCheckClassI();
|
||||||
|
|
||||||
|
vtlist.vt_systime++;
|
||||||
if (&vtlist != (VTList *)vtlist.vt_next) {
|
if (&vtlist != (VTList *)vtlist.vt_next) {
|
||||||
VirtualTimer *vtp;
|
VirtualTimer *vtp;
|
||||||
|
|
||||||
while (((VirtualTimer *)&vtlist != (vtp = vtlist.vt_next)) &&
|
--vtlist.vt_next->vt_time;
|
||||||
(vtp->vt_time == systime)) {
|
while (!(vtp = vtlist.vt_next)->vt_time) {
|
||||||
vtfunc_t fn = vtp->vt_func;
|
vtfunc_t fn = vtp->vt_func;
|
||||||
chVTDoResetI(vtp);
|
vtp->vt_func = (vtfunc_t)NULL;
|
||||||
|
vtp->vt_next->vt_prev = (void *)&vtlist;
|
||||||
|
(&vtlist)->vt_next = vtp->vt_next;
|
||||||
chSysUnlockFromIsr();
|
chSysUnlockFromIsr();
|
||||||
fn(vtp->vt_par);
|
fn(vtp->vt_par);
|
||||||
chSysLockFromIsr();
|
chSysLockFromIsr();
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void queue_prio_insert(Thread *tp, ThreadsQueue *tqp) {
|
void queue_prio_insert(Thread *tp, threads_queue_t *tqp) {
|
||||||
|
|
||||||
/* cp iterates over the queue.*/
|
/* cp iterates over the queue.*/
|
||||||
Thread *cp = (Thread *)tqp;
|
Thread *cp = (Thread *)tqp;
|
||||||
|
@ -88,7 +88,7 @@ void queue_prio_insert(Thread *tp, ThreadsQueue *tqp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void queue_insert(Thread *tp, ThreadsQueue *tqp) {
|
void queue_insert(Thread *tp, threads_queue_t *tqp) {
|
||||||
|
|
||||||
tp->p_next = (Thread *)tqp;
|
tp->p_next = (Thread *)tqp;
|
||||||
tp->p_prev = tqp->p_prev;
|
tp->p_prev = tqp->p_prev;
|
||||||
|
@ -105,7 +105,7 @@ void queue_insert(Thread *tp, ThreadsQueue *tqp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
Thread *queue_fifo_remove(ThreadsQueue *tqp) {
|
Thread *queue_fifo_remove(threads_queue_t *tqp) {
|
||||||
Thread *tp = tqp->p_next;
|
Thread *tp = tqp->p_next;
|
||||||
|
|
||||||
(tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp;
|
(tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp;
|
||||||
|
@ -122,7 +122,7 @@ Thread *queue_fifo_remove(ThreadsQueue *tqp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
Thread *queue_lifo_remove(ThreadsQueue *tqp) {
|
Thread *queue_lifo_remove(threads_queue_t *tqp) {
|
||||||
Thread *tp = tqp->p_prev;
|
Thread *tp = tqp->p_prev;
|
||||||
|
|
||||||
(tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp;
|
(tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp;
|
||||||
|
@ -154,7 +154,7 @@ Thread *queue_dequeue(Thread *tp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void list_insert(Thread *tp, ThreadsList *tlp) {
|
void list_insert(Thread *tp, threads_list_t *tlp) {
|
||||||
|
|
||||||
tp->p_next = tlp->p_next;
|
tp->p_next = tlp->p_next;
|
||||||
tlp->p_next = tp;
|
tlp->p_next = tp;
|
||||||
|
@ -169,7 +169,7 @@ void list_insert(Thread *tp, ThreadsList *tlp) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
Thread *list_remove(ThreadsList *tlp) {
|
Thread *list_remove(threads_list_t *tlp) {
|
||||||
|
|
||||||
Thread *tp = tlp->p_next;
|
Thread *tp = tlp->p_next;
|
||||||
tlp->p_next = tp->p_next;
|
tlp->p_next = tp->p_next;
|
||||||
|
|
|
@ -132,7 +132,8 @@ void chMtxLockS(Mutex *mp) {
|
||||||
switch (tp->p_state) {
|
switch (tp->p_state) {
|
||||||
case THD_STATE_WTMTX:
|
case THD_STATE_WTMTX:
|
||||||
/* Re-enqueues the mutex owner with its new priority.*/
|
/* Re-enqueues the mutex owner with its new priority.*/
|
||||||
queue_prio_insert(queue_dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp);
|
queue_prio_insert(queue_dequeue(tp),
|
||||||
|
(threads_queue_t *)tp->p_u.wtobjp);
|
||||||
tp = ((Mutex *)tp->p_u.wtobjp)->m_owner;
|
tp = ((Mutex *)tp->p_u.wtobjp)->m_owner;
|
||||||
continue;
|
continue;
|
||||||
#if CH_USE_CONDVARS | \
|
#if CH_USE_CONDVARS | \
|
||||||
|
@ -148,7 +149,8 @@ void chMtxLockS(Mutex *mp) {
|
||||||
case THD_STATE_SNDMSGQ:
|
case THD_STATE_SNDMSGQ:
|
||||||
#endif
|
#endif
|
||||||
/* Re-enqueues tp with its new priority on the queue.*/
|
/* Re-enqueues tp with its new priority on the queue.*/
|
||||||
queue_prio_insert(queue_dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp);
|
queue_prio_insert(queue_dequeue(tp),
|
||||||
|
(threads_queue_t *)tp->p_u.wtobjp);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case THD_STATE_READY:
|
case THD_STATE_READY:
|
||||||
|
|
|
@ -186,7 +186,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
|
||||||
if (TIME_INFINITE != time) {
|
if (TIME_INFINITE != time) {
|
||||||
VirtualTimer vt;
|
VirtualTimer vt;
|
||||||
|
|
||||||
chVTSetI(&vt, time, wakeup, currp);
|
chVTDoSetI(&vt, time, wakeup, currp);
|
||||||
chSchGoSleepS(newstate);
|
chSchGoSleepS(newstate);
|
||||||
if (chVTIsArmedI(&vt))
|
if (chVTIsArmedI(&vt))
|
||||||
chVTDoResetI(&vt);
|
chVTDoResetI(&vt);
|
||||||
|
|
|
@ -67,7 +67,8 @@ VTList vtlist;
|
||||||
void _vt_init(void) {
|
void _vt_init(void) {
|
||||||
|
|
||||||
vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist;
|
vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist;
|
||||||
vtlist.vt_time = 0;
|
vtlist.vt_time = (systime_t)-1;
|
||||||
|
vtlist.vt_systime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,12 +94,18 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enables a virtual timer.
|
* @brief Enables a virtual timer.
|
||||||
* @details The timer is enabled and programmed to trigger at the absolute
|
* @details The timer is enabled and programmed to trigger after the delay
|
||||||
* system time specified as parameter.
|
* specified as parameter.
|
||||||
* @note The associated function is invoked from interrupt context.
|
* @pre The timer must not be already armed before calling this function.
|
||||||
|
* @note The callback function is invoked from interrupt context.
|
||||||
*
|
*
|
||||||
* @param[out] vtp the @p VirtualTimer structure pointer
|
* @param[out] vtp the @p VirtualTimer structure pointer
|
||||||
* @param[in] time absolute system time
|
* @param[in] delay 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.
|
||||||
|
* - @a TIME_IMMEDIATE this value is not allowed.
|
||||||
|
* .
|
||||||
* @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
|
||||||
* be disposed or reused.
|
* be disposed or reused.
|
||||||
|
@ -107,51 +114,50 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) {
|
||||||
*
|
*
|
||||||
* @iclass
|
* @iclass
|
||||||
*/
|
*/
|
||||||
void chVTSetAbsoluteI(VirtualTimer *vtp, systime_t time,
|
void chVTDoSetI(VirtualTimer *vtp, systime_t delay,
|
||||||
vtfunc_t vtfunc, void *par) {
|
vtfunc_t vtfunc, void *par) {
|
||||||
VirtualTimer *p;
|
VirtualTimer *p;
|
||||||
systime_t systime = vtlist.vt_time;
|
|
||||||
|
|
||||||
chDbgCheckClassI();
|
chDbgCheckClassI();
|
||||||
chDbgCheck((vtp != NULL) && (vtfunc != NULL), "chVTSetI");
|
chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE),
|
||||||
|
"chVTDoSetI");
|
||||||
|
|
||||||
vtp->vt_par = par;
|
vtp->vt_par = par;
|
||||||
vtp->vt_func = vtfunc;
|
vtp->vt_func = vtfunc;
|
||||||
vtp->vt_time = time;
|
|
||||||
if (time <= systime) {
|
|
||||||
p = vtlist.vt_prev;
|
|
||||||
while ((p->vt_time <= systime) && (p->vt_time > time))
|
|
||||||
p = p->vt_prev;
|
|
||||||
vtp->vt_next = (vtp->vt_prev = p)->vt_next;
|
|
||||||
vtp->vt_next->vt_prev = p->vt_next = vtp;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
p = vtlist.vt_next;
|
p = vtlist.vt_next;
|
||||||
while ((p->vt_time > systime) && (p->vt_time < time))
|
while (p->vt_time < delay) {
|
||||||
|
delay -= p->vt_time;
|
||||||
p = p->vt_next;
|
p = p->vt_next;
|
||||||
|
}
|
||||||
|
|
||||||
vtp->vt_prev = (vtp->vt_next = p)->vt_prev;
|
vtp->vt_prev = (vtp->vt_next = p)->vt_prev;
|
||||||
vtp->vt_prev->vt_next = p->vt_prev = vtp;
|
vtp->vt_prev->vt_next = p->vt_prev = vtp;
|
||||||
}
|
vtp->vt_time = delay;
|
||||||
|
if (p != (void *)&vtlist)
|
||||||
|
p->vt_time -= delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Disables a Virtual Timer.
|
* @brief Disables a Virtual Timer.
|
||||||
* @note The timer is first checked and disabled only if armed.
|
* @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 VirtualTimer structure pointer
|
||||||
*
|
*
|
||||||
* @iclass
|
* @iclass
|
||||||
*/
|
*/
|
||||||
void chVTResetI(VirtualTimer *vtp) {
|
void chVTDoResetI(VirtualTimer *vtp) {
|
||||||
|
|
||||||
chDbgCheckClassI();
|
chDbgCheckClassI();
|
||||||
chDbgCheck(vtp != NULL, "chVTResetI");
|
chDbgCheck(vtp != NULL, "chVTDoResetI");
|
||||||
|
chDbgAssert(vtp->vt_func != NULL,
|
||||||
|
"chVTDoResetI(), #1",
|
||||||
|
"timer not set or already triggered");
|
||||||
|
|
||||||
if (chVTIsArmedI(vtp)) {
|
if (vtp->vt_next != (void *)&vtlist)
|
||||||
|
vtp->vt_next->vt_time += vtp->vt_time;
|
||||||
vtp->vt_prev->vt_next = vtp->vt_next;
|
vtp->vt_prev->vt_next = vtp->vt_next;
|
||||||
vtp->vt_next->vt_prev = vtp->vt_prev;
|
vtp->vt_next->vt_prev = vtp->vt_prev;
|
||||||
vtp->vt_func = (vtfunc_t)NULL;
|
vtp->vt_func = (vtfunc_t)NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -507,8 +507,8 @@ static void bmk10_execute(void) {
|
||||||
test_start_timer(1000);
|
test_start_timer(1000);
|
||||||
do {
|
do {
|
||||||
chSysLock();
|
chSysLock();
|
||||||
chVTSetI(&vt1, 1, tmo, NULL);
|
chVTDoSetI(&vt1, 1, tmo, NULL);
|
||||||
chVTSetI(&vt2, 10000, tmo, NULL);
|
chVTDoSetI(&vt2, 10000, tmo, NULL);
|
||||||
chVTResetI(&vt1);
|
chVTResetI(&vt1);
|
||||||
chVTResetI(&vt2);
|
chVTResetI(&vt2);
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
|
|
Loading…
Reference in New Issue