2014-09-12 16:01:33 +02:00
|
|
|
/*
|
2017-10-25 13:39:20 +02:00
|
|
|
* Licensed under the GNU General Public License version 2 with exceptions. See
|
|
|
|
* LICENSE file in the project root for full license information
|
2014-09-12 16:01:33 +02:00
|
|
|
*/
|
2015-05-07 17:43:02 +02:00
|
|
|
|
|
|
|
/** \file
|
2014-09-12 16:01:33 +02:00
|
|
|
* \brief
|
|
|
|
* Headerfile for esc.h
|
|
|
|
*/
|
2015-05-07 17:43:02 +02:00
|
|
|
|
2014-09-12 16:01:33 +02:00
|
|
|
#ifndef __esc__
|
|
|
|
#define __esc__
|
|
|
|
|
2015-05-18 16:54:09 +02:00
|
|
|
#include <cc.h>
|
2019-01-20 15:35:23 +01:00
|
|
|
#include <esc_coe.h>
|
2019-04-02 13:08:49 +02:00
|
|
|
#include "options.h"
|
2015-05-18 16:54:09 +02:00
|
|
|
|
2017-10-25 14:38:38 +02:00
|
|
|
#define ESCREG_ADDRESS 0x0010
|
|
|
|
#define ESCREG_DLSTATUS 0x0110
|
|
|
|
#define ESCREG_ALCONTROL 0x0120
|
|
|
|
#define ESCREG_ALSTATUS 0x0130
|
|
|
|
#define ESCREG_ALERROR 0x0134
|
|
|
|
#define ESCREG_ALEVENTMASK 0x0204
|
|
|
|
#define ESCREG_ALEVENT 0x0220
|
|
|
|
#define ESCREG_ALEVENT_SM_MASK 0x0310
|
|
|
|
#define ESCREG_ALEVENT_SMCHANGE 0x0010
|
|
|
|
#define ESCREG_ALEVENT_CONTROL 0x0001
|
|
|
|
#define ESCREG_ALEVENT_DC_LATCH 0x0002
|
|
|
|
#define ESCREG_ALEVENT_DC_SYNC0 0x0004
|
|
|
|
#define ESCREG_ALEVENT_DC_SYNC1 0x0008
|
|
|
|
#define ESCREG_ALEVENT_EEP 0x0020
|
2019-01-30 10:27:07 +01:00
|
|
|
#define ESCREG_ALEVENT_WD 0x0040
|
2017-10-25 14:38:38 +02:00
|
|
|
#define ESCREG_ALEVENT_SM0 0x0100
|
|
|
|
#define ESCREG_ALEVENT_SM1 0x0200
|
|
|
|
#define ESCREG_ALEVENT_SM2 0x0400
|
|
|
|
#define ESCREG_ALEVENT_SM3 0x0800
|
|
|
|
#define ESCREG_WDSTATUS 0x0440
|
|
|
|
#define ESCREG_EECONTSTAT 0x0502
|
|
|
|
#define ESCREG_EEDATA 0x0508
|
|
|
|
#define ESCREG_SM0 0x0800
|
|
|
|
#define ESCREG_SM0STATUS (ESCREG_SM0 + 5)
|
2018-01-31 09:30:11 +01:00
|
|
|
#define ESCREG_SM0ACTIVATE (ESCREG_SM0 + 6)
|
2017-10-25 14:38:38 +02:00
|
|
|
#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
|
2018-01-31 09:30:11 +01:00
|
|
|
#define ESCREG_LOCALTIME_OFFSET 0x0920
|
2017-10-25 14:38:38 +02:00
|
|
|
#define ESCREG_SYNC_ACT 0x0981
|
|
|
|
#define ESCREG_SYNC_ACT_ACTIVATED 0x01
|
|
|
|
#define ESCREG_SYNC_SYNC0_EN 0x02
|
|
|
|
#define ESCREG_SYNC_SYNC1_EN 0x04
|
|
|
|
#define ESCREG_SYNC_AUTO_ACTIVATED 0x08
|
|
|
|
#define ESCREG_SYNC0_CYCLE_TIME 0x09A0
|
|
|
|
#define ESCREG_SYNC1_CYCLE_TIME 0x09A4
|
|
|
|
#define ESCREG_SMENABLE_BIT 0x01
|
|
|
|
#define ESCREG_AL_STATEMASK 0x001f
|
|
|
|
#define ESCREG_AL_ALLBUTINITMASK 0x0e
|
|
|
|
#define ESCREG_AL_ERRACKMASK 0x0f
|
|
|
|
|
|
|
|
#define SYNCTYPE_SUPPORT_FREERUN 0x01
|
|
|
|
#define SYNCTYPE_SUPPORT_SYNCHRON 0x02
|
|
|
|
#define SYNCTYPE_SUPPORT_DCSYNC0 0x04
|
|
|
|
#define SYNCTYPE_SUPPORT_DCSYNC1 0x08
|
|
|
|
#define SYNCTYPE_SUPPORT_SUBCYCLE 0x10
|
2014-09-12 16:01:33 +02:00
|
|
|
|
|
|
|
#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
|
2017-10-25 14:38:38 +02:00
|
|
|
#define ALERR_NOVALIDFIRMWARE 0x0014
|
2014-09-12 16:01:33 +02:00
|
|
|
#define ALERR_INVALIDBOOTMBXCONFIG 0x0015
|
|
|
|
#define ALERR_INVALIDMBXCONFIG 0x0016
|
|
|
|
#define ALERR_INVALIDSMCONFIG 0x0017
|
2017-10-25 14:38:38 +02:00
|
|
|
#define ALERR_SYNCERROR 0x001A
|
2014-09-12 16:01:33 +02:00
|
|
|
#define ALERR_WATCHDOG 0x001B
|
|
|
|
#define ALERR_INVALIDOUTPUTSM 0x001D
|
|
|
|
#define ALERR_INVALIDINPUTSM 0x001E
|
2017-10-25 14:38:38 +02:00
|
|
|
#define ALERR_DCINVALIDSYNCCFG 0x0030
|
|
|
|
#define ALERR_DCSYNC0CYCLETIME 0x0036
|
2014-09-12 16:01:33 +02:00
|
|
|
|
|
|
|
#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
|
2019-01-20 15:35:23 +01:00
|
|
|
#define ABORT_SUBINDEX0_NOT_ZERO 0x06010003
|
|
|
|
#define ABORT_EXCEEDS_MBOX_SIZE 0x06010005
|
2014-09-12 16:01:33 +02:00
|
|
|
#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
|
2016-01-27 22:14:36 +01:00
|
|
|
#define COE_MINIMUM_LENGTH 8
|
2014-09-12 16:01:33 +02:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2018-11-13 11:14:19 +01:00
|
|
|
#define EOE_RESULT_SUCCESS 0x0000
|
|
|
|
#define EOE_RESULT_UNSPECIFIED_ERROR 0x0001
|
|
|
|
#define EOE_RESULT_UNSUPPORTED_FRAME_TYPE 0x0002
|
|
|
|
#define EOE_RESULT_NO_IP_SUPPORT 0x0201
|
|
|
|
#define EOE_RESULT_NO_DHCP_SUPPORT 0x0202
|
|
|
|
#define EOE_RESULT_NO_FILTER_SUPPORT 0x0401
|
|
|
|
|
2017-10-25 20:28:13 +02:00
|
|
|
#define APPSTATE_IDLE 0x00
|
|
|
|
#define APPSTATE_INPUT 0x01
|
|
|
|
#define APPSTATE_OUTPUT 0x02
|
|
|
|
|
|
|
|
typedef struct sm_cfg
|
|
|
|
{
|
|
|
|
uint16_t cfg_sma;
|
|
|
|
uint16_t cfg_sml;
|
|
|
|
uint16_t cfg_sme;
|
|
|
|
uint8_t cfg_smc;
|
|
|
|
uint8_t cfg_smact;
|
|
|
|
}sm_cfg_t;
|
|
|
|
|
|
|
|
typedef struct esc_cfg
|
|
|
|
{
|
|
|
|
void * user_arg;
|
|
|
|
int use_interrupt;
|
|
|
|
int watchdog_cnt;
|
2019-04-02 14:16:26 +02:00
|
|
|
void (*set_defaults_hook) (void);
|
2017-10-25 20:28:13 +02:00
|
|
|
void (*pre_state_change_hook) (uint8_t * as, uint8_t * an);
|
|
|
|
void (*post_state_change_hook) (uint8_t * as, uint8_t * an);
|
|
|
|
void (*application_hook) (void);
|
|
|
|
void (*safeoutput_override) (void);
|
2019-04-02 21:26:46 +02:00
|
|
|
uint32_t (*pre_object_download_hook) (uint16_t index,
|
2019-01-30 11:07:46 +01:00
|
|
|
uint8_t subindex,
|
|
|
|
void * data,
|
|
|
|
size_t size,
|
|
|
|
uint16_t flags);
|
|
|
|
void (*post_object_download_hook) (uint16_t index,
|
|
|
|
uint8_t subindex,
|
|
|
|
uint16_t flags);
|
2017-10-25 20:28:13 +02:00
|
|
|
void (*rxpdo_override) (void);
|
|
|
|
void (*txpdo_override) (void);
|
|
|
|
void (*esc_hw_interrupt_enable) (uint32_t mask);
|
|
|
|
void (*esc_hw_interrupt_disable) (uint32_t mask);
|
|
|
|
void (*esc_hw_eep_handler) (void);
|
2019-01-30 10:31:02 +01:00
|
|
|
uint16_t (*esc_check_dc_handler) (void);
|
2017-10-25 20:28:13 +02:00
|
|
|
} esc_cfg_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t state;
|
|
|
|
} _App;
|
|
|
|
|
2014-09-12 16:01:33 +02:00
|
|
|
// Attention! this struct is always little-endian
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t PSA;
|
|
|
|
uint16_t Length;
|
2014-09-12 16:01:33 +02:00
|
|
|
|
|
|
|
#if defined(EC_LITTLE_ENDIAN)
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t Mode:2;
|
|
|
|
uint8_t Direction:2;
|
|
|
|
uint8_t IntECAT:1;
|
|
|
|
uint8_t IntPDI:1;
|
|
|
|
uint8_t WTE:1;
|
|
|
|
uint8_t R1:1;
|
|
|
|
|
|
|
|
uint8_t IntW:1;
|
|
|
|
uint8_t IntR:1;
|
|
|
|
uint8_t R2:1;
|
|
|
|
uint8_t MBXstat:1;
|
|
|
|
uint8_t BUFstat:2;
|
|
|
|
uint8_t R3:2;
|
|
|
|
|
|
|
|
uint8_t ECsm:1;
|
|
|
|
uint8_t ECrep:1;
|
|
|
|
uint8_t ECr4:4;
|
|
|
|
uint8_t EClatchEC:1;
|
|
|
|
uint8_t EClatchPDI:1;
|
|
|
|
|
|
|
|
uint8_t PDIsm:1;
|
|
|
|
uint8_t PDIrep:1;
|
|
|
|
uint8_t PDIr5:6;
|
2014-09-12 16:01:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(EC_BIG_ENDIAN)
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t R1:1;
|
|
|
|
uint8_t WTE:1;
|
|
|
|
uint8_t IntPDI:1;
|
|
|
|
uint8_t IntECAT:1;
|
|
|
|
uint8_t Direction:2;
|
|
|
|
uint8_t Mode:2;
|
|
|
|
|
|
|
|
uint8_t R3:2;
|
|
|
|
uint8_t BUFstat:2;
|
|
|
|
uint8_t MBXstat:1;
|
|
|
|
uint8_t R2:1;
|
|
|
|
uint8_t IntR:1;
|
|
|
|
uint8_t IntW:1;
|
|
|
|
|
|
|
|
uint8_t EClatchPDI:1;
|
|
|
|
uint8_t EClatchEC:1;
|
|
|
|
uint8_t ECr4:4;
|
|
|
|
uint8_t ECrep:1;
|
|
|
|
uint8_t ECsm:1;
|
|
|
|
|
|
|
|
uint8_t PDIr5:6;
|
|
|
|
uint8_t PDIrep:1;
|
|
|
|
uint8_t PDIsm:1;
|
2014-09-12 16:01:33 +02:00
|
|
|
#endif
|
|
|
|
} _ESCsm;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
|
|
|
/* Attention! this struct is always little-endian */
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t PSA;
|
|
|
|
uint16_t Length;
|
|
|
|
uint8_t Command;
|
|
|
|
uint8_t Status;
|
|
|
|
uint8_t ActESC;
|
|
|
|
uint8_t ActPDI;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _ESCsm2;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t PSA;
|
|
|
|
uint16_t Length;
|
|
|
|
uint8_t Command;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _ESCsmCompact;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2019-01-31 18:44:28 +01:00
|
|
|
typedef struct
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
2017-10-25 20:28:13 +02:00
|
|
|
/* Configuration input is saved so the user variable may go out-of-scope */
|
|
|
|
int use_interrupt;
|
|
|
|
sm_cfg_t mb[2];
|
|
|
|
sm_cfg_t mbboot[2];
|
2019-04-02 14:16:26 +02:00
|
|
|
void (*set_defaults_hook) (void);
|
2017-10-25 20:28:13 +02:00
|
|
|
void (*pre_state_change_hook) (uint8_t * as, uint8_t * an);
|
|
|
|
void (*post_state_change_hook) (uint8_t * as, uint8_t * an);
|
|
|
|
void (*application_hook) (void);
|
|
|
|
void (*safeoutput_override) (void);
|
2019-04-02 21:26:46 +02:00
|
|
|
uint32_t (*pre_object_download_hook) (uint16_t index,
|
2019-01-30 11:07:46 +01:00
|
|
|
uint8_t subindex,
|
|
|
|
void * data,
|
|
|
|
size_t size,
|
|
|
|
uint16_t flags);
|
|
|
|
void (*post_object_download_hook) (uint16_t index,
|
|
|
|
uint8_t subindex,
|
|
|
|
uint16_t flags);
|
2017-10-25 20:28:13 +02:00
|
|
|
void (*rxpdo_override) (void);
|
|
|
|
void (*txpdo_override) (void);
|
|
|
|
void (*esc_hw_interrupt_enable) (uint32_t mask);
|
|
|
|
void (*esc_hw_interrupt_disable) (uint32_t mask);
|
|
|
|
void (*esc_hw_eep_handler) (void);
|
2019-01-30 10:31:02 +01:00
|
|
|
uint16_t (*esc_check_dc_handler) (void);
|
2017-10-25 20:28:13 +02:00
|
|
|
uint8_t MBXrun;
|
|
|
|
size_t activembxsize;
|
|
|
|
sm_cfg_t * activemb0;
|
|
|
|
sm_cfg_t * activemb1;
|
|
|
|
uint16_t ESC_SM2_sml;
|
|
|
|
uint16_t ESC_SM3_sml;
|
|
|
|
uint8_t dcsync;
|
|
|
|
uint16_t synccounterlimit;
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t ALstatus;
|
|
|
|
uint16_t ALcontrol;
|
|
|
|
uint16_t ALerror;
|
|
|
|
uint16_t DLstatus;
|
|
|
|
uint16_t address;
|
|
|
|
uint8_t mbxcnt;
|
|
|
|
uint8_t mbxincnt;
|
|
|
|
uint8_t mbxoutpost;
|
|
|
|
uint8_t mbxbackup;
|
|
|
|
uint8_t xoe;
|
|
|
|
uint8_t txcue;
|
|
|
|
uint8_t mbxfree;
|
|
|
|
uint8_t segmented;
|
2014-09-12 16:01:33 +02:00
|
|
|
void *data;
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t entries;
|
|
|
|
uint16_t frags;
|
|
|
|
uint16_t fragsleft;
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2019-01-31 18:44:28 +01:00
|
|
|
uint8_t toggle;
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2019-01-20 15:35:23 +01:00
|
|
|
int sm2mappings;
|
|
|
|
int sm3mappings;
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t SMtestresult;
|
|
|
|
uint32_t PrevTime;
|
2014-09-12 16:01:33 +02:00
|
|
|
_ESCsm SM[4];
|
2017-10-25 20:28:13 +02:00
|
|
|
/* Volatile since it may be read from ISR */
|
|
|
|
volatile int watchdogcnt;
|
|
|
|
volatile uint32_t Time;
|
|
|
|
volatile uint16_t ALevent;
|
|
|
|
volatile int8_t synccounter;
|
|
|
|
volatile _App App;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _ESCvar;
|
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t length;
|
|
|
|
uint16_t address;
|
2014-09-12 16:01:33 +02:00
|
|
|
|
|
|
|
#if defined(EC_LITTLE_ENDIAN)
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t channel:6;
|
|
|
|
uint8_t priority:2;
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t mbxtype:4;
|
|
|
|
uint8_t mbxcnt:4;
|
2014-09-12 16:01:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(EC_BIG_ENDIAN)
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t priority:2;
|
|
|
|
uint8_t channel:6;
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t mbxcnt:4;
|
|
|
|
uint8_t mbxtype:4;
|
2014-09-12 16:01:33 +02:00
|
|
|
#endif
|
|
|
|
} _MBXh;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
|
|
|
_MBXh header;
|
2017-10-25 14:31:30 +02:00
|
|
|
uint8_t b[0];
|
2014-09-12 16:01:33 +02:00
|
|
|
} _MBX;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t numberservice;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _COEh;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
|
|
|
#if defined(EC_LITTLE_ENDIAN)
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t opcode:7;
|
|
|
|
uint8_t incomplete:1;
|
2014-09-12 16:01:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(EC_BIG_ENDIAN)
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t incomplete:1;
|
|
|
|
uint8_t opcode:7;
|
2014-09-12 16:01:33 +02:00
|
|
|
#endif
|
|
|
|
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t reserved;
|
|
|
|
uint16_t fragmentsleft;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _INFOh;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
|
|
|
_MBXh mbxheader;
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t type;
|
|
|
|
uint16_t detail;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _MBXerr;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
|
|
|
_MBXh mbxheader;
|
|
|
|
_COEh coeheader;
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t command;
|
|
|
|
uint16_t index;
|
|
|
|
uint8_t subindex;
|
|
|
|
uint32_t size;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _COEsdo;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
|
|
|
_MBXh mbxheader;
|
|
|
|
_COEh coeheader;
|
|
|
|
_INFOh infoheader;
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t index;
|
|
|
|
uint16_t datatype;
|
|
|
|
uint8_t maxsub;
|
|
|
|
uint8_t objectcode;
|
2014-09-12 16:01:33 +02:00
|
|
|
char name;
|
|
|
|
} _COEobjdesc;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
|
|
|
_MBXh mbxheader;
|
|
|
|
_COEh coeheader;
|
|
|
|
_INFOh infoheader;
|
2015-05-21 10:41:13 +02:00
|
|
|
uint16_t index;
|
|
|
|
uint8_t subindex;
|
|
|
|
uint8_t valueinfo;
|
|
|
|
uint16_t datatype;
|
|
|
|
uint16_t bitlength;
|
|
|
|
uint16_t access;
|
2014-09-12 16:01:33 +02:00
|
|
|
char name;
|
|
|
|
} _COEentdesc;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t opcode;
|
|
|
|
uint8_t reserved;
|
2014-09-12 16:01:33 +02:00
|
|
|
union
|
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint32_t password;
|
|
|
|
uint32_t packetnumber;
|
|
|
|
uint32_t errorcode;
|
2014-09-12 16:01:33 +02:00
|
|
|
};
|
|
|
|
} _FOEh;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2014-09-12 16:01:33 +02:00
|
|
|
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_BEGIN
|
2015-05-18 16:54:09 +02:00
|
|
|
typedef struct CC_PACKED
|
2014-09-12 16:01:33 +02:00
|
|
|
{
|
|
|
|
_MBXh mbxheader;
|
|
|
|
_FOEh foeheader;
|
|
|
|
union
|
|
|
|
{
|
2017-10-25 14:31:30 +02:00
|
|
|
char filename[0];
|
|
|
|
uint8_t data[0];
|
|
|
|
char errortext[0];
|
2014-09-12 16:01:33 +02:00
|
|
|
};
|
|
|
|
} _FOE;
|
2017-10-25 14:41:07 +02:00
|
|
|
CC_PACKED_END
|
2018-11-13 11:14:19 +01:00
|
|
|
|
|
|
|
CC_PACKED_BEGIN
|
|
|
|
typedef struct CC_PACKED
|
|
|
|
{
|
|
|
|
uint16_t frameinfo1;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
uint16_t frameinfo2;
|
|
|
|
uint16_t result;
|
|
|
|
};
|
|
|
|
} _EOEh;
|
|
|
|
CC_PACKED_END
|
|
|
|
|
|
|
|
CC_PACKED_BEGIN
|
|
|
|
typedef struct CC_PACKED
|
|
|
|
{
|
|
|
|
_MBXh mbxheader;
|
|
|
|
_EOEh eoeheader;
|
|
|
|
uint8_t data[0];
|
|
|
|
} _EOE;
|
|
|
|
CC_PACKED_END
|
|
|
|
|
2014-09-12 16:01:33 +02:00
|
|
|
/* state definition in mailbox
|
|
|
|
* 0 : idle
|
|
|
|
* 1 : claimed for inbox
|
|
|
|
* 2 : claimed for outbox
|
|
|
|
* 3 : request post outbox
|
|
|
|
* 4 : outbox posted not send
|
|
|
|
* 5 : backup outbox
|
|
|
|
* 6 : mailbox needs to be transmitted again
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t state;
|
2014-09-12 16:01:33 +02:00
|
|
|
} _MBXcontrol;
|
|
|
|
|
2017-10-25 14:31:30 +02:00
|
|
|
/* Stack reference to application configuration of the ESC */
|
2017-10-25 20:28:13 +02:00
|
|
|
#define ESC_MBXSIZE (ESCvar.activembxsize)
|
|
|
|
#define ESC_MBX0_sma (ESCvar.activemb0->cfg_sma)
|
|
|
|
#define ESC_MBX0_sml (ESCvar.activemb0->cfg_sml)
|
|
|
|
#define ESC_MBX0_sme (ESCvar.activemb0->cfg_sme)
|
|
|
|
#define ESC_MBX0_smc (ESCvar.activemb0->cfg_smc)
|
|
|
|
#define ESC_MBX1_sma (ESCvar.activemb1->cfg_sma)
|
|
|
|
#define ESC_MBX1_sml (ESCvar.activemb1->cfg_sml)
|
|
|
|
#define ESC_MBX1_sme (ESCvar.activemb1->cfg_sme)
|
|
|
|
#define ESC_MBX1_smc (ESCvar.activemb1->cfg_smc)
|
2019-04-02 13:08:49 +02:00
|
|
|
#define ESC_MBXBUFFERS (MBXBUFFERS)
|
|
|
|
#define ESC_SM2_sma (SM2_sma)
|
|
|
|
#define ESC_SM2_smc (SM2_smc)
|
|
|
|
#define ESC_SM2_act (SM2_act)
|
|
|
|
#define ESC_SM3_sma (SM3_sma)
|
|
|
|
#define ESC_SM3_smc (SM3_smc)
|
|
|
|
#define ESC_SM3_act (SM3_act)
|
2017-10-25 14:31:30 +02:00
|
|
|
|
|
|
|
#define ESC_MBXHSIZE sizeof(_MBXh)
|
|
|
|
#define ESC_MBXDSIZE (ESC_MBXSIZE - ESC_MBXHSIZE)
|
|
|
|
#define ESC_FOEHSIZE sizeof(_FOEh)
|
|
|
|
#define ESC_FOE_DATA_SIZE (ESC_MBXSIZE - (ESC_MBXHSIZE +ESC_FOEHSIZE))
|
2018-11-13 11:14:19 +01:00
|
|
|
#define ESC_EOEHSIZE sizeof(_EOEh)
|
|
|
|
#define ESC_EOE_DATA_SIZE (ESC_MBXSIZE - (ESC_MBXHSIZE +ESC_EOEHSIZE))
|
2017-10-25 14:31:30 +02:00
|
|
|
|
2014-09-12 16:01:33 +02:00
|
|
|
void ESC_config (esc_cfg_t * cfg);
|
2015-05-21 10:41:13 +02:00
|
|
|
void ESC_ALerror (uint16_t errornumber);
|
2017-10-25 14:38:38 +02:00
|
|
|
void ESC_ALeventwrite (uint32_t event);
|
|
|
|
uint32_t ESC_ALeventread (void);
|
|
|
|
void ESC_ALeventmaskwrite (uint32_t mask);
|
|
|
|
uint32_t ESC_ALeventmaskread (void);
|
2015-05-21 10:41:13 +02:00
|
|
|
void ESC_ALstatus (uint8_t status);
|
2019-01-30 10:27:07 +01:00
|
|
|
void ESC_ALstatusgotoerror (uint8_t status, uint16_t errornumber);
|
2015-05-21 10:41:13 +02:00
|
|
|
void ESC_SMstatus (uint8_t n);
|
|
|
|
uint8_t ESC_WDstatus (void);
|
|
|
|
uint8_t ESC_claimbuffer (void);
|
|
|
|
uint8_t ESC_startmbx (uint8_t state);
|
2014-09-12 16:01:33 +02:00
|
|
|
void ESC_stopmbx (void);
|
2015-05-21 10:41:13 +02:00
|
|
|
void MBX_error (uint16_t error);
|
|
|
|
uint8_t ESC_mbxprocess (void);
|
2014-09-12 16:01:33 +02:00
|
|
|
void ESC_xoeprocess (void);
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t ESC_startinput (uint8_t state);
|
2014-09-12 16:01:33 +02:00
|
|
|
void ESC_stopinput (void);
|
2015-05-21 10:41:13 +02:00
|
|
|
uint8_t ESC_startoutput (uint8_t state);
|
2014-09-12 16:01:33 +02:00
|
|
|
void ESC_stopoutput (void);
|
|
|
|
void ESC_state (void);
|
2017-10-25 14:38:38 +02:00
|
|
|
void ESC_sm_act_event (void);
|
2014-09-12 16:01:33 +02:00
|
|
|
|
|
|
|
/* From hardware file */
|
2016-08-26 16:53:32 +02:00
|
|
|
void ESC_read (uint16_t address, void *buf, uint16_t len);
|
|
|
|
void ESC_write (uint16_t address, void *buf, uint16_t len);
|
2017-10-25 14:31:30 +02:00
|
|
|
void ESC_init (const esc_cfg_t * cfg);
|
2015-05-20 13:15:49 +02:00
|
|
|
void ESC_reset (void);
|
|
|
|
|
2014-09-12 16:01:33 +02:00
|
|
|
/* From application */
|
|
|
|
extern void APP_safeoutput ();
|
2017-10-25 20:28:13 +02:00
|
|
|
extern _ESCvar ESCvar;
|
2017-10-25 14:31:30 +02:00
|
|
|
extern _MBXcontrol MBXcontrol[];
|
2017-10-25 20:28:13 +02:00
|
|
|
extern uint8_t MBX[];
|
2019-01-20 15:35:23 +01:00
|
|
|
extern _SMmap SMmap2[];
|
|
|
|
extern _SMmap SMmap3[];
|
2017-10-25 14:38:38 +02:00
|
|
|
|
|
|
|
/* ATOMIC operations are used when running interrupt driven */
|
|
|
|
#ifndef CC_ATOMIC_SET
|
|
|
|
#define CC_ATOMIC_SET(var,val) (var = val)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CC_ATOMIC_GET
|
|
|
|
#define CC_ATOMIC_GET(var) (var)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CC_ATOMIC_ADD
|
|
|
|
#define CC_ATOMIC_ADD(var,val) (var += val)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CC_ATOMIC_SUB
|
|
|
|
#define CC_ATOMIC_SUB(var,val) (var -= val)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CC_ATOMIC_AND
|
|
|
|
#define CC_ATOMIC_AND(var,val) (var &= val)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CC_ATOMIC_OR
|
|
|
|
#define CC_ATOMIC_OR(var,val) (var |= val)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-09-12 16:01:33 +02:00
|
|
|
#endif
|