📄 mailbox.c
字号:
//*************************************************************************
//
// Copyright (C) SEIKO EPSON CORP. 1997
// All Rights Reserved
//
// Filename : mailbox.c
// Function : Mailbox functions
// Revision :
// 1997/08/01 H.Matsuoka start
// 1999/08/09 H.Matsuoka BUG FIX(mail box link list)
// 1999/08/27 H.Matsuoka BUG FIX(critical section)
// 1999/11/25 H.Matsuoka Add isnd_msg
// 2000/02/23 H.Matsuoka Fix suspend status problem
// 2000/11/30 Y.Taka Add Enter/Return_critical_section
// 2001/01/22 Y.Taka Add trcv_msg()
// 2001/03/08 Y.Taka Change critical section
//
//*************************************************************************
#include "Ros33.h"
#include "internal.h"
//****************************************************************************
//*** 3.3 Synchronization and Communication Functions ***
//****************************************************************************
//********************************************************************
// Send Message to Mailbox
// [Parameters]
// ID mbxid MailboxID
// T_MSG *pk_msg Start Address of Message Packet
// [Return Parameters]
// ER ercd ErrorCode
//********************************************************************
ER snd_msg
(
ID mbxid,
T_MSG* pk_msg
)
{
T_TSKCB* pTskcb;
T_MLBXCB* pMlbxcb;
// UW psr;
UW psr;
#ifndef NO_ERROR_CHECK
if(mbxid <= 0)
{
return E_ID;
}
if(mbxid > MLBX_NUM)
{
return E_NOEXS;
}
if(pk_msg->pNxt != 0)
{
return E_PAR;
}
#endif
psr = ent_cri();
pMlbxcb = &g_sMlbxcb[mbxid-1];
if(pMlbxcb->pNxtTsk != (UW*)pMlbxcb) { // exist mail wait task
pTskcb = (T_TSKCB*)pMlbxcb->pNxtTsk;
*(pTskcb->pMsg) = pk_msg;
pTskcb->ubStatus &= ~TTS_WAI;
pTskcb->ubWaitStat &= ~TTW_MBX;
if(pTskcb->ubIntinfo == 0) /* interrupt information */
{
((T_SAVEDREG_MIN*)(pTskcb->uwSP))->returnvalue = E_OK; //gfd
}
/* clear time out task link */
vfnDelInitMember((T_NODE*)&(pTskcb->pNxtTmoTsk));
vfnDelAddMember((T_NODE*)&g_sReadyQueue[pTskcb->bPriority],
(T_NODE*)pTskcb);
int_dispatch(); // dispatch & disable interrupt
} else { // add messege to mail list
pMlbxcb->count++;
if(pMlbxcb->pMsg == 0)
{
pMlbxcb->pMsg = pk_msg;
} else { // 1999/08/09 H.Matsuoka BUG FIX
// (mail box link list)
T_MSG* pTemp;
pTemp = pMlbxcb->pMsg;
while(pTemp->pNxt != 0)
{
pTemp = pTemp->pNxt;
}
pTemp->pNxt = pk_msg;
}
}
ret_cri(psr);
#ifndef NO_RETURN_VALUE
return E_OK;
#endif
}
//********************************************************************
// Receive Message from Mailbox
// [Parameters]
// ID mbxid MailboxID
// TMO tmout Timeout
// [Return Parameters]
// ER ercd ErrorCode
// T_MSG *pk_msg Start Address of Message Packet
//********************************************************************
ER trcv_msg
(
T_MSG** ppk_msg,
ID mbxid,
TMO tmout
)
{
T_TSKCB* pTskcb;
T_MLBXCB* pMlbxcb;
UW psr;
#ifndef NO_ERROR_CHECK
if((g_ubIntNestCnt != 0) // issued from task-independent portions
|| (g_ubSysStat & TSS_DDSP)) // task in dispatch disabled state
{
return E_CTX;
}
if(mbxid <= 0)
{
return E_ID;
}
if(mbxid > MLBX_NUM)
{
return E_NOEXS;
}
if(tmout <= -2)
{
return E_PAR;
}
#endif
psr = ent_cri();
pMlbxcb = &g_sMlbxcb[mbxid-1];
if(pMlbxcb->pMsg == 0) // message nothing
{
if (tmout == TMO_POL)
{
ret_cri(psr);
return E_TMOUT;
}
g_pCurTsk->pMsg = ppk_msg;
g_pCurTsk->ubStatus |= TTS_WAI;
g_pCurTsk->ubWaitStat |= TTW_MBX;
vfnDelAddMember((T_NODE*)pMlbxcb, (T_NODE*)g_pCurTsk);
/* set time out */
if(tmout != TMO_FEVR) {
g_pCurTsk->utime = g_sSysTime.utime;
if (g_sSysTime.ltime > g_sSysTime.ltime + tmout)
g_pCurTsk->utime += 1;
g_pCurTsk->ltime = g_sSysTime.ltime + tmout;
vfnAddTimer((T_NODE*)&(g_pCurTsk->pNxtTmoTsk));
}
int_dispatch(); // dispatch & disable interrupt
ret_cri(psr);
MOV_R1TOR0; // mov r1(from the returnvalue in the stack) to ro (in asm)
return; // return value is E_OK or E_RLWAI
} else {
*ppk_msg = pMlbxcb->pMsg;
pMlbxcb->pMsg = pMlbxcb->pMsg->pNxt;
pMlbxcb->count--;
}
ret_cri(psr);
#ifndef NO_RETURN_VALUE
return E_OK;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -