#ifOS_MBOX_POST_OPT_EN >0u
INT8U OSMboxPostOpt(OS_EVENT *pevent,void*pmsg,INT8U opt){#ifOS_CRITICAL_METHOD ==3u/* Allocate storage for CPU status register */OS_CPU_SR cpu_sr =0u;#endif#ifOS_ARG_CHK_EN >0uif(pevent ==(OS_EVENT *)0)/* Validate 'pevent' */{return(OS_ERR_PEVENT_NULL);}if(pmsg ==(void*)0)/* Make sure we are not posting a NULL pointer */{return(OS_ERR_POST_NULL_PTR);}#endifif(pevent->OSEventType != OS_EVENT_TYPE_MBOX)/* Validate event block type */{return(OS_ERR_EVENT_TYPE);}OS_ENTER_CRITICAL();if(pevent->OSEventGrp !=0u)/* See if any task pending on mailbox */{if((opt & OS_POST_OPT_BROADCAST)!=0x00u)/* Do we need to post msg to ALL waiting tasks ? */{while(pevent->OSEventGrp !=0u)/* Yes, Post to ALL tasks waiting on mailbox */{(void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_MBOX, OS_STAT_PEND_OK);}}else/* No, Post to HPT waiting on mbox */{(void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_MBOX, OS_STAT_PEND_OK);}OS_EXIT_CRITICAL();if((opt & OS_POST_OPT_NO_SCHED)==0u)/* See if scheduler needs to be invoked */{OS_Sched();/* Find HPT ready to run */}return(OS_ERR_NONE);}if(pevent->OSEventPtr !=(void*)0)/* Make sure mailbox doesn't already have a msg */{OS_EXIT_CRITICAL();return(OS_ERR_MBOX_FULL);}pevent->OSEventPtr = pmsg;/* Place message in mailbox */OS_EXIT_CRITICAL();return(OS_ERR_NONE);}#endif
从消息邮箱获取/无等待
#ifOS_MBOX_ACCEPT_EN >0uvoid*OSMboxAccept(OS_EVENT *pevent){void*pmsg;#ifOS_CRITICAL_METHOD ==3u/* Allocate storage for CPU status register */OS_CPU_SR cpu_sr =0u;#endif#ifOS_ARG_CHK_EN >0uif(pevent ==(OS_EVENT *)0)/* Validate 'pevent' */{return((void*)0);}#endifif(pevent->OSEventType != OS_EVENT_TYPE_MBOX)/* Validate event block type */{return((void*)0);}OS_ENTER_CRITICAL();pmsg = pevent->OSEventPtr;pevent->OSEventPtr =(void*)0;/* Clear the mailbox */OS_EXIT_CRITICAL();return(pmsg);/* Return the message received (or NULL) */}#endif
消息邮箱状态查询
#ifOS_MBOX_QUERY_EN >0u
INT8U OSMboxQuery(OS_EVENT *pevent,OS_MBOX_DATA *p_mbox_data){INT8U i;OS_PRIO *psrc;OS_PRIO *pdest;#ifOS_CRITICAL_METHOD ==3u/* Allocate storage for CPU status register */OS_CPU_SR cpu_sr =0u;#endif#ifOS_ARG_CHK_EN >0uif(pevent ==(OS_EVENT *)0)/* Validate 'pevent' */{return(OS_ERR_PEVENT_NULL);}if(p_mbox_data ==(OS_MBOX_DATA *)0)/* Validate 'p_mbox_data' */{return(OS_ERR_PDATA_NULL);}#endifif(pevent->OSEventType != OS_EVENT_TYPE_MBOX)/* Validate event block type */{return(OS_ERR_EVENT_TYPE);}OS_ENTER_CRITICAL();p_mbox_data->OSEventGrp = pevent->OSEventGrp;/* Copy message mailbox wait list */psrc =&pevent->OSEventTbl[0];pdest =&p_mbox_data->OSEventTbl[0];for(i =0u; i < OS_EVENT_TBL_SIZE; i++){*pdest++=*psrc++;}p_mbox_data->OSMsg = pevent->OSEventPtr;/* Get message from mailbox */OS_EXIT_CRITICAL();return(OS_ERR_NONE);}#endif
消息邮箱中断等待
#ifOS_MBOX_PEND_ABORT_EN >0u
INT8U OSMboxPendAbort(OS_EVENT *pevent,INT8U opt,INT8U *perr){INT8U nbr_tasks;#ifOS_CRITICAL_METHOD ==3u/* Allocate storage for CPU status register */OS_CPU_SR cpu_sr =0u;#endif#ifdefOS_SAFETY_CRITICALif(perr ==(INT8U *)0){OS_SAFETY_CRITICAL_EXCEPTION();return(0u);}#endif#ifOS_ARG_CHK_EN >0uif(pevent ==(OS_EVENT *)0)/* Validate 'pevent' */{*perr = OS_ERR_PEVENT_NULL;return(0u);}#endifif(pevent->OSEventType != OS_EVENT_TYPE_MBOX)/* Validate event block type */{*perr = OS_ERR_EVENT_TYPE;return(0u);}OS_ENTER_CRITICAL();if(pevent->OSEventGrp !=0u)/* See if any task waiting on mailbox? */{nbr_tasks =0u;switch(opt){case OS_PEND_OPT_BROADCAST:/* Do we need to abort ALL waiting tasks? */while(pevent->OSEventGrp !=0u)/* Yes, ready ALL tasks waiting on mailbox */{(void)OS_EventTaskRdy(pevent,(void*)0, OS_STAT_MBOX, OS_STAT_PEND_ABORT);nbr_tasks++;}break;case OS_PEND_OPT_NONE:default:/* No, ready HPT waiting on mailbox */(void)OS_EventTaskRdy(pevent,(void*)0, OS_STAT_MBOX, OS_STAT_PEND_ABORT);nbr_tasks++;break;}OS_EXIT_CRITICAL();OS_Sched();/* Find HPT ready to run */*perr = OS_ERR_PEND_ABORT;return(nbr_tasks);}OS_EXIT_CRITICAL();*perr = OS_ERR_NONE;return(0u);/* No tasks waiting on mailbox */}#endif