📄 mega16pro.lst
字号:
(0119) #if OS_ARG_CHK_EN > 0
(0120) if (perr == (INT8U *)0) { /* Validate 'perr' */
(0121) return (0);
(0122) }
(0123) if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? */
(0124) *perr = OS_ERR_PEVENT_NULL;
(0125) return (0);
(0126) }
(0127) if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? */
(0128) *perr = OS_ERR_PNAME_NULL;
(0129) return (0);
(0130) }
(0131) #endif
(0132) if (OSIntNesting > 0) { /* See if trying to call from an ISR */
(0133) *perr = OS_ERR_NAME_GET_ISR;
(0134) return (0);
(0135) }
(0136) switch (pevent->OSEventType) {
(0137) case OS_EVENT_TYPE_SEM:
(0138) case OS_EVENT_TYPE_MUTEX:
(0139) case OS_EVENT_TYPE_MBOX:
(0140) case OS_EVENT_TYPE_Q:
(0141) break;
(0142)
(0143) default:
(0144) *perr = OS_ERR_EVENT_TYPE;
(0145) return (0);
(0146) }
(0147) OS_ENTER_CRITICAL();
(0148) len = OS_StrCopy(pname, pevent->OSEventName); /* Copy name from OS_EVENT */
(0149) OS_EXIT_CRITICAL();
(0150) *perr = OS_ERR_NONE;
(0151) return (len);
(0152) }
(0153) #endif
(0154)
(0155) /*
(0156) *********************************************************************************************************
(0157) * ASSIGN A NAME TO A SEMAPHORE, MUTEX, MAILBOX or QUEUE
(0158) *
(0159) * Description: This function assigns a name to a semaphore, mutex, mailbox or queue.
(0160) *
(0161) * Arguments : pevent is a pointer to the event group. 'pevent' can point either to a semaphore,
(0162) * a mutex, a mailbox or a queue. Where this function is concerned, it doesn't
(0163) * matter the actual type.
(0164) *
(0165) * pname is a pointer to an ASCII string that will be used as the name of the semaphore,
(0166) * mutex, mailbox or queue. The string must be able to hold at least
(0167) * OS_EVENT_NAME_SIZE characters.
(0168) *
(0169) * perr is a pointer to an error code that can contain one of the following values:
(0170) *
(0171) * OS_ERR_NONE if the requested task is resumed
(0172) * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to the proper event
(0173) * control block type.
(0174) * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
(0175) * OS_ERR_PEVENT_NULL if you passed a NULL pointer for 'pevent'
(0176) * OS_ERR_NAME_SET_ISR if you called this function from an ISR
(0177) *
(0178) * Returns : None
(0179) *********************************************************************************************************
(0180) */
(0181)
(0182) #if (OS_EVENT_EN) && (OS_EVENT_NAME_SIZE > 1)
(0183) void OSEventNameSet (OS_EVENT *pevent, INT8U *pname, INT8U *perr)
(0184) {
(0185) INT8U len;
(0186) #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
(0187) OS_CPU_SR cpu_sr = 0;
(0188) #endif
(0189)
(0190)
(0191)
(0192) #if OS_ARG_CHK_EN > 0
(0193) if (perr == (INT8U *)0) { /* Validate 'perr' */
(0194) return;
(0195) }
(0196) if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? */
(0197) *perr = OS_ERR_PEVENT_NULL;
(0198) return;
(0199) }
(0200) if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? */
(0201) *perr = OS_ERR_PNAME_NULL;
(0202) return;
(0203) }
(0204) #endif
(0205) if (OSIntNesting > 0) { /* See if trying to call from an ISR */
(0206) *perr = OS_ERR_NAME_SET_ISR;
(0207) return;
(0208) }
(0209) switch (pevent->OSEventType) {
(0210) case OS_EVENT_TYPE_SEM:
(0211) case OS_EVENT_TYPE_MUTEX:
(0212) case OS_EVENT_TYPE_MBOX:
(0213) case OS_EVENT_TYPE_Q:
(0214) break;
(0215)
(0216) default:
(0217) *perr = OS_ERR_EVENT_TYPE;
(0218) return;
(0219) }
(0220) OS_ENTER_CRITICAL();
(0221) len = OS_StrLen(pname); /* Can we fit the string in the storage area? */
(0222) if (len > (OS_EVENT_NAME_SIZE - 1)) { /* No */
(0223) OS_EXIT_CRITICAL();
(0224) *perr = OS_ERR_EVENT_NAME_TOO_LONG;
(0225) return;
(0226) }
(0227) (void)OS_StrCopy(pevent->OSEventName, pname); /* Yes, copy name to the event control block */
(0228) OS_EXIT_CRITICAL();
(0229) *perr = OS_ERR_NONE;
(0230) }
(0231) #endif
(0232)
(0233)
(0234) /*
(0235) *********************************************************************************************************
(0236) * PEND ON MULTIPLE EVENTS
(0237) *
(0238) * Description: This function waits for multiple events. If multiple events are ready at the start of the
(0239) * pend call, then all available events are returned as ready. If the task must pend on the
(0240) * multiple events, then only the first posted or aborted event is returned as ready.
(0241) *
(0242) * Arguments : pevents_pend is a pointer to a NULL-terminated array of event control blocks to wait for.
(0243) *
(0244) * pevents_rdy is a pointer to an array to return which event control blocks are available
(0245) * or ready. The size of the array MUST be greater than or equal to the size
(0246) * of the 'pevents_pend' array, including terminating NULL.
(0247) *
(0248) * pmsgs_rdy is a pointer to an array to return messages from any available message-type
(0249) * events. The size of the array MUST be greater than or equal to the size of
(0250) * the 'pevents_pend' array, excluding the terminating NULL. Since NULL
(0251) * messages are valid messages, this array cannot be NULL-terminated. Instead,
(0252) * every available message-type event returns its messages in the 'pmsgs_rdy'
(0253) * array at the same index as the event is returned in the 'pevents_rdy' array.
(0254) * All other 'pmsgs_rdy' array indices are filled with NULL messages.
(0255) *
(0256) * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
(0257) * wait for the resources up to the amount of time specified by this argument.
(0258) * If you specify 0, however, your task will wait forever for the specified
(0259) * events or, until the resources becomes available (or the events occur).
(0260) *
(0261) * perr is a pointer to where an error message will be deposited. Possible error
(0262) * messages are:
(0263) *
(0264) * OS_ERR_NONE The call was successful and your task owns the resources
(0265) * or, the events you are waiting for occurred; check the
(0266) * 'pevents_rdy' array for which events are available.
(0267) * OS_ERR_PEND_ABORT The wait on the events was aborted; check the
(0268) * 'pevents_rdy' array for which events were aborted.
(0269) * OS_ERR_TIMEOUT The events were not received within the specified
(0270) * 'timeout'.
(0271) * OS_ERR_PEVENT_NULL If 'pevents_pend', 'pevents_rdy', or 'pmsgs_rdy' is a
(0272) * NULL pointer.
(0273) * OS_ERR_EVENT_TYPE If you didn't pass a pointer to an array of semaphores,
(0274) * mailboxes, and/or queues.
(0275) * OS_ERR_PEND_ISR If you called this function from an ISR and the result
(0276) * would lead to a suspension.
(0277) * OS_ERR_PEND_LOCKED If you called this function when the scheduler is locked.
(0278) *
(0279) * Returns : > 0 the number of events returned as ready or aborted.
(0280) * == 0 if no events are returned as ready because of timeout or upon error.
(0281) *
(0282) * Notes : 1) a. Validate 'pevents_pend' array as valid OS_EVENTs :
(0283) *
(0284) * semaphores, mailboxes, queues
(0285) *
(0286) * b. Return ALL available events and messages, if any
(0287) *
(0288) * c. Add current task priority as pending to each events's wait list
(0289) * Performed in OS_EventTaskWaitMulti()
(0290) *
(0291) * d. Wait on any of multiple events
(0292) *
(0293) * e. Remove current task priority as pending from each events's wait list
(0294) * Performed in OS_EventTaskRdy(), if events posted or aborted
(0295) *
(0296) * f. Return any event posted or aborted, if any
(0297) * else
(0298) * Return timeout
(0299) *
(0300) * 2) 'pevents_rdy' initialized to NULL PRIOR to all other validation or function handling in
(0301) * case of any error(s).
(0302) *********************************************************************************************************
(0303) */
(0304)
(0305) #if ((OS_EVENT_EN) && (OS_EVENT_MULTI_EN > 0))
(0306) INT16U OSEventPendMulti (OS_EVENT **pevents_pend, OS_EVENT **pevents_rdy, void **pmsgs_rdy, INT16U timeout, INT8U *perr)
(0307) {
(0308) OS_EVENT **pevents;
(0309) OS_EVENT *pevent;
(0310) #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
(0311) OS_Q *pq;
(0312) #endif
(0313) BOOLEAN events_rdy;
(0314) INT16U events_rdy_nbr;
(0315) INT8U events_stat;
(0316) #if (OS_CRITICAL_METHOD == 3) /* Allocate storage for CPU status register */
(0317) OS_CPU_SR cpu_sr = 0;
(0318) #endif
(0319)
(0320)
(0321)
(0322) #if (OS_ARG_CHK_EN > 0)
(0323) if (perr == (INT8U *)0) { /* Validate 'perr' */
(0324) return (0);
(0325) }
(0326) if (pevents_pend == (OS_EVENT **)0) { /* Validate 'pevents_pend' */
(0327) *perr = OS_ERR_PEVENT_NULL;
(0328) return (0);
(0329) }
(0330) if (pevents_rdy == (OS_EVENT **)0) { /* Validate 'pevents_rdy' */
(0331) *perr = OS_ERR_PEVENT_NULL;
(0332) return (0);
(0333) }
(0334) if (pmsgs_rdy == (void **)0) { /* Validate 'pmsgs_rdy' */
(0335) *perr = OS_ERR_PEVENT_NULL;
(0336) return (0);
(0337) }
(0338) #endif
(0339)
(0340) *pevents_rdy = (OS_EVENT *)0; /* Init array to NULL in case of errors */
(0341)
(0342) pevents = pevents_pend;
(0343) pevent = *pevents;
(0344) while (pevent != (OS_EVENT *)0) {
(0345) switch (pevent->OSEventType) { /* Validate event block types */
(0346) #if (OS_SEM_EN > 0)
(0347) case OS_EVENT_TYPE_SEM:
(0348) break;
(0349) #endif
(0350) #if (OS_MBOX_EN > 0)
(0351) case OS_EVENT_TYPE_MBOX:
(0352) break;
(0353) #endif
(0354) #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
(0355) case OS_EVENT_TYPE_Q:
(0356) break;
(0357) #endif
(0358)
(0359) case OS_EVENT_TYPE_MUTEX:
(0360) case OS_EVENT_TYPE_FLAG:
(0361) default:
(0362) *perr = OS_ERR_EVENT_TYPE;
(0363) return (0);
(0364) }
(0365) pevents++;
(0366) pevent = *pevents;
(0367) }
(0368)
(0369) if (OSIntNesting > 0) { /* See if called from ISR ... */
(0370) *perr = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
(0371) return (0);
(0372) }
(0373) if (OSLockNesting > 0) { /* See if called with scheduler locked ... */
(0374) *perr = OS_ERR_PEND_LOCKED; /* ... can't PEND when locked */
(0375) return (0);
(0376) }
(0377)
(0378)
(0379) OS_ENTER_CRITICAL();
(0380) events_rdy = OS_FALSE;
(0381) events_rdy_nbr = 0;
(0382) events_stat = OS_STAT_RDY;
(0383) pevents = pevents_pend;
(0384) pevent = *pevents;
(0385) while (pevent != (OS_EVENT *)0) { /* See if any events already available */
(0386) switch (pevent->OSEventType) {
(0387) #if (OS_SEM_EN > 0)
(0388) case OS_EVENT_TYPE_SEM:
(0389) if (pevent->OSEventCnt > 0) { /* If semaphore count > 0, resource available; */
(0390) pevent->OSEventCnt--; /* ... decrement semaphore, ... */
(0391) *pevents_rdy++ = pevent; /* ... and return available semaphore event */
(0392) events_rdy = OS_TRUE;
(0393) *pmsgs_rdy++ = (void *)0; /* NO message returned for semaphores */
(0394) events_rdy_nbr++;
(0395)
(0396) } else {
(0397) events_stat |= OS_STAT_SEM; /* Configure multi-pend for semaphore events */
(0398) }
(0399) break;
(0400) #endif
(0401)
(0402) #if (OS_MBOX_EN > 0)
(0403) case OS_EVENT_TYPE_MBOX:
(0404) if (pevent->OSEventPtr != (void *)0) { /* If mailbox NOT empty; ... */
(0405) /* ... return available message, ... */
(0406) *pmsgs_rdy++ = (void *)pevent->OSEventPtr;
(0407) pevent->OSEventPtr = (void *)0;
(0408) *pevents_rdy++ = pevent; /* ... and return available mailbox event */
(0409) events_rdy = OS_TRUE;
(0410) events_rdy_nbr++;
(0411)
(0412) } else {
(0413) events_stat |= OS_STAT_MBOX; /* Configure multi-pend for mailbox events */
(0414) }
(0415) break;
(0416) #endif
(0417)
(0418) #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
(0419) case OS_EVENT_TYPE_Q:
(0420) pq = (OS_Q *)pevent->OSEventPtr;
(0421) if (pq->OSQEntries > 0) { /* If queue NOT empty; ... */
(0422) /* ... return available message, ... */
(0423) *pmsgs_rdy++ = (void *)*pq->OSQOut++;
(0424) if (pq->OSQOut ==
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -