Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: EasyCAT_LAB_simple EasyCAT_LAB_very_simple EasyCAT_LAB
ethercateoe.h
00001 /* 00002 * Licensed under the GNU General Public License version 2 with exceptions. See 00003 * LICENSE file in the project root for full license information 00004 */ 00005 00006 /** \file 00007 * \brief 00008 * Headerfile for ethercatfoe.c 00009 */ 00010 00011 #ifndef _ethercateoe_ 00012 #define _ethercateoe_ 00013 00014 #ifdef __cplusplus 00015 extern "C" 00016 { 00017 #endif 00018 00019 #include <ethercattype.h> 00020 00021 /** DNS length according to ETG 1000.6 */ 00022 #define EOE_DNS_NAME_LENGTH 32 00023 /** Ethernet address length not including VLAN */ 00024 #define EOE_ETHADDR_LENGTH 6 00025 00026 #define EOE_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ 00027 ((uint32_t)((b) & 0xff) << 16) | \ 00028 ((uint32_t)((c) & 0xff) << 8) | \ 00029 (uint32_t)((d) & 0xff)) 00030 00031 #if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) 00032 00033 #define EOE_HTONS(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8)) 00034 #define EOE_NTOHS(x) EOE_HTONS(x) 00035 #define EOE_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \ 00036 (((x) & 0x0000ff00UL) << 8) | \ 00037 (((x) & 0x00ff0000UL) >> 8) | \ 00038 (((x) & 0xff000000UL) >> 24)) 00039 #define EOE_NTOHL(x) EOE_HTONL(x) 00040 #else 00041 #define EOE_HTONS(x) (x) 00042 #define EOE_NTOHS(x) (x) 00043 #define EOE_HTONL(x) (x) 00044 #define EOE_NTOHL(x) (x) 00045 #endif /* !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) */ 00046 00047 /** Get one byte from the 4-byte address */ 00048 #define eoe_ip4_addr1(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[0]) 00049 #define eoe_ip4_addr2(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[1]) 00050 #define eoe_ip4_addr3(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[2]) 00051 #define eoe_ip4_addr4(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[3]) 00052 00053 /** Set an IP address given by the four byte-parts */ 00054 #define EOE_IP4_ADDR_TO_U32(ipaddr,a,b,c,d) \ 00055 (ipaddr)->addr = EOE_HTONL(EOE_MAKEU32(a,b,c,d)) 00056 00057 /** Header frame info 1 */ 00058 #define EOE_HDR_FRAME_TYPE_OFFSET 0 00059 #define EOE_HDR_FRAME_TYPE (0xF << 0) 00060 #define EOE_HDR_FRAME_TYPE_SET(x) (((x) & 0xF) << 0) 00061 #define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF) 00062 #define EOE_HDR_FRAME_PORT_OFFSET 4 00063 #define EOE_HDR_FRAME_PORT (0xF << 4) 00064 #define EOE_HDR_FRAME_PORT_SET(x) (((x) & 0xF) << 4) 00065 #define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF) 00066 #define EOE_HDR_LAST_FRAGMENT_OFFSET 8 00067 #define EOE_HDR_LAST_FRAGMENT (0x1 << 8) 00068 #define EOE_HDR_LAST_FRAGMENT_SET(x) (((x) & 0x1) << 8) 00069 #define EOE_HDR_LAST_FRAGMENT_GET(x) (((x) >> 8) & 0x1) 00070 #define EOE_HDR_TIME_APPEND_OFFSET 9 00071 #define EOE_HDR_TIME_APPEND (0x1 << 9) 00072 #define EOE_HDR_TIME_APPEND_SET(x) (((x) & 0x1) << 9) 00073 #define EOE_HDR_TIME_APPEND_GET(x) (((x) >> 9) & 0x1) 00074 #define EOE_HDR_TIME_REQUEST_OFFSET 10 00075 #define EOE_HDR_TIME_REQUEST (0x1 << 10) 00076 #define EOE_HDR_TIME_REQUEST_SET(x) (((x) & 0x1) << 10) 00077 #define EOE_HDR_TIME_REQUEST_GET(x) (((x) >> 10) & 0x1) 00078 00079 /** Header frame info 2 */ 00080 #define EOE_HDR_FRAG_NO_OFFSET 0 00081 #define EOE_HDR_FRAG_NO (0x3F << 0) 00082 #define EOE_HDR_FRAG_NO_SET(x) (((x) & 0x3F) << 0) 00083 #define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F) 00084 #define EOE_HDR_FRAME_OFFSET_OFFSET 6 00085 #define EOE_HDR_FRAME_OFFSET (0x3F << 6) 00086 #define EOE_HDR_FRAME_OFFSET_SET(x) (((x) & 0x3F) << 6) 00087 #define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F) 00088 #define EOE_HDR_FRAME_NO_OFFSET 12 00089 #define EOE_HDR_FRAME_NO (0xF << 12) 00090 #define EOE_HDR_FRAME_NO_SET(x) (((x) & 0xF) << 12) 00091 #define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF) 00092 00093 /** EOE param */ 00094 #define EOE_PARAM_OFFSET 4 00095 #define EOE_PARAM_MAC_INCLUDE (0x1 << 0) 00096 #define EOE_PARAM_IP_INCLUDE (0x1 << 1) 00097 #define EOE_PARAM_SUBNET_IP_INCLUDE (0x1 << 2) 00098 #define EOE_PARAM_DEFAULT_GATEWAY_INCLUDE (0x1 << 3) 00099 #define EOE_PARAM_DNS_IP_INCLUDE (0x1 << 4) 00100 #define EOE_PARAM_DNS_NAME_INCLUDE (0x1 << 5) 00101 00102 /** EoE frame types */ 00103 #define EOE_FRAG_DATA 0 00104 #define EOE_INIT_RESP_TIMESTAMP 1 00105 #define EOE_INIT_REQ 2 /* Spec SET IP REQ */ 00106 #define EOE_INIT_RESP 3 /* Spec SET IP RESP */ 00107 #define EOE_SET_ADDR_FILTER_REQ 4 00108 #define EOE_SET_ADDR_FILTER_RESP 5 00109 #define EOE_GET_IP_PARAM_REQ 6 00110 #define EOE_GET_IP_PARAM_RESP 7 00111 #define EOE_GET_ADDR_FILTER_REQ 8 00112 #define EOE_GET_ADDR_FILTER_RESP 9 00113 00114 /** EoE parameter result codes */ 00115 #define EOE_RESULT_SUCCESS 0x0000 00116 #define EOE_RESULT_UNSPECIFIED_ERROR 0x0001 00117 #define EOE_RESULT_UNSUPPORTED_FRAME_TYPE 0x0002 00118 #define EOE_RESULT_NO_IP_SUPPORT 0x0201 00119 #define EOE_RESULT_NO_DHCP_SUPPORT 0x0202 00120 #define EOE_RESULT_NO_FILTER_SUPPORT 0x0401 00121 00122 00123 /** EOE ip4 address in network order */ 00124 typedef struct eoe_ip4_addr { 00125 uint32_t addr; 00126 }eoe_ip4_addr_t; 00127 00128 /** EOE ethernet address */ 00129 PACKED_BEGIN 00130 typedef struct PACKED eoe_ethaddr 00131 { 00132 uint8_t addr[EOE_ETHADDR_LENGTH]; 00133 } eoe_ethaddr_t; 00134 PACKED_END 00135 00136 /** EoE IP request structure, storage only, no need to pack */ 00137 typedef struct eoe_param 00138 { 00139 uint8_t mac_set : 1; 00140 uint8_t ip_set : 1; 00141 uint8_t subnet_set : 1; 00142 uint8_t default_gateway_set : 1; 00143 uint8_t dns_ip_set : 1; 00144 uint8_t dns_name_set : 1; 00145 eoe_ethaddr_t mac; 00146 eoe_ip4_addr_t ip; 00147 eoe_ip4_addr_t subnet; 00148 eoe_ip4_addr_t default_gateway; 00149 eoe_ip4_addr_t dns_ip; 00150 char dns_name[EOE_DNS_NAME_LENGTH]; 00151 } eoe_param_t; 00152 00153 /** EOE structure. 00154 * Used to interpret EoE mailbox packets. 00155 */ 00156 PACKED_BEGIN 00157 typedef struct PACKED 00158 { 00159 ec_mbxheadert mbxheader; 00160 uint16_t frameinfo1; 00161 union 00162 { 00163 uint16_t frameinfo2; 00164 uint16_t result; 00165 }; 00166 uint8 data[0]; 00167 } ec_EOEt; 00168 PACKED_END 00169 00170 int ecx_EOEdefinehook(ecx_contextt *context, void *hook); 00171 int ecx_EOEsetIp(ecx_contextt *context, 00172 uint16 slave, 00173 uint8 port, 00174 eoe_param_t * ipparam, 00175 int timeout); 00176 int ecx_EOEgetIp(ecx_contextt *context, 00177 uint16 slave, 00178 uint8 port, 00179 eoe_param_t * ipparam, 00180 int timeout); 00181 int ecx_EOEsend(ecx_contextt *context, 00182 uint16 slave, 00183 uint8 port, 00184 int psize, 00185 void *p, 00186 int timeout); 00187 int ecx_EOErecv(ecx_contextt *context, 00188 uint16 slave, 00189 uint8 port, 00190 int * psize, 00191 void *p, 00192 int timeout); 00193 int ecx_EOEreadfragment( 00194 ec_mbxbuft * MbxIn, 00195 uint8 * rxfragmentno, 00196 uint16 * rxframesize, 00197 uint16 * rxframeoffset, 00198 uint16 * rxframeno, 00199 int * psize, 00200 void *p); 00201 00202 #ifdef __cplusplus 00203 } 00204 #endif 00205 00206 #endif
Generated on Tue Jul 12 2022 18:21:13 by
