ec_def.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*
  2. * Copyright (c) 2025, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef EC_DEF_H
  7. #define EC_DEF_H
  8. /*
  9. * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble
  10. * and FCS/CRC (frame check sequence).
  11. */
  12. #define ETH_ALEN 6 /* Octets in one ethernet addr */
  13. #define ETH_TLEN 2 /* Octets in ethernet type field */
  14. #define ETH_HLEN 14 /* Total octets in header. */
  15. #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
  16. #define ETH_DATA_LEN 1500 /* Max. octets in payload */
  17. #define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */
  18. #define ETH_FCS_LEN 4 /* Octets in the FCS */
  19. #define ETH_MIN_MTU 68 /* Min IPv4 MTU per RFC791 */
  20. #define ETH_MAX_MTU 0xFFFFU /* 65535, same as IP_MAX_MTU */
  21. /** Datagram timeout in microseconds. */
  22. #define EC_IO_TIMEOUT 500
  23. /** Time to send a byte in nanoseconds.
  24. *
  25. * t_ns = 1 / (100 MBit/s / 8 bit/byte) = 80 ns/byte
  26. */
  27. #define EC_BYTE_TRANSMISSION_TIME_NS 80
  28. /** Minimum size of a buffer used with ec_state_string(). */
  29. #define EC_STATE_STRING_SIZE 32
  30. /** Maximum SII size in words, to avoid infinite reading. */
  31. #define EC_MAX_SII_SIZE 4096
  32. /** Number of statistic rate intervals to maintain. */
  33. #define EC_RATE_COUNT 3
  34. /*****************************************************************************
  35. * EtherCAT protocol
  36. ****************************************************************************/
  37. /** Size of an EtherCAT frame header. */
  38. #define EC_FRAME_HEADER_SIZE 2
  39. /** Size of an EtherCAT datagram header. */
  40. #define EC_DATAGRAM_HEADER_SIZE 10
  41. /** Size of an EtherCAT datagram workcounter. */
  42. #define EC_DATAGRAM_WC_SIZE 2
  43. /** Size of the EtherCAT address field. */
  44. #define EC_ADDR_LEN 4
  45. /** Resulting maximum data size of a single datagram in a frame. */
  46. #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_WC_SIZE)
  47. /** Mailbox header size. */
  48. #define EC_MBOX_HEADER_SIZE 6
  49. /** Word offset of first SII category. */
  50. #define EC_FIRST_SII_CATEGORY_OFFSET 0x40
  51. /** Size of a sync manager configuration page. */
  52. #define EC_SYNC_PAGE_SIZE 8
  53. /** Maximum number of FMMUs per slave. */
  54. #define EC_MAX_FMMUS 16
  55. /** Size of an FMMU configuration page. */
  56. #define EC_FMMU_PAGE_SIZE 16
  57. /** Number of DC sync signals. */
  58. #define EC_SYNC_SIGNAL_COUNT 2
  59. /** Size of the datagram decription string.
  60. *
  61. * This is also used as the maximum lenth of EoE device names.
  62. **/
  63. #define EC_DATAGRAM_NAME_SIZE 20
  64. /** Maximum hostname size.
  65. *
  66. * Used inside the EoE set IP parameter request.
  67. */
  68. #define EC_MAX_HOSTNAME_SIZE 32
  69. /** Maximum number of sync managers per slave.
  70. */
  71. #define EC_MAX_SYNC_MANAGERS 16
  72. /** Maximum string length.
  73. *
  74. * Used in ec_slave_info_t.
  75. */
  76. #define EC_MAX_STRING_LENGTH 64
  77. /** Maximum number of slave ports. */
  78. #define EC_MAX_PORTS 4
  79. /** Slave state mask.
  80. *
  81. * Apply this mask to a slave state byte to get the slave state without
  82. * the error flag.
  83. */
  84. #define EC_SLAVE_STATE_MASK 0x0F
  85. /** State of an EtherCAT slave.
  86. */
  87. typedef enum {
  88. EC_SLAVE_STATE_UNKNOWN = 0x00,
  89. /**< unknown state */
  90. EC_SLAVE_STATE_INIT = 0x01,
  91. /**< INIT state (no mailbox communication, no IO) */
  92. EC_SLAVE_STATE_PREOP = 0x02,
  93. /**< PREOP state (mailbox communication, no IO) */
  94. EC_SLAVE_STATE_BOOT = 0x03,
  95. /**< Bootstrap state (mailbox communication, firmware update) */
  96. EC_SLAVE_STATE_SAFEOP = 0x04,
  97. /**< SAFEOP (mailbox communication and input update) */
  98. EC_SLAVE_STATE_OP = 0x08,
  99. /**< OP (mailbox communication and input/output update) */
  100. EC_SLAVE_STATE_ACK_ERR = 0x10
  101. /**< Acknowledge/Error bit (no actual state) */
  102. } ec_slave_state_t;
  103. typedef enum {
  104. EC_PORT_NOT_IMPLEMENTED, /**< Port is not implemented. */
  105. EC_PORT_NOT_CONFIGURED, /**< Port is not configured. */
  106. EC_PORT_EBUS, /**< Port is an E-Bus. */
  107. EC_PORT_MII /**< Port is a MII. */
  108. } ec_slave_port_desc_t;
  109. /** Slave information interface CANopen over EtherCAT details flags.
  110. */
  111. typedef struct {
  112. uint8_t enable_sdo : 1; /**< Enable SDO access. */
  113. uint8_t enable_sdo_info : 1; /**< SDO information service available. */
  114. uint8_t enable_pdo_assign : 1; /**< PDO mapping configurable. */
  115. uint8_t enable_pdo_configuration : 1; /**< PDO configuration possible. */
  116. uint8_t enable_upload_at_startup : 1; /**< ?. */
  117. uint8_t enable_sdo_complete_access : 1; /**< Complete access possible. */
  118. uint8_t : 2; /**< Reserved bits. */
  119. } ec_sii_coe_details_t;
  120. /** Slave information interface general flags.
  121. */
  122. typedef struct {
  123. uint8_t enable_safeop : 1; /**< ?. */
  124. uint8_t enable_not_lrw : 1; /**< Slave does not support LRW. */
  125. uint8_t : 6; /**< Reserved bits. */
  126. } ec_sii_general_flags_t;
  127. /** EtherCAT slave distributed clocks range.
  128. */
  129. typedef enum {
  130. EC_DC_32, /**< 32 bit. */
  131. EC_DC_64 /*< 64 bit for system time, system time offset and
  132. port 0 receive time. */
  133. } ec_slave_dc_range_t;
  134. /** EtherCAT slave sync signal configuration.
  135. */
  136. typedef struct {
  137. uint32_t cycle_time; /**< Cycle time [ns]. */
  138. int32_t shift_time; /**< Shift time [ns]. */
  139. } ec_sync_signal_t;
  140. /** Master netdev.
  141. */
  142. typedef enum {
  143. EC_NETDEV_MAIN, /**< Main netdev. */
  144. EC_NETDEV_BACKUP /**< Backup netdev */
  145. } ec_netdev_index_t;
  146. typedef struct ec_alstatus {
  147. uint16_t alstatus;
  148. uint16_t unused;
  149. uint16_t alstatuscode;
  150. } ec_alstatus_t;
  151. /* AL Status Codes */
  152. #define EC_ALSTATUSCODE_NOERROR 0x0000 /**< No error*/
  153. #define EC_ALSTATUSCODE_UNSPECIFIEDERROR 0x0001 /**< Unspecified error*/
  154. #define EC_ALSTATUSCODE_NOMEMORY 0x0002 /**< No Memory*/
  155. #define EC_ALSTATUSCODE_INVALID_REVISION 0x0004 /**< Output/Input mapping is not valid for this hardware or software revision (0x1018:03)*/
  156. #define EC_ALSTATUSCODE_FW_SII_NOT_MATCH 0x0006 /**< Firmware and EEPROM do not match. Slave needs BOOT-INIT transition*/
  157. #define EC_ALSTATUSCODE_FW_UPDATE_FAILED 0x0007 /**< Firmware update not successful. Old firmware still running*/
  158. #define EC_ALSTATUSCODE_INVALIDALCONTROL 0x0011 /**< Invalid requested state change*/
  159. #define EC_ALSTATUSCODE_UNKNOWNALCONTROL 0x0012 /**< Unknown requested state*/
  160. #define EC_ALSTATUSCODE_BOOTNOTSUPP 0x0013 /**< Bootstrap not supported*/
  161. #define EC_ALSTATUSCODE_NOVALIDFIRMWARE 0x0014 /**< No valid firmware*/
  162. #define EC_ALSTATUSCODE_INVALIDMBXCFGINBOOT 0x0015 /**< Invalid mailbox configuration (BOOT state)*/
  163. #define EC_ALSTATUSCODE_INVALIDMBXCFGINPREOP 0x0016 /**< Invalid mailbox configuration (PreOP state)*/
  164. #define EC_ALSTATUSCODE_INVALIDSMCFG 0x0017 /**< Invalid sync manager configuration*/
  165. #define EC_ALSTATUSCODE_NOVALIDINPUTS 0x0018 /**< No valid inputs available*/
  166. #define EC_ALSTATUSCODE_NOVALIDOUTPUTS 0x0019 /**< No valid outputs*/
  167. #define EC_ALSTATUSCODE_SYNCERROR 0x001A /**< Synchronization error*/
  168. #define EC_ALSTATUSCODE_SMWATCHDOG 0x001B /**< Sync manager watchdog*/
  169. #define EC_ALSTATUSCODE_SYNCTYPESNOTCOMPATIBLE 0x001C /**< Invalid Sync Manager Types*/
  170. #define EC_ALSTATUSCODE_INVALIDSMOUTCFG 0x001D /**< Invalid Output Configuration*/
  171. #define EC_ALSTATUSCODE_INVALIDSMINCFG 0x001E /**< Invalid Input Configuration*/
  172. #define EC_ALSTATUSCODE_INVALIDWDCFG 0x001F /**< Invalid Watchdog Configuration*/
  173. #define EC_ALSTATUSCODE_WAITFORCOLDSTART 0x0020 /**< Slave needs cold start*/
  174. #define EC_ALSTATUSCODE_WAITFORINIT 0x0021 /**< Slave needs INIT*/
  175. #define EC_ALSTATUSCODE_WAITFORPREOP 0x0022 /**< Slave needs PREOP*/
  176. #define EC_ALSTATUSCODE_WAITFORSAFEOP 0x0023 /**< Slave needs SAFEOP*/
  177. #define EC_ALSTATUSCODE_INVALIDINPUTMAPPING 0x0024 /**< Invalid Input Mapping*/
  178. #define EC_ALSTATUSCODE_INVALIDOUTPUTMAPPING 0x0025 /**< Invalid Output Mapping*/
  179. #define EC_ALSTATUSCODE_INCONSISTENTSETTINGS 0x0026 /**< Inconsistent Settings*/
  180. #define EC_ALSTATUSCODE_FREERUNNOTSUPPORTED 0x0027 /**< FreeRun not supported*/
  181. #define EC_ALSTATUSCODE_SYNCHRONNOTSUPPORTED 0x0028 /**< SyncMode not supported*/
  182. #define EC_ALSTATUSCODE_FREERUNNEEDS3BUFFERMODE 0x0029 /**< FreeRun needs 3Buffer Mode*/
  183. #define EC_ALSTATUSCODE_BACKGROUNDWATCHDOG 0x002A /**< Background Watchdog*/
  184. #define EC_ALSTATUSCODE_NOVALIDINPUTSANDOUTPUTS 0x002B /**< No Valid Inputs and Outputs*/
  185. #define EC_ALSTATUSCODE_FATALSYNCERROR 0x002C /**< Fatal Sync Error*/
  186. #define EC_ALSTATUSCODE_NOSYNCERROR 0x002D /**< No Sync Error*/
  187. #define EC_ALSTATUSCODE_CYCLETIMETOOSMALL 0x002E /**< EtherCAT cycle time smaller Minimum Cycle Time supported by slave*/
  188. #define EC_ALSTATUSCODE_DCINVALIDSYNCCFG 0x0030 /**< Invalid DC SYNCH Configuration*/
  189. #define EC_ALSTATUSCODE_DCINVALIDLATCHCFG 0x0031 /**< Invalid DC Latch Configuration*/
  190. #define EC_ALSTATUSCODE_DCPLLSYNCERROR 0x0032 /**< PLL Error*/
  191. #define EC_ALSTATUSCODE_DCSYNCIOERROR 0x0033 /**< DC Sync IO Error*/
  192. #define EC_ALSTATUSCODE_DCSYNCMISSEDERROR 0x0034 /**< DC Sync Timeout Error*/
  193. #define EC_ALSTATUSCODE_DCINVALIDSYNCCYCLETIME 0x0035 /**< DC Invalid Sync Cycle Time*/
  194. #define EC_ALSTATUSCODE_DCSYNC0CYCLETIME 0x0036 /**< DC Sync0 Cycle Time*/
  195. #define EC_ALSTATUSCODE_DCSYNC1CYCLETIME 0x0037 /**< DC Sync1 Cycle Time*/
  196. #define EC_ALSTATUSCODE_MBX_AOE 0x0041 /**< MBX_AOE*/
  197. #define EC_ALSTATUSCODE_MBX_EOE 0x0042 /**< MBX_EOE*/
  198. #define EC_ALSTATUSCODE_MBX_COE 0x0043 /**< MBX_COE*/
  199. #define EC_ALSTATUSCODE_MBX_FOE 0x0044 /**< MBX_FOE*/
  200. #define EC_ALSTATUSCODE_MBX_SOE 0x0045 /**< MBX_SOE*/
  201. #define EC_ALSTATUSCODE_MBX_VOE 0x004F /**< MBX_VOE*/
  202. #define EC_ALSTATUSCODE_EE_NOACCESS 0x0050 /**< EEPROM no access*/
  203. #define EC_ALSTATUSCODE_EE_ERROR 0x0051 /**< EEPROM Error*/
  204. #define EC_ALSTATUSCODE_EXT_HARDWARE_NOT_READY 0x0052 /**< External hardware not ready. This AL Status Code should be used if the EtherCAT-Slave refused the state transition due to an external connection to another device or signal is missing*/
  205. #define EC_ALSTATUSCODE_DEVICE_IDENT_VALUE_UPDATED 0x0061 /**< In legacy identification mode (dip switch mapped to register 0x12) this error is returned if the EEPROM ID value does not match to dipswitch value*/
  206. #define EC_ALSTATUSCODE_MODULE_ID_LIST_NOT_MATCH 0x0070 /**< Detected Module Ident List (0xF030) and Configured Module Ident List (0xF050) does not match*/
  207. #define EC_ALSTATUSCODE_SUPPLY_VOLTAGE_TOO_LOW 0x0080 /**< The slave supply voltage is too low*/
  208. #define EC_ALSTATUSCODE_SUPPLY_VOLTAGE_TOO_HIGH 0x0081 /**< The slave supply voltage is too high*/
  209. #define EC_ALSTATUSCODE_TEMPERATURE_TOO_LOW 0x0082 /**< The slave temperature is too low*/
  210. #define EC_ALSTATUSCODE_TEMPERATURE_TOO_HIGH 0x0083 /**< The slave temperature is too high*/
  211. #define EC_SII_ADDRESS_MANUF (0x0008)
  212. #define EC_SII_ADDRESS_PRODUCTCODE (0x000a)
  213. #define EC_SII_ADDRESS_REVISION (0x000c)
  214. #define EC_SII_ADDRESS_SN (0x000E)
  215. #define EC_SII_ADDRESS_BOOTRXMBX (0x0014)
  216. #define EC_SII_ADDRESS_BOOTTXMBX (0x0016)
  217. #define EC_SII_ADDRESS_MBXSIZE (0x0019)
  218. #define EC_SII_ADDRESS_TXMBXADR (0x001a)
  219. #define EC_SII_ADDRESS_RXMBXADR (0x0018)
  220. #define EC_SII_ADDRESS_MBXPROTO (0x001c)
  221. #define EC_SII_ADDRESS_ADDITIONAL_INFO (0x0040)
  222. #define EC_SII_TYPE_NOP 0x0000
  223. #define EC_SII_TYPE_STRINGS 0x000A
  224. #define EC_SII_TYPE_DATATYPES 0x0014
  225. #define EC_SII_TYPE_GENERAL 0x001E
  226. #define EC_SII_TYPE_FMMU 0x0028
  227. #define EC_SII_TYPE_SM 0x0029
  228. #define EC_SII_TYPE_FMMUX 0x002A
  229. #define EC_SII_TYPE_SYNCUNIT 0x002B
  230. #define EC_SII_TYPE_TXPDO 0x0032
  231. #define EC_SII_TYPE_RXPDO 0x0033
  232. #define EC_SII_TYPE_DC 0x003C
  233. #define EC_SII_TYPE_END 0xFFFF
  234. #define EC_SII_FMMU_NONE 0x0000
  235. #define EC_SII_FMMU_READ 0x0001
  236. #define EC_SII_FMMU_WRITE 0x0002
  237. #define EC_SII_FMMU_SM_STATUS 0x0003
  238. #define EC_SII_SM_UNKNOWN 0x0000
  239. #define EC_SII_SM_MBX_OUT 0x0001
  240. #define EC_SII_SM_MBX_IN 0x0002
  241. #define EC_SII_SM_PROCESS_DATA_OUTPUT 0x0003
  242. #define EC_SII_SM_PROCESS_DATA_INPUT 0x0004
  243. #define EC_SM_INDEX_MBX_WRITE 0x0000
  244. #define EC_SM_INDEX_MBX_READ 0x0001
  245. #define EC_SM_INDEX_PROCESS_DATA_OUTPUT 0x0002
  246. #define EC_SM_INDEX_PROCESS_DATA_INPUT 0x0003
  247. typedef struct __PACKED ec_sii_base {
  248. uint16_t pdi_control;
  249. uint16_t pdi_config;
  250. uint16_t sync_impulselen;
  251. uint16_t pdi_config2;
  252. uint16_t aliasaddr; /**< Configured station alias. */
  253. uint8_t reserved[4];
  254. uint16_t checksum;
  255. uint32_t vendor_id; /**< Vendor ID. */
  256. uint32_t product_code; /**< Vendor-specific product code. */
  257. uint32_t revision_number; /**< Revision number. */
  258. uint32_t serial_number; /**< Serial number. */
  259. uint8_t reserved2[8];
  260. uint16_t boot_rx_mailbox_offset; /**< Bootstrap receive mailbox address. */
  261. uint16_t boot_rx_mailbox_size; /**< Bootstrap receive mailbox size. */
  262. uint16_t boot_tx_mailbox_offset; /**< Bootstrap transmit mailbox address. */
  263. uint16_t boot_tx_mailbox_size; /**< Bootstrap transmit mailbox size. */
  264. uint16_t std_rx_mailbox_offset; /**< Standard receive mailbox address. */
  265. uint16_t std_rx_mailbox_size; /**< Standard receive mailbox size. */
  266. uint16_t std_tx_mailbox_offset; /**< Standard transmit mailbox address. */
  267. uint16_t std_tx_mailbox_size; /**< Standard transmit mailbox size. */
  268. uint16_t mailbox_protocols; /**< Supported mailbox protocols. */
  269. uint8_t reserved3[66];
  270. uint16_t size;
  271. uint16_t version;
  272. } ec_sii_base_t;
  273. typedef struct __PACKED ec_sii_general {
  274. uint8_t groupidx;
  275. uint8_t imgidx;
  276. uint8_t orderidx;
  277. uint8_t nameidx;
  278. uint8_t reserved1;
  279. ec_sii_coe_details_t coe_details;
  280. uint8_t foe_details;
  281. uint8_t eoe_details;
  282. uint8_t soe_channels;
  283. uint8_t ds402_channels;
  284. uint8_t sysmanclass;
  285. ec_sii_general_flags_t flags;
  286. int16_t current_on_ebus;
  287. uint8_t reserved2;
  288. uint8_t reserved3;
  289. uint16_t phy_port;
  290. uint16_t phy_memaddress;
  291. uint8_t pad[12];
  292. } ec_sii_general_t;
  293. typedef struct __PACKED ec_sii_sm {
  294. uint16_t physical_start_address;
  295. uint16_t length;
  296. uint8_t control;
  297. uint8_t status;
  298. uint8_t active;
  299. uint8_t type;
  300. } ec_sii_sm_t;
  301. typedef struct __PACKED ec_sii_pdo_entry {
  302. uint16_t index;
  303. uint8_t subindex;
  304. uint8_t nameidx;
  305. uint8_t data_type;
  306. uint8_t bitlen;
  307. uint16_t flags;
  308. } ec_sii_pdo_entry_t;
  309. typedef struct __PACKED ec_sii_pdo_mapping {
  310. uint16_t index; /* txpdo: 1a00~1bff, rxpdo: 1600~17ff */
  311. uint8_t nentry;
  312. uint8_t sm_idx;
  313. uint8_t synchronization;
  314. uint8_t nameidx;
  315. uint16_t flags;
  316. ec_sii_pdo_entry_t entry[];
  317. } ec_sii_pdo_mapping_t;
  318. typedef struct __PACKED ec_sm_reg {
  319. uint16_t physical_start_address;
  320. uint16_t length;
  321. uint8_t control;
  322. uint8_t status;
  323. uint8_t active;
  324. uint8_t pdi_control;
  325. } ec_sm_reg_t;
  326. typedef struct __PACKED ec_fmmu_reg {
  327. uint32_t logical_start_address;
  328. uint16_t length;
  329. uint8_t logical_start_bit;
  330. uint8_t logical_stop_bit;
  331. uint16_t physical_start_address;
  332. uint8_t physical_start_bit;
  333. uint8_t type;
  334. uint8_t active;
  335. uint8_t reserved[3];
  336. } ec_fmmu_reg_t;
  337. /**
  338. * \brief SmAssignObjects SyncManager Assignment Objects
  339. * SyncManager 2 : 0x1C12<br>
  340. * SyncManager 3 : 0x1C13<br>
  341. */
  342. typedef struct __PACKED ec_pdo_assign_t {
  343. uint16_t count; /**< PDO mapping count. */
  344. uint16_t entry[CONFIG_EC_PER_SM_MAX_PDOS];
  345. } ec_pdo_assign_t;
  346. typedef struct __PACKED ec_pdo_mapping_t {
  347. uint16_t count; /**< PDO entry count. */
  348. uint32_t entry[CONFIG_EC_PER_PDO_MAX_PDO_ENTRIES];
  349. } ec_pdo_mapping_t;
  350. typedef struct __PACKED ec_mailbox_header {
  351. uint16_t length;
  352. uint16_t address;
  353. uint8_t channel : 6;
  354. uint8_t priority : 2;
  355. uint8_t type : 4;
  356. uint8_t counter : 3;
  357. uint8_t reserved : 1;
  358. } ec_mailbox_header_t;
  359. /** Size of the mailbox header.
  360. */
  361. #define EC_MBOX_HEADER_SIZE 6
  362. #define EC_MBXPROT_AOE 0x0001
  363. #define EC_MBXPROT_EOE 0x0002
  364. #define EC_MBXPROT_COE 0x0004
  365. #define EC_MBXPROT_FOE 0x0008
  366. #define EC_MBXPROT_SOE 0x0010
  367. #define EC_MBXPROT_VOE 0x0020
  368. /** Mailbox types.
  369. *
  370. * These are used in the 'Type' field of the mailbox header.
  371. */
  372. enum {
  373. EC_MBOX_TYPE_EOE = 0x02,
  374. EC_MBOX_TYPE_COE = 0x03,
  375. EC_MBOX_TYPE_FOE = 0x04,
  376. EC_MBOX_TYPE_SOE = 0x05,
  377. EC_MBOX_TYPE_VOE = 0x0f,
  378. };
  379. #define EC_MBXERR_SYNTAX 0x01 /**< \brief Mailbox error "syntax"*/
  380. #define EC_MBXERR_UNSUPPORTEDPROTOCOL 0x02 /**< \brief Mailbox error "unsupported protocol"*/
  381. #define EC_MBXERR_INVALIDCHANNEL 0x03 /**< \brief Mailbox error "invalid channel"*/
  382. #define EC_MBXERR_SERVICENOTSUPPORTED 0x04 /**< \brief Mailbox error "service not supported"*/
  383. #define EC_MBXERR_INVALIDHEADER 0x05 /**< \brief Mailbox error "invalid header"*/
  384. #define EC_MBXERR_SIZETOOSHORT 0x06 /**< \brief Mailbox error "Size too short"*/
  385. #define EC_MBXERR_NOMOREMEMORY 0x07 /**< \brief Mailbox error "No memory"*/
  386. #define EC_MBXERR_INVALIDSIZE 0x08 /**< \brief Mailbox error "Invalid size"*/
  387. #define EC_MBXERR_SERVICEINWORK 0x09 /**< \brief Mailbox error "Service in work"*/
  388. typedef struct __PACKED ec_coe_header {
  389. uint16_t number : 9;
  390. uint16_t reserved : 3;
  391. uint16_t service : 4;
  392. } ec_coe_header_t;
  393. typedef struct __PACKED ec_sdo_header_common {
  394. uint8_t size_indicator : 1;
  395. uint8_t transfertype : 1; // expedited transfer
  396. uint8_t data_set_size : 2;
  397. uint8_t complete_access : 1;
  398. uint8_t command : 3;
  399. } ec_sdo_header_common_t;
  400. typedef struct __PACKED ec_sdo_header_segment {
  401. uint8_t more_follows : 1;
  402. uint8_t segdata_size : 3;
  403. uint8_t toggle : 1;
  404. uint8_t command : 3;
  405. } ec_sdo_header_segment_t;
  406. typedef struct __PACKED ec_sdo_header {
  407. union {
  408. uint8_t byte;
  409. ec_sdo_header_common_t common;
  410. ec_sdo_header_segment_t segment;
  411. };
  412. uint16_t index;
  413. uint8_t subindex;
  414. } ec_sdo_header_t;
  415. #define EC_COE_SERVICE_EMERGENCY 0x01
  416. #define EC_COE_SERVICE_SDO_REQUEST 0x02
  417. #define EC_COE_SERVICE_SDO_RESPONSE 0x03
  418. #define EC_COE_SERVICE_TXPDO 0x04
  419. #define EC_COE_SERVICE_RXPDO 0x05
  420. #define EC_COE_SERVICE_TXPDO_REMOTE_REQUSET 0x06
  421. #define EC_COE_SERVICE_RXPDO_REMOTE_REQUEST 0x07
  422. #define EC_COE_SERVICE_SDOINFO 0x08
  423. #define EC_COE_REQUEST_SEGMENT_DOWNLOAD 0x00
  424. #define EC_COE_REQUEST_DOWNLOAD 0x01
  425. #define EC_COE_REQUEST_UPLOAD 0x02
  426. #define EC_COE_REQUEST_SEGMENT_UPLOAD 0x03
  427. #define EC_COE_REQUEST_ABORT 0x04
  428. #define EC_COE_RESPONSE_SEGMENT_UPLOAD 0x00
  429. #define EC_COE_RESPONSE_SEGMENT_DOWNLOAD 0x01
  430. #define EC_COE_RESPONSE_UPLOAD 0x02
  431. #define EC_COE_RESPONSE_DOWNLOAD 0x03
  432. typedef struct __PACKED {
  433. uint16_t opcode;
  434. union {
  435. uint32_t password;
  436. uint32_t packet_number;
  437. uint32_t error_code;
  438. };
  439. } ec_foe_header_t;
  440. #define EC_FOE_OPCODE_READ 0x0001
  441. #define EC_FOE_OPCODE_WRITE 0x0002
  442. #define EC_FOE_OPCODE_DATA 0x0003
  443. #define EC_FOE_OPCODE_ACK 0x0004
  444. #define EC_FOE_OPCODE_ERROR 0x0005
  445. #define EC_FOE_OPCODE_BUSY 0x0006
  446. #define EC_FOE_ERRCODE_NOTDEFINED 0x8000 /**< \brief Not defined*/
  447. #define EC_FOE_ERRCODE_NOTFOUND 0x8001 /**< \brief The file requested by an FoE upload service could not be found on the server*/
  448. #define EC_FOE_ERRCODE_ACCESS 0x8002 /**< \brief Read or write access to this file not allowed (e.g. due to local control).*/
  449. #define EC_FOE_ERRCODE_DISKFULL 0x8003 /**< \brief Disk to store file is full or memory allocation exceeded*/
  450. #define EC_FOE_ERRCODE_ILLEGAL 0x8004 /**< \brief Illegal FoE operation, e.g. service identifier invalid*/
  451. #define EC_FOE_ERRCODE_PACKENO 0x8005 /**< \brief FoE packet number invalid*/
  452. #define EC_FOE_ERRCODE_EXISTS 0x8006 /**< \brief The file which is requested to be downloaded does already exist*/
  453. #define EC_FOE_ERRCODE_NOUSER 0x8007 /**< \brief No User*/
  454. #define EC_FOE_ERRCODE_BOOTSTRAPONLY 0x8008 /**< \brief FoE only supported in Bootstrap*/
  455. #define EC_FOE_ERRCODE_NOTINBOOTSTRAP 0x8009 /**< \brief This file may not be accessed in BOOTSTRAP state*/
  456. #define EC_FOE_ERRCODE_NORIGHTS 0x800A /**< \brief Password invalid*/
  457. #define EC_FOE_ERRCODE_PROGERROR 0x800B /**< \brief Generic programming error. Should only be returned if error reason cannot be distinguished*/
  458. #define EC_FOE_ERRCODE_INVALID_CHECKSUM 0x800C /**< \brief checksum included in the file is invalid*/
  459. #define EC_FOE_ERRCODE_INVALID_FIRMWARE 0x800D /**< \brief The hardware does not support the downloaded firmware*/
  460. #define EC_FOE_ERRCODE_NO_FILE 0x800F /**< \brief Do not use (identical with 0x8001)*/
  461. #define EC_FOE_ERRCODE_NO_FILE_HEADER 0x8010 /**< \brief Missing file header of error in file header*/
  462. #define EC_FOE_ERRCODE_FLASH_ERROR 0x8011 /**< \brief Flash cannot be accessed*/
  463. #define EC_EOE_TYPE_FRAGMENT 0x00
  464. #define EC_EOE_TYPE_TIMESTAMP 0x01
  465. #define EC_EOE_TYPE_SET_IP_REQUEST 0x02
  466. #define EC_EOE_TYPE_SET_IP_RESPONSE 0x03
  467. #define EC_EOE_TYPE_MACFILTER_REQUEST 0x04
  468. #define EC_EOE_TYPE_MACFILTER_RESPONSE 0x05
  469. #define EC_EOE_TYPE_GET_IP_REQUEST 0x06
  470. #define EC_EOE_TYPE_GET_IP_RESPONSE 0x07
  471. #define EC_EOE_TYPE_GET_MAC_FILTER_REQUEST 0x08
  472. #define EC_EOE_TYPE_GET_MAC_FILTER_RESPONSE 0x09
  473. #define EC_EOE_RESULT_NOERROR 0x0000 /**< \brief No Error*/
  474. #define EC_EOE_RESULT_UNSPECIFIED_ERROR 0x0001 /**< \brief Unspecified error*/
  475. #define EC_EOE_RESULT_UNSUPPORTED_TYPE 0x0002 /**< \brief unsupported type*/
  476. #define EC_EOE_RESULT_NO_IP_SUPPORT 0x0201 /**< \brief No IP supported*/
  477. #define EC_EOE_RESULT_NO_DHCP_SUPPORT 0x0202 /**< \brief No DHCP supported*/
  478. #define EC_EOE_RESULT_NO_MACFILTERMASK_SUPPORT 0x0401 /**< \brief No mac filter supported*/
  479. typedef enum {
  480. EC_DIR_OUTPUT, /**< Values written by the master. */
  481. EC_DIR_INPUT, /**< Values read by the master. */
  482. } ec_direction_t;
  483. typedef enum {
  484. EC_WD_DEFAULT, /**< Use the default setting of the sync manager. */
  485. EC_WD_ENABLE, /**< Enable the watchdog. */
  486. EC_WD_DISABLE, /**< Disable the watchdog. */
  487. } ec_watchdog_mode_t;
  488. typedef struct {
  489. uint16_t index; /**< PDO entry index. */
  490. uint8_t subindex; /**< PDO entry subindex. */
  491. uint8_t bit_length; /**< Size of the PDO entry in bit. */
  492. } ec_pdo_entry_info_t;
  493. typedef struct {
  494. uint16_t index; /**< PDO index. */
  495. uint32_t n_entries;
  496. ec_pdo_entry_info_t const *entries;
  497. } ec_pdo_info_t;
  498. typedef struct {
  499. uint8_t index; /**< Sync manager index. */
  500. ec_direction_t dir;
  501. uint32_t n_pdos;
  502. ec_pdo_info_t const *pdos;
  503. ec_watchdog_mode_t watchdog_mode;
  504. } ec_sync_info_t;
  505. #define EC_CIA402_OPERATION_MODE_NO_MODE 0x00
  506. #define EC_CIA402_OPERATION_MODE_CSP 0x01
  507. #define EC_CIA402_OPERATION_MODE_CSV 0x02
  508. #define EC_CIA402_OPERATION_MODE_CSP_CSV 0x03
  509. #define EC_CIA402_OPERATION_MODE_CST 0x04
  510. #define EC_CIA402_OPERATION_MODE_HOME 0x05
  511. #endif