ec_slave.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2025, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef EC_SLAVE_H
  7. #define EC_SLAVE_H
  8. typedef struct ec_master ec_master_t;
  9. typedef struct ec_slave ec_slave_t;
  10. typedef void (*ec_pdo_callback_t)(ec_slave_t *slave, uint8_t *output, uint8_t *input);
  11. typedef struct
  12. {
  13. ec_direction_t dir;
  14. uint32_t logical_start_address;
  15. uint32_t data_size;
  16. } ec_fmmu_info_t;
  17. typedef struct {
  18. uint16_t physical_start_address;
  19. uint16_t length;
  20. uint8_t control;
  21. uint8_t enable;
  22. ec_pdo_assign_t pdo_assign;
  23. ec_pdo_mapping_t pdo_mapping[CONFIG_EC_PER_SM_MAX_PDOS];
  24. ec_fmmu_info_t fmmu;
  25. bool fmmu_enable;
  26. } ec_sm_info_t;
  27. typedef struct {
  28. ec_sync_info_t *sync; /**< Sync manager configuration. */
  29. uint8_t sync_count; /**< Number of sync managers. */
  30. ec_pdo_callback_t pdo_callback; /**< PDO process data callback. */
  31. uint16_t dc_assign_activate; /**< dc assign control */
  32. ec_sync_signal_t dc_sync[EC_SYNC_SIGNAL_COUNT]; /**< DC sync signals. */
  33. } ec_slave_config_t;
  34. /** EtherCAT slave port descriptor.
  35. */
  36. typedef enum {
  37. EC_PORT_NOT_IMPLEMENTED, /**< Port is not implemented. */
  38. EC_PORT_NOT_CONFIGURED, /**< Port is not configured. */
  39. EC_PORT_EBUS, /**< Port is an E-Bus. */
  40. EC_PORT_MII /**< Port is a MII. */
  41. } ec_slave_port_desc_t;
  42. /** EtherCAT slave port information.
  43. */
  44. typedef struct {
  45. uint8_t link_up; /**< Link detected. */
  46. uint8_t loop_closed; /**< Loop closed. */
  47. uint8_t signal_detected; /**< Detected signal on RX port. */
  48. } ec_slave_port_link_t;
  49. typedef struct {
  50. ec_slave_port_desc_t desc; /**< Port descriptors. */
  51. ec_slave_port_link_t link; /**< Port link status. */
  52. ec_slave_t *next_slave; /**< Connected slaves. */
  53. uint32_t receive_time; /**< Port receive times for delay measurement. */
  54. uint32_t delay_to_next_dc; /**< Delay to next slave with DC support behind this port [ns]. */
  55. } ec_slave_port_t;
  56. typedef struct ec_slave {
  57. uint32_t index; /**< Index of the slave in the master slave array. */
  58. ec_master_t *master; /**< Master owning the slave. */
  59. ec_netdev_index_t netdev_idx; /**< Index of device the slave responds on. */
  60. uint16_t autoinc_address; /**< Auto-increment address. */
  61. uint16_t station_address; /**< Configured station address. */
  62. uint16_t effective_alias; /**< Effective alias address. */
  63. ec_slave_port_t ports[EC_MAX_PORTS]; /**< Port information. */
  64. ec_slave_state_t requested_state; /**< Requested application state. */
  65. ec_slave_state_t current_state; /**< Current application state. */
  66. uint32_t alstatus_code; /**< Error code in AL Status register. */
  67. bool force_update; /**< Force update of the slave. */
  68. uint16_t configured_rx_mailbox_offset; /**< Configured receive mailbox offset. */
  69. uint16_t configured_rx_mailbox_size; /**< Configured receive mailbox size.*/
  70. uint16_t configured_tx_mailbox_offset; /**< Configured send mailbox offset. */
  71. uint16_t configured_tx_mailbox_size; /**< Configured send mailbox size. */
  72. uint8_t base_type; /**< Slave type. */
  73. uint8_t base_revision; /**< Revision. */
  74. uint16_t base_build; /**< Build number. */
  75. uint8_t base_fmmu_count; /**< Number of supported FMMUs. */
  76. uint8_t base_sync_count; /**< Number of supported sync managers. */
  77. uint8_t base_fmmu_bit_operation; /**< FMMU bit operation is supported. */
  78. uint8_t base_dc_supported; /**< Distributed clocks are supported. */
  79. ec_slave_dc_range_t base_dc_range; /**< DC range. */
  80. uint8_t has_dc_system_time; /**< The slave supports the DC system time register. Otherwise it can only be used for delay measurement. */
  81. uint32_t transmission_delay; /**< DC system time transmission delay (offset from reference clock). */
  82. uint32_t logical_start_address;
  83. uint32_t odata_size;
  84. uint32_t idata_size;
  85. uint32_t expected_working_counter;
  86. uint32_t actual_working_counter;
  87. uint16_t *sii_image; /**< Complete SII image. */
  88. size_t sii_nwords; /**< Size of the SII contents in words. */
  89. ec_sii_t sii; /**< Extracted SII data. */
  90. ec_sm_info_t *sm_info;
  91. uint8_t sm_count; /**< Number of sync managers. */
  92. ec_slave_config_t *config; /**< Slave custom configuration. */
  93. } ec_slave_t;
  94. void ec_slaves_scanning(ec_master_t *master);
  95. char *ec_slave_get_sii_string(const ec_slave_t *slave, uint32_t index);
  96. #endif