ec_def.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. /** Slave information interface CANopen over EtherCAT details flags.
  104. */
  105. typedef struct {
  106. uint8_t enable_sdo : 1; /**< Enable SDO access. */
  107. uint8_t enable_sdo_info : 1; /**< SDO information service available. */
  108. uint8_t enable_pdo_assign : 1; /**< PDO mapping configurable. */
  109. uint8_t enable_pdo_configuration : 1; /**< PDO configuration possible. */
  110. uint8_t enable_upload_at_startup : 1; /**< ?. */
  111. uint8_t enable_sdo_complete_access : 1; /**< Complete access possible. */
  112. uint8_t : 2; /**< Reserved bits. */
  113. } ec_sii_coe_details_t;
  114. /** Slave information interface general flags.
  115. */
  116. typedef struct {
  117. uint8_t enable_safeop : 1; /**< ?. */
  118. uint8_t enable_not_lrw : 1; /**< Slave does not support LRW. */
  119. uint8_t : 6; /**< Reserved bits. */
  120. } ec_sii_general_flags_t;
  121. /** EtherCAT slave distributed clocks range.
  122. */
  123. typedef enum {
  124. EC_DC_32, /**< 32 bit. */
  125. EC_DC_64 /*< 64 bit for system time, system time offset and
  126. port 0 receive time. */
  127. } ec_slave_dc_range_t;
  128. /** EtherCAT slave sync signal configuration.
  129. */
  130. typedef struct {
  131. uint32_t cycle_time; /**< Cycle time [ns]. */
  132. int32_t shift_time; /**< Shift time [ns]. */
  133. } ec_sync_signal_t;
  134. /** Master netdev.
  135. */
  136. typedef enum {
  137. EC_NETDEV_MAIN, /**< Main netdev. */
  138. EC_NETDEV_BACKUP /**< Backup netdev */
  139. } ec_netdev_index_t;
  140. typedef struct ec_alstatus {
  141. uint16_t alstatus;
  142. uint16_t unused;
  143. uint16_t alstatuscode;
  144. } ec_alstatus_t;
  145. /* AL Status Codes */
  146. #define EC_ALSTATUSCODE_NOERROR 0x0000 /**< No error*/
  147. #define EC_ALSTATUSCODE_UNSPECIFIEDERROR 0x0001 /**< Unspecified error*/
  148. #define EC_ALSTATUSCODE_NOMEMORY 0x0002 /**< No Memory*/
  149. #define EC_ALSTATUSCODE_INVALID_REVISION 0x0004 /**< Output/Input mapping is not valid for this hardware or software revision (0x1018:03)*/
  150. #define EC_ALSTATUSCODE_FW_SII_NOT_MATCH 0x0006 /**< Firmware and EEPROM do not match. Slave needs BOOT-INIT transition*/
  151. #define EC_ALSTATUSCODE_FW_UPDATE_FAILED 0x0007 /**< Firmware update not successful. Old firmware still running*/
  152. #define EC_ALSTATUSCODE_INVALIDALCONTROL 0x0011 /**< Invalid requested state change*/
  153. #define EC_ALSTATUSCODE_UNKNOWNALCONTROL 0x0012 /**< Unknown requested state*/
  154. #define EC_ALSTATUSCODE_BOOTNOTSUPP 0x0013 /**< Bootstrap not supported*/
  155. #define EC_ALSTATUSCODE_NOVALIDFIRMWARE 0x0014 /**< No valid firmware*/
  156. #define EC_ALSTATUSCODE_INVALIDMBXCFGINBOOT 0x0015 /**< Invalid mailbox configuration (BOOT state)*/
  157. #define EC_ALSTATUSCODE_INVALIDMBXCFGINPREOP 0x0016 /**< Invalid mailbox configuration (PreOP state)*/
  158. #define EC_ALSTATUSCODE_INVALIDSMCFG 0x0017 /**< Invalid sync manager configuration*/
  159. #define EC_ALSTATUSCODE_NOVALIDINPUTS 0x0018 /**< No valid inputs available*/
  160. #define EC_ALSTATUSCODE_NOVALIDOUTPUTS 0x0019 /**< No valid outputs*/
  161. #define EC_ALSTATUSCODE_SYNCERROR 0x001A /**< Synchronization error*/
  162. #define EC_ALSTATUSCODE_SMWATCHDOG 0x001B /**< Sync manager watchdog*/
  163. #define EC_ALSTATUSCODE_SYNCTYPESNOTCOMPATIBLE 0x001C /**< Invalid Sync Manager Types*/
  164. #define EC_ALSTATUSCODE_INVALIDSMOUTCFG 0x001D /**< Invalid Output Configuration*/
  165. #define EC_ALSTATUSCODE_INVALIDSMINCFG 0x001E /**< Invalid Input Configuration*/
  166. #define EC_ALSTATUSCODE_INVALIDWDCFG 0x001F /**< Invalid Watchdog Configuration*/
  167. #define EC_ALSTATUSCODE_WAITFORCOLDSTART 0x0020 /**< Slave needs cold start*/
  168. #define EC_ALSTATUSCODE_WAITFORINIT 0x0021 /**< Slave needs INIT*/
  169. #define EC_ALSTATUSCODE_WAITFORPREOP 0x0022 /**< Slave needs PREOP*/
  170. #define EC_ALSTATUSCODE_WAITFORSAFEOP 0x0023 /**< Slave needs SAFEOP*/
  171. #define EC_ALSTATUSCODE_INVALIDINPUTMAPPING 0x0024 /**< Invalid Input Mapping*/
  172. #define EC_ALSTATUSCODE_INVALIDOUTPUTMAPPING 0x0025 /**< Invalid Output Mapping*/
  173. #define EC_ALSTATUSCODE_INCONSISTENTSETTINGS 0x0026 /**< Inconsistent Settings*/
  174. #define EC_ALSTATUSCODE_FREERUNNOTSUPPORTED 0x0027 /**< FreeRun not supported*/
  175. #define EC_ALSTATUSCODE_SYNCHRONNOTSUPPORTED 0x0028 /**< SyncMode not supported*/
  176. #define EC_ALSTATUSCODE_FREERUNNEEDS3BUFFERMODE 0x0029 /**< FreeRun needs 3Buffer Mode*/
  177. #define EC_ALSTATUSCODE_BACKGROUNDWATCHDOG 0x002A /**< Background Watchdog*/
  178. #define EC_ALSTATUSCODE_NOVALIDINPUTSANDOUTPUTS 0x002B /**< No Valid Inputs and Outputs*/
  179. #define EC_ALSTATUSCODE_FATALSYNCERROR 0x002C /**< Fatal Sync Error*/
  180. #define EC_ALSTATUSCODE_NOSYNCERROR 0x002D /**< No Sync Error*/
  181. #define EC_ALSTATUSCODE_CYCLETIMETOOSMALL 0x002E /**< EtherCAT cycle time smaller Minimum Cycle Time supported by slave*/
  182. #define EC_ALSTATUSCODE_DCINVALIDSYNCCFG 0x0030 /**< Invalid DC SYNCH Configuration*/
  183. #define EC_ALSTATUSCODE_DCINVALIDLATCHCFG 0x0031 /**< Invalid DC Latch Configuration*/
  184. #define EC_ALSTATUSCODE_DCPLLSYNCERROR 0x0032 /**< PLL Error*/
  185. #define EC_ALSTATUSCODE_DCSYNCIOERROR 0x0033 /**< DC Sync IO Error*/
  186. #define EC_ALSTATUSCODE_DCSYNCMISSEDERROR 0x0034 /**< DC Sync Timeout Error*/
  187. #define EC_ALSTATUSCODE_DCINVALIDSYNCCYCLETIME 0x0035 /**< DC Invalid Sync Cycle Time*/
  188. #define EC_ALSTATUSCODE_DCSYNC0CYCLETIME 0x0036 /**< DC Sync0 Cycle Time*/
  189. #define EC_ALSTATUSCODE_DCSYNC1CYCLETIME 0x0037 /**< DC Sync1 Cycle Time*/
  190. #define EC_ALSTATUSCODE_MBX_AOE 0x0041 /**< MBX_AOE*/
  191. #define EC_ALSTATUSCODE_MBX_EOE 0x0042 /**< MBX_EOE*/
  192. #define EC_ALSTATUSCODE_MBX_COE 0x0043 /**< MBX_COE*/
  193. #define EC_ALSTATUSCODE_MBX_FOE 0x0044 /**< MBX_FOE*/
  194. #define EC_ALSTATUSCODE_MBX_SOE 0x0045 /**< MBX_SOE*/
  195. #define EC_ALSTATUSCODE_MBX_VOE 0x004F /**< MBX_VOE*/
  196. #define EC_ALSTATUSCODE_EE_NOACCESS 0x0050 /**< EEPROM no access*/
  197. #define EC_ALSTATUSCODE_EE_ERROR 0x0051 /**< EEPROM Error*/
  198. #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*/
  199. #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*/
  200. #define EC_ALSTATUSCODE_MODULE_ID_LIST_NOT_MATCH 0x0070 /**< Detected Module Ident List (0xF030) and Configured Module Ident List (0xF050) does not match*/
  201. #define EC_ALSTATUSCODE_SUPPLY_VOLTAGE_TOO_LOW 0x0080 /**< The slave supply voltage is too low*/
  202. #define EC_ALSTATUSCODE_SUPPLY_VOLTAGE_TOO_HIGH 0x0081 /**< The slave supply voltage is too high*/
  203. #define EC_ALSTATUSCODE_TEMPERATURE_TOO_LOW 0x0082 /**< The slave temperature is too low*/
  204. #define EC_ALSTATUSCODE_TEMPERATURE_TOO_HIGH 0x0083 /**< The slave temperature is too high*/
  205. #define EC_SII_ADDRESS_MANUF (0x0008)
  206. #define EC_SII_ADDRESS_PRODUCTCODE (0x000a)
  207. #define EC_SII_ADDRESS_REVISION (0x000c)
  208. #define EC_SII_ADDRESS_SN (0x000E)
  209. #define EC_SII_ADDRESS_BOOTRXMBX (0x0014)
  210. #define EC_SII_ADDRESS_BOOTTXMBX (0x0016)
  211. #define EC_SII_ADDRESS_MBXSIZE (0x0019)
  212. #define EC_SII_ADDRESS_TXMBXADR (0x001a)
  213. #define EC_SII_ADDRESS_RXMBXADR (0x0018)
  214. #define EC_SII_ADDRESS_MBXPROTO (0x001c)
  215. #define EC_SII_ADDRESS_ADDITIONAL_INFO (0x0040)
  216. #define EC_SII_TYPE_NOP 0x0000
  217. #define EC_SII_TYPE_STRINGS 0x000A
  218. #define EC_SII_TYPE_DATATYPES 0x0014
  219. #define EC_SII_TYPE_GENERAL 0x001E
  220. #define EC_SII_TYPE_FMMU 0x0028
  221. #define EC_SII_TYPE_SM 0x0029
  222. #define EC_SII_TYPE_FMMUX 0x002A
  223. #define EC_SII_TYPE_SYNCUNIT 0x002B
  224. #define EC_SII_TYPE_TXPDO 0x0032
  225. #define EC_SII_TYPE_RXPDO 0x0033
  226. #define EC_SII_TYPE_DC 0x003C
  227. #define EC_SII_TYPE_END 0xFFFF
  228. #define EC_SII_FMMU_NONE 0x0000
  229. #define EC_SII_FMMU_READ 0x0001
  230. #define EC_SII_FMMU_WRITE 0x0002
  231. #define EC_SII_FMMU_SM_STATUS 0x0003
  232. #define EC_SII_SM_UNKNOWN 0x0000
  233. #define EC_SII_SM_MBX_OUT 0x0001
  234. #define EC_SII_SM_MBX_IN 0x0002
  235. #define EC_SII_SM_PROCESS_DATA_OUTPUT 0x0003
  236. #define EC_SII_SM_PROCESS_DATA_INPUT 0x0004
  237. #define EC_SM_INDEX_MBX_WRITE 0x0000
  238. #define EC_SM_INDEX_MBX_READ 0x0001
  239. #define EC_SM_INDEX_PROCESS_DATA_OUTPUT 0x0002
  240. #define EC_SM_INDEX_PROCESS_DATA_INPUT 0x0003
  241. typedef struct __PACKED ec_sii_base {
  242. uint16_t pdi_control;
  243. uint16_t pdi_config;
  244. uint16_t sync_impulselen;
  245. uint16_t pdi_config2;
  246. uint16_t aliasaddr; /**< Configured station alias. */
  247. uint8_t reserved[4];
  248. uint16_t checksum;
  249. uint32_t vendor_id; /**< Vendor ID. */
  250. uint32_t product_code; /**< Vendor-specific product code. */
  251. uint32_t revision_number; /**< Revision number. */
  252. uint32_t serial_number; /**< Serial number. */
  253. uint8_t reserved2[8];
  254. uint16_t boot_rx_mailbox_offset; /**< Bootstrap receive mailbox address. */
  255. uint16_t boot_rx_mailbox_size; /**< Bootstrap receive mailbox size. */
  256. uint16_t boot_tx_mailbox_offset; /**< Bootstrap transmit mailbox address. */
  257. uint16_t boot_tx_mailbox_size; /**< Bootstrap transmit mailbox size. */
  258. uint16_t std_rx_mailbox_offset; /**< Standard receive mailbox address. */
  259. uint16_t std_rx_mailbox_size; /**< Standard receive mailbox size. */
  260. uint16_t std_tx_mailbox_offset; /**< Standard transmit mailbox address. */
  261. uint16_t std_tx_mailbox_size; /**< Standard transmit mailbox size. */
  262. uint16_t mailbox_protocols; /**< Supported mailbox protocols. */
  263. uint8_t reserved3[66];
  264. uint16_t size;
  265. uint16_t version;
  266. } ec_sii_base_t;
  267. typedef struct __PACKED ec_sii_general {
  268. uint8_t groupidx;
  269. uint8_t imgidx;
  270. uint8_t orderidx;
  271. uint8_t nameidx;
  272. uint8_t reserved1;
  273. ec_sii_coe_details_t coe_details;
  274. uint8_t foe_details;
  275. uint8_t eoe_details;
  276. uint8_t soe_channels;
  277. uint8_t ds402_channels;
  278. uint8_t sysmanclass;
  279. ec_sii_general_flags_t flags;
  280. int16_t current_on_ebus;
  281. uint8_t reserved2;
  282. uint8_t reserved3;
  283. uint16_t phy_port;
  284. uint16_t phy_memaddress;
  285. uint8_t pad[12];
  286. } ec_sii_general_t;
  287. typedef struct __PACKED ec_sii_sm {
  288. uint16_t physical_start_address;
  289. uint16_t length;
  290. uint8_t control;
  291. uint8_t status;
  292. uint8_t active;
  293. uint8_t type;
  294. } ec_sii_sm_t;
  295. typedef struct __PACKED ec_sii_pdo_entry {
  296. uint16_t index;
  297. uint8_t subindex;
  298. uint8_t nameidx;
  299. uint8_t data_type;
  300. uint8_t bitlen;
  301. uint16_t flags;
  302. } ec_sii_pdo_entry_t;
  303. typedef struct __PACKED ec_sii_pdo_mapping {
  304. uint16_t index; /* txpdo: 1a00~1bff, rxpdo: 1600~17ff */
  305. uint8_t nentry;
  306. uint8_t sm_idx;
  307. uint8_t synchronization;
  308. uint8_t nameidx;
  309. uint16_t flags;
  310. ec_sii_pdo_entry_t entry[];
  311. } ec_sii_pdo_mapping_t;
  312. typedef struct __PACKED ec_sm_reg {
  313. uint16_t physical_start_address;
  314. uint16_t length;
  315. uint8_t control;
  316. uint8_t status;
  317. uint8_t active;
  318. uint8_t pdi_control;
  319. } ec_sm_reg_t;
  320. typedef struct __PACKED ec_fmmu_reg {
  321. uint32_t logical_start_address;
  322. uint16_t length;
  323. uint8_t logical_start_bit;
  324. uint8_t logical_stop_bit;
  325. uint16_t physical_start_address;
  326. uint8_t physical_start_bit;
  327. uint8_t type;
  328. uint8_t active;
  329. uint8_t reserved[3];
  330. } ec_fmmu_reg_t;
  331. /**
  332. * \brief SmAssignObjects SyncManager Assignment Objects
  333. * SyncManager 2 : 0x1C12<br>
  334. * SyncManager 3 : 0x1C13<br>
  335. */
  336. typedef struct __PACKED ec_pdo_assign_t {
  337. uint16_t count; /**< PDO mapping count. */
  338. uint16_t entry[CONFIG_EC_PER_SM_MAX_PDOS];
  339. } ec_pdo_assign_t;
  340. typedef struct __PACKED ec_pdo_mapping_t {
  341. uint16_t count; /**< PDO entry count. */
  342. uint32_t entry[CONFIG_EC_PER_PDO_MAX_PDO_ENTRIES];
  343. } ec_pdo_mapping_t;
  344. typedef struct __PACKED ec_mailbox_header {
  345. uint16_t length;
  346. uint16_t address;
  347. uint8_t channel : 6;
  348. uint8_t priority : 2;
  349. uint8_t type : 4;
  350. uint8_t counter : 3;
  351. uint8_t reserved : 1;
  352. } ec_mailbox_header_t;
  353. /** Size of the mailbox header.
  354. */
  355. #define EC_MBOX_HEADER_SIZE 6
  356. #define EC_MBXPROT_AOE 0x0001
  357. #define EC_MBXPROT_EOE 0x0002
  358. #define EC_MBXPROT_COE 0x0004
  359. #define EC_MBXPROT_FOE 0x0008
  360. #define EC_MBXPROT_SOE 0x0010
  361. #define EC_MBXPROT_VOE 0x0020
  362. /** Mailbox types.
  363. *
  364. * These are used in the 'Type' field of the mailbox header.
  365. */
  366. enum {
  367. EC_MBOX_TYPE_EOE = 0x02,
  368. EC_MBOX_TYPE_COE = 0x03,
  369. EC_MBOX_TYPE_FOE = 0x04,
  370. EC_MBOX_TYPE_SOE = 0x05,
  371. EC_MBOX_TYPE_VOE = 0x0f,
  372. };
  373. #define EC_MBXERR_SYNTAX 0x01 /**< \brief Mailbox error "syntax"*/
  374. #define EC_MBXERR_UNSUPPORTEDPROTOCOL 0x02 /**< \brief Mailbox error "unsupported protocol"*/
  375. #define EC_MBXERR_INVALIDCHANNEL 0x03 /**< \brief Mailbox error "invalid channel"*/
  376. #define EC_MBXERR_SERVICENOTSUPPORTED 0x04 /**< \brief Mailbox error "service not supported"*/
  377. #define EC_MBXERR_INVALIDHEADER 0x05 /**< \brief Mailbox error "invalid header"*/
  378. #define EC_MBXERR_SIZETOOSHORT 0x06 /**< \brief Mailbox error "Size too short"*/
  379. #define EC_MBXERR_NOMOREMEMORY 0x07 /**< \brief Mailbox error "No memory"*/
  380. #define EC_MBXERR_INVALIDSIZE 0x08 /**< \brief Mailbox error "Invalid size"*/
  381. #define EC_MBXERR_SERVICEINWORK 0x09 /**< \brief Mailbox error "Service in work"*/
  382. typedef struct __PACKED ec_coe_header {
  383. uint16_t number : 9;
  384. uint16_t reserved : 3;
  385. uint16_t service : 4;
  386. } ec_coe_header_t;
  387. typedef struct __PACKED ec_sdo_header_common {
  388. uint8_t size_indicator : 1;
  389. uint8_t transfertype : 1; // expedited transfer
  390. uint8_t data_set_size : 2;
  391. uint8_t complete_access : 1;
  392. uint8_t command : 3;
  393. } ec_sdo_header_common_t;
  394. typedef struct __PACKED ec_sdo_header_segment {
  395. uint8_t more_follows : 1;
  396. uint8_t segdata_size : 3;
  397. uint8_t toggle : 1;
  398. uint8_t command : 3;
  399. } ec_sdo_header_segment_t;
  400. typedef struct __PACKED ec_sdo_header {
  401. union {
  402. uint8_t byte;
  403. ec_sdo_header_common_t common;
  404. ec_sdo_header_segment_t segment;
  405. };
  406. uint16_t index;
  407. uint8_t subindex;
  408. } ec_sdo_header_t;
  409. #define EC_COE_SERVICE_EMERGENCY 0x01
  410. #define EC_COE_SERVICE_SDO_REQUEST 0x02
  411. #define EC_COE_SERVICE_SDO_RESPONSE 0x03
  412. #define EC_COE_SERVICE_TXPDO 0x04
  413. #define EC_COE_SERVICE_RXPDO 0x05
  414. #define EC_COE_SERVICE_TXPDO_REMOTE_REQUSET 0x06
  415. #define EC_COE_SERVICE_RXPDO_REMOTE_REQUEST 0x07
  416. #define EC_COE_SERVICE_SDOINFO 0x08
  417. #define EC_COE_REQUEST_SEGMENT_DOWNLOAD 0x00
  418. #define EC_COE_REQUEST_DOWNLOAD 0x01
  419. #define EC_COE_REQUEST_UPLOAD 0x02
  420. #define EC_COE_REQUEST_SEGMENT_UPLOAD 0x03
  421. #define EC_COE_REQUEST_ABORT 0x04
  422. #define EC_COE_RESPONSE_SEGMENT_UPLOAD 0x00
  423. #define EC_COE_RESPONSE_SEGMENT_DOWNLOAD 0x01
  424. #define EC_COE_RESPONSE_UPLOAD 0x02
  425. #define EC_COE_RESPONSE_DOWNLOAD 0x03
  426. typedef struct __PACKED {
  427. uint16_t opcode;
  428. union {
  429. uint32_t password;
  430. uint32_t packet_number;
  431. uint32_t error_code;
  432. };
  433. } ec_foe_header_t;
  434. #define EC_FOE_OPCODE_READ 0x0001
  435. #define EC_FOE_OPCODE_WRITE 0x0002
  436. #define EC_FOE_OPCODE_DATA 0x0003
  437. #define EC_FOE_OPCODE_ACK 0x0004
  438. #define EC_FOE_OPCODE_ERROR 0x0005
  439. #define EC_FOE_OPCODE_BUSY 0x0006
  440. #define EC_FOE_ERRCODE_NOTDEFINED 0x8000 /**< \brief Not defined*/
  441. #define EC_FOE_ERRCODE_NOTFOUND 0x8001 /**< \brief The file requested by an FoE upload service could not be found on the server*/
  442. #define EC_FOE_ERRCODE_ACCESS 0x8002 /**< \brief Read or write access to this file not allowed (e.g. due to local control).*/
  443. #define EC_FOE_ERRCODE_DISKFULL 0x8003 /**< \brief Disk to store file is full or memory allocation exceeded*/
  444. #define EC_FOE_ERRCODE_ILLEGAL 0x8004 /**< \brief Illegal FoE operation, e.g. service identifier invalid*/
  445. #define EC_FOE_ERRCODE_PACKENO 0x8005 /**< \brief FoE packet number invalid*/
  446. #define EC_FOE_ERRCODE_EXISTS 0x8006 /**< \brief The file which is requested to be downloaded does already exist*/
  447. #define EC_FOE_ERRCODE_NOUSER 0x8007 /**< \brief No User*/
  448. #define EC_FOE_ERRCODE_BOOTSTRAPONLY 0x8008 /**< \brief FoE only supported in Bootstrap*/
  449. #define EC_FOE_ERRCODE_NOTINBOOTSTRAP 0x8009 /**< \brief This file may not be accessed in BOOTSTRAP state*/
  450. #define EC_FOE_ERRCODE_NORIGHTS 0x800A /**< \brief Password invalid*/
  451. #define EC_FOE_ERRCODE_PROGERROR 0x800B /**< \brief Generic programming error. Should only be returned if error reason cannot be distinguished*/
  452. #define EC_FOE_ERRCODE_INVALID_CHECKSUM 0x800C /**< \brief checksum included in the file is invalid*/
  453. #define EC_FOE_ERRCODE_INVALID_FIRMWARE 0x800D /**< \brief The hardware does not support the downloaded firmware*/
  454. #define EC_FOE_ERRCODE_NO_FILE 0x800F /**< \brief Do not use (identical with 0x8001)*/
  455. #define EC_FOE_ERRCODE_NO_FILE_HEADER 0x8010 /**< \brief Missing file header of error in file header*/
  456. #define EC_FOE_ERRCODE_FLASH_ERROR 0x8011 /**< \brief Flash cannot be accessed*/
  457. #define EC_EOE_TYPE_FRAGMENT 0x00
  458. #define EC_EOE_TYPE_TIMESTAMP 0x01
  459. #define EC_EOE_TYPE_SET_IP_REQUEST 0x02
  460. #define EC_EOE_TYPE_SET_IP_RESPONSE 0x03
  461. #define EC_EOE_TYPE_MACFILTER_REQUEST 0x04
  462. #define EC_EOE_TYPE_MACFILTER_RESPONSE 0x05
  463. #define EC_EOE_TYPE_GET_IP_REQUEST 0x06
  464. #define EC_EOE_TYPE_GET_IP_RESPONSE 0x07
  465. #define EC_EOE_TYPE_GET_MAC_FILTER_REQUEST 0x08
  466. #define EC_EOE_TYPE_GET_MAC_FILTER_RESPONSE 0x09
  467. #define EC_EOE_RESULT_NOERROR 0x0000 /**< \brief No Error*/
  468. #define EC_EOE_RESULT_UNSPECIFIED_ERROR 0x0001 /**< \brief Unspecified error*/
  469. #define EC_EOE_RESULT_UNSUPPORTED_TYPE 0x0002 /**< \brief unsupported type*/
  470. #define EC_EOE_RESULT_NO_IP_SUPPORT 0x0201 /**< \brief No IP supported*/
  471. #define EC_EOE_RESULT_NO_DHCP_SUPPORT 0x0202 /**< \brief No DHCP supported*/
  472. #define EC_EOE_RESULT_NO_MACFILTERMASK_SUPPORT 0x0401 /**< \brief No mac filter supported*/
  473. typedef enum {
  474. EC_DIR_OUTPUT, /**< Values written by the master. */
  475. EC_DIR_INPUT, /**< Values read by the master. */
  476. } ec_direction_t;
  477. typedef enum {
  478. EC_WD_DEFAULT, /**< Use the default setting of the sync manager. */
  479. EC_WD_ENABLE, /**< Enable the watchdog. */
  480. EC_WD_DISABLE, /**< Disable the watchdog. */
  481. } ec_watchdog_mode_t;
  482. typedef struct {
  483. uint16_t index; /**< PDO entry index. */
  484. uint8_t subindex; /**< PDO entry subindex. */
  485. uint8_t bit_length; /**< Size of the PDO entry in bit. */
  486. } ec_pdo_entry_info_t;
  487. typedef struct {
  488. uint16_t index; /**< PDO index. */
  489. uint32_t n_entries;
  490. ec_pdo_entry_info_t const *entries;
  491. } ec_pdo_info_t;
  492. typedef struct {
  493. uint8_t index; /**< Sync manager index. */
  494. ec_direction_t dir;
  495. uint32_t n_pdos;
  496. ec_pdo_info_t const *pdos;
  497. ec_watchdog_mode_t watchdog_mode;
  498. } ec_sync_info_t;
  499. #endif