cipethernetlink.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*******************************************************************************
  2. * Copyright (c) 2009, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #ifndef OPENER_CIPETHERNETLINK_H_
  7. #define OPENER_CIPETHERNETLINK_H_
  8. /** @file
  9. * @brief Declare public interface of the CIP Ethernet Link Object
  10. */
  11. #include "typedefs.h"
  12. #include "ciptypes.h"
  13. /** @brief This Ethernet Link class code as #define is still needed for a static
  14. * initialization. */
  15. #define CIP_ETHERNETLINK_CLASS_CODE 0xF6U
  16. /** @brief Ethernet Link class code */
  17. static const CipUint kCipEthernetLinkClassCode = CIP_ETHERNETLINK_CLASS_CODE;
  18. /* public type definitions */
  19. /** @brief Provide values for the Interface Flags (attribute #2) */
  20. typedef enum {
  21. /** Set this bit if your device needs a reset to take over new settings made via
  22. * attribute #6. It is duplicates the meaning of kEthLinkCapManualReset */
  23. kEthLinkFlagsManualReset = 0x20,
  24. } CipEthLinkIfaceFlags;
  25. /** @brief Provide values for the Interface Control (attribute #6) Control bits member */
  26. typedef enum {
  27. /** Set this bit to enable Auto-negotiation of ethernet link parameters. */
  28. kEthLinkIfCntrlAutonegotiate = 0x01,
  29. /** When Auto-negotiation is disabled set this bit to force Full-Duplex mode else
  30. * Half-Duplex mode is forced. */
  31. kEthLinkIfCntrlForceDuplexFD = 0x02,
  32. /** For convenience declare the sum of valid bits as the maximum allowed value. */
  33. kEthLinkIfCntrlMaxValid = kEthLinkIfCntrlAutonegotiate +
  34. kEthLinkIfCntrlForceDuplexFD,
  35. } CipEthLinkIfaceControl;
  36. /** @brief Provide values for the Interface Type (attribute #7) */
  37. typedef enum {
  38. /** Unknown interface type */
  39. kEthLinkIfTypeUnknown = 0x00,
  40. /** Internal (switch) port */
  41. kEthLinkIfTypeInternal = 0x01,
  42. /** Twisted pair (e.g., 10Base-T, 100Base-TX, 1000Base-T, etc.) */
  43. kEthLinkIfTypeTwistedPair = 0x02,
  44. /** Optical fiber (e.g., 100Base-FX) */
  45. kEthLinkIfTypeOptical = 0x03,
  46. } CipEthLinkIfaceType;
  47. /** @brief Provide bit masks for the Interface Capability (#11) attribute's Capability Bits */
  48. typedef enum {
  49. /** Interface needs reset to activate attribute #6 */
  50. kEthLinkCapManualReset = 0x01,
  51. /** Interface supports link auto-negotiation */
  52. kEthLinkCapAutoNeg = 0x02,
  53. /** Interface supports link auto-crossover */
  54. kEthLinkCapAutoMDX = 0x04,
  55. /** Interface supports setting of Interface Control attribute(#6) */
  56. kEthLinkCapManualSpeed = 0x08,
  57. } CipEthLinkCapabilityBits;
  58. /** @brief Provide bit masks to select available speed / duplex combinations
  59. *
  60. * Keep the bit index of these bit masks in sync with the array index of the
  61. * matching speed / duplex structure in the internal @p speed_duplex_table
  62. * of cipethernetlink.c
  63. */
  64. typedef enum {
  65. kEthLinkSpeedDpx_10_HD = 0x01,
  66. kEthLinkSpeedDpx_10_FD = 0x02,
  67. kEthLinkSpeedDpx_100_HD = 0x04,
  68. kEthLinkSpeedDpx_100_FD = 0x08,
  69. kEthLinkSpeedDpx_1000_HD = 0x10,
  70. kEthLinkSpeedDpx_1000_FD = 0x20,
  71. } CipEthLinkSpeedDpxSelect;
  72. /** @brief Type definition to describe the Interface Capability
  73. *
  74. * This structure is not a direct representation of the Interface Capability
  75. * attribute (#11) but replaces the needed array of speed / duplex list entries
  76. * by @ref speed_duplex_selector to create the needed array on the fly.
  77. */
  78. typedef struct {
  79. /** Capability flags of CipEthLinkCapabilityBits group */
  80. CipDword capability_bits;
  81. /** Speed / duplex selector bit map of CipEthLinkSpeedDpxSelect */
  82. uint16_t speed_duplex_selector;
  83. } CipEthernetLinkMetaInterfaceCapability;
  84. #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
  85. /** @brief Type definition of the Interface Counters attribute #4
  86. *
  87. * This union holds the 32-bit Interface Counters of the Ethernet Link object.
  88. * This is attribute is becomes required if the HC Interface Counters attribute or
  89. * Media Counters attribute is implemented, otherwise highly recommended.
  90. * That means for DLR capable devices this attribute is required because the
  91. * Media Counters attribute is required for DLR capable devices.
  92. */
  93. typedef union {
  94. CipUdint cntr32[11];
  95. struct {
  96. CipUdint in_octets;
  97. CipUdint in_ucast;
  98. CipUdint in_nucast;
  99. CipUdint in_discards;
  100. CipUdint in_errors;
  101. CipUdint in_unknown_protos;
  102. CipUdint out_octets;
  103. CipUdint out_ucast;
  104. CipUdint out_nucast;
  105. CipUdint out_discards;
  106. CipUdint out_errors;
  107. } ul;
  108. } CipEthernetLinkInterfaceCounters;
  109. /** @brief Type definition of the Media Counters attribute #5
  110. *
  111. * This union holds the 32-bit Media Counters of the Ethernet Link object.
  112. * This attribute becomes required if the devices supports DLR or if the
  113. * HC Media Counters attribute is implemented, otherwise highly recommended.
  114. */
  115. typedef union {
  116. CipUdint cntr32[12];
  117. struct {
  118. CipUdint align_errs;
  119. CipUdint fcs_errs;
  120. CipUdint single_coll;
  121. CipUdint multi_coll;
  122. CipUdint sqe_test_errs;
  123. CipUdint def_trans;
  124. CipUdint late_coll;
  125. CipUdint exc_coll;
  126. CipUdint mac_tx_errs;
  127. CipUdint crs_errs;
  128. CipUdint frame_too_long;
  129. CipUdint mac_rx_errs;
  130. } ul;
  131. } CipEthernetLinkMediaCounters;
  132. #endif /* ... && OPENER_ETHLINK_CNTRS_ENABLE != 0 */
  133. /** @brief Type definition of the Interface Control attribute (#6)
  134. *
  135. */
  136. typedef struct {
  137. CipWord control_bits;
  138. CipUint forced_interface_speed;
  139. } CipEthernetLinkInterfaceControl;
  140. /** @brief Data of an CIP Ethernet Link object */
  141. typedef struct {
  142. EipUint32 interface_speed; /**< Attribute #1: 10/100/1000 Mbit/sec */
  143. EipUint32 interface_flags; /**< Attribute #2: Interface flags as defined in the CIP specification */
  144. EipUint8 physical_address[6]; /**< Attribute #3: MAC address of the Ethernet link */
  145. #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
  146. CipEthernetLinkInterfaceCounters interface_cntrs; /**< Attribute #4: Interface counters 32-bit wide */
  147. CipEthernetLinkMediaCounters media_cntrs; /**< Attribute #5: Media counters 32-bit wide */
  148. #endif
  149. #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
  150. 0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
  151. CipEthernetLinkInterfaceControl interface_control; /** Attribute #6: control link properties */
  152. #endif
  153. CipUsint interface_type; /**< Attribute #7: Type of interface */
  154. CipShortString interface_label; /**< Attribute #10: Interface label */
  155. CipEthernetLinkMetaInterfaceCapability interface_caps; /**< Attribute #11: Interface capabilities */
  156. } CipEthernetLinkObject;
  157. /* public functions */
  158. /** @brief Initialize the Ethernet Link Objects data
  159. *
  160. * @return kEipStatusOk if initialization was successful, otherwise kEipStatusError
  161. */
  162. EipStatus CipEthernetLinkInit(void);
  163. /** @brief Initialize the Ethernet MAC of the Ethernet Link object instances
  164. *
  165. * @param p_physical_address pointer to 6 bytes of MAC address
  166. *
  167. * This function sets the MAC address of all involved Ethernet Link objects.
  168. */
  169. void CipEthernetLinkSetMac(EipUint8 *p_physical_address);
  170. /* global object instance(s) */
  171. extern CipEthernetLinkObject g_ethernet_link[];
  172. #endif /* OPENER_CIPETHERNETLINK_H_*/