?? os_mbox.c
字號(hào):
return (OS_ERR_POST_NULL_PTR);
}//發(fā)送的不是空指針
if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
return (OS_ERR_EVENT_TYPE);
}
#endif
OS_ENTER_CRITICAL();
if (pevent->OSEventGrp != 0x00) { /* See if any task pending on mailbox */
//是不是有任務(wù)在等待該郵箱中的消息,如果OSEventGrp非零,則表明有任務(wù)
OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX); /* Ready highest priority task waiting on event */
//將最高優(yōu)先級(jí)的任務(wù)從等待列表中刪除
OS_EXIT_CRITICAL();
OS_Sched(); /* Find highest priority task ready to run */
//任務(wù)調(diào)度,檢查該任務(wù)是否系統(tǒng)中就緒任務(wù)優(yōu)先級(jí)最高,如果是,任務(wù)切換,
//該任務(wù)得以執(zhí)行,如果不是,則OS_Sched()返回,OSMboxPost的調(diào)用函數(shù)繼續(xù)。
return (OS_NO_ERR);
}
if (pevent->OSEventPtr != (void *)0) { /* Make sure mailbox doesn't already have a msg */
OS_EXIT_CRITICAL();
return (OS_MBOX_FULL);//如果郵箱中有消息,表明郵箱滿了
}
pevent->OSEventPtr = msg; /* Place message in mailbox */
//將消息放到郵箱中
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* POST MESSAGE TO A MAILBOX
*
* Description: This function sends a message to a mailbox
*
* Arguments : pevent is a pointer to the event control block associated with the desired mailbox
*
* msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
*
* opt determines the type of POST performed:
* OS_POST_OPT_NONE POST to a single waiting task
* (Identical to OSMboxPost())
* OS_POST_OPT_BROADCAST POST to ALL tasks that are waiting on the mailbox
*
* Returns : OS_NO_ERR The call was successful and the message was sent
* OS_MBOX_FULL If the mailbox already contains a message. You can can only send one
* message at a time and thus, the message MUST be consumed before you
* are allowed to send another one.
* OS_ERR_EVENT_TYPE If you are attempting to post to a non mailbox.
* OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
* OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
*
* Warning : Interrupts can be disabled for a long time if you do a 'broadcast'. In fact, the
* interrupt disable time is proportional to the number of tasks waiting on the mailbox.
功能更強(qiáng)的向郵箱中發(fā)送一則消息
描述:發(fā)送一個(gè)消息到郵箱
參數(shù):pevent:指向目標(biāo)郵箱的ECB的指針
msg:將要發(fā)送的消息指針,不能發(fā)送空指針
opt:決定如下發(fā)送模式:
OS_POST_OPT_NONE :發(fā)給單片等待任務(wù),這個(gè)和OSMboxPost()等同。
OS_POST_OPT_BROADCAST:向在郵箱中等待的所有任務(wù)發(fā)送。
返回: OS_NO_ERR:消息發(fā)送成功
OS_MBOX_FULL :如果郵箱中已經(jīng)有消息了,一次只能發(fā)送一條消息,
在你允許發(fā)送另一條前,消息必須用掉
OS_ERR_EVENT_TYPE:如果你要發(fā)送到的不是郵箱
OS_ERR_PEVENT_NULL:如果目標(biāo)ECB是空指針
OS_ERR_POST_NULL_PTR:如果你想發(fā)空指針
*********************************************************************************************************
*/
#if OS_MBOX_POST_OPT_EN > 0
INT8U OSMboxPostOpt (OS_EVENT *pevent, void *msg, INT8U opt)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
#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);
}//保證是郵箱類(lèi)型
#endif
OS_ENTER_CRITICAL();
if (pevent->OSEventGrp != 0x00) { /* See if any task pending on mailbox */
//是否有任務(wù)在郵箱中掛起
if ((opt & OS_POST_OPT_BROADCAST) != 0x00) { /* Do we need to post msg to ALL waiting tasks ? */
//是不是向所有任務(wù)發(fā)消息?
while (pevent->OSEventGrp != 0x00) { /* Yes, Post to ALL tasks waiting on mailbox */
//如果是,向所有等待任務(wù)發(fā),將所有任務(wù)從等待列表中刪除
OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);
}
} else {
OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX); /* No, Post to HPT waiting on mbox */
//如果沒(méi)有廣播,則只有最高優(yōu)先級(jí)進(jìn)入就緒態(tài),準(zhǔn)備運(yùn)行,
//OS_EventTaskRdy函數(shù)只將最高優(yōu)先級(jí)任務(wù)從等待列表中刪除
}
OS_EXIT_CRITICAL();
OS_Sched(); /* Find highest priority task ready to run */
//任務(wù)調(diào)度
return (OS_NO_ERR);
}
if (pevent->OSEventPtr != (void *)0) { /* Make sure mailbox doesn't already have a msg */
OS_EXIT_CRITICAL();
return (OS_MBOX_FULL);//如果郵箱中有郵件,返回已經(jīng)滿了。
}
pevent->OSEventPtr = msg; /* Place message in mailbox */
//保存郵箱中的消息
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* QUERY A MESSAGE MAILBOX
*
* Description: This function obtains information about a message mailbox.
*
* Arguments : pevent is a pointer to the event control block associated with the desired mailbox
*
* pdata is a pointer to a structure that will contain information about the message
* mailbox.
*
* Returns : OS_NO_ERR The call was successful and the message was sent
* OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non mailbox.
* OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
查詢一個(gè)郵箱的狀態(tài)
描述:包含消息郵箱的信息
參數(shù):pevent:指向目標(biāo)郵箱ECB的指針
pdata:包含消息郵箱信息的結(jié)構(gòu)指針
返回:OS_NO_ERR 調(diào)用成功,消息發(fā)送成功
* OS_ERR_EVENT_TYPE 你想從非郵箱中得到數(shù)據(jù)
* OS_ERR_PEVENT_NULL 如果pevent是NULL
*********************************************************************************************************
*/
#if OS_MBOX_QUERY_EN > 0
INT8U OSMboxQuery (OS_EVENT *pevent, OS_MBOX_DATA *pdata)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U *psrc;
INT8U *pdest;
#if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}//不合理的pevent
if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
return (OS_ERR_EVENT_TYPE);
}//如果不是郵箱類(lèi)型
#endif
OS_ENTER_CRITICAL();
pdata->OSEventGrp = pevent->OSEventGrp; /* Copy message mailbox wait list */
//拷貝消息郵箱等待列表
psrc = &pevent->OSEventTbl[0];
pdest = &pdata->OSEventTbl[0];//郵箱中等待事件發(fā)生鏈表
//復(fù)制等待任務(wù)列表,,之所以使用條件編譯產(chǎn)生的內(nèi)嵌代碼,不用循環(huán)語(yǔ)句,
//是因?yàn)檫@樣代碼運(yùn)行速度更快
#if OS_EVENT_TBL_SIZE > 0
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 1
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 2
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 3
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 4
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 5
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 6
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 7
*pdest = *psrc;
#endif
pdata->OSMsg = pevent->OSEventPtr; /* Get message from mailbox */
//從郵箱中獲得消息
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif /* OS_MBOX_QUERY_EN */
#endif /* OS_MBOX_EN */
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -