📄 os_core.lst
字号:
switch (pevent->OSEventType) {
case OS_EVENT_TYPE_SEM:
case OS_EVENT_TYPE_MUTEX:
case OS_EVENT_TYPE_MBOX:
case OS_EVENT_TYPE_Q:
break;
default:
*perr = OS_ERR_EVENT_TYPE;
return;
}
OS_ENTER_CRITICAL();
len = OS_StrLen(pname); /* Can we fit the string in the storage area? */
if (len > (OS_EVENT_NAME_SIZE - 1)) { /* No */
OS_EXIT_CRITICAL();
*perr = OS_ERR_EVENT_NAME_TOO_LONG;
return;
}
(void)OS_StrCopy(pevent->OSEventName, pname); /* Yes, copy name to the event control block */
OS_EXIT_CRITICAL();
*perr = OS_ERR_NONE;
}
#endif
232
233 /*$PAGE*/
234 /*
235 *********************************************************************************************************
236 * PEND ON MULTIPLE EVENTS
237 *
238 * Description: This function waits for multiple events. If multiple events are ready at the start of the
239 * pend call, then all available events are returned as ready. If the task must pend on the
C51 COMPILER V8.17 OS_CORE 03/26/2009 14:24:24 PAGE 5
240 * multiple events, then only the first posted or aborted event is returned as ready.
241 *
242 * Arguments : pevents_pend is a pointer to a NULL-terminated array of event control blocks to wait for.
243 *
244 * pevents_rdy is a pointer to an array to return which event control blocks are available
245 * or ready. The size of the array MUST be greater than or equal to the size
246 * of the 'pevents_pend' array, including terminating NULL.
247 *
248 * pmsgs_rdy is a pointer to an array to return messages from any available message-type
249 * events. The size of the array MUST be greater than or equal to the size of
250 * the 'pevents_pend' array, excluding the terminating NULL. Since NULL
251 * messages are valid messages, this array cannot be NULL-terminated. Instead,
252 * every available message-type event returns its messages in the 'pmsgs_rdy'
253 * array at the same index as the event is returned in the 'pevents_rdy' array.
254 * All other 'pmsgs_rdy' array indices are filled with NULL messages.
255 *
256 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
257 * wait for the resources up to the amount of time specified by this argument.
258 * If you specify 0, however, your task will wait forever for the specified
259 * events or, until the resources becomes available (or the events occur).
260 *
261 * perr is a pointer to where an error message will be deposited. Possible error
262 * messages are:
263 *
264 * OS_ERR_NONE The call was successful and your task owns the resources
265 * or, the events you are waiting for occurred; check the
266 * 'pevents_rdy' array for which events are available.
267 * OS_ERR_PEND_ABORT The wait on the events was aborted; check the
268 * 'pevents_rdy' array for which events were aborted.
269 * OS_ERR_TIMEOUT The events were not received within the specified
270 * 'timeout'.
271 * OS_ERR_PEVENT_NULL If 'pevents_pend', 'pevents_rdy', or 'pmsgs_rdy' is a
272 * NULL pointer.
273 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to an array of semaphores,
274 * mailboxes, and/or queues.
275 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
276 * would lead to a suspension.
277 * OS_ERR_PEND_LOCKED If you called this function when the scheduler is locked.
278 *
279 * Returns : > 0 the number of events returned as ready or aborted.
280 * == 0 if no events are returned as ready because of timeout or upon error.
281 *
282 * Notes : 1) a. Validate 'pevents_pend' array as valid OS_EVENTs :
283 *
284 * semaphores, mailboxes, queues
285 *
286 * b. Return ALL available events and messages, if any
287 *
288 * c. Add current task priority as pending to each events's wait list
289 * Performed in OS_EventTaskWaitMulti()
290 *
291 * d. Wait on any of multiple events
292 *
293 * e. Remove current task priority as pending from each events's wait list
294 * Performed in OS_EventTaskRdy(), if events posted or aborted
295 *
296 * f. Return any event posted or aborted, if any
297 * else
298 * Return timeout
299 *
300 * 2) 'pevents_rdy' initialized to NULL PRIOR to all other validation or function handling in
301 * case of any error(s).
C51 COMPILER V8.17 OS_CORE 03/26/2009 14:24:24 PAGE 6
302 *********************************************************************************************************
303 */
304 /*$PAGE*/
305 #if ((OS_EVENT_EN) && (OS_EVENT_MULTI_EN > 0))
INT16U OSEventPendMulti (OS_EVENT **pevents_pend, OS_EVENT **pevents_rdy, void **pmsgs_rdy, INT16U timeou
-t, INT8U *perr)
{
OS_EVENT **pevents;
OS_EVENT *pevent;
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
OS_Q *pq;
#endif
BOOLEAN events_rdy;
INT16U events_rdy_nbr;
INT8U events_stat;
#if (OS_CRITICAL_METHOD == 3) /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
#if (OS_ARG_CHK_EN > 0)
if (perr == (INT8U *)0) { /* Validate 'perr' */
return (0);
}
if (pevents_pend == (OS_EVENT **)0) { /* Validate 'pevents_pend' */
*perr = OS_ERR_PEVENT_NULL;
return (0);
}
if (pevents_rdy == (OS_EVENT **)0) { /* Validate 'pevents_rdy' */
*perr = OS_ERR_PEVENT_NULL;
return (0);
}
if (pmsgs_rdy == (void **)0) { /* Validate 'pmsgs_rdy' */
*perr = OS_ERR_PEVENT_NULL;
return (0);
}
#endif
*pevents_rdy = (OS_EVENT *)0; /* Init array to NULL in case of errors */
pevents = pevents_pend;
pevent = *pevents;
while (pevent != (OS_EVENT *)0) {
switch (pevent->OSEventType) { /* Validate event block types */
#if (OS_SEM_EN > 0)
case OS_EVENT_TYPE_SEM:
break;
#endif
#if (OS_MBOX_EN > 0)
case OS_EVENT_TYPE_MBOX:
break;
#endif
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
case OS_EVENT_TYPE_Q:
break;
#endif
case OS_EVENT_TYPE_MUTEX:
case OS_EVENT_TYPE_FLAG:
default:
*perr = OS_ERR_EVENT_TYPE;
C51 COMPILER V8.17 OS_CORE 03/26/2009 14:24:24 PAGE 7
return (0);
}
pevents++;
pevent = *pevents;
}
if (OSIntNesting > 0) { /* See if called from ISR ... */
*perr = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
return (0);
}
if (OSLockNesting > 0) { /* See if called with scheduler locked ... */
*perr = OS_ERR_PEND_LOCKED; /* ... can't PEND when locked */
return (0);
}
/*$PAGE*/
OS_ENTER_CRITICAL();
events_rdy = OS_FALSE;
events_rdy_nbr = 0;
events_stat = OS_STAT_RDY;
pevents = pevents_pend;
pevent = *pevents;
while (pevent != (OS_EVENT *)0) { /* See if any events already available */
switch (pevent->OSEventType) {
#if (OS_SEM_EN > 0)
case OS_EVENT_TYPE_SEM:
if (pevent->OSEventCnt > 0) { /* If semaphore count > 0, resource available; */
pevent->OSEventCnt--; /* ... decrement semaphore, ... */
*pevents_rdy++ = pevent; /* ... and return available semaphore event */
events_rdy = OS_TRUE;
*pmsgs_rdy++ = (void *)0; /* NO message returned for semaphores */
events_rdy_nbr++;
} else {
events_stat |= OS_STAT_SEM; /* Configure multi-pend for semaphore events */
}
break;
#endif
#if (OS_MBOX_EN > 0)
case OS_EVENT_TYPE_MBOX:
if (pevent->OSEventPtr != (void *)0) { /* If mailbox NOT empty; ... */
/* ... return available message, ... */
*pmsgs_rdy++ = (void *)pevent->OSEventPtr;
pevent->OSEventPtr = (void *)0;
*pevents_rdy++ = pevent; /* ... and return available mailbox event */
events_rdy = OS_TRUE;
events_rdy_nbr++;
} else {
events_stat |= OS_STAT_MBOX; /* Configure multi-pend for mailbox events */
}
break;
#endif
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
case OS_EVENT_TYPE_Q:
pq = (OS_Q *)pevent->OSEventPtr;
if (pq->OSQEntries > 0) { /* If queue NOT empty; ... */
/* ... return available message, ... */
*pmsgs_rdy++ = (void *)*pq->OSQOut++;
if (pq->OSQOut == pq->OSQEnd) { /* If OUT ptr at queue end, ... */
C51 COMPILER V8.17 OS_CORE 03/26/2009 14:24:24 PAGE 8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -