diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-02-21 18:00:06 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-02-21 18:00:06 +0000 |
commit | 17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd (patch) | |
tree | c8b3af451582e77e9364817fa26466f942ee10df /os/kernel/src | |
parent | fcb39bcbab4beeb5d1ce9bcbd886e54ac1321d34 (diff) | |
download | ChibiOS-17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd.tar.gz ChibiOS-17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd.tar.bz2 ChibiOS-17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2756 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel/src')
-rw-r--r-- | os/kernel/src/chevents.c | 26 | ||||
-rw-r--r-- | os/kernel/src/chmboxes.c | 83 |
2 files changed, 101 insertions, 8 deletions
diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index a0ef2d1bb..a64f59bdc 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -160,12 +160,12 @@ eventmask_t chEvtAddFlags(eventmask_t mask) { *
* @api
*/
-void chEvtSignal(Thread *tp, eventmask_t mask) {
+void chEvtSignalFlags(Thread *tp, eventmask_t mask) {
chDbgCheck(tp != NULL, "chEvtSignal");
chSysLock();
- chEvtSignalI(tp, mask);
+ chEvtSignalFlagsI(tp, mask);
chSchRescheduleS();
chSysUnlock();
}
@@ -182,7 +182,7 @@ void chEvtSignal(Thread *tp, eventmask_t mask) { *
* @iclass
*/
-void chEvtSignalI(Thread *tp, eventmask_t mask) {
+void chEvtSignalFlagsI(Thread *tp, eventmask_t mask) {
chDbgCheck(tp != NULL, "chEvtSignalI");
@@ -198,15 +198,20 @@ void chEvtSignalI(Thread *tp, eventmask_t mask) { /**
* @brief Signals all the Event Listeners registered on the specified Event
* Source.
+ * @details This function variants ORs the specified event flags to all the
+ * threads registered on the @p EventSource in addition to the event
+ * flags specified by the threads themselves in the
+ * @p EventListener objects.
*
* @param[in] esp pointer to the @p EventSource structure
+ * @param[in] mask the event flags set to be ORed
*
* @api
*/
-void chEvtBroadcast(EventSource *esp) {
+void chEvtBroadcastFlags(EventSource *esp, eventmask_t mask) {
chSysLock();
- chEvtBroadcastI(esp);
+ chEvtBroadcastFlagsI(esp, mask);
chSchRescheduleS();
chSysUnlock();
}
@@ -214,23 +219,28 @@ void chEvtBroadcast(EventSource *esp) { /**
* @brief Signals all the Event Listeners registered on the specified Event
* Source.
+ * @details This function variants ORs the specified event flags to all the
+ * threads registered on the @p EventSource in addition to the event
+ * flags specified by the threads themselves in the
+ * @p EventListener objects.
* @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
+ * @param[in] mask the event flags set to be ORed
*
* @iclass
*/
-void chEvtBroadcastI(EventSource *esp) {
+void chEvtBroadcastFlagsI(EventSource *esp, eventmask_t mask) {
EventListener *elp;
- chDbgCheck(esp != NULL, "chEvtBroadcastI");
+ chDbgCheck(esp != NULL, "chEvtBroadcastMaskI");
elp = esp->es_next;
while (elp != (EventListener *)esp) {
- chEvtSignalI(elp->el_listener, elp->el_mask);
+ chEvtSignalFlagsI(elp->el_listener, elp->el_mask | mask);
elp = elp->el_next;
}
}
diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index b2cef2470..e0b6ca014 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -156,6 +156,34 @@ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { }
/**
+ * @brief Posts a message into a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[in] msg the message to be posted on the mailbox
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be
+ * posted.
+ *
+ * @iclass
+ */
+msg_t chMBPostI(Mailbox *mbp, msg_t msg) {
+
+ chDbgCheck(mbp != NULL, "chMBPostI");
+
+ if (chSemGetCounterI(&mbp->mb_emptysem) <= 0)
+ return RDY_TIMEOUT;
+ chSemFastWaitI(&mbp->mb_emptysem);
+ *mbp->mb_wrptr++ = msg;
+ if (mbp->mb_wrptr >= mbp->mb_top)
+ mbp->mb_wrptr = mbp->mb_buffer;
+ chSemSignalI(&mbp->mb_fullsem);
+ return RDY_OK;
+}
+
+/**
* @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.
@@ -219,6 +247,34 @@ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { }
/**
+ * @brief Posts an high priority message into a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[in] msg the message to be posted on the mailbox
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be
+ * posted.
+ *
+ * @iclass
+ */
+msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) {
+
+ chDbgCheck(mbp != NULL, "chMBPostAheadI");
+
+ if (chSemGetCounterI(&mbp->mb_emptysem) <= 0)
+ return RDY_TIMEOUT;
+ chSemFastWaitI(&mbp->mb_emptysem);
+ if (--mbp->mb_rdptr < mbp->mb_buffer)
+ mbp->mb_rdptr = mbp->mb_top - 1;
+ *mbp->mb_rdptr = msg;
+ chSemSignalI(&mbp->mb_fullsem);
+ return RDY_OK;
+}
+
+/**
* @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.
@@ -280,6 +336,33 @@ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { }
return rdymsg;
}
+
+/**
+ * @brief Retrieves a message from a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[out] msgp pointer to a message variable for the received message
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly fetched.
+ * @retval RDY_TIMEOUT if the mailbox is empty and a message cannot be
+ * fetched.
+ *
+ * @iclass
+ */
+msg_t chMBFetchI(Mailbox *mbp, msg_t *msgp) {
+
+ chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI");
+
+ if (chSemGetCounterI(&mbp->mb_fullsem) <= 0)
+ return RDY_TIMEOUT;
+ *msgp = *mbp->mb_rdptr++;
+ if (mbp->mb_rdptr >= mbp->mb_top)
+ mbp->mb_rdptr = mbp->mb_buffer;
+ chSemSignalI(&mbp->mb_emptysem);
+ return RDY_OK;
+}
#endif /* CH_USE_MAILBOXES */
/** @} */
|