📄 mailbox.c
字号:
////////////////////////////////////////////////////////////////////////////////
// File Name : Mailbox.c
// Create Date : 2001-6-27 pm 01:02:56
// Written by : CYu
// Decription :
//------------------------------------------------------------------------------
// Copyright: CNASIC Proprietary Material
// Copyright (c) 2001, All Rights Reserved By:
// National ASIC System Engineering Research Center (CNASIC)
// SouthEast University
//
// DISTRIBUTION PROHIBITED without written authorization from CNASIC
//------------------------------------------------------------------------------
// Modification History
//
// 2001/10/31 by longn_qi revise.
//
////////////////////////////////////////////////////////////////////////////////
/* System and Standard Header */
#include <sys\sysdebug.h>
#include <kernel\ros33\itron.h>
#include <kernel\ros33\ros33.h>
#define _SIZE_T_DEFINED
#include <windows.h>
/* Application Header */
#include "internal.h"
//--- macro and definition -----------------------------------------------------
//--- static variables ---------------------------------------------------------
//--- external variables -------------------------------------------------------
//--- shared variables ---------------------------------------------------------
//--- static functions ---------------------------------------------------------
//--- external functions -------------------------------------------------------
/* Function Definition */
//------------------------------------------------------------------------------
// Function name : snd_msg
// Description :
// Return type : ER
// Argument : ID mbxid
// Argument : T_MSG* pk_msg
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER snd_msg( ID mbxid, T_MSG* pk_msg )
{
ID idTask;
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[24].sta++;
#endif
if( mbxid<=0 )
return E_ID;
if( mbxid>MLBX_NUM )
return E_NOEXS;
if( pk_msg->pNxt )
return E_PAR;
ENTER_CS
if( aMxcb[mbxid].idTask )
{
idTask = aMxcb[mbxid].idTask;
*aTcb[idTask].pMsg = pk_msg;
aMxcb[mbxid].idTask = 0;
aTcb[idTask].ubStatus &= ~TTS_WAI;
aTcb[idTask].ubWaitStat &= ~TTW_MBX;
aTcb[idTask].vwWaitRet = E_OK;
AppendTaskToReadyQueue( idTask );
#if ENABLE_SYSMSG_STATISTIC
// fprintf( DebugLogFile, "MailBox %d: get immediately\n", mbxid );
#endif
LEAVE_CS
ContextSwitch( );
}
else
{
if( !aMxcb[mbxid].pMsg )
aMxcb[mbxid].pMsg = pk_msg;
else
{
T_MSG* pTemp;
pTemp = aMxcb[mbxid].pMsg;
while( pTemp->pNxt )
pTemp = pTemp->pNxt;
pTemp->pNxt = pk_msg;
}
#if ENABLE_SYSMSG_STATISTIC
gSysMsgSta[mbxid].cur++;
if( gSysMsgSta[mbxid].cur > gSysMsgSta[mbxid].max )
gSysMsgSta[mbxid].max = gSysMsgSta[mbxid].cur;
// fprintf( DebugLogFile, "MailBox %d: len %ld, max %ld\n", mbxid, gDebugSysMsg[mbxid].cur, gDebugSysMsg[mbxid].max );
#endif
LEAVE_CS
}
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : trcv_msg
// Description :
// Return type : ER
// Argument : T_MSG** ppk_msg
// Argument : ID mbxid
// Argument : TMO tmout
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER trcv_msg( T_MSG** ppk_msg, ID mbxid, TMO tmout )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[27].sta++;
#endif
if( g_ubSysStat & TSS_DDSP )
return E_CTX;
if( mbxid<=0 )
return E_ID;
if( mbxid>MLBX_NUM )
return E_NOEXS;
if( tmout<=-2 )
return E_PAR;
ENTER_CS
if( !aMxcb[mbxid].pMsg )// no message in queue
{
if( tmout==TMO_POL )
{
LEAVE_CS
return E_TMOUT;
}
aTcb[idCurTask].pMsg=ppk_msg;
aTcb[idCurTask].ubStatus |= TTS_WAI;
aTcb[idCurTask].ubWaitStat |= TTW_MBX;
aMxcb[mbxid].idTask = idCurTask;
RemoveTaskFromReadyQueue( aTcb[idCurTask].bPriority, idCurTask );
if( tmout!=TMO_FEVR )
SetTimer( hwndClient, idCurTask, tmout, ( TIMERPROC )PollingTimerHandler );
LEAVE_CS
ContextSwitch( );
aMxcb[mbxid].idTask = 0;
return aTcb[idCurTask].vwWaitRet;
}
else
{
*ppk_msg = aMxcb[mbxid].pMsg;
aMxcb[mbxid].pMsg = aMxcb[mbxid].pMsg->pNxt;
#if ENABLE_SYSMSG_STATISTIC
gSysMsgSta[mbxid].cur--;
// fprintf( DebugLogFile, "MailBox %d: len %ld, max %ld\n", mbxid, gDebugSysMsg[mbxid].cur, gDebugSysMsg[mbxid].max );
#endif
LEAVE_CS
}
return E_OK;
}
//----------------------------- The End of the File ----------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -