![]() |
ECAT_Slave_in_ПЧ2П_c402
0.8
Реализация EtherCAT Slave для CM TMS320F28388D
|
Implementation This file contains the EtherCAT State Machine. Подробнее...
#include "ecatslv.h"#include "ecatappl.h"#include "mailbox.h"#include "ecatcoe.h"#include "objdef.h"#include "cia402appl.h"Макросы | |
| #define | _ECATSLV_ 1 |
Функции | |
| void | ResetALEventMask (UINT16 intMask) |
| This function makes an logical and with the AL Event Mask register (0x204) Подробнее... | |
| void | SetALEventMask (UINT16 intMask) |
| This function makes an logical or with the AL Event Mask register (0x204) Подробнее... | |
| void | UpdateEEPROMLoadedState (void) |
| This function reads the EEPROM loaded state. Подробнее... | |
| TSYNCMAN ESCMEM * | GetSyncMan (UINT8 channel) |
| This function is called to read the SYNC Manager channel descriptions of the process data SYNC Managers. Подробнее... | |
| void | DisableSyncManChannel (UINT8 channel) |
| This function disables a Sync Manager channel. Подробнее... | |
| void | EnableSyncManChannel (UINT8 channel) |
| This function enables a Sync Manager channel. Подробнее... | |
| UINT8 | CheckSmSettings (UINT8 maxChannel) |
| This function checks all SM channels. Подробнее... | |
| UINT16 | StartInputHandler (void) |
| This function is called in case of the state transition from PREOP to SAFEOP. |brief the areas of the Sync Managers will be checked for overlapping,. Подробнее... | |
| UINT16 | StartOutputHandler (void) |
| This function is called in case of the state transition from SAFEOP to OP. Подробнее... | |
| void | StopOutputHandler (void) |
| This function is called in case of the state transition from OP to SAFEOP. Подробнее... | |
| void | StopInputHandler (void) |
| This function is called in case of the state transition from SAFEOP to PREOP. Подробнее... | |
| void | BackToInitTransition (void) |
| This function is called when a X to Init transition is completed. Подробнее... | |
| void | SetALStatus (UINT8 alStatus, UINT16 alStatusCode) |
| The function changes the state of the EtherCAT ASIC to the requested. Подробнее... | |
| void | AL_ControlInd (UINT8 alControl, UINT16 alStatusCode) |
| This function handles the EtherCAT State Machine. It is called in case of an AL Control event (Bit 0 of AL-Event (Reg 0x220), when the Master has written the AL Control Register (from ECAT_Main), alControl contains the content of the AL Control (Reg 0x120) in case of a SM-Change event (Bit 4 of AL-Event (Reg 0x220)), when an Activate SYNCM y register is written by the master (from ECAT_Main), alControl contains the actual state (Bit 0-3 of AL Status (Reg 0x130)) in case of a locally expired watchdog (from ECAT_Main), alControl contains the requested new state (SAFE_OP) in case of an application specific event to change the EtherCAT state (from application), alControl contains the requested new state (INIT, PRE_OP or SAFE_OP) Подробнее... | |
| void | AL_ControlRes (void) |
| This function is called cyclic if a state transition is pending (bEcatWaitForAlControlRes == TRUE) Подробнее... | |
| void | DC_CheckWatchdog (void) |
| This function checks the current Sync state and set the local flags The analyse of the local flags is handled in "CheckIfEcatError". Подробнее... | |
| void | CheckIfEcatError (void) |
| Checks communication and synchronisation variables and update AL status / AL status code if an error has occurred. Подробнее... | |
| void | ECAT_StateChange (UINT8 alStatus, UINT16 alStatusCode) |
| This function changes the state of the EtherCAT slave if the requested state is lower than the actual state, otherwise the error condition will be reset. Подробнее... | |
| void | ECAT_Init (void) |
| This function initialize the EtherCAT Slave Interface. Подробнее... | |
| void | ECAT_Main (void) |
| This function has to be called cyclically. Подробнее... | |
Переменные | |
| UINT16 | u16ALEventMask |
| VARVOLATILE UINT8 | u8dummy |
| VARVOLATILE UINT8 | SMActivate = 0 |
| TSYNCMAN | SyncManInfo |
| BOOL | EepromLoaded = FALSE |
Implementation This file contains the EtherCAT State Machine.
Changes to version V5.12:
V5.13 BOOT1: support Init-to-Init transition in bootloader application
V5.13 CIA402 3: change define "CIA402_DEVICE" to "CiA402_SAMPLE_APPLICATION"
V5.13 CIA402 4: decouple CIA402 state machine and application from ESM (according ETG.6010, clause 4)
V5.13 ECAT1: handle Sync mapped to AL Event
V5.13 ECAT2: explicit device ID handling, the ID value shall only be latched on the rising edge of 0x120.5
V5.13 ECAT3: reset local Error flag in case of two consecutive pending state response and the the first failes
V5.13 ESM1: local error handling update, ECAT_StateChange triggers only transitions from Op->Any or reject/accept a pending transition
V5.13 ESM2: support ErrorSafeOP to OP transition
V5.13 ESM3: Safe-to-OP transition in DC mode, ack OP state if no error was detected
V5.13 ESM4: implement disable sync error reaction 0x10F1.2 is set to 0
V5.13 MBX1: change mbx_read flag handling to SM1 buffer state handling (required in case of a mbx read frame with an invalid CRC, the read flag would be set but the SM bufer is still locked)
Changes to version V5.11:
V5.12 BOOT1: add a bootloader sample application (only the ESM and FoE is supported)
V5.12 ECAT1: update SM Parameter measurement (based on the system time), enhancement for input only devices and no mailbox support, use only 16Bit pointer in process data length caluclation
V5.12 ECAT4: update Sync1 watchdog calculation (in case of subordinated cycles take one addiitonal Sync0 cycle into account )
V5.12 ECAT5: update Sync error counter/flag handling,check enum memory alignment depending on the processor,in case of a polled timer disable ESC interrupts during DC_CheckWatchdog
V5.12 ECAT7: set error single flash also in case of an application error
V5.12 ESM1: overwrite the current error in case of a local error with a lower target state,Do not overwrite the current AL Status in case of an local error
V5.12 ESM2: enable the PD SM in case of a clear error transition
V5.12 ESM3: set internal ESM timeout to -10% of the configured value (to return an errorcode before the master will run into an timeout)
V5.12 ESM4: enable the AL Event mask in case of pending ESM transition
V5.12 TEST2: add pending ESM test,trigger complete ESM transition from ecat main
Changes to version V5.10:
V5.11 COE3: change 0x10F3.2 (Sync Error limit) from UINT32 to UINT16 (according to the ETG.1020)
V5.11 DIAG4: change parameter handling in DIAG_CreateNewMessage()
V5.11 ECAT10: change PROTO handling to prevent compiler errors
V5.11 ECAT4: enhance SM/Sync monitoring for input/output only slaves
V5.11 ECAT5: "Add missing ""bEscIntEnabled"" initialization if ""AL_EVENT_ENBALED"" is 0"""
V5.11 ECAT7: add missing big endian swapping
V5.11 ESC1: update max address calculation
V5.11 ESM1: update calculation of subordinated cycles
V5.11 ESM2: DC_SUPPORTED, Sync0 is not supported and Sync0 is generated according register values the state transition to SafeOP shall be rejected
V5.11 ESM3: update checking of the user configured sync type
V5.11 ESM4: prevent to go from ErrSafeOP to OP without re enabling Sync0/1
V5.11 ESM5: DPRAM range was double checked
V5.11 ESM6: in the SO transition wait by default until the master has send process data
V5.11 HW1: "move hardware independent functions ""HW_DisableSyncManChannel()"", ""HW_EnableSyncManChannel()"", ""HW_GetSyncMan()"", ""HW_ResetALEventMask()"", ""HW_SetALEventMask()"" to ecatalv.c"
V5.11 HW2: check during ESM handling if the SM address and length is aligned according the ESC access
V5.11 TEST9: "add behaviour 0x2020.7 (SDO requests on 0x3006.0 are set to pending until an FoE read request on ""UnlockSdoResp"" is received or in case that no mbx queue is supported when a new mbx request was received)"
Changes to version V5.01:
V5.10 COE1: Define one entry description for all 0x1C3x objects and change data type of SI11,12,13 to UINT16 (according ETG.1020)
V5.10 DIAG1: Define diagmessage textIDs
V5.10 ECAT13: Update Synchronisation handling (FreeRun,SM Sync, Sync0, Sync1)
Compare DC UINT configuration (by ESC Config data) vs. DC activation register settings
Update 0x1C3x entries
V5.10 ESC2: Check if defined SM settings do not exceed the available DPRAM range (in error case AL Status 0x14 is returned)
V5.10 ESC3: Handle DC cControl register values in case of 32Bit ESC access (a Sync activation mask need to defined/used)
V5.10 ESC4: Mask lower 4 Bit of AL status to get Run led value
Invalid RunLed code was calculated if ESC set ECAT Run Led
V5.10 ESC5: Add missing swapping
V5.10 ESM2: Update "bApplEsmPending" flag during a transition to a lower state
V5.10 ESM3: Add "volatile" directive for ESM dummy variables
V5.10 HW5: Block ESC interrupts during Timer ISR
V5.10 TEST9: Add option to prevent SM3 unlock during PS
Changes to version V5.0:
V5.01 APPL3: Include library demo application
V5.01 ESC2: Add missed value swapping
V5.01 ESM1: Don't overwrite the error reason in case of an failed PS transition
V5.01 ESM2: Don't check the "appl trigger" flag in case on an regular transition to a lower state (OS, SP, PI).
V5.01 ESM3: Call Error acknowledge indication only if error was acknowledged by the master
V5.01 HW3: Update blink code of an SM watchdog error
Changes to version V4.42:
V5.0 ECAT1: Support Explicit Device ID.
V5.0 ECAT2: Application specific functions are moved to application files.
V5.0 ECAT3: Global dummy variables used for dummy ESC operations.
V5.0 ESC1: ESC 32Bit Access added.
V5.0 ESC2: Support ESC EtherCAT LED Indication.
V5.0 ESC3: Support EEPROM Emulation.
V5.0 ESM1: Update "LocalErrorFlag" handling.
V5.0 ESM2: Update Error Acknowledge by ALControl INIT (without error acknowledge)
V5.0 ESM3: Handle pending ESM transition
V5.0 ESM4: ECAT_StateChange() will only be called form application. In case of an communication error AL_ControlInd is called.
V5.0 MBX1: Support configuration without mailbox protocol support.
V5.0 TEST1: Add test application. See Application Note ET9300 for more details.
Changes to version V4.40:
V4.42 ESM1: Reset local error flag if master set the acknowledge bit (0x120.4)
Changes to version V4.30:
V4.40 ESM5: Enable output SyncManager if local error acknowledged
V4.40 HW0: Use common hardware access functions
V4.40 PDO3: Add support if only input process data is used
V4.40 ECAT4: Add read SM activation register to acknowledge SM Change event
V4.40 PDO2: Check if max process data size was exceed
V4.40 DIAG1: add diagnosis message support
V4.40 ESM4: Change Check WD setup; add define OP_PD_REQUIRED (defines if process data required in state change to OP)
V4.40 WD1: change WD behaviour depending if process data required in OP state
V4.40 MBX4: Change processing order of mailbox SyncManager flags
V4.40 ECAT1: Merge content of HW_Main (spihw.c /mcihw.c) to ECAT_Main
V4.40 ECAT2: Added CheckIfLocalError() to check local flags and set ALStatus /Al Status code if required. This function is called cyclic from MainLoop.
V4.40 ESM2: Add AL_ControlRes() to complete pending state requests. Change SafeOP to OP state response
V4.40 ESM1: Prevent double call of StopOutputHandler()
V4.40 BOOT1: Enable Mailbox SyncManger on state change to BOOT state (to enable FoE)
V4.40 ESM3: Change State machine behaviour according to ETG.1000 V1.0.2 (state change #26)
V4.40 LED1: Set error blink code
V4.40 TIMER1: Added DC_CheckWatchdog() triggered from ECAT_CheckTimer(). Change local Sync0 watchdog variables. Change bus cycle calculation
V4.40 WD1: Change check process data watchdog settings
Changes to version V4.20:
V4.30 OBJ 3: initialize the object dictionary in state change INIT->PREOP; clear object dictionary in state change PREOP->INIT
V4.30 SYNC: add 0x1C32:10; 0x1C33:10 (Sync0 cycle), change synchronisation control functionality
V4.30 CiA402: add CiA402_Init() call in state change from PREOP to SAFEOP if DC synchronisation is enabled,
else the Init function is called when bus cycle time is calculated [CalcSMCycleTime() ].
trigger error handling if the EtherCAT state machine gets a transition from OP to an "lower" state
V4.20 ECAT 1: add LEGACY_MODE behaviour in ECAT_CheckWatchdog()
V4.20 DC 1: Add DC pending state machine handling and Dc watchdog functionality
V4.20 ESM 2: Add State transition from BOOT to INIT
V4.20 ESM 1: Non LEGACY_MODE State change handling
V4.11 Renamed the function parameter "code" of Function "SendSmFailedEmergency() to avoid<br>
problems with some compilers"
V4.11 ECAT 1: Fixed a possible problem with state change Init -> SafeOP. The output syncmanager
was enabled by the state change-flag and not by the actual state
V4.11 LED 1: Clear the error LED during error acknowledgement
V4.11 ESC 1: fixed size of MBXHEADER in the TFOEMBX struct
Changes to version V4.08:
V4.10 ECAT 1: clear bEcatOutputsReceived in startMailboxhandler()
V4.10 ECAT 2: clear bEcatOutputsReceived in stopMailboxhandler()
V4.10 ECAT 3: when switching from INIT to BOOT the SM settings shall be checked
V4.10 ECAT 4: APPL_StartInputHandler shall always be called and bEcatInputUpdateRunning shall always be set
in StartInputHandler independent of the input size
V4.10 ECAT 5: AL_ControlInd: the error acknowledge behaviour was changed
according to the protocol enhancements and the conformance test
V4.10 ECAT 6: AL_ControlInd: if a state transitions failed the corresponding stop function is
called to get a consistent set of variables
V4.10 ECAT 7: the local application requested to leave the state OP so we have to disable the SM2
and make the state change from OP to SAFEOP by calling StopOutputHandler
V4.10 ECAT 8: the AL Status Code has to be reset if the error was acknowledged by the master
V4.10 ECAT 9: ECAT_StateChange: when waiting for a State Change response from the application the
AL Status shall only be written if the final state was reached
Changes to version V4.07:
V4.08 ECAT 1: The watchdog value was not rounded up
V4.08 ECAT 2: The value of u16WdValue was not set 0 if the register 0x420 is 0
V4.08 ECAT 3: The AlStatusCode is changed as parameter of the function AL_ControlInd
V4.08 ECAT 4: In a state transition OP2PREOP, SAFEOP2INIT or OP2INIT is requested,
this was not working correctly if one of the application functions
APPL_StopInputHandler or APPL_StopOutputHandler were returning NOERROR_INWORK
(because only the first state transition was made in that case)
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
Changes to version V4.00:
V4.01 ECAT 1: The Output sync Manager was not disabled when the state OP was left
by a local request (watchdog or io error)
V4.01 ECAT 2: APPL_StopOutputHandler returns an UINT16
V4.01 ECAT 3: TwinCAT compatibility mode: The state transition to OP is allowed when the
WD-Trigger-Bit of the SM2-Control-Byte (0x814.6) is FALSE, in that case the
watchdog will not be started before the outputs were received the first time
V4.01 ECAT 4: "else" was too much
Changes to version V3.20:
V4.00 ECAT 1: The handling of the Sync Manager Parameter was included according to
the EtherCAT Guidelines and Protocol Enhancements Specification
V4.00 ECAT 2: The output sync manager is initialized during the state transition
from PREOP to SAFEOP that the master can check if the slave could update
inputs and outputs before switching the slave to OP
behaviour according to the EtherCAT Guidelines and Protocol Enhancements Specification
V4.00 ECAT 3: The watchdog will be enabled in SAFE-OP that it can be checked if the last SM event
was received during the watchdog time before switching to OP
V4.00 ECAT 4: The function CheckSmChannelParameters is included in the function
CheckSmSettings to get a better overview
V4.00 ECAT 5: In synchronous mode the slave should support 1- and 3-buffer mode, 3-buffer mode
should be the standard setting, because the controlling if the process data was updated
should be done with the TxPDO Toggle, but the 1-buffer mode should be setable too,
that the master could easily check if all slaves are synchronous by checking the
the working counter (if the outputs were not read or the inputs were not written
the ESC of the slave would not increment the working counter with expected value
if the 1-buffer mode is running)
V4.00 ECAT 6: The function ECAT_StateChange was added, which the application should call if a local error
is detected (with the parameters alStatus = STATE_SAFEOP, alStatusCode = error code (> 0x1000))
or gone (with the parameters alStatus = STATE_OP, alStatusCode = 0)
or if one of the functions APPL_StartMailboxHandler, APPL_StopMailboxHandler, APPL_StartInputHandler,
APPL_StopInputHandler, APPL_StartOutputHandler, APPL_StopOutputHandler has returned NOERROR_INWORK
to acknowledge the last state transition (with the parameters alStatus = new AL-Status, alStatusCode =
new AL-Status-Code)
V4.00 ECAT 7: The return values for the AL-StatusCode were changed to UINT16
См. определение в файле ecatslv.c