SOES v1.0.0
Data Structures | Defines | Typedefs | Functions | Variables
esc.h File Reference

Headerfile for esc.h. More...

Data Structures

struct  _ESCsm
struct  _ESCsm2
struct  PACKED
struct  _ESCvar
struct  _MBXh
struct  _MBX
struct  _COEh
struct  _INFOh
struct  _MBXerr
struct  _COEsdo
struct  _COEobjdesc
struct  _COEentdesc
struct  _FOEh
struct  _FOE
struct  _MBXcontrol
struct  esc_cfg_t

Defines

#define FLASHSTORE   const
#define PACKED   __attribute__((__packed__))
#define ESCREG_ADDRESS   0x0010
#define ESCREG_DLSTATUS   0x0110
#define ESCREG_ALCONTROL   0x0120
#define ESCREG_ALSTATUS   0x0130
#define ESCREG_ALERROR   0x0134
#define ESCREG_ALEVENT_SM_MASK   0x0310
#define ESCREG_ALEVENT_SMCHANGE   0x0010
#define ESCREG_ALEVENT_CONTROL   0x0001
#define ESCREG_ALEVENT_SM2   0x0400
#define ESCREG_ALEVENT_SM3   0x0800
#define ESCREG_WDSTATUS   0x0440
#define ESCREG_SM0   0x0800
#define ESCREG_SM0STATUS   (ESCREG_SM0 + 5)
#define ESCREG_SM0PDI   (ESCREG_SM0 + 7)
#define ESCREG_SM1   (ESCREG_SM0 + 0x08)
#define ESCREG_SM2   (ESCREG_SM0 + 0x10)
#define ESCREG_SM3   (ESCREG_SM0 + 0x18)
#define ESCREG_LOCALTIME   0x0910
#define ESCREG_SMENABLE_BIT   0x01
#define ESCREG_AL_STATEMASK   0x001f
#define ESCREG_AL_ALLBUTINITMASK   0x0e
#define ESCREG_AL_ERRACKMASK   0x0f
#define ESCinit   0x01
#define ESCpreop   0x02
#define ESCboot   0x03
#define ESCsafeop   0x04
#define ESCop   0x08
#define ESCerror   0x10
#define INIT_TO_INIT   0x11
#define INIT_TO_PREOP   0x21
#define INIT_TO_BOOT   0x31
#define INIT_TO_SAFEOP   0x41
#define INIT_TO_OP   0x81
#define PREOP_TO_INIT   0x12
#define PREOP_TO_PREOP   0x22
#define PREOP_TO_BOOT   0x32
#define PREOP_TO_SAFEOP   0x42
#define PREOP_TO_OP   0x82
#define BOOT_TO_INIT   0x13
#define BOOT_TO_PREOP   0x23
#define BOOT_TO_BOOT   0x33
#define BOOT_TO_SAFEOP   0x43
#define BOOT_TO_OP   0x83
#define SAFEOP_TO_INIT   0x14
#define SAFEOP_TO_PREOP   0x24
#define SAFEOP_TO_BOOT   0x34
#define SAFEOP_TO_SAFEOP   0x44
#define SAFEOP_TO_OP   0x84
#define OP_TO_INIT   0x18
#define OP_TO_PREOP   0x28
#define OP_TO_BOOT   0x38
#define OP_TO_SAFEOP   0x48
#define OP_TO_OP   0x88
#define ALERR_NONE   0x0000
#define ALERR_INVALIDSTATECHANGE   0x0011
#define ALERR_UNKNOWNSTATE   0x0012
#define ALERR_BOOTNOTSUPPORTED   0x0013
#define ALERR_INVALIDBOOTMBXCONFIG   0x0015
#define ALERR_INVALIDMBXCONFIG   0x0016
#define ALERR_INVALIDSMCONFIG   0x0017
#define ALERR_WATCHDOG   0x0019
#define ALERR_INVALIDOUTPUTSM   0x001D
#define ALERR_INVALIDINPUTSM   0x001E
#define MBXERR_SYNTAX   0x0001
#define MBXERR_UNSUPPORTEDPROTOCOL   0x0002
#define MBXERR_INVALIDCHANNEL   0x0003
#define MBXERR_SERVICENOTSUPPORTED   0x0004
#define MBXERR_INVALIDHEADER   0x0005
#define MBXERR_SIZETOOSHORT   0x0006
#define MBXERR_NOMOREMEMORY   0x0007
#define MBXERR_INVALIDSIZE   0x0008
#define ABORT_NOTOGGLE   0x05030000
#define ABORT_UNKNOWN   0x05040001
#define ABORT_UNSUPPORTED   0x06010000
#define ABORT_WRITEONLY   0x06010001
#define ABORT_READONLY   0x06010002
#define ABORT_NOOBJECT   0x06020000
#define ABORT_TYPEMISMATCH   0x06070010
#define ABORT_NOSUBINDEX   0x06090011
#define ABORT_GENERALERROR   0x08000000
#define ABORT_NOTINTHISSTATE   0x08000022
#define MBXstate_idle   0x00
#define MBXstate_inclaim   0x01
#define MBXstate_outclaim   0x02
#define MBXstate_outreq   0x03
#define MBXstate_outpost   0x04
#define MBXstate_backup   0x05
#define MBXstate_again   0x06
#define COE_DEFAULTLENGTH   0x0a
#define COE_HEADERSIZE   0x0a
#define COE_SEGMENTHEADERSIZE   0x03
#define COE_SDOREQUEST   0x02
#define COE_SDORESPONSE   0x03
#define COE_SDOINFORMATION   0x08
#define COE_COMMAND_SDOABORT   0x80
#define COE_COMMAND_UPLOADREQUEST   0x40
#define COE_COMMAND_UPLOADRESPONSE   0x40
#define COE_COMMAND_UPLOADSEGMENT   0x00
#define COE_COMMAND_UPLOADSEGREQ   0x60
#define COE_COMMAND_DOWNLOADRESPONSE   0x60
#define COE_COMMAND_LASTSEGMENTBIT   0x01
#define COE_SIZE_INDICATOR   0x01
#define COE_EXPEDITED_INDICATOR   0x02
#define COE_COMPLETEACCESS   0x10
#define COE_TOGGLEBIT   0x10
#define COE_INFOERROR   0x07
#define COE_GETODLISTRESPONSE   0x02
#define COE_GETODRESPONSE   0x04
#define COE_ENTRYDESCRIPTIONRESPONSE   0x06
#define COE_VALUEINFO_ACCESS   0x01
#define COE_VALUEINFO_OBJECT   0x02
#define COE_VALUEINFO_MAPPABLE   0x04
#define COE_VALUEINFO_TYPE   0x08
#define COE_VALUEINFO_DEFAULT   0x10
#define COE_VALUEINFO_MINIMUM   0x20
#define COE_VALUEINFO_MAXIMUM   0x40
#define MBXSIZE   0x80
#define MBXSIZEBOOT   0x80
#define MBXBUFFERS   3
#define MBX0_sma   0x1000
#define MBX0_sml   MBXSIZE
#define MBX0_sme   MBX0_sma+MBX0_sml-1
#define MBX0_smc   0x26
#define MBX1_sma   0x1080
#define MBX1_sml   MBXSIZE
#define MBX1_sme   MBX1_sma+MBX1_sml-1
#define MBX1_smc   0x22
#define MBX0_sma_b   0x1000
#define MBX0_sml_b   MBXSIZEBOOT
#define MBX0_sme_b   MBX0_sma_b+MBX0_sml_b-1
#define MBX0_smc_b   0x26
#define MBX1_sma_b   0x1080
#define MBX1_sml_b   MBXSIZEBOOT
#define MBX1_sme_b   MBX1_sma_b+MBX1_sml_b-1
#define MBX1_smc_b   0x22
#define SM2_sma   0x1100
#define SM2_smc   0x24
#define SM2_act   0x01
#define SM3_sma   0x1180
#define SM3_smc   0x20
#define SM3_act   0x01
#define MBXHSIZE   sizeof(_MBXh)
#define MBXDSIZE   MBXSIZE-MBXHSIZE
#define MBXERR   0x00
#define MBXAOE   0x01
#define MBXEOE   0x02
#define MBXCOE   0x03
#define MBXFOE   0x04
#define MBXODL   0x10
#define MBXOD   0x20
#define MBXED   0x30
#define MBXSEU   0x40
#define MBXSED   0x50
#define SMRESULT_ERRSM0   0x01
#define SMRESULT_ERRSM1   0x02
#define SMRESULT_ERRSM2   0x04
#define SMRESULT_ERRSM3   0x08
#define FOE_ERR_NOTDEFINED   0x8000
#define FOE_ERR_NOTFOUND   0x8001
#define FOE_ERR_ACCESS   0x8002
#define FOE_ERR_DISKFULL   0x8003
#define FOE_ERR_ILLEGAL   0x8004
#define FOE_ERR_PACKETNO   0x8005
#define FOE_ERR_EXISTS   0x8006
#define FOE_ERR_NOUSER   0x8007
#define FOE_ERR_BOOTSTRAPONLY   0x8008
#define FOE_ERR_NOTINBOOTSTRAP   0x8009
#define FOE_ERR_NORIGHTS   0x800A
#define FOE_ERR_PROGERROR   0x800B
#define FOE_OP_RRQ   1
#define FOE_OP_WRQ   2
#define FOE_OP_DATA   3
#define FOE_OP_ACK   4
#define FOE_OP_ERR   5
#define FOE_OP_BUSY   6
#define FOE_READY   0
#define FOE_WAIT_FOR_ACK   1
#define FOE_WAIT_FOR_FINAL_ACK   2
#define FOE_WAIT_FOR_DATA   3
#define EC_LITTLE_ENDIAN
#define FOEHSIZE   (sizeof(_FOEh))
#define FOE_DATA_SIZE   (MBXSIZEBOOT - (MBXHSIZE+FOEHSIZE))

Typedefs

typedef FLASHSTORE struct PACKED _ESCsmCompact

Functions

void ESC_config (esc_cfg_t *cfg)
void ESC_ALerror (uint16 errornumber)
void ESC_ALstatus (uint8 status)
void ESC_SMstatus (uint8 n)
uint8 ESC_WDstatus (void)
uint8 ESC_claimbuffer (void)
uint8 ESC_startmbx (uint8 state)
void ESC_stopmbx (void)
void MBX_error (uint16 error)
uint8 ESC_mbxprocess (void)
void ESC_xoeprocess (void)
uint8 ESC_startinput (uint8 state)
void ESC_stopinput (void)
uint8 ESC_startoutput (uint8 state)
void ESC_stopoutput (void)
void ESC_ALevent (void)
void ESC_state (void)
uint8 ESC_read (uint16 address, void *buf, uint16 len, void *tALevent)
uint8 ESC_write (uint16 address, void *buf, uint16 len, void *tALevent)
void ESC_init (void *arg)
void APP_safeoutput ()

Variables

volatile _ESCvar ESCvar
_MBX MBX [MBXBUFFERS]
_MBXcontrol MBXcontrol [MBXBUFFERS]
uint8 MBXrun
uint16 SM2_sml
uint16 SM3_sml

Detailed Description

Headerfile for esc.h.


Define Documentation

#define ABORT_GENERALERROR   0x08000000
#define ABORT_NOOBJECT   0x06020000
#define ABORT_NOSUBINDEX   0x06090011
#define ABORT_NOTINTHISSTATE   0x08000022
#define ABORT_NOTOGGLE   0x05030000
#define ABORT_READONLY   0x06010002
#define ABORT_TYPEMISMATCH   0x06070010
#define ABORT_UNKNOWN   0x05040001
#define ABORT_UNSUPPORTED   0x06010000
#define ABORT_WRITEONLY   0x06010001
#define ALERR_BOOTNOTSUPPORTED   0x0013
#define ALERR_INVALIDBOOTMBXCONFIG   0x0015
#define ALERR_INVALIDINPUTSM   0x001E
#define ALERR_INVALIDMBXCONFIG   0x0016
#define ALERR_INVALIDOUTPUTSM   0x001D
#define ALERR_INVALIDSMCONFIG   0x0017
#define ALERR_INVALIDSTATECHANGE   0x0011
#define ALERR_NONE   0x0000
#define ALERR_UNKNOWNSTATE   0x0012
#define ALERR_WATCHDOG   0x0019
#define BOOT_TO_BOOT   0x33
#define BOOT_TO_INIT   0x13
#define BOOT_TO_OP   0x83
#define BOOT_TO_PREOP   0x23
#define BOOT_TO_SAFEOP   0x43
#define COE_COMMAND_DOWNLOADRESPONSE   0x60
#define COE_COMMAND_LASTSEGMENTBIT   0x01
#define COE_COMMAND_SDOABORT   0x80
#define COE_COMMAND_UPLOADREQUEST   0x40
#define COE_COMMAND_UPLOADRESPONSE   0x40
#define COE_COMMAND_UPLOADSEGMENT   0x00
#define COE_COMMAND_UPLOADSEGREQ   0x60
#define COE_COMPLETEACCESS   0x10
#define COE_DEFAULTLENGTH   0x0a
#define COE_ENTRYDESCRIPTIONRESPONSE   0x06
#define COE_EXPEDITED_INDICATOR   0x02
#define COE_GETODLISTRESPONSE   0x02
#define COE_GETODRESPONSE   0x04
#define COE_HEADERSIZE   0x0a
#define COE_INFOERROR   0x07
#define COE_SDOINFORMATION   0x08
#define COE_SDOREQUEST   0x02
#define COE_SDORESPONSE   0x03
#define COE_SEGMENTHEADERSIZE   0x03
#define COE_SIZE_INDICATOR   0x01
#define COE_TOGGLEBIT   0x10
#define COE_VALUEINFO_ACCESS   0x01
#define COE_VALUEINFO_DEFAULT   0x10
#define COE_VALUEINFO_MAPPABLE   0x04
#define COE_VALUEINFO_MAXIMUM   0x40
#define COE_VALUEINFO_MINIMUM   0x20
#define COE_VALUEINFO_OBJECT   0x02
#define COE_VALUEINFO_TYPE   0x08
#define EC_LITTLE_ENDIAN
#define ESCboot   0x03
#define ESCerror   0x10
#define ESCinit   0x01
#define ESCop   0x08
#define ESCpreop   0x02
#define ESCREG_ADDRESS   0x0010
#define ESCREG_AL_ALLBUTINITMASK   0x0e
#define ESCREG_AL_ERRACKMASK   0x0f
#define ESCREG_AL_STATEMASK   0x001f
#define ESCREG_ALCONTROL   0x0120
#define ESCREG_ALERROR   0x0134
#define ESCREG_ALEVENT_CONTROL   0x0001
#define ESCREG_ALEVENT_SM2   0x0400
#define ESCREG_ALEVENT_SM3   0x0800
#define ESCREG_ALEVENT_SM_MASK   0x0310
#define ESCREG_ALEVENT_SMCHANGE   0x0010
#define ESCREG_ALSTATUS   0x0130
#define ESCREG_DLSTATUS   0x0110
#define ESCREG_LOCALTIME   0x0910
#define ESCREG_SM0   0x0800
#define ESCREG_SM0PDI   (ESCREG_SM0 + 7)
#define ESCREG_SM0STATUS   (ESCREG_SM0 + 5)
#define ESCREG_SM1   (ESCREG_SM0 + 0x08)
#define ESCREG_SM2   (ESCREG_SM0 + 0x10)
#define ESCREG_SM3   (ESCREG_SM0 + 0x18)
#define ESCREG_SMENABLE_BIT   0x01
#define ESCREG_WDSTATUS   0x0440
#define ESCsafeop   0x04
#define FLASHSTORE   const
#define FOE_DATA_SIZE   (MBXSIZEBOOT - (MBXHSIZE+FOEHSIZE))
#define FOE_ERR_ACCESS   0x8002
#define FOE_ERR_BOOTSTRAPONLY   0x8008
#define FOE_ERR_DISKFULL   0x8003
#define FOE_ERR_EXISTS   0x8006
#define FOE_ERR_ILLEGAL   0x8004
#define FOE_ERR_NORIGHTS   0x800A
#define FOE_ERR_NOTDEFINED   0x8000
#define FOE_ERR_NOTFOUND   0x8001
#define FOE_ERR_NOTINBOOTSTRAP   0x8009
#define FOE_ERR_NOUSER   0x8007
#define FOE_ERR_PACKETNO   0x8005
#define FOE_ERR_PROGERROR   0x800B
#define FOE_OP_ACK   4
#define FOE_OP_BUSY   6
#define FOE_OP_DATA   3
#define FOE_OP_ERR   5
#define FOE_OP_RRQ   1
#define FOE_OP_WRQ   2
#define FOE_READY   0
#define FOE_WAIT_FOR_ACK   1
#define FOE_WAIT_FOR_DATA   3
#define FOE_WAIT_FOR_FINAL_ACK   2
#define FOEHSIZE   (sizeof(_FOEh))
#define INIT_TO_BOOT   0x31
#define INIT_TO_INIT   0x11
#define INIT_TO_OP   0x81
#define INIT_TO_PREOP   0x21
#define INIT_TO_SAFEOP   0x41
#define MBX0_sma   0x1000
#define MBX0_sma_b   0x1000
#define MBX0_smc   0x26
#define MBX0_smc_b   0x26
#define MBX0_sme   MBX0_sma+MBX0_sml-1
#define MBX0_sme_b   MBX0_sma_b+MBX0_sml_b-1
#define MBX0_sml   MBXSIZE
#define MBX0_sml_b   MBXSIZEBOOT
#define MBX1_sma   0x1080
#define MBX1_sma_b   0x1080
#define MBX1_smc   0x22
#define MBX1_smc_b   0x22
#define MBX1_sme   MBX1_sma+MBX1_sml-1
#define MBX1_sme_b   MBX1_sma_b+MBX1_sml_b-1
#define MBX1_sml   MBXSIZE
#define MBX1_sml_b   MBXSIZEBOOT
#define MBXAOE   0x01
#define MBXBUFFERS   3
#define MBXCOE   0x03
#define MBXDSIZE   MBXSIZE-MBXHSIZE
#define MBXED   0x30
#define MBXEOE   0x02
#define MBXERR   0x00
#define MBXERR_INVALIDCHANNEL   0x0003
#define MBXERR_INVALIDHEADER   0x0005
#define MBXERR_INVALIDSIZE   0x0008
#define MBXERR_NOMOREMEMORY   0x0007
#define MBXERR_SERVICENOTSUPPORTED   0x0004
#define MBXERR_SIZETOOSHORT   0x0006
#define MBXERR_SYNTAX   0x0001
#define MBXERR_UNSUPPORTEDPROTOCOL   0x0002
#define MBXFOE   0x04
#define MBXHSIZE   sizeof(_MBXh)
#define MBXOD   0x20
#define MBXODL   0x10
#define MBXSED   0x50
#define MBXSEU   0x40
#define MBXSIZE   0x80
#define MBXSIZEBOOT   0x80
#define MBXstate_again   0x06
#define MBXstate_backup   0x05
#define MBXstate_idle   0x00
#define MBXstate_inclaim   0x01
#define MBXstate_outclaim   0x02
#define MBXstate_outpost   0x04
#define MBXstate_outreq   0x03
#define OP_TO_BOOT   0x38
#define OP_TO_INIT   0x18
#define OP_TO_OP   0x88
#define OP_TO_PREOP   0x28
#define OP_TO_SAFEOP   0x48
#define PACKED   __attribute__((__packed__))
#define PREOP_TO_BOOT   0x32
#define PREOP_TO_INIT   0x12
#define PREOP_TO_OP   0x82
#define PREOP_TO_PREOP   0x22
#define PREOP_TO_SAFEOP   0x42
#define SAFEOP_TO_BOOT   0x34
#define SAFEOP_TO_INIT   0x14
#define SAFEOP_TO_OP   0x84
#define SAFEOP_TO_PREOP   0x24
#define SAFEOP_TO_SAFEOP   0x44
#define SM2_act   0x01
#define SM2_sma   0x1100
#define SM2_smc   0x24
#define SM3_act   0x01
#define SM3_sma   0x1180
#define SM3_smc   0x20
#define SMRESULT_ERRSM0   0x01
#define SMRESULT_ERRSM1   0x02
#define SMRESULT_ERRSM2   0x04
#define SMRESULT_ERRSM3   0x08

Typedef Documentation

typedef FLASHSTORE struct PACKED _ESCsmCompact

Function Documentation

void APP_safeoutput ( )
void ESC_ALerror ( uint16  errornumber)

Write AL Status Code to the ESC.

Parameters:
[in]errornumber= Write an by EtherCAT specified Error number register 0x134 AL Status Code
void ESC_ALevent ( void  )
void ESC_ALstatus ( uint8  status)

Write AL Status to the ESC.

Parameters:
[in]status= Write current slave status to register 0x130 AL Status reflecting actual state and error indication if present
uint8 ESC_claimbuffer ( void  )

Allocate and prepare a mailbox buffer. Take the first Idle buffer from the End. Set Mailbox control state to be used for outbox and fill the mailbox buffer with address master and mailbox next CNT value between 1-7.

Returns:
The index of Mailbox buffer prepared for outbox. IF no buffer is available return 0.
void ESC_config ( esc_cfg_t cfg)

Function copying the application configuration variable to the stack local pointer variable.

Parameters:
[in]cfg= Pointer to by the Application static declared configuration variable holding application specific details. Ex. post- and pre state change hooks
void ESC_init ( void *  arg)
uint8 ESC_mbxprocess ( void  )

Mailbox routine for implementing the low-level part of the mailbox protocol used by Application Layers running on-top of mailboxes. It takes care of sending a mailbox, re-sending a mailbox, reading a mailbox and handles a mailbox full event.

Returns:
=0 if nothing to do. =1 if something to be handled by mailbox protocols.
uint8 ESC_read ( uint16  address,
void *  buf,
uint16  len,
void *  tALevent 
)
void ESC_SMstatus ( uint8  n)

Read SM Status register 0x805(+ offset to SyncManager n) and save the result in global variable ESCvar.SM[n].

Parameters:
[in]n= Read Sync Manager no. n
uint8 ESC_startinput ( uint8  state)

Function trying to enable start updating the process data inputs. It calls the check SM 2 & 3 routine, based on the result from there if enables or disables the Input SyncManager, in addition it updates the ALStatusCode case something didn't pass the check.

Parameters:
[in]state= Requested state.
Returns:
= state, incoming state request if every thing checks out OK. =state (PREOP | ERROR) if something isn't correct.
uint8 ESC_startmbx ( uint8  state)

Try to start mailboxes for current ALControl state request by enabling SyncManager 0 and 1. If all mailbox settings is correct we return incoming state request, otherwise we return state Init with Error flag set and update local ALerror with code 0x16 Invalid mailbox configuration.

Parameters:
[in]state= Current state request read from ALControl 0x0120
Returns:
if all Mailbox values is correct we return incoming state, otherwise we return state Init with Error flag set.
uint8 ESC_startoutput ( uint8  state)

Unconditional start of updating outputs by enabling Sync Manager 2. Set the App.state to APPSTATE_OUTPUT.

Parameters:
[in]state= Not used.
Returns:
= state unchanged.
void ESC_state ( void  )

The state handler acting on ALControl Bit(0) and SyncManager Activation BIT(4) events in the Al Event Request register 0x220.

void ESC_stopinput ( void  )

Unconditional stop of updating inputs by disabling Sync Manager 2 & 3. Set the App.state to APPSTATE_IDLE.

void ESC_stopmbx ( void  )

Stop mailboxes by disabling SyncManager 0 and 1. Clear local mailbox variables stored in ESCvar.

void ESC_stopoutput ( void  )

Unconditional stop of updating outputs by disabling Sync Manager 2. Set the App.state to APPSTATE_ONPUT. Call application hook APP_safeoutput letting the user to set safe state values on outputs.

uint8 ESC_WDstatus ( void  )

Read Watchdog Status register 0x440. Result Bit0 0= Expired, 1= Active or disabled.

Returns:
value of register Watchdog Status.
uint8 ESC_write ( uint16  address,
void *  buf,
uint16  len,
void *  tALevent 
)
void ESC_xoeprocess ( void  )

Handler for incorrect or unsupported mailbox data. Write error response in Mailbox.

void MBX_error ( uint16  error)

Allocate and prepare a mailbox buffer for sending an error message. Take the first Idle buffer from the end. Set Mailbox control state to be used for outbox and fill the mailbox buffer with error information.

Parameters:
[in]n= Error number to be sent in mailbox error message.

Variable Documentation

volatile _ESCvar ESCvar
_MBX MBX[MBXBUFFERS]
_MBXcontrol MBXcontrol[MBXBUFFERS]
uint8 MBXrun
uint16 SM2_sml
uint16 SM3_sml