Changes to mailboxes, added S-class APIs.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@810 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2009-03-07 10:17:12 +00:00
parent 75813bcef3
commit b7935679d5
3 changed files with 77 additions and 19 deletions

View File

@ -26,7 +26,7 @@
#include <ch.h> #include <ch.h>
#if CH_USE_MAILBOXES #if CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT
/** /**
* @brief Initializes a Mailbox object. * @brief Initializes a Mailbox object.
* *
@ -63,7 +63,6 @@ void chMBReset(Mailbox *mbp) {
chSysUnlock(); chSysUnlock();
} }
#if CH_USE_SEMAPHORES_TIMEOUT
/** /**
* @brief Posts a message into a mailbox. * @brief Posts a message into a mailbox.
* @details The invoking thread waits until a empty slot in the mailbox becomes * @details The invoking thread waits until a empty slot in the mailbox becomes
@ -80,9 +79,30 @@ void chMBReset(Mailbox *mbp) {
msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout) { msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout) {
msg_t rdymsg; msg_t rdymsg;
chDbgCheck(mbp != NULL, "chMBPost");
chSysLock(); chSysLock();
rdymsg = chMBPostS(mbp, msg, timeout);
chSysUnlock();
return rdymsg;
}
/**
* @brief Posts a message into a mailbox.
* @details The invoking thread waits until a empty slot in the mailbox becomes
* available or the specified time runs out.
*
* @param[in] mbp the pointer to an initialized Mailbox object
* @param[in] msg the message to be posted on the mailbox
* @param[in] timeout the number of ticks before the operation fails
* @return The operation status.
* @retval RDY_OK if the message was correctly posted.
* @retval RDY_RESET if the mailbox was reset while waiting.
* @retval RDY_TIMEOUT if the operation timed out.
*/
msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t timeout) {
msg_t rdymsg;
chDbgCheck(mbp != NULL, "chMBPostS");
rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout);
if (rdymsg == RDY_OK) { if (rdymsg == RDY_OK) {
*mbp->mb_wrptr++ = msg; *mbp->mb_wrptr++ = msg;
@ -91,7 +111,6 @@ msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout) {
chSemSignalI(&mbp->mb_fullsem); chSemSignalI(&mbp->mb_fullsem);
chSchRescheduleS(); chSchRescheduleS();
} }
chSysUnlock();
return rdymsg; return rdymsg;
} }
@ -111,9 +130,30 @@ msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout) {
msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout) { msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout) {
msg_t rdymsg; msg_t rdymsg;
chDbgCheck(mbp != NULL, "chMBPostAhead");
chSysLock(); chSysLock();
rdymsg = chMBPostAheadS(mbp, msg, timeout);
chSysUnlock();
return rdymsg;
}
/**
* @brief Posts an high priority message into a mailbox.
* @details The invoking thread waits until a empty slot in the mailbox becomes
* available or the specified time runs out.
*
* @param[in] mbp the pointer to an initialized Mailbox object
* @param[in] msg the message to be posted on the mailbox
* @param[in] timeout the number of ticks before the operation timeouts
* @return The operation status.
* @retval RDY_OK if the message was correctly posted.
* @retval RDY_RESET if the mailbox was reset while waiting.
* @retval RDY_TIMEOUT if the operation timed out.
*/
msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t timeout) {
msg_t rdymsg;
chDbgCheck(mbp != NULL, "chMBPostAheadS");
rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout);
if (rdymsg == RDY_OK) { if (rdymsg == RDY_OK) {
if (--mbp->mb_rdptr < mbp->mb_buffer) if (--mbp->mb_rdptr < mbp->mb_buffer)
@ -122,7 +162,6 @@ msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout) {
chSemSignalI(&mbp->mb_fullsem); chSemSignalI(&mbp->mb_fullsem);
chSchRescheduleS(); chSchRescheduleS();
} }
chSysUnlock();
return rdymsg; return rdymsg;
} }
@ -142,9 +181,30 @@ msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout) {
msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout) { msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout) {
msg_t rdymsg; msg_t rdymsg;
chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetch");
chSysLock(); chSysLock();
rdymsg = chMBFetchS(mbp, msgp, timeout);
chSysUnlock();
return rdymsg;
}
/**
* @brief Retrieves a message from a mailbox.
* @details The invoking thread waits until a message is posted in the mailbox
* or the specified time runs out.
*
* @param[in] mbp the pointer to an initialized Mailbox object
* @param[out] msgp pointer to a message variable for the received message
* @param[in] timeout the number of ticks before the operation timeouts
* @return The operation status.
* @retval RDY_OK if a message was correctly fetched.
* @retval RDY_RESET if the mailbox was reset while waiting.
* @retval RDY_TIMEOUT if the operation timed out.
*/
msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t timeout) {
msg_t rdymsg;
chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchS");
rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, timeout); rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, timeout);
if (rdymsg == RDY_OK) { if (rdymsg == RDY_OK) {
*msgp = *mbp->mb_rdptr++; *msgp = *mbp->mb_rdptr++;
@ -153,11 +213,8 @@ msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout) {
chSemSignalI(&mbp->mb_emptysem); chSemSignalI(&mbp->mb_emptysem);
chSchRescheduleS(); chSchRescheduleS();
} }
chSysUnlock();
return rdymsg; return rdymsg;
} }
#endif /* CH_USE_SEMAPHORES_TIMEOUT */ #endif /* CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT */
#endif /* CH_USE_MAILBOXES */
/** @} */ /** @} */

View File

@ -27,7 +27,7 @@
#ifndef _MAILBOXES_H_ #ifndef _MAILBOXES_H_
#define _MAILBOXES_H_ #define _MAILBOXES_H_
#if CH_USE_MAILBOXES #if CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT
typedef struct { typedef struct {
msg_t *mb_buffer; /**< Pointer to the mailbox buffer.*/ msg_t *mb_buffer; /**< Pointer to the mailbox buffer.*/
@ -45,8 +45,11 @@ extern "C" {
void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n); void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n);
void chMBReset(Mailbox *mbp); void chMBReset(Mailbox *mbp);
msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout); msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout);
msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t timeout);
msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout); msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout);
msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t timeout);
msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout); msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout);
msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t timeout);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -88,7 +91,7 @@ extern "C" {
*/ */
#define chMBPeek(mbp) (*(mbp)->mb_rdptr) #define chMBPeek(mbp) (*(mbp)->mb_rdptr)
#endif /* CH_USE_MAILBOXES */ #endif /* CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT */
#endif /* _MAILBOXES_H_ */ #endif /* _MAILBOXES_H_ */

View File

@ -17,13 +17,11 @@ After 1.0.0:
* Add checks to all APIs. * Add checks to all APIs.
* Stack checks option. * Stack checks option.
* Threads profiling option. * Threads profiling option.
- Registers clearing on thread start.
* Idle loop hook macro. * Idle loop hook macro.
* Switch the configuration options to TRUE/FALSE rather than def/undef. * Switch the configuration options to TRUE/FALSE rather than def/undef.
* Remove port_puts() from all the ports. * Remove port_puts() from all the ports.
* Stack sizes article into the documentation. * Stack sizes article into the documentation.
- Find out and document main stack settings in MSP430 and AVR runtimes. * Logo...
- Logo...
After 1.2.0: After 1.2.0:
X Abstract I/O channels rather than just serial ports. X Abstract I/O channels rather than just serial ports.