📄 os_mbox.lst
字号:
} else {
tasks_waiting = FALSE; /* No */
}
switch (opt) {
case OS_DEL_NO_PEND: /* Delete mailbox only if no task waiting */
if (tasks_waiting == FALSE) {
pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
OSEventFreeList = pevent; /* Get next free event control block */
OS_EXIT_CRITICAL();
*err = OS_NO_ERR;
return ((OS_EVENT *)0); /* Mailbox has been deleted */
} else {
C51 COMPILER V7.20 OS_MBOX 06/15/2006 16:15:50 PAGE 4
OS_EXIT_CRITICAL();
*err = OS_ERR_TASK_WAITING;
return (pevent);
}
case OS_DEL_ALWAYS: /* Always delete the mailbox */
while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for mailbox */
OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
}
pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
OSEventFreeList = pevent; /* Get next free event control block */
OS_EXIT_CRITICAL();
if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
OS_Sched(); /* Find highest priority task ready to run */
}
*err = OS_NO_ERR;
return ((OS_EVENT *)0); /* Mailbox has been deleted */
default:
OS_EXIT_CRITICAL();
*err = OS_ERR_INVALID_OPT;
return (pevent);
}
}
#endif
206
207 /*$PAGE*/
208 /*
209 *********************************************************************************************************
210 * PEND ON MAILBOX FOR A MESSAGE
211 *
212 * Description: This function waits for a message to be sent to a mailbox
213 *
214 * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
215 *
216 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
217 * wait for a message to arrive at the mailbox up to the amount of time
218 * specified by this argument. If you specify 0, however, your task will wait
219 * forever at the specified mailbox or, until a message arrives.
220 *
221 * err is a pointer to where an error message will be deposited. Possible error
222 * messages are:
223 *
224 * OS_NO_ERR The call was successful and your task received a
225 * message.
226 * OS_TIMEOUT A message was not received within the specified timeout
227 * OS_ERR_EVENT_TYPE Invalid event type
228 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
229 * would lead to a suspension.
230 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
231 *
232 * Returns : != (void *)0 is a pointer to the message received
233 * == (void *)0 if no message was received or,
234 * if 'pevent' is a NULL pointer or,
235 * if you didn't pass the proper pointer to the event control block.
236 *********************************************************************************************************
237 */
238 #if OS_MBOX_PEND_EN>0
239 void *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant
240 {
241 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
C51 COMPILER V7.20 OS_MBOX 06/15/2006 16:15:50 PAGE 5
OS_CPU_SR cpu_sr;
#endif
244 1 void *msg;
245 1
246 1
247 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
248 2 *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
249 2 return ((void *)0);
250 2 }
251 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
*err = OS_ERR_PEVENT_NULL;
return ((void *)0);
}
if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
*err = OS_ERR_EVENT_TYPE;
return ((void *)0);
}
#endif
261 1 OS_ENTER_CRITICAL();
262 1 msg = pevent->OSEventPtr;
263 1 if (msg != (void *)0) { /* See if there is already a message */
264 2 pevent->OSEventPtr = (void *)0; /* Clear the mailbox */
265 2 OS_EXIT_CRITICAL();
266 2 *err = OS_NO_ERR;
267 2 return (msg); /* Return the message received (or NULL) */
268 2 }
269 1 OSTCBCur->OSTCBStat |= OS_STAT_MBOX; /* Message not available, task will pend */
270 1 OSTCBCur->OSTCBDly = timeout; /* Load timeout in TCB */
271 1 OS_EventTaskWait(pevent); /* Suspend task until event or timeout occurs */
272 1 OS_EXIT_CRITICAL();
273 1 OS_Sched(); /* Find next highest priority task ready to run */
274 1 OS_ENTER_CRITICAL();
275 1 msg = OSTCBCur->OSTCBMsg;
276 1 if (msg != (void *)0) { /* See if we were given the message */
277 2 OSTCBCur->OSTCBMsg = (void *)0; /* Yes, clear message received */
278 2 OSTCBCur->OSTCBStat = OS_STAT_RDY;
279 2 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
280 2 OS_EXIT_CRITICAL();
281 2 *err = OS_NO_ERR;
282 2 return (msg); /* Return the message received */
283 2 }
284 1 OS_EventTO(pevent); /* Timed out, Make task ready */
285 1 OS_EXIT_CRITICAL();
286 1 *err = OS_TIMEOUT; /* Indicate that a timeout occured */
287 1 return ((void *)0); /* Return a NULL message */
288 1 }
289 #endif
290 /*$PAGE*/
291 /*
292 *********************************************************************************************************
293 * POST MESSAGE TO A MAILBOX
294 *
295 * Description: This function sends a message to a mailbox
296 *
297 * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
298 *
299 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
300 *
301 * Returns : OS_NO_ERR The call was successful and the message was sent
302 * OS_MBOX_FULL If the mailbox already contains a message. You can can only send one
303 * message at a time and thus, the message MUST be consumed before you
C51 COMPILER V7.20 OS_MBOX 06/15/2006 16:15:50 PAGE 6
304 * are allowed to send another one.
305 * OS_ERR_EVENT_TYPE If you are attempting to post to a non mailbox.
306 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
307 * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
308 *********************************************************************************************************
309 */
310
311 #if OS_MBOX_POST_EN > 0
312 INT8U OSMboxPost (OS_EVENT *pevent, void *msg) reentrant
313 {
314 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
317 1
318 1
319 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
if (msg == (void *)0) { /* Make sure we are not posting a NULL pointer */
return (OS_ERR_POST_NULL_PTR);
}
if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
return (OS_ERR_EVENT_TYPE);
}
#endif
330 1 OS_ENTER_CRITICAL();
331 1 if (pevent->OSEventGrp != 0x00) { /* See if any task pending on mailbox */
332 2 OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX); /* Ready highest priority task waiting on event */
333 2 OS_EXIT_CRITICAL();
334 2 OS_Sched(); /* Find highest priority task ready to run */
335 2 return (OS_NO_ERR);
336 2 }
337 1 if (pevent->OSEventPtr != (void *)0) { /* Make sure mailbox doesn't already have a msg */
338 2 OS_EXIT_CRITICAL();
339 2 return (OS_MBOX_FULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -