EtherCAT Slave - mailbox.c
作者:互联网
mailbox.c Implementation
Description of the mailbox buffer handling (MAILBOX_QUEUE = 0):
There are two mailbox buffer for sending and receiving mailbox services.
Normal operation:
When starting the mailbox handler psWriteMbx contains mailbox buffer 1, psReadMbx, psRepeatMbx and psStoreMbx are 0.
In this state a repeat request would be ignored because there was no service sent yet.
When the first mailbox service is sent (in MBX_CopyToSendMailbox), psWriteMbx gets mailbox buffer 2
and psReadMbx gets the sent mailbox buffer 1, psRepeatMbx and psStoreMbx are still 0.
When the first mailbox service was read from the master, the sent mailbox buffer 1 is stored
in psRepeatMbx (in MBX_MailboxReadInd).
After that psReadMbx gets always the actual sent mailbox buffer, psWriteMbx is set to 0 (another
received mailbox service from the master will not be handled until the sent mailbox service was read
and MBX_MailboxReadInd was called).
When the mailbox service is read, psWriteMbx gets the Buffer of psRepeatMbx and psRepeatMbx gets the buffer of psReadMbx.
Repeat Request from the master:
When a Repeat from the master is requested (MBX_MailboxRepeatReq), there are three different possibilities:
- no mailbox service was sent since the mailbox handler was started (psRepeatMbx = 0): nothing to do
- the acknowledge of the last sent mailbox service was received (in MBX_MailboxReadInd) (bSendMbxIsFull = 0):
the last sent mailbox service (psRepeatMbx) will be sent again (in MBX_CopyToSendMailbox) and stored in psReadMbx,
psRepeatMbx will be set to 0 - the acknowledge of the last sent mailbox service was not received (psReadMbx and psRepeatMbx contain different buffers,
psReadMbx is still in the mailbox (because MBX_MailboxReadInd is not called yet, bSendMbxIsFull = 1):
psReadMbx will be deleted in the mailbox (call of DisableSyncManChannel and EnableSyncManChannel) and
stored in psStoreMbx, psRepeatMbx will be sent again (in MBX_CopyToSendMailbox) and stored in psReadMbx,
psRepeatMbx will be set to 0.
When the repeated mailbox service was sent (call of MBX_MailboxReadInd), psReadMbx will be stored in psRepeatMbx
and psStoreMbx will be sent (in MBX_CopyToSendMailbox) and stored in psReadMbx, psStoreMbx will be set to 0.
Description of the mailbox buffer handling (MAILBOX_QUEUE = 1):
There are two mailbox buffer for sending and receiving mailbox services.
Normal operation (psWriteMbx is only used for local storage):
When starting the mailbox handler psReadMbx, psRepeatMbx and psStoreMbx are 0.
In this state a repeat request would be ignored because there was no service sent yet.
When a mailbox service is received from the master (in MBX_CheckAndCopyMailbox) a mailbox buffer
will be get with APPL_AllocMailboxBuffer and the corresponding protocol service function will
be called (in MBX_WriteMailboxInd). This buffer shall be used for the protocol service response.
When the first mailbox service is sent (in MBX_CopyToSendMailbox), psReadMbx gets the sent mailbox buffer,
psRepeatMbx and psStoreMbx are still 0.
When the first mailbox service was read from the master, the sent mailbox buffer (psReadMbx) is stored
in psRepeatMbx (in MBX_MailboxReadInd).
After that psReadMbx gets always the actual sent mailbox buffer (in MBX_CopyToSendMailbox)
When the mailbox service is read, psRepeatMbx is returned (with APPL_FreeMailboxBuffer) and psRepeatMbx gets the
buffer of psReadMbx.
Repeat Request from the master:
When a Repeat from the master is requested (MBX_MailboxRepeatReq), there are three different possibilities:
- no mailbox service was sent since the mailbox handler was started (psRepeatMbx = 0): nothing to do
- the acknowledge of the last sent mailbox service was received (in MBX_MailboxReadInd) (bSendMbxIsFull = 0):
the last sent mailbox service (psRepeatMbx) will be sent again (in MBX_CopyToSendMailbox) and stored in psReadMbx,
psRepeatMbx will be set to 0 - the acknowledge of the last sent mailbox service was not received (psReadMbx and psRepeatMbx contain different buffers,
psReadMbx is still in the mailbox (because MBX_MailboxReadInd is not called yet, bSendMbxIsFull = 1):
psReadMbx will be deleted in the mailbox (call of DisableSyncManChannel and EnableSyncManChannel) and
stored in psStoreMbx, psRepeatMbx will be sent again (in MBX_CopyToSendMailbox) and stored in psReadMbx,
psRepeatMbx will be set to 0.
When the repeated mailbox service was sent (call of MBX_MailboxReadInd), psReadMbx will be stored in psRepeatMbx
and psStoreMbx will be sent (in MBX_CopyToSendMailbox) and stored in psReadMbx, psStoreMbx will be set to 0.
void MBX_Main(void)
- GetOutOfMbxQueue(&sMbxReceiveQueue);
to check if a received mailbox service was stroed. - MailboxServiceInd(pMbx);
to check the mailbox header for the requested service and calls the corresponding XXX_ServiceInd function. - if (bReceiveMbxIsLocked)
MBX_CheckAndCopyMailbox();
UINT8 MailboxServiceInd(TMBX MBXMEM *pMbx)
checks the mailbox header:
(pMbx->Mbxheader.Flags[MBX_OFFS_TYPE] & MBX_MASK_TYPE) >> MBX_SHIFT_TYPE
when mailbox header type is MBX_TYPE_COE, it calls:
COE_ServiceInd((TCOEMBX MBXMEM *) pMbx);
UINT8 COE_ServiceInd(TCOEMBX MBXMEM * pCoeMbx)
- COESERVICE_SDOREQUEST
SDOS_SdoInd( (TINITSDOMBX MBXMEM *) pCoeMbx ); - COESERVICE_SDORESPONSE
- COESERVICE_SDOINFO
SDOS_SdoInfoInd( (TSDOINFORMATION MBXMEM *) pCoeMbx );
void MBX_CheckAndCopyMailbox(void)
标签:Slave,service,psRepeatMbx,psReadMbx,mailbox,MBX,EtherCAT,sent 来源: https://www.cnblogs.com/salvare/p/11058237.html