📄 mailbox.c
字号:
/****************************************************************************/
/* TEXAS INSTRUMENTS PROPRIETARY INFORMATION */
/* */
/* (c) Copyright, Texas Instruments Incorporated, 2006. */
/* All Rights Reserved. */
/* */
/* Property of Texas Instruments Incorporated. Restricted Rights - */
/* Use, duplication, or disclosure is subject to restrictions set */
/* forth in TI's program license agreement and associated documentation. */
/****************************************************************************/
/****************************************************************************/
/* mailbox.c */
/* */
/* Application mailbox interface. */
/****************************************************************************/
#include "common.h"
#include "ddp2230_rtos_include.h"
#include "tmr.h"
#include "global.h"
#include "mailbox.h"
#include "dbmessage.h"
#include "testpoints.h"
/****************************************************************************/
/* Local declarations. */
/****************************************************************************/
typedef struct _appMBoxMsgStruct
{
uint16 msgID;
uint08 wait;
uint08 dispose;
uint32 eventID;
uint32 parm;
uint32 parm2;
}
APP_MBOXMESSAGE;
/****************************************************************************/
/* Format and send an application mailbox message. */
/* */
/* mbxID: Mailbox to receive message */
/* msgID: Mailbox-specific message identifer */
/* blocktime: Milliseconds to wait for transfer ( <0 is no wait ) */
/* parm: Untyped parameter */
/* dispose: Indicates parm is a pointer to a dynanically allocated block */
/* which is to be freed upon completion of message processing. */
/****************************************************************************/
MBM_CC mbSend( uint32 mbxID, uint16 msgID, int32 blocktime, uint32 parm, BOOL dispose, uint32 parm2 )
{
APP_MBOXMESSAGE mbm; /* mailbox message */
int08 cc; /* completion code */
uint32 taskID; /* current task ID */
TPM_SendSWTestMuxSignal( TP_MBSEND, TRUE );
taskID = RTA_TaskGetCurrentTaskID(); /* current task ID */
dbmsg_ftrace( DBM_MBOXROUTE, "mbSend: mbx: %04x msg: %04x tID: %02x\r\n",
mbxID, msgID, taskID );
/****************************************************/
/* Format the message. */
/****************************************************/
mbm.msgID = msgID;
mbm.wait = ( blocktime >= 0 );
if( mbm.wait) /* if caller waits for completion */
{
if( RTA_SUCCESS != RTA_EventCreate( &mbm.eventID, "mbe" ))
return MBM_EVENT;
RTA_EventClear( mbm.eventID );
}
mbm.dispose = dispose;
mbm.parm = parm;
mbm.parm2 = parm2;
/****************************************************/
/* Send the message and wait for complete if needed.*/
/****************************************************/
if( RTA_SUCCESS != RTA_MbxMsgSend( mbxID, &mbm, MED_PRI, sizeof( mbm ), gID_MemPool ))
{
dbmsg_trace( DBM_MBOXROUTE, "mbSend: cannot send\r\n" );
if( mbm.wait ) /* if an event was created */
RTA_EventDelete( mbm.eventID );
return MBM_SEND;
}
if( mbm.wait ) /* if waiting for complete */
{
cc = RTA_EventWait( mbm.eventID, TRUE, TMR_ConvertMSToTicks( blocktime ));
RTA_EventDelete( mbm.eventID );
if( cc != RTA_SUCCESS )
{
dbmsg_trace( DBM_MBOXROUTE, "mbSend: timeout waiting for response\r\n" );
return MBM_NORESP;
}
}
TPM_SendSWTestMuxSignal( TP_MBSEND, FALSE );
return MBM_PASS;
}
/****************************************************************************/
/* Receive an application mailbox message. */
/* */
/* mbxID: Mailbox from which to receive message */
/* blocktime: Milliseconds to wait for message */
/* mbCallback: Callback when message is received */
/* msgID: Mailbox-specific message identifer */
/* parm: Untyped parameter */
/****************************************************************************/
MBM_CC mbRecv( uint32 mbxID, int32 blocktime, void (*mbCallback)( uint16 msgID, uint32 parm, uint32 parm2 ))
{
APP_MBOXMESSAGE mbm; /* mailbox message */
int08 cc; /* completion code */
cc = RTA_MbxMsgReceive( mbxID, &mbm, TMR_ConvertMSToTicks( blocktime ));
TPM_SendSWTestMuxSignal( TP_MBRECV, TRUE ); /* timing test */
/****************************************************/
/* Handle successful message receive. */
/****************************************************/
if( cc == RTA_SUCCESS )
{
dbmsg_ftrace( DBM_MBOXROUTE, "mbRecv: mbx: %04x msg: %04x\r\n", mbxID, mbm.msgID );
(*mbCallback)( mbm.msgID, mbm.parm, mbm.parm2 );
if( mbm.wait ) /* if sender is waiting for a response */
RTA_EventSet( mbm.eventID );
if( mbm.dispose ) /* if message parm points to disposable memory */
RTA_MemRelease( (void*)mbm.parm );
}
else if( cc == RTA_TIMED_OUT ) /* if no message received */
{
return MBM_NOMSG;
}
else /* if error in receive */
{
dbmsg_ftrace( DBM_MBOXROUTE, "mbRecv: cc=%d\r\n", cc );
return MBM_RECV;
}
TPM_SendSWTestMuxSignal( TP_MBRECV, FALSE ); /* timing test */
return PASS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -