git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@53 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2007-10-15 14:52:56 +00:00
parent 779840691f
commit 70c86d43ec
17 changed files with 117 additions and 57 deletions

View File

@ -69,7 +69,7 @@ void PlaySound(int freq, t_time duration) {
chSysLock(); chSysLock();
if (bvt.vt_func) { // If a sound is already being played if (chVTIsArmedI(&bvt)) { // If a sound is already being played
chVTResetI(&bvt); // then aborts it. chVTResetI(&bvt); // then aborts it.
StopCounter(tc); StopCounter(tc);
} }

View File

@ -51,6 +51,10 @@
* function is included in the kernel.*/ * function is included in the kernel.*/
#define CH_USE_RESUME #define CH_USE_RESUME
/** Configuration option: if specified then the \p chThdSuspend()
* function is included in the kernel.*/
#define CH_USE_SUSPEND
/** Configuration option: if specified then the \p chThdTerminate() /** Configuration option: if specified then the \p chThdTerminate()
* and \p chThdShouldTerminate() functions are included in the kernel.*/ * and \p chThdShouldTerminate() functions are included in the kernel.*/
#define CH_USE_TERMINATE #define CH_USE_TERMINATE

View File

@ -52,6 +52,10 @@
* function is included in the kernel.*/ * function is included in the kernel.*/
#define CH_USE_RESUME #define CH_USE_RESUME
/** Configuration option: if specified then the \p chThdSuspend()
* function is included in the kernel.*/
#define CH_USE_SUSPEND
/** Configuration option: if specified then the \p chThdTerminate() /** Configuration option: if specified then the \p chThdTerminate()
* and \p chThdShouldTerminate() functions are included in the kernel.*/ * and \p chThdShouldTerminate() functions are included in the kernel.*/
#define CH_USE_TERMINATE #define CH_USE_TERMINATE

View File

@ -56,6 +56,10 @@
* function is included in the kernel.*/ * function is included in the kernel.*/
#define CH_USE_RESUME #define CH_USE_RESUME
/** Configuration option: if specified then the \p chThdSuspend()
* function is included in the kernel.*/
#define CH_USE_SUSPEND
/** Configuration option: if specified then the \p chThdTerminate() /** Configuration option: if specified then the \p chThdTerminate()
* and \p chThdShouldTerminate() functions are included in the kernel.*/ * and \p chThdShouldTerminate() functions are included in the kernel.*/
#define CH_USE_TERMINATE #define CH_USE_TERMINATE

View File

@ -56,6 +56,10 @@
* function is included in the kernel.*/ * function is included in the kernel.*/
#define CH_USE_RESUME #define CH_USE_RESUME
/** Configuration option: if specified then the \p chThdSuspend()
* function is included in the kernel.*/
#define CH_USE_SUSPEND
/** Configuration option: if specified then the \p chThdTerminate() /** Configuration option: if specified then the \p chThdTerminate()
* and \p chThdShouldTerminate() functions are included in the kernel.*/ * and \p chThdShouldTerminate() functions are included in the kernel.*/
#define CH_USE_TERMINATE #define CH_USE_TERMINATE

View File

@ -227,6 +227,7 @@ PREDEFINED = __JUST_STUBS__ \
CH_USE_SYSTEMTIME \ CH_USE_SYSTEMTIME \
CH_USE_SLEEP \ CH_USE_SLEEP \
CH_USE_RESUME \ CH_USE_RESUME \
CH_USE_SUSPEND \
CH_USE_TERMINATE \ CH_USE_TERMINATE \
CH_USE_WAITEXIT \ CH_USE_WAITEXIT \
CH_USE_SEMAPHORES \ CH_USE_SEMAPHORES \

View File

@ -106,12 +106,12 @@ static void OutNotify2(void) {
u->UART_IER |= IER_THRE; u->UART_IER |= IER_THRE;
} }
void UART0Irq(void){ void UART0Irq(void) {
ServeInterrupt(U0Base, &COM1); ServeInterrupt(U0Base, &COM1);
} }
void UART1Irq(void){ void UART1Irq(void) {
ServeInterrupt(U1Base, &COM2); ServeInterrupt(U1Base, &COM2);
} }

View File

@ -40,8 +40,10 @@ AVR-AT90CANx-GCC - Port on AVER AT90CAN128, not complete yet.
*** 0.3.4 *** *** 0.3.4 ***
- Fixed a problem in chVTSetI(). - Fixed a problem in chVTSetI().
- Modified chEvtWaitTimeout() to work correctly in the TIME_INFINITE - New API, chVTIsArmedI(), it is a macro in delta.h.
scenario. - New API, chThdResumeI(), it is a macro in threads.h. This function is just
an alias for chSchReadyI() but makes the code more readable.
- New API, chThdSuspend(). New switch CH_USE_SUSPEND added to chconf.h.
*** 0.3.3 *** *** 0.3.3 ***
- Modified the chVTSetI(), now for the "time" parameter can have value zero - Modified the chVTSetI(), now for the "time" parameter can have value zero
@ -54,7 +56,7 @@ AVR-AT90CANx-GCC - Port on AVER AT90CAN128, not complete yet.
- Modified the chSysInit() to give the idle thread absolute priority, the - Modified the chSysInit() to give the idle thread absolute priority, the
priority is then lowered to the minimum value into the chSysPause(). This priority is then lowered to the minimum value into the chSysPause(). This
is done in order to ensure that the initializations performed into the is done in order to ensure that the initializations performed into the
main() procedure are performed before any thread starts. main() procedure are finished before any thread starts.
- Added chThdSetPriority() new API. - Added chThdSetPriority() new API.
- Added a generic events generator timer modulee to the library code. - Added a generic events generator timer modulee to the library code.
- Modified the ARM7-LPC214x-GCC demo to show the use of the event timer. - Modified the ARM7-LPC214x-GCC demo to show the use of the event timer.

View File

@ -40,7 +40,9 @@ void chVTInit(void) {
* Enables a virtual timer. * Enables a virtual timer.
* @param vtp the \p VirtualTimer structure pointer * @param vtp the \p VirtualTimer structure pointer
* @param time the number of time ticks, the value zero is allowed with * @param time the number of time ticks, the value zero is allowed with
* meaning "infinite". * meaning "infinite". In this case the structure is initialized
* but not inserted in the delta list, the timer will never be
* triggered.
* @param vtfunc the timer callback function. After invoking the callback * @param vtfunc the timer callback function. After invoking the callback
* the timer is disabled and the structure can be disposed or * the timer is disabled and the structure can be disposed or
* reused. * reused.
@ -51,8 +53,8 @@ void chVTInit(void) {
void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par) { void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par) {
vtp->vt_par = par; vtp->vt_par = par;
vtp->vt_func = vtfunc;
if (time) { if (time) {
vtp->vt_func = vtfunc;
VirtualTimer *p = dlist.dl_next; VirtualTimer *p = dlist.dl_next;
while (p->vt_dtime < time) { while (p->vt_dtime < time) {
time -= p->vt_dtime; time -= p->vt_dtime;
@ -66,7 +68,7 @@ void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par) {
p->vt_dtime -= time; p->vt_dtime -= time;
} }
else else
vtp->vt_func = NULL; vtp->vt_next = vtp->vt_prev = vtp; // Allows a chVTResetI() on the fake timer.
} }
/** /**

View File

@ -205,7 +205,6 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask,
t_time time) { t_time time) {
t_eventid i; t_eventid i;
t_eventmask m; t_eventmask m;
t_msg msg;
chSysLock(); chSysLock();
@ -221,11 +220,10 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask,
chVTSetI(&vt, time, unwait, currp); chVTSetI(&vt, time, unwait, currp);
currp->p_ewmask = ewmask; currp->p_ewmask = ewmask;
chSchGoSleepS(PRWTEVENT); chSchGoSleepS(PRWTEVENT);
if (!vt.vt_func) { if (!chVTIsArmedI(&vt)) {
t_msg msg = currp->p_rdymsg;
chSysUnlock(); chSysUnlock();
return msg; return RDY_TIMEOUT;
} }
chVTResetI(&vt); chVTResetI(&vt);
} }

View File

@ -115,7 +115,7 @@ t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time) {
currp->p_msg = msg; currp->p_msg = msg;
chSchGoSleepS(PRSNDMSG); chSchGoSleepS(PRSNDMSG);
msg = currp->p_rdymsg; msg = currp->p_rdymsg;
if (vt.vt_func) if (chVTIsArmedI(&vt))
chVTResetI(&vt); chVTResetI(&vt);
chSysUnlock(); chSysUnlock();

View File

@ -139,7 +139,7 @@ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) {
currp->p_semp = sp; currp->p_semp = sp;
chSchGoSleepS(PRWTSEM); chSchGoSleepS(PRWTSEM);
msg = currp->p_rdymsg; msg = currp->p_rdymsg;
if (vt.vt_func) if (chVTIsArmedI(&vt))
chVTResetI(&vt); chVTResetI(&vt);
chSysUnlock(); chSysUnlock();
@ -169,7 +169,7 @@ t_msg chSemWaitTimeoutS(Semaphore *sp, t_time time) {
fifo_insert(currp, &sp->s_queue); fifo_insert(currp, &sp->s_queue);
currp->p_semp = sp; currp->p_semp = sp;
chSchGoSleepS(PRWTSEM); chSchGoSleepS(PRWTSEM);
if (vt.vt_func) if (chVTIsArmedI(&vt))
chVTResetI(&vt); chVTResetI(&vt);
return currp->p_rdymsg; return currp->p_rdymsg;
} }

View File

@ -121,9 +121,34 @@ void chThdSetPriority(t_prio newprio) {
chSysUnlock(); chSysUnlock();
} }
#ifdef CH_USE_SUSPEND
/**
* Suspends the invoking thread.
*
* @param tpp pointer to a \p Thread pointer, the \p Thread pointer is set
* to point to the suspended process before it enters the
* \p PRSUSPENDED state, it is set to \p NULL after it is resumed.
* This allows to implement a "test and resume" on the variable
* into interrupt handlers.
* @note The function is available only if the \p CH_USE_SUSPEND
* option is enabled in \p chconf.h.
*/
void chThdSuspend(Thread **tpp) {
chSysLock();
*tpp = currp;
chSchGoSleepS(PRSUSPENDED);
*tpp = NULL;
chSysUnlock();
}
#endif /* CH_USE_SUSPEND */
#ifdef CH_USE_RESUME #ifdef CH_USE_RESUME
/** /**
* Resumes a thread created with the \p P_SUSPENDED option. * Resumes a thread created with the \p P_SUSPENDED option or suspended with
* \p chThdSuspend().
* @param tp the pointer to the thread * @param tp the pointer to the thread
* @note The function has no effect on threads in any other state than * @note The function has no effect on threads in any other state than
* \p PRSUSPENDED. * \p PRSUSPENDED.
@ -134,8 +159,8 @@ void chThdResume(Thread *tp) {
chSysLock(); chSysLock();
if (tp->p_state == PRSUSPENDED) if ((tp)->p_state == PRSUSPENDED)
chSchWakeupS(tp, RDY_OK); chSchWakeupS((tp), RDY_OK);
chSysUnlock(); chSysUnlock();
} }

View File

@ -97,6 +97,9 @@ extern "C" {
} }
#endif #endif
/** Returns TRUE if the speciified timer is armed.*/
#define chVTIsArmedI(vtp) ((vtp)->vt_func != NULL)
#endif /* CH_USE_VIRTUAL_TIMER */ #endif /* CH_USE_VIRTUAL_TIMER */
#endif /* _DELTA_H_ */ #endif /* _DELTA_H_ */

View File

@ -192,8 +192,10 @@ extern "C" {
Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace, Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace,
t_size wsize, t_tfunc pf, void *arg); t_size wsize, t_tfunc pf, void *arg);
void chThdSetPriority(t_prio newprio); void chThdSetPriority(t_prio newprio);
void chThdResume(Thread *tp);
void chThdExit(t_msg msg); void chThdExit(t_msg msg);
#ifdef CH_USE_RESUME
void chThdResume(Thread *tp);
#endif
#ifdef CH_USE_TERMINATE #ifdef CH_USE_TERMINATE
void chThdTerminate(Thread *tp); void chThdTerminate(Thread *tp);
#endif #endif
@ -240,6 +242,13 @@ extern "C" {
*/ */
#define chThdGetExitEventSource(tp) (&(tp)->p_exitesource) #define chThdGetExitEventSource(tp) (&(tp)->p_exitesource)
/**
* Resumes a thread created with the \p P_SUSPENDED option or suspended with
* \p chThdSuspend().
* @param tp the pointer to the thread
*/
#define chThdResumeI(tp) chSchReadyI(tp)
#endif /* _THREADS_H_ */ #endif /* _THREADS_H_ */
/** @} */ /** @} */

View File

@ -45,7 +45,7 @@ void evtStart(EvTimer *etp) {
chSysLock(); chSysLock();
if (!etp->et_vt.vt_func) if (!chVTIsArmedI(&etp->et_vt))
chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp); chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
chSysUnlock(); chSysUnlock();
@ -60,7 +60,7 @@ void evtStop(EvTimer *etp) {
chSysLock(); chSysLock();
if (etp->et_vt.vt_func) if (chVTIsArmedI(&etp->et_vt))
chVTResetI(&etp->et_vt); chVTResetI(&etp->et_vt);
chSysUnlock(); chSysUnlock();

View File

@ -52,6 +52,10 @@
* function is included in the kernel.*/ * function is included in the kernel.*/
#define CH_USE_RESUME #define CH_USE_RESUME
/** Configuration option: if specified then the \p chThdSuspend()
* function is included in the kernel.*/
#define CH_USE_SUSPEND
/** Configuration option: if specified then the \p chThdTerminate() /** Configuration option: if specified then the \p chThdTerminate()
* and \p chThdShouldTerminate() functions are included in the kernel.*/ * and \p chThdShouldTerminate() functions are included in the kernel.*/
#define CH_USE_TERMINATE #define CH_USE_TERMINATE