![]() |
ECAT_Slave_in_ПЧ2П_c402
0.8
Реализация EtherCAT Slave для CM TMS320F28388D
|
Implementation. Подробнее...
#include "ecat_def.h"#include "ecatslv.h"#include "mailbox.h"#include "ecatcoe.h"#include "ecatfoe.h"Макросы | |
| #define | _MAILBOX_ 1 |
Функции | |
| UINT8 | PutInMbxQueue (TMBX MBXMEM *pMbx, TMBXQUEUE MBXMEM *pQueue) |
| TMBX MBXMEM * | GetOutOfMbxQueue (TMBXQUEUE MBXMEM *pQueue) |
| void | MBX_Init (void) |
| This function intialize the Mailbox Interface. Подробнее... | |
| UINT16 | MBX_StartMailboxHandler (void) |
| This function includes the state transition from INIT to. Подробнее... | |
| void | MBX_StopMailboxHandler (void) |
| This function includes the state transition from. Подробнее... | |
| UINT8 | MailboxServiceInd (TMBX MBXMEM *pMbx) |
| The function checks the mailbox header for the requested service and calls the. Подробнее... | |
| void | MBX_MailboxWriteInd (TMBX MBXMEM *pMbx) |
| This function is called when the Master has written the Receive-Mailbox. Подробнее... | |
| void | MBX_MailboxReadInd (void) |
| This function is called when the Master has read the Send-Mailbox. Подробнее... | |
| void | MBX_MailboxRepeatReq (void) |
| This function is called if the Master has requested a resending of the last. Подробнее... | |
| UINT8 | MBX_MailboxSendReq (TMBX MBXMEM *pMbx, UINT8 flags) |
| This function puts a new Mailbox service in the Send Mailbox. Подробнее... | |
| void | MBX_CheckAndCopyMailbox (void) |
| This function is used to check if the received mailbox command can be processed. Подробнее... | |
| UINT8 | MBX_CopyToSendMailbox (TMBX MBXMEM *pMbx) |
| This function copies data to the Send Mailbox. Подробнее... | |
| void | MBX_Main (void) |
| This function is called cyclically to check if a received Mailbox service was stored. Подробнее... | |
Переменные | |
| VARVOLATILE UINT8 | u8dummy |
| BOOL | bNoMbxMemoryAvailable |
| Indicates if enough dynamic memory is available to handle at least one mailbox datagram. Подробнее... | |
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:
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:
Changes to version V5.12:
V5.13 EOE1:
V5.13 MBX2: clear unused bytes before write mailbox response
V5.13 MBX3: fix potential double free memory and lost of last read mailbox data
V5.13 TEST3: 0x2040.4 send ARP on unsupported mailbox request
Changes to version V5.11:
V5.12 EOE5: free pending buffer in EoE_Init, EoE_Init is called on startup and PI transition
V5.12 MBX1: use only 16Bit variables to write the last byte of the mailbox buffer in case of ESC_16BIT_Access,update clear message queue in case of stop mailbox handler
V5.12 MBX2: do not set the pending indication in case of a EoE request, application triggered eoe datagram update
V5.12 MBX3: handle incomplete mailbox communication
V5.12 MBX4: in case of a disable mailbox queue and two consecutive foe uploads the mailbox receive handler is blocked
Changes to version V5.10:
V5.11 ECAT10: change PROTO handling to prevent compiler errors
V5.11 ECAT7: add missing big endian swapping
V5.11 HW1: "move hardware independent functions ""HW_DisableSyncManChannel()"", ""HW_EnableSyncManChannel()"", ""HW_GetSyncMan()"", ""HW_ResetALEventMask()"", ""HW_SetALEventMask()"" to ecatalv.c"
V5.11 MBX2: "check in IP if enough dynamic memory is available to handle mailbox communication, if it is not the case the mbx error ""no memory"" is returned on any mbx request"
V5.11 MBX3: set application triggered emergency and EoE data to pending if no mailbox queue is supported and another mailbox request is currently handled, Handle only one mailbox request at a time (in case that MAILBPX_QUEUE is disabled)
V5.11 TEST4: add new mailbox test behavior (the master mailbox cnt shall be incremented by 1 and the slave mailbox cnt is alternating)
Changes to version V5.01:
V5.10 EOE3: Change local send frame pending indication variable to a global variable (it need to be resetted if the mailbox is stopped and a frame is pending)
V5.10 ESC6: Update SyncManager register size (only for 8Bit ESC access)
V5.10 MBX2: Allocate only memory for current configured mailbox size (max supported size was allocated before)
Changes to version V5.0:
V5.01 ESC2: Add missed value swapping
V5.01 MBX2: Return an error if length specified in mailbnox header is too large.
Changes to version V4.40:
V5.0 ECAT3: Global dummy variables used for dummy ESC operations.
V5.0 ESC1: ESC 32Bit Access added.
V5.0 MBX2: Prevent double swapping (MBX repeat service) of MBX length field.
V5.0 MBX4: Unlock SM buffer based on SM state.
Changes to version V4.11:
V4.40 MBX8: Handle pending mailbox data even if mailbox queue is enabled
V4.40 MBX7: Reset SyncManger 1 Repeat Acknowledge bit if local variable is reset
V4.40 EMCY2: Send queued emergency messages
V4.40 BOOT2: Support only FoE in Bootstrap state
V4.40 MBX5: Prevent multiple free buffer
V4.40 MBX6: change return value if no mailbox buffer is available
Changes to version V4.08:
V4.11 MBX 1: free some dynamic memory to avoid memory leaks in the mailbox queue
Changes to version V4.07:
V4.10 MBX 1: check Mailbox message buffer and print emergency messages
during state change Init -> PreOP
Changes to version V4.07:
V4.08 MBX 1: The mailbox queue was added (switch MAILBOX_QUEUE), if the
mailbox should be handled in the ESC-Interrupt Service Routine
the defines ENTER_MBX_CRITICAL and LEAVE_MBX_CRITICAL could be used
to disable the interrupts or change the priority
V4.08 AOE 1: AoE was added
Changes to version V4.06:
V4.07 ECAT 1: The sources for SPI and MCI were merged (in ecat_def.h
set the switch MCI_HW to 1 when using the MCI,
set the switch SPI_HW to 1 when using the SPI
См. определение в файле mailbox.c