git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1504 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
4165c207ca
commit
78167cbb9f
|
@ -131,8 +131,8 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
|
||||||
* been reset.
|
* been reset.
|
||||||
* @note The function is not atomic, if you need atomicity it is suggested
|
* @note The function is not atomic, if you need atomicity it is suggested
|
||||||
* to use a semaphore or a mutex for mutual exclusion.
|
* to use a semaphore or a mutex for mutual exclusion.
|
||||||
* @note The queue callback is invoked one time <b>for each</b> byte removed
|
* @note The queue callback is invoked before entering a sleep state and at
|
||||||
* from the queue.
|
* the end of the transfer.
|
||||||
*
|
*
|
||||||
* @param[in] iqp pointer to an @p InputQueue structure
|
* @param[in] iqp pointer to an @p InputQueue structure
|
||||||
* @param[out] bp pointer to the data buffer
|
* @param[out] bp pointer to the data buffer
|
||||||
|
@ -149,12 +149,18 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
|
||||||
qnotify_t nfy = iqp->q_notify;
|
qnotify_t nfy = iqp->q_notify;
|
||||||
size_t r = 0;
|
size_t r = 0;
|
||||||
|
|
||||||
do {
|
|
||||||
chSysLock();
|
chSysLock();
|
||||||
if (chSemWaitTimeoutS(&iqp->q_sem, time) != RDY_OK) {
|
while (TRUE) {
|
||||||
|
if (chIQIsEmpty(iqp)) {
|
||||||
|
if (nfy)
|
||||||
|
nfy();
|
||||||
|
if ((chSemWaitTimeoutS(&iqp->q_sem, time) != RDY_OK)) {
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
chSemFastWaitI(&iqp->q_sem);
|
||||||
*bp++ = *iqp->q_rdptr++;
|
*bp++ = *iqp->q_rdptr++;
|
||||||
if (iqp->q_rdptr >= iqp->q_top)
|
if (iqp->q_rdptr >= iqp->q_top)
|
||||||
iqp->q_rdptr = iqp->q_buffer;
|
iqp->q_rdptr = iqp->q_buffer;
|
||||||
|
@ -162,8 +168,15 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
|
||||||
nfy();
|
nfy();
|
||||||
chSysUnlock(); /* Gives a preemption chance in a controlled point.*/
|
chSysUnlock(); /* Gives a preemption chance in a controlled point.*/
|
||||||
r++;
|
r++;
|
||||||
} while (--n > 0);
|
if (--n == 0) {
|
||||||
|
chSysLock();
|
||||||
|
if (nfy)
|
||||||
|
nfy();
|
||||||
|
chSysUnlock();
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
|
chSysLock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -270,8 +283,8 @@ msg_t chOQGetI(OutputQueue *oqp) {
|
||||||
* been reset.
|
* been reset.
|
||||||
* @note The function is not atomic, if you need atomicity it is suggested
|
* @note The function is not atomic, if you need atomicity it is suggested
|
||||||
* to use a semaphore or a mutex for mutual exclusion.
|
* to use a semaphore or a mutex for mutual exclusion.
|
||||||
* @note The queue callback is invoked one time <b>for each</b> byte inserted
|
* @note The queue callback is invoked before entering a sleep state and at
|
||||||
* into the queue.
|
* the end of the transfer.
|
||||||
*
|
*
|
||||||
* @param[in] oqp pointer to an @p OutputQueue structure
|
* @param[in] oqp pointer to an @p OutputQueue structure
|
||||||
* @param[out] bp pointer to the data buffer
|
* @param[out] bp pointer to the data buffer
|
||||||
|
@ -288,21 +301,32 @@ size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp,
|
||||||
qnotify_t nfy = oqp->q_notify;
|
qnotify_t nfy = oqp->q_notify;
|
||||||
size_t w = 0;
|
size_t w = 0;
|
||||||
|
|
||||||
do {
|
|
||||||
chSysLock();
|
chSysLock();
|
||||||
if (chSemWaitTimeoutS(&oqp->q_sem, time) != RDY_OK) {
|
while (TRUE) {
|
||||||
|
if (chOQIsFull(oqp)) {
|
||||||
|
if (nfy)
|
||||||
|
nfy();
|
||||||
|
if ((chSemWaitTimeoutS(&oqp->q_sem, time) != RDY_OK)) {
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
chSemFastWaitI(&oqp->q_sem);
|
||||||
*oqp->q_wrptr++ = *bp++;
|
*oqp->q_wrptr++ = *bp++;
|
||||||
if (oqp->q_wrptr >= oqp->q_top)
|
if (oqp->q_wrptr >= oqp->q_top)
|
||||||
oqp->q_wrptr = oqp->q_buffer;
|
oqp->q_wrptr = oqp->q_buffer;
|
||||||
if (nfy)
|
|
||||||
nfy();
|
|
||||||
chSysUnlock(); /* Gives a preemption chance in a controlled point.*/
|
chSysUnlock(); /* Gives a preemption chance in a controlled point.*/
|
||||||
w++;
|
w++;
|
||||||
} while (--n > 0);
|
if (--n == 0) {
|
||||||
|
chSysLock();
|
||||||
|
if (nfy)
|
||||||
|
nfy();
|
||||||
|
chSysUnlock();
|
||||||
return w;
|
return w;
|
||||||
|
}
|
||||||
|
chSysLock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* CH_USE_QUEUES */
|
#endif /* CH_USE_QUEUES */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue