SOEM EtherCAT Master library for STM Nucleo F767ZI
Dependents: EasyCAT_LAB_simple EasyCAT_LAB_very_simple EasyCAT_LAB
- This repository contains the SOEM (Simple Open EtherCAT® Master) library by rt-labs, that has been ported in the
ecosystem by AB&T Tecnologie Informatiche.
- It has been developed for the EasyCAT LAB , a complete educational and experimental EtherCAT® system, composed of one master and two slaves .
- The EasyCAT LAB is provided as a kit by AB&T Tecnologie Informatiche, to allow everybody to have an educational EtherCAT® system up and running in a matter of minutes.
Warning
- Currently only the Nucleo STM32F767ZI board is supported.
SOEM/ethercattype.h@0:543d6784d4cc, 2019-06-11 (annotated)
- Committer:
- EasyCAT
- Date:
- Tue Jun 11 10:29:09 2019 +0000
- Revision:
- 0:543d6784d4cc
SOEM EtherCAT Master Library for STM Nucleo F767ZI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EasyCAT | 0:543d6784d4cc | 1 | /* |
EasyCAT | 0:543d6784d4cc | 2 | * Licensed under the GNU General Public License version 2 with exceptions. See |
EasyCAT | 0:543d6784d4cc | 3 | * LICENSE file in the project root for full license information |
EasyCAT | 0:543d6784d4cc | 4 | */ |
EasyCAT | 0:543d6784d4cc | 5 | |
EasyCAT | 0:543d6784d4cc | 6 | /** \file |
EasyCAT | 0:543d6784d4cc | 7 | * \brief |
EasyCAT | 0:543d6784d4cc | 8 | * General typedefs and defines for EtherCAT. |
EasyCAT | 0:543d6784d4cc | 9 | * |
EasyCAT | 0:543d6784d4cc | 10 | * Defines that could need optimisation for specific applications |
EasyCAT | 0:543d6784d4cc | 11 | * are the EC_TIMEOUTxxx. Assumptions for the standard settings are a |
EasyCAT | 0:543d6784d4cc | 12 | * standard linux PC or laptop and a wired connection to maximal 100 slaves. |
EasyCAT | 0:543d6784d4cc | 13 | * For use with wireless connections or lots of slaves the timeouts need |
EasyCAT | 0:543d6784d4cc | 14 | * increasing. For fast systems running Xenomai and RT-net or alike the |
EasyCAT | 0:543d6784d4cc | 15 | * timeouts need to be shorter. |
EasyCAT | 0:543d6784d4cc | 16 | */ |
EasyCAT | 0:543d6784d4cc | 17 | |
EasyCAT | 0:543d6784d4cc | 18 | #ifndef _EC_TYPE_H |
EasyCAT | 0:543d6784d4cc | 19 | #define _EC_TYPE_H |
EasyCAT | 0:543d6784d4cc | 20 | |
EasyCAT | 0:543d6784d4cc | 21 | #ifdef __cplusplus |
EasyCAT | 0:543d6784d4cc | 22 | extern "C" |
EasyCAT | 0:543d6784d4cc | 23 | { |
EasyCAT | 0:543d6784d4cc | 24 | #endif |
EasyCAT | 0:543d6784d4cc | 25 | |
EasyCAT | 0:543d6784d4cc | 26 | /** Define Little or Big endian target */ |
EasyCAT | 0:543d6784d4cc | 27 | #define EC_LITTLE_ENDIAN |
EasyCAT | 0:543d6784d4cc | 28 | |
EasyCAT | 0:543d6784d4cc | 29 | /** define EC_VER1 if version 1 default context and functions are needed |
EasyCAT | 0:543d6784d4cc | 30 | * comment if application uses only ecx_ functions and own context */ |
EasyCAT | 0:543d6784d4cc | 31 | #define EC_VER1 |
EasyCAT | 0:543d6784d4cc | 32 | |
EasyCAT | 0:543d6784d4cc | 33 | #include "osal.h" |
EasyCAT | 0:543d6784d4cc | 34 | |
EasyCAT | 0:543d6784d4cc | 35 | /** return value general error */ |
EasyCAT | 0:543d6784d4cc | 36 | #define EC_ERROR -3 |
EasyCAT | 0:543d6784d4cc | 37 | /** return value no frame returned */ |
EasyCAT | 0:543d6784d4cc | 38 | #define EC_NOFRAME -1 |
EasyCAT | 0:543d6784d4cc | 39 | /** return value unknown frame received */ |
EasyCAT | 0:543d6784d4cc | 40 | #define EC_OTHERFRAME -2 |
EasyCAT | 0:543d6784d4cc | 41 | /** maximum EtherCAT frame length in bytes */ |
EasyCAT | 0:543d6784d4cc | 42 | #define EC_MAXECATFRAME 1518 |
EasyCAT | 0:543d6784d4cc | 43 | /** maximum EtherCAT LRW frame length in bytes */ |
EasyCAT | 0:543d6784d4cc | 44 | /* MTU - Ethernet header - length - datagram header - WCK - FCS */ |
EasyCAT | 0:543d6784d4cc | 45 | #define EC_MAXLRWDATA (EC_MAXECATFRAME - 14 - 2 - 10 - 2 - 4) |
EasyCAT | 0:543d6784d4cc | 46 | /** size of DC datagram used in first LRW frame */ |
EasyCAT | 0:543d6784d4cc | 47 | #define EC_FIRSTDCDATAGRAM 20 |
EasyCAT | 0:543d6784d4cc | 48 | /** standard frame buffer size in bytes */ |
EasyCAT | 0:543d6784d4cc | 49 | #define EC_BUFSIZE EC_MAXECATFRAME |
EasyCAT | 0:543d6784d4cc | 50 | /** datagram type EtherCAT */ |
EasyCAT | 0:543d6784d4cc | 51 | #define EC_ECATTYPE 0x1000 |
EasyCAT | 0:543d6784d4cc | 52 | /** number of frame buffers per channel (tx, rx1 rx2) */ |
EasyCAT | 0:543d6784d4cc | 53 | #define EC_MAXBUF 16 |
EasyCAT | 0:543d6784d4cc | 54 | /** timeout value in us for tx frame to return to rx */ |
EasyCAT | 0:543d6784d4cc | 55 | //#define EC_TIMEOUTRET 2000 |
EasyCAT | 0:543d6784d4cc | 56 | |
EasyCAT | 0:543d6784d4cc | 57 | #define EC_TIMEOUTRET 500 //Changed: must be less than the CYCLE_TIME |
EasyCAT | 0:543d6784d4cc | 58 | |
EasyCAT | 0:543d6784d4cc | 59 | /** timeout value in us for safe data transfer, max. triple retry */ |
EasyCAT | 0:543d6784d4cc | 60 | #define EC_TIMEOUTRET3 (EC_TIMEOUTRET * 3) |
EasyCAT | 0:543d6784d4cc | 61 | /** timeout value in us for return "safe" variant (f.e. wireless) */ |
EasyCAT | 0:543d6784d4cc | 62 | #define EC_TIMEOUTSAFE 20000 |
EasyCAT | 0:543d6784d4cc | 63 | /** timeout value in us for EEPROM access */ |
EasyCAT | 0:543d6784d4cc | 64 | #define EC_TIMEOUTEEP 20000 |
EasyCAT | 0:543d6784d4cc | 65 | /** timeout value in us for tx mailbox cycle */ |
EasyCAT | 0:543d6784d4cc | 66 | #define EC_TIMEOUTTXM 20000 |
EasyCAT | 0:543d6784d4cc | 67 | /** timeout value in us for rx mailbox cycle */ |
EasyCAT | 0:543d6784d4cc | 68 | #define EC_TIMEOUTRXM 700000 |
EasyCAT | 0:543d6784d4cc | 69 | /** timeout value in us for check statechange */ |
EasyCAT | 0:543d6784d4cc | 70 | #define EC_TIMEOUTSTATE 2000000 |
EasyCAT | 0:543d6784d4cc | 71 | /** size of EEPROM bitmap cache */ |
EasyCAT | 0:543d6784d4cc | 72 | #define EC_MAXEEPBITMAP 128 |
EasyCAT | 0:543d6784d4cc | 73 | /** size of EEPROM cache buffer */ |
EasyCAT | 0:543d6784d4cc | 74 | #define EC_MAXEEPBUF EC_MAXEEPBITMAP << 5 |
EasyCAT | 0:543d6784d4cc | 75 | /** default number of retries if wkc <= 0 */ |
EasyCAT | 0:543d6784d4cc | 76 | #define EC_DEFAULTRETRIES 3 |
EasyCAT | 0:543d6784d4cc | 77 | /** default group size in 2^x */ |
EasyCAT | 0:543d6784d4cc | 78 | #define EC_LOGGROUPOFFSET 16 |
EasyCAT | 0:543d6784d4cc | 79 | |
EasyCAT | 0:543d6784d4cc | 80 | /** definition for frame buffers */ |
EasyCAT | 0:543d6784d4cc | 81 | typedef uint8 ec_bufT[EC_BUFSIZE]; |
EasyCAT | 0:543d6784d4cc | 82 | |
EasyCAT | 0:543d6784d4cc | 83 | /** ethernet header definition */ |
EasyCAT | 0:543d6784d4cc | 84 | PACKED_BEGIN |
EasyCAT | 0:543d6784d4cc | 85 | typedef struct PACKED |
EasyCAT | 0:543d6784d4cc | 86 | { |
EasyCAT | 0:543d6784d4cc | 87 | /** destination MAC */ |
EasyCAT | 0:543d6784d4cc | 88 | uint16 da0,da1,da2; |
EasyCAT | 0:543d6784d4cc | 89 | /** source MAC */ |
EasyCAT | 0:543d6784d4cc | 90 | uint16 sa0,sa1,sa2; |
EasyCAT | 0:543d6784d4cc | 91 | /** ethernet type */ |
EasyCAT | 0:543d6784d4cc | 92 | uint16 etype; |
EasyCAT | 0:543d6784d4cc | 93 | } ec_etherheadert; |
EasyCAT | 0:543d6784d4cc | 94 | PACKED_END |
EasyCAT | 0:543d6784d4cc | 95 | |
EasyCAT | 0:543d6784d4cc | 96 | /** ethernet header size */ |
EasyCAT | 0:543d6784d4cc | 97 | #define ETH_HEADERSIZE sizeof(ec_etherheadert) |
EasyCAT | 0:543d6784d4cc | 98 | |
EasyCAT | 0:543d6784d4cc | 99 | /** EtherCAT datagram header definition */ |
EasyCAT | 0:543d6784d4cc | 100 | PACKED_BEGIN |
EasyCAT | 0:543d6784d4cc | 101 | typedef struct PACKED |
EasyCAT | 0:543d6784d4cc | 102 | { |
EasyCAT | 0:543d6784d4cc | 103 | /** length of EtherCAT datagram */ |
EasyCAT | 0:543d6784d4cc | 104 | uint16 elength; |
EasyCAT | 0:543d6784d4cc | 105 | /** EtherCAT command, see ec_cmdtype */ |
EasyCAT | 0:543d6784d4cc | 106 | uint8 command; |
EasyCAT | 0:543d6784d4cc | 107 | /** index, used in SOEM for Tx to Rx recombination */ |
EasyCAT | 0:543d6784d4cc | 108 | uint8 index; |
EasyCAT | 0:543d6784d4cc | 109 | /** ADP */ |
EasyCAT | 0:543d6784d4cc | 110 | uint16 ADP; |
EasyCAT | 0:543d6784d4cc | 111 | /** ADO */ |
EasyCAT | 0:543d6784d4cc | 112 | uint16 ADO; |
EasyCAT | 0:543d6784d4cc | 113 | /** length of data portion in datagram */ |
EasyCAT | 0:543d6784d4cc | 114 | uint16 dlength; |
EasyCAT | 0:543d6784d4cc | 115 | /** interrupt, currently unused */ |
EasyCAT | 0:543d6784d4cc | 116 | uint16 irpt; |
EasyCAT | 0:543d6784d4cc | 117 | } ec_comt; |
EasyCAT | 0:543d6784d4cc | 118 | PACKED_END |
EasyCAT | 0:543d6784d4cc | 119 | |
EasyCAT | 0:543d6784d4cc | 120 | /** EtherCAT header size */ |
EasyCAT | 0:543d6784d4cc | 121 | #define EC_HEADERSIZE sizeof(ec_comt) |
EasyCAT | 0:543d6784d4cc | 122 | /** size of ec_comt.elength item in EtherCAT header */ |
EasyCAT | 0:543d6784d4cc | 123 | #define EC_ELENGTHSIZE sizeof(uint16) |
EasyCAT | 0:543d6784d4cc | 124 | /** offset position of command in EtherCAT header */ |
EasyCAT | 0:543d6784d4cc | 125 | #define EC_CMDOFFSET EC_ELENGTHSIZE |
EasyCAT | 0:543d6784d4cc | 126 | /** size of workcounter item in EtherCAT datagram */ |
EasyCAT | 0:543d6784d4cc | 127 | #define EC_WKCSIZE sizeof(uint16) |
EasyCAT | 0:543d6784d4cc | 128 | /** definition of datagram follows bit in ec_comt.dlength */ |
EasyCAT | 0:543d6784d4cc | 129 | #define EC_DATAGRAMFOLLOWS (1 << 15) |
EasyCAT | 0:543d6784d4cc | 130 | |
EasyCAT | 0:543d6784d4cc | 131 | /** Possible error codes returned. */ |
EasyCAT | 0:543d6784d4cc | 132 | typedef enum |
EasyCAT | 0:543d6784d4cc | 133 | { |
EasyCAT | 0:543d6784d4cc | 134 | /** No error */ |
EasyCAT | 0:543d6784d4cc | 135 | EC_ERR_OK = 0, |
EasyCAT | 0:543d6784d4cc | 136 | /** Library already initialized. */ |
EasyCAT | 0:543d6784d4cc | 137 | EC_ERR_ALREADY_INITIALIZED, |
EasyCAT | 0:543d6784d4cc | 138 | /** Library not initialized. */ |
EasyCAT | 0:543d6784d4cc | 139 | EC_ERR_NOT_INITIALIZED, |
EasyCAT | 0:543d6784d4cc | 140 | /** Timeout occurred during execution of the function. */ |
EasyCAT | 0:543d6784d4cc | 141 | EC_ERR_TIMEOUT, |
EasyCAT | 0:543d6784d4cc | 142 | /** No slaves were found. */ |
EasyCAT | 0:543d6784d4cc | 143 | EC_ERR_NO_SLAVES, |
EasyCAT | 0:543d6784d4cc | 144 | /** Function failed. */ |
EasyCAT | 0:543d6784d4cc | 145 | EC_ERR_NOK |
EasyCAT | 0:543d6784d4cc | 146 | } ec_err; |
EasyCAT | 0:543d6784d4cc | 147 | |
EasyCAT | 0:543d6784d4cc | 148 | /** Possible EtherCAT slave states */ |
EasyCAT | 0:543d6784d4cc | 149 | typedef enum |
EasyCAT | 0:543d6784d4cc | 150 | { |
EasyCAT | 0:543d6784d4cc | 151 | /** No valid state. */ |
EasyCAT | 0:543d6784d4cc | 152 | EC_STATE_NONE = 0x00, |
EasyCAT | 0:543d6784d4cc | 153 | /** Init state*/ |
EasyCAT | 0:543d6784d4cc | 154 | EC_STATE_INIT = 0x01, |
EasyCAT | 0:543d6784d4cc | 155 | /** Pre-operational. */ |
EasyCAT | 0:543d6784d4cc | 156 | EC_STATE_PRE_OP = 0x02, |
EasyCAT | 0:543d6784d4cc | 157 | /** Boot state*/ |
EasyCAT | 0:543d6784d4cc | 158 | EC_STATE_BOOT = 0x03, |
EasyCAT | 0:543d6784d4cc | 159 | /** Safe-operational. */ |
EasyCAT | 0:543d6784d4cc | 160 | EC_STATE_SAFE_OP = 0x04, |
EasyCAT | 0:543d6784d4cc | 161 | /** Operational */ |
EasyCAT | 0:543d6784d4cc | 162 | EC_STATE_OPERATIONAL = 0x08, |
EasyCAT | 0:543d6784d4cc | 163 | /** Error or ACK error */ |
EasyCAT | 0:543d6784d4cc | 164 | EC_STATE_ACK = 0x10, |
EasyCAT | 0:543d6784d4cc | 165 | EC_STATE_ERROR = 0x10 |
EasyCAT | 0:543d6784d4cc | 166 | } ec_state; |
EasyCAT | 0:543d6784d4cc | 167 | |
EasyCAT | 0:543d6784d4cc | 168 | /** Possible buffer states */ |
EasyCAT | 0:543d6784d4cc | 169 | typedef enum |
EasyCAT | 0:543d6784d4cc | 170 | { |
EasyCAT | 0:543d6784d4cc | 171 | /** Empty */ |
EasyCAT | 0:543d6784d4cc | 172 | EC_BUF_EMPTY = 0x00, |
EasyCAT | 0:543d6784d4cc | 173 | /** Allocated, but not filled */ |
EasyCAT | 0:543d6784d4cc | 174 | EC_BUF_ALLOC = 0x01, |
EasyCAT | 0:543d6784d4cc | 175 | /** Transmitted */ |
EasyCAT | 0:543d6784d4cc | 176 | EC_BUF_TX = 0x02, |
EasyCAT | 0:543d6784d4cc | 177 | /** Received, but not consumed */ |
EasyCAT | 0:543d6784d4cc | 178 | EC_BUF_RCVD = 0x03, |
EasyCAT | 0:543d6784d4cc | 179 | /** Cycle completed */ |
EasyCAT | 0:543d6784d4cc | 180 | EC_BUF_COMPLETE = 0x04 |
EasyCAT | 0:543d6784d4cc | 181 | } ec_bufstate; |
EasyCAT | 0:543d6784d4cc | 182 | |
EasyCAT | 0:543d6784d4cc | 183 | /** Ethercat data types */ |
EasyCAT | 0:543d6784d4cc | 184 | typedef enum |
EasyCAT | 0:543d6784d4cc | 185 | { |
EasyCAT | 0:543d6784d4cc | 186 | ECT_BOOLEAN = 0x0001, |
EasyCAT | 0:543d6784d4cc | 187 | ECT_INTEGER8 = 0x0002, |
EasyCAT | 0:543d6784d4cc | 188 | ECT_INTEGER16 = 0x0003, |
EasyCAT | 0:543d6784d4cc | 189 | ECT_INTEGER32 = 0x0004, |
EasyCAT | 0:543d6784d4cc | 190 | ECT_UNSIGNED8 = 0x0005, |
EasyCAT | 0:543d6784d4cc | 191 | ECT_UNSIGNED16 = 0x0006, |
EasyCAT | 0:543d6784d4cc | 192 | ECT_UNSIGNED32 = 0x0007, |
EasyCAT | 0:543d6784d4cc | 193 | ECT_REAL32 = 0x0008, |
EasyCAT | 0:543d6784d4cc | 194 | ECT_VISIBLE_STRING = 0x0009, |
EasyCAT | 0:543d6784d4cc | 195 | ECT_OCTET_STRING = 0x000A, |
EasyCAT | 0:543d6784d4cc | 196 | ECT_UNICODE_STRING = 0x000B, |
EasyCAT | 0:543d6784d4cc | 197 | ECT_TIME_OF_DAY = 0x000C, |
EasyCAT | 0:543d6784d4cc | 198 | ECT_TIME_DIFFERENCE = 0x000D, |
EasyCAT | 0:543d6784d4cc | 199 | ECT_DOMAIN = 0x000F, |
EasyCAT | 0:543d6784d4cc | 200 | ECT_INTEGER24 = 0x0010, |
EasyCAT | 0:543d6784d4cc | 201 | ECT_REAL64 = 0x0011, |
EasyCAT | 0:543d6784d4cc | 202 | ECT_INTEGER64 = 0x0015, |
EasyCAT | 0:543d6784d4cc | 203 | ECT_UNSIGNED24 = 0x0016, |
EasyCAT | 0:543d6784d4cc | 204 | ECT_UNSIGNED64 = 0x001B, |
EasyCAT | 0:543d6784d4cc | 205 | ECT_BIT1 = 0x0030, |
EasyCAT | 0:543d6784d4cc | 206 | ECT_BIT2 = 0x0031, |
EasyCAT | 0:543d6784d4cc | 207 | ECT_BIT3 = 0x0032, |
EasyCAT | 0:543d6784d4cc | 208 | ECT_BIT4 = 0x0033, |
EasyCAT | 0:543d6784d4cc | 209 | ECT_BIT5 = 0x0034, |
EasyCAT | 0:543d6784d4cc | 210 | ECT_BIT6 = 0x0035, |
EasyCAT | 0:543d6784d4cc | 211 | ECT_BIT7 = 0x0036, |
EasyCAT | 0:543d6784d4cc | 212 | ECT_BIT8 = 0x0037 |
EasyCAT | 0:543d6784d4cc | 213 | } ec_datatype; |
EasyCAT | 0:543d6784d4cc | 214 | |
EasyCAT | 0:543d6784d4cc | 215 | /** Ethercat command types */ |
EasyCAT | 0:543d6784d4cc | 216 | typedef enum |
EasyCAT | 0:543d6784d4cc | 217 | { |
EasyCAT | 0:543d6784d4cc | 218 | /** No operation */ |
EasyCAT | 0:543d6784d4cc | 219 | EC_CMD_NOP = 0x00, |
EasyCAT | 0:543d6784d4cc | 220 | /** Auto Increment Read */ |
EasyCAT | 0:543d6784d4cc | 221 | EC_CMD_APRD, |
EasyCAT | 0:543d6784d4cc | 222 | /** Auto Increment Write */ |
EasyCAT | 0:543d6784d4cc | 223 | EC_CMD_APWR, |
EasyCAT | 0:543d6784d4cc | 224 | /** Auto Increment Read Write */ |
EasyCAT | 0:543d6784d4cc | 225 | EC_CMD_APRW, |
EasyCAT | 0:543d6784d4cc | 226 | /** Configured Address Read */ |
EasyCAT | 0:543d6784d4cc | 227 | EC_CMD_FPRD, |
EasyCAT | 0:543d6784d4cc | 228 | /** Configured Address Write */ |
EasyCAT | 0:543d6784d4cc | 229 | EC_CMD_FPWR, |
EasyCAT | 0:543d6784d4cc | 230 | /** Configured Address Read Write */ |
EasyCAT | 0:543d6784d4cc | 231 | EC_CMD_FPRW, |
EasyCAT | 0:543d6784d4cc | 232 | /** Broadcast Read */ |
EasyCAT | 0:543d6784d4cc | 233 | EC_CMD_BRD, |
EasyCAT | 0:543d6784d4cc | 234 | /** Broadcast Write */ |
EasyCAT | 0:543d6784d4cc | 235 | EC_CMD_BWR, |
EasyCAT | 0:543d6784d4cc | 236 | /** Broadcast Read Write */ |
EasyCAT | 0:543d6784d4cc | 237 | EC_CMD_BRW, |
EasyCAT | 0:543d6784d4cc | 238 | /** Logical Memory Read */ |
EasyCAT | 0:543d6784d4cc | 239 | EC_CMD_LRD, |
EasyCAT | 0:543d6784d4cc | 240 | /** Logical Memory Write */ |
EasyCAT | 0:543d6784d4cc | 241 | EC_CMD_LWR, |
EasyCAT | 0:543d6784d4cc | 242 | /** Logical Memory Read Write */ |
EasyCAT | 0:543d6784d4cc | 243 | EC_CMD_LRW, |
EasyCAT | 0:543d6784d4cc | 244 | /** Auto Increment Read Multiple Write */ |
EasyCAT | 0:543d6784d4cc | 245 | EC_CMD_ARMW, |
EasyCAT | 0:543d6784d4cc | 246 | /** Configured Read Multiple Write */ |
EasyCAT | 0:543d6784d4cc | 247 | EC_CMD_FRMW |
EasyCAT | 0:543d6784d4cc | 248 | /** Reserved */ |
EasyCAT | 0:543d6784d4cc | 249 | } ec_cmdtype; |
EasyCAT | 0:543d6784d4cc | 250 | |
EasyCAT | 0:543d6784d4cc | 251 | /** Ethercat EEprom command types */ |
EasyCAT | 0:543d6784d4cc | 252 | typedef enum |
EasyCAT | 0:543d6784d4cc | 253 | { |
EasyCAT | 0:543d6784d4cc | 254 | /** No operation */ |
EasyCAT | 0:543d6784d4cc | 255 | EC_ECMD_NOP = 0x0000, |
EasyCAT | 0:543d6784d4cc | 256 | /** Read */ |
EasyCAT | 0:543d6784d4cc | 257 | EC_ECMD_READ = 0x0100, |
EasyCAT | 0:543d6784d4cc | 258 | /** Write */ |
EasyCAT | 0:543d6784d4cc | 259 | EC_ECMD_WRITE = 0x0201, |
EasyCAT | 0:543d6784d4cc | 260 | /** Reload */ |
EasyCAT | 0:543d6784d4cc | 261 | EC_ECMD_RELOAD = 0x0300 |
EasyCAT | 0:543d6784d4cc | 262 | } ec_ecmdtype; |
EasyCAT | 0:543d6784d4cc | 263 | |
EasyCAT | 0:543d6784d4cc | 264 | /** EEprom state machine read size */ |
EasyCAT | 0:543d6784d4cc | 265 | #define EC_ESTAT_R64 0x0040 |
EasyCAT | 0:543d6784d4cc | 266 | /** EEprom state machine busy flag */ |
EasyCAT | 0:543d6784d4cc | 267 | #define EC_ESTAT_BUSY 0x8000 |
EasyCAT | 0:543d6784d4cc | 268 | /** EEprom state machine error flag mask */ |
EasyCAT | 0:543d6784d4cc | 269 | #define EC_ESTAT_EMASK 0x7800 |
EasyCAT | 0:543d6784d4cc | 270 | /** EEprom state machine error acknowledge */ |
EasyCAT | 0:543d6784d4cc | 271 | #define EC_ESTAT_NACK 0x2000 |
EasyCAT | 0:543d6784d4cc | 272 | |
EasyCAT | 0:543d6784d4cc | 273 | /* Ethercat SSI (Slave Information Interface) */ |
EasyCAT | 0:543d6784d4cc | 274 | |
EasyCAT | 0:543d6784d4cc | 275 | /** Start address SII sections in Eeprom */ |
EasyCAT | 0:543d6784d4cc | 276 | #define ECT_SII_START 0x0040 |
EasyCAT | 0:543d6784d4cc | 277 | |
EasyCAT | 0:543d6784d4cc | 278 | enum |
EasyCAT | 0:543d6784d4cc | 279 | { |
EasyCAT | 0:543d6784d4cc | 280 | /** SII category strings */ |
EasyCAT | 0:543d6784d4cc | 281 | ECT_SII_STRING = 10, |
EasyCAT | 0:543d6784d4cc | 282 | /** SII category general */ |
EasyCAT | 0:543d6784d4cc | 283 | ECT_SII_GENERAL = 30, |
EasyCAT | 0:543d6784d4cc | 284 | /** SII category FMMU */ |
EasyCAT | 0:543d6784d4cc | 285 | ECT_SII_FMMU = 40, |
EasyCAT | 0:543d6784d4cc | 286 | /** SII category SM */ |
EasyCAT | 0:543d6784d4cc | 287 | ECT_SII_SM = 41, |
EasyCAT | 0:543d6784d4cc | 288 | /** SII category PDO */ |
EasyCAT | 0:543d6784d4cc | 289 | ECT_SII_PDO = 50 |
EasyCAT | 0:543d6784d4cc | 290 | }; |
EasyCAT | 0:543d6784d4cc | 291 | |
EasyCAT | 0:543d6784d4cc | 292 | /** Item offsets in SII general section */ |
EasyCAT | 0:543d6784d4cc | 293 | enum |
EasyCAT | 0:543d6784d4cc | 294 | { |
EasyCAT | 0:543d6784d4cc | 295 | ECT_SII_MANUF = 0x0008, |
EasyCAT | 0:543d6784d4cc | 296 | ECT_SII_ID = 0x000a, |
EasyCAT | 0:543d6784d4cc | 297 | ECT_SII_REV = 0x000c, |
EasyCAT | 0:543d6784d4cc | 298 | ECT_SII_BOOTRXMBX = 0x0014, |
EasyCAT | 0:543d6784d4cc | 299 | ECT_SII_BOOTTXMBX = 0x0016, |
EasyCAT | 0:543d6784d4cc | 300 | ECT_SII_MBXSIZE = 0x0019, |
EasyCAT | 0:543d6784d4cc | 301 | ECT_SII_TXMBXADR = 0x001a, |
EasyCAT | 0:543d6784d4cc | 302 | ECT_SII_RXMBXADR = 0x0018, |
EasyCAT | 0:543d6784d4cc | 303 | ECT_SII_MBXPROTO = 0x001c |
EasyCAT | 0:543d6784d4cc | 304 | }; |
EasyCAT | 0:543d6784d4cc | 305 | |
EasyCAT | 0:543d6784d4cc | 306 | /** Mailbox types definitions */ |
EasyCAT | 0:543d6784d4cc | 307 | enum |
EasyCAT | 0:543d6784d4cc | 308 | { |
EasyCAT | 0:543d6784d4cc | 309 | /** Error mailbox type */ |
EasyCAT | 0:543d6784d4cc | 310 | ECT_MBXT_ERR = 0x00, |
EasyCAT | 0:543d6784d4cc | 311 | /** ADS over EtherCAT mailbox type */ |
EasyCAT | 0:543d6784d4cc | 312 | ECT_MBXT_AOE, |
EasyCAT | 0:543d6784d4cc | 313 | /** Ethernet over EtherCAT mailbox type */ |
EasyCAT | 0:543d6784d4cc | 314 | ECT_MBXT_EOE, |
EasyCAT | 0:543d6784d4cc | 315 | /** CANopen over EtherCAT mailbox type */ |
EasyCAT | 0:543d6784d4cc | 316 | ECT_MBXT_COE, |
EasyCAT | 0:543d6784d4cc | 317 | /** File over EtherCAT mailbox type */ |
EasyCAT | 0:543d6784d4cc | 318 | ECT_MBXT_FOE, |
EasyCAT | 0:543d6784d4cc | 319 | /** Servo over EtherCAT mailbox type */ |
EasyCAT | 0:543d6784d4cc | 320 | ECT_MBXT_SOE, |
EasyCAT | 0:543d6784d4cc | 321 | /** Vendor over EtherCAT mailbox type */ |
EasyCAT | 0:543d6784d4cc | 322 | ECT_MBXT_VOE = 0x0f |
EasyCAT | 0:543d6784d4cc | 323 | }; |
EasyCAT | 0:543d6784d4cc | 324 | |
EasyCAT | 0:543d6784d4cc | 325 | /** CoE mailbox types */ |
EasyCAT | 0:543d6784d4cc | 326 | enum |
EasyCAT | 0:543d6784d4cc | 327 | { |
EasyCAT | 0:543d6784d4cc | 328 | ECT_COES_EMERGENCY = 0x01, |
EasyCAT | 0:543d6784d4cc | 329 | ECT_COES_SDOREQ, |
EasyCAT | 0:543d6784d4cc | 330 | ECT_COES_SDORES, |
EasyCAT | 0:543d6784d4cc | 331 | ECT_COES_TXPDO, |
EasyCAT | 0:543d6784d4cc | 332 | ECT_COES_RXPDO, |
EasyCAT | 0:543d6784d4cc | 333 | ECT_COES_TXPDO_RR, |
EasyCAT | 0:543d6784d4cc | 334 | ECT_COES_RXPDO_RR, |
EasyCAT | 0:543d6784d4cc | 335 | ECT_COES_SDOINFO |
EasyCAT | 0:543d6784d4cc | 336 | }; |
EasyCAT | 0:543d6784d4cc | 337 | |
EasyCAT | 0:543d6784d4cc | 338 | /** CoE SDO commands */ |
EasyCAT | 0:543d6784d4cc | 339 | enum |
EasyCAT | 0:543d6784d4cc | 340 | { |
EasyCAT | 0:543d6784d4cc | 341 | ECT_SDO_DOWN_INIT = 0x21, |
EasyCAT | 0:543d6784d4cc | 342 | ECT_SDO_DOWN_EXP = 0x23, |
EasyCAT | 0:543d6784d4cc | 343 | ECT_SDO_DOWN_INIT_CA = 0x31, |
EasyCAT | 0:543d6784d4cc | 344 | ECT_SDO_UP_REQ = 0x40, |
EasyCAT | 0:543d6784d4cc | 345 | ECT_SDO_UP_REQ_CA = 0x50, |
EasyCAT | 0:543d6784d4cc | 346 | ECT_SDO_SEG_UP_REQ = 0x60, |
EasyCAT | 0:543d6784d4cc | 347 | ECT_SDO_ABORT = 0x80 |
EasyCAT | 0:543d6784d4cc | 348 | }; |
EasyCAT | 0:543d6784d4cc | 349 | |
EasyCAT | 0:543d6784d4cc | 350 | /** CoE Object Description commands */ |
EasyCAT | 0:543d6784d4cc | 351 | enum |
EasyCAT | 0:543d6784d4cc | 352 | { |
EasyCAT | 0:543d6784d4cc | 353 | ECT_GET_ODLIST_REQ = 0x01, |
EasyCAT | 0:543d6784d4cc | 354 | ECT_GET_ODLIST_RES = 0x02, |
EasyCAT | 0:543d6784d4cc | 355 | ECT_GET_OD_REQ = 0x03, |
EasyCAT | 0:543d6784d4cc | 356 | ECT_GET_OD_RES = 0x04, |
EasyCAT | 0:543d6784d4cc | 357 | ECT_GET_OE_REQ = 0x05, |
EasyCAT | 0:543d6784d4cc | 358 | ECT_GET_OE_RES = 0x06, |
EasyCAT | 0:543d6784d4cc | 359 | ECT_SDOINFO_ERROR = 0x07 |
EasyCAT | 0:543d6784d4cc | 360 | }; |
EasyCAT | 0:543d6784d4cc | 361 | |
EasyCAT | 0:543d6784d4cc | 362 | /** FoE opcodes */ |
EasyCAT | 0:543d6784d4cc | 363 | enum |
EasyCAT | 0:543d6784d4cc | 364 | { |
EasyCAT | 0:543d6784d4cc | 365 | ECT_FOE_READ = 0x01, |
EasyCAT | 0:543d6784d4cc | 366 | ECT_FOE_WRITE, |
EasyCAT | 0:543d6784d4cc | 367 | ECT_FOE_DATA, |
EasyCAT | 0:543d6784d4cc | 368 | ECT_FOE_ACK, |
EasyCAT | 0:543d6784d4cc | 369 | ECT_FOE_ERROR, |
EasyCAT | 0:543d6784d4cc | 370 | ECT_FOE_BUSY |
EasyCAT | 0:543d6784d4cc | 371 | }; |
EasyCAT | 0:543d6784d4cc | 372 | |
EasyCAT | 0:543d6784d4cc | 373 | /** SoE opcodes */ |
EasyCAT | 0:543d6784d4cc | 374 | enum |
EasyCAT | 0:543d6784d4cc | 375 | { |
EasyCAT | 0:543d6784d4cc | 376 | ECT_SOE_READREQ = 0x01, |
EasyCAT | 0:543d6784d4cc | 377 | ECT_SOE_READRES, |
EasyCAT | 0:543d6784d4cc | 378 | ECT_SOE_WRITEREQ, |
EasyCAT | 0:543d6784d4cc | 379 | ECT_SOE_WRITERES, |
EasyCAT | 0:543d6784d4cc | 380 | ECT_SOE_NOTIFICATION, |
EasyCAT | 0:543d6784d4cc | 381 | ECT_SOE_EMERGENCY |
EasyCAT | 0:543d6784d4cc | 382 | }; |
EasyCAT | 0:543d6784d4cc | 383 | |
EasyCAT | 0:543d6784d4cc | 384 | /** Ethercat registers */ |
EasyCAT | 0:543d6784d4cc | 385 | enum |
EasyCAT | 0:543d6784d4cc | 386 | { |
EasyCAT | 0:543d6784d4cc | 387 | ECT_REG_TYPE = 0x0000, |
EasyCAT | 0:543d6784d4cc | 388 | ECT_REG_PORTDES = 0x0007, |
EasyCAT | 0:543d6784d4cc | 389 | ECT_REG_ESCSUP = 0x0008, |
EasyCAT | 0:543d6784d4cc | 390 | ECT_REG_STADR = 0x0010, |
EasyCAT | 0:543d6784d4cc | 391 | ECT_REG_ALIAS = 0x0012, |
EasyCAT | 0:543d6784d4cc | 392 | ECT_REG_DLCTL = 0x0100, |
EasyCAT | 0:543d6784d4cc | 393 | ECT_REG_DLPORT = 0x0101, |
EasyCAT | 0:543d6784d4cc | 394 | ECT_REG_DLALIAS = 0x0103, |
EasyCAT | 0:543d6784d4cc | 395 | ECT_REG_DLSTAT = 0x0110, |
EasyCAT | 0:543d6784d4cc | 396 | ECT_REG_ALCTL = 0x0120, |
EasyCAT | 0:543d6784d4cc | 397 | ECT_REG_ALSTAT = 0x0130, |
EasyCAT | 0:543d6784d4cc | 398 | ECT_REG_ALSTATCODE = 0x0134, |
EasyCAT | 0:543d6784d4cc | 399 | ECT_REG_PDICTL = 0x0140, |
EasyCAT | 0:543d6784d4cc | 400 | ECT_REG_IRQMASK = 0x0200, |
EasyCAT | 0:543d6784d4cc | 401 | ECT_REG_RXERR = 0x0300, |
EasyCAT | 0:543d6784d4cc | 402 | ECT_REG_FRXERR = 0x0308, |
EasyCAT | 0:543d6784d4cc | 403 | ECT_REG_EPUECNT = 0x030C, |
EasyCAT | 0:543d6784d4cc | 404 | ECT_REG_PECNT = 0x030D, |
EasyCAT | 0:543d6784d4cc | 405 | ECT_REG_PECODE = 0x030E, |
EasyCAT | 0:543d6784d4cc | 406 | ECT_REG_LLCNT = 0x0310, |
EasyCAT | 0:543d6784d4cc | 407 | ECT_REG_WDCNT = 0x0442, |
EasyCAT | 0:543d6784d4cc | 408 | ECT_REG_EEPCFG = 0x0500, |
EasyCAT | 0:543d6784d4cc | 409 | ECT_REG_EEPCTL = 0x0502, |
EasyCAT | 0:543d6784d4cc | 410 | ECT_REG_EEPSTAT = 0x0502, |
EasyCAT | 0:543d6784d4cc | 411 | ECT_REG_EEPADR = 0x0504, |
EasyCAT | 0:543d6784d4cc | 412 | ECT_REG_EEPDAT = 0x0508, |
EasyCAT | 0:543d6784d4cc | 413 | ECT_REG_FMMU0 = 0x0600, |
EasyCAT | 0:543d6784d4cc | 414 | ECT_REG_FMMU1 = ECT_REG_FMMU0 + 0x10, |
EasyCAT | 0:543d6784d4cc | 415 | ECT_REG_FMMU2 = ECT_REG_FMMU1 + 0x10, |
EasyCAT | 0:543d6784d4cc | 416 | ECT_REG_FMMU3 = ECT_REG_FMMU2 + 0x10, |
EasyCAT | 0:543d6784d4cc | 417 | ECT_REG_SM0 = 0x0800, |
EasyCAT | 0:543d6784d4cc | 418 | ECT_REG_SM1 = ECT_REG_SM0 + 0x08, |
EasyCAT | 0:543d6784d4cc | 419 | ECT_REG_SM2 = ECT_REG_SM1 + 0x08, |
EasyCAT | 0:543d6784d4cc | 420 | ECT_REG_SM3 = ECT_REG_SM2 + 0x08, |
EasyCAT | 0:543d6784d4cc | 421 | ECT_REG_SM0STAT = ECT_REG_SM0 + 0x05, |
EasyCAT | 0:543d6784d4cc | 422 | ECT_REG_SM1STAT = ECT_REG_SM1 + 0x05, |
EasyCAT | 0:543d6784d4cc | 423 | ECT_REG_SM1ACT = ECT_REG_SM1 + 0x06, |
EasyCAT | 0:543d6784d4cc | 424 | ECT_REG_SM1CONTR = ECT_REG_SM1 + 0x07, |
EasyCAT | 0:543d6784d4cc | 425 | ECT_REG_DCTIME0 = 0x0900, |
EasyCAT | 0:543d6784d4cc | 426 | ECT_REG_DCTIME1 = 0x0904, |
EasyCAT | 0:543d6784d4cc | 427 | ECT_REG_DCTIME2 = 0x0908, |
EasyCAT | 0:543d6784d4cc | 428 | ECT_REG_DCTIME3 = 0x090C, |
EasyCAT | 0:543d6784d4cc | 429 | ECT_REG_DCSYSTIME = 0x0910, |
EasyCAT | 0:543d6784d4cc | 430 | ECT_REG_DCSOF = 0x0918, |
EasyCAT | 0:543d6784d4cc | 431 | ECT_REG_DCSYSOFFSET = 0x0920, |
EasyCAT | 0:543d6784d4cc | 432 | ECT_REG_DCSYSDELAY = 0x0928, |
EasyCAT | 0:543d6784d4cc | 433 | ECT_REG_DCSYSDIFF = 0x092C, |
EasyCAT | 0:543d6784d4cc | 434 | ECT_REG_DCSPEEDCNT = 0x0930, |
EasyCAT | 0:543d6784d4cc | 435 | ECT_REG_DCTIMEFILT = 0x0934, |
EasyCAT | 0:543d6784d4cc | 436 | ECT_REG_DCCUC = 0x0980, |
EasyCAT | 0:543d6784d4cc | 437 | ECT_REG_DCSYNCACT = 0x0981, |
EasyCAT | 0:543d6784d4cc | 438 | ECT_REG_DCSTART0 = 0x0990, |
EasyCAT | 0:543d6784d4cc | 439 | ECT_REG_DCCYCLE0 = 0x09A0, |
EasyCAT | 0:543d6784d4cc | 440 | ECT_REG_DCCYCLE1 = 0x09A4 |
EasyCAT | 0:543d6784d4cc | 441 | }; |
EasyCAT | 0:543d6784d4cc | 442 | |
EasyCAT | 0:543d6784d4cc | 443 | /** standard SDO Sync Manager Communication Type */ |
EasyCAT | 0:543d6784d4cc | 444 | #define ECT_SDO_SMCOMMTYPE 0x1c00 |
EasyCAT | 0:543d6784d4cc | 445 | /** standard SDO PDO assignment */ |
EasyCAT | 0:543d6784d4cc | 446 | #define ECT_SDO_PDOASSIGN 0x1c10 |
EasyCAT | 0:543d6784d4cc | 447 | /** standard SDO RxPDO assignment */ |
EasyCAT | 0:543d6784d4cc | 448 | #define ECT_SDO_RXPDOASSIGN 0x1c12 |
EasyCAT | 0:543d6784d4cc | 449 | /** standard SDO TxPDO assignment */ |
EasyCAT | 0:543d6784d4cc | 450 | #define ECT_SDO_TXPDOASSIGN 0x1c13 |
EasyCAT | 0:543d6784d4cc | 451 | |
EasyCAT | 0:543d6784d4cc | 452 | /** Ethercat packet type */ |
EasyCAT | 0:543d6784d4cc | 453 | #define ETH_P_ECAT 0x88A4 |
EasyCAT | 0:543d6784d4cc | 454 | |
EasyCAT | 0:543d6784d4cc | 455 | /** Error types */ |
EasyCAT | 0:543d6784d4cc | 456 | typedef enum |
EasyCAT | 0:543d6784d4cc | 457 | { |
EasyCAT | 0:543d6784d4cc | 458 | EC_ERR_TYPE_SDO_ERROR = 0, |
EasyCAT | 0:543d6784d4cc | 459 | EC_ERR_TYPE_EMERGENCY = 1, |
EasyCAT | 0:543d6784d4cc | 460 | EC_ERR_TYPE_PACKET_ERROR = 3, |
EasyCAT | 0:543d6784d4cc | 461 | EC_ERR_TYPE_SDOINFO_ERROR = 4, |
EasyCAT | 0:543d6784d4cc | 462 | EC_ERR_TYPE_FOE_ERROR = 5, |
EasyCAT | 0:543d6784d4cc | 463 | EC_ERR_TYPE_FOE_BUF2SMALL = 6, |
EasyCAT | 0:543d6784d4cc | 464 | EC_ERR_TYPE_FOE_PACKETNUMBER = 7, |
EasyCAT | 0:543d6784d4cc | 465 | EC_ERR_TYPE_SOE_ERROR = 8, |
EasyCAT | 0:543d6784d4cc | 466 | EC_ERR_TYPE_MBX_ERROR = 9, |
EasyCAT | 0:543d6784d4cc | 467 | EC_ERR_TYPE_FOE_FILE_NOTFOUND = 10, |
EasyCAT | 0:543d6784d4cc | 468 | EC_ERR_TYPE_EOE_INVALID_RX_DATA = 11 |
EasyCAT | 0:543d6784d4cc | 469 | } ec_err_type; |
EasyCAT | 0:543d6784d4cc | 470 | |
EasyCAT | 0:543d6784d4cc | 471 | /** Struct to retrieve errors. */ |
EasyCAT | 0:543d6784d4cc | 472 | typedef struct |
EasyCAT | 0:543d6784d4cc | 473 | { |
EasyCAT | 0:543d6784d4cc | 474 | /** Time at which the error was generated. */ |
EasyCAT | 0:543d6784d4cc | 475 | ec_timet Time; |
EasyCAT | 0:543d6784d4cc | 476 | /** Signal bit, error set but not read */ |
EasyCAT | 0:543d6784d4cc | 477 | boolean Signal; |
EasyCAT | 0:543d6784d4cc | 478 | /** Slave number that generated the error */ |
EasyCAT | 0:543d6784d4cc | 479 | uint16 Slave; |
EasyCAT | 0:543d6784d4cc | 480 | /** CoE SDO index that generated the error */ |
EasyCAT | 0:543d6784d4cc | 481 | uint16 Index; |
EasyCAT | 0:543d6784d4cc | 482 | /** CoE SDO subindex that generated the error */ |
EasyCAT | 0:543d6784d4cc | 483 | uint8 SubIdx; |
EasyCAT | 0:543d6784d4cc | 484 | /** Type of error */ |
EasyCAT | 0:543d6784d4cc | 485 | ec_err_type Etype; |
EasyCAT | 0:543d6784d4cc | 486 | union |
EasyCAT | 0:543d6784d4cc | 487 | { |
EasyCAT | 0:543d6784d4cc | 488 | /** General abortcode */ |
EasyCAT | 0:543d6784d4cc | 489 | int32 AbortCode; |
EasyCAT | 0:543d6784d4cc | 490 | /** Specific error for Emergency mailbox */ |
EasyCAT | 0:543d6784d4cc | 491 | struct |
EasyCAT | 0:543d6784d4cc | 492 | { |
EasyCAT | 0:543d6784d4cc | 493 | uint16 ErrorCode; |
EasyCAT | 0:543d6784d4cc | 494 | uint8 ErrorReg; |
EasyCAT | 0:543d6784d4cc | 495 | uint8 b1; |
EasyCAT | 0:543d6784d4cc | 496 | uint16 w1; |
EasyCAT | 0:543d6784d4cc | 497 | uint16 w2; |
EasyCAT | 0:543d6784d4cc | 498 | }; |
EasyCAT | 0:543d6784d4cc | 499 | }; |
EasyCAT | 0:543d6784d4cc | 500 | } ec_errort; |
EasyCAT | 0:543d6784d4cc | 501 | |
EasyCAT | 0:543d6784d4cc | 502 | /** Helper macros */ |
EasyCAT | 0:543d6784d4cc | 503 | /** Macro to make a word from 2 bytes */ |
EasyCAT | 0:543d6784d4cc | 504 | #define MK_WORD(msb, lsb) ((((uint16)(msb))<<8) | (lsb)) |
EasyCAT | 0:543d6784d4cc | 505 | /** Macro to get hi byte of a word */ |
EasyCAT | 0:543d6784d4cc | 506 | #define HI_BYTE(w) ((w) >> 8) |
EasyCAT | 0:543d6784d4cc | 507 | /** Macro to get low byte of a word */ |
EasyCAT | 0:543d6784d4cc | 508 | #define LO_BYTE(w) ((w) & 0x00ff) |
EasyCAT | 0:543d6784d4cc | 509 | /** Macro to swap hi and low byte of a word */ |
EasyCAT | 0:543d6784d4cc | 510 | #define SWAP(w) ((((w)& 0xff00) >> 8) | (((w) & 0x00ff) << 8)) |
EasyCAT | 0:543d6784d4cc | 511 | /** Macro to get hi word of a dword */ |
EasyCAT | 0:543d6784d4cc | 512 | #define LO_WORD(l) ((l) & 0xffff) |
EasyCAT | 0:543d6784d4cc | 513 | /** Macro to get hi word of a dword */ |
EasyCAT | 0:543d6784d4cc | 514 | #define HI_WORD(l) ((l) >> 16) |
EasyCAT | 0:543d6784d4cc | 515 | |
EasyCAT | 0:543d6784d4cc | 516 | #define get_unaligned(ptr) \ |
EasyCAT | 0:543d6784d4cc | 517 | ({ __typeof__(*(ptr)) __tmp; memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; }) |
EasyCAT | 0:543d6784d4cc | 518 | |
EasyCAT | 0:543d6784d4cc | 519 | #define put_unaligned32(val, ptr) \ |
EasyCAT | 0:543d6784d4cc | 520 | (memcpy((ptr), &(val), 4)) |
EasyCAT | 0:543d6784d4cc | 521 | |
EasyCAT | 0:543d6784d4cc | 522 | #define put_unaligned64(val, ptr) \ |
EasyCAT | 0:543d6784d4cc | 523 | (memcpy((ptr), &(val), 8)) |
EasyCAT | 0:543d6784d4cc | 524 | |
EasyCAT | 0:543d6784d4cc | 525 | #if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) |
EasyCAT | 0:543d6784d4cc | 526 | |
EasyCAT | 0:543d6784d4cc | 527 | #define htoes(A) (A) |
EasyCAT | 0:543d6784d4cc | 528 | #define htoel(A) (A) |
EasyCAT | 0:543d6784d4cc | 529 | #define htoell(A) (A) |
EasyCAT | 0:543d6784d4cc | 530 | #define etohs(A) (A) |
EasyCAT | 0:543d6784d4cc | 531 | #define etohl(A) (A) |
EasyCAT | 0:543d6784d4cc | 532 | #define etohll(A) (A) |
EasyCAT | 0:543d6784d4cc | 533 | |
EasyCAT | 0:543d6784d4cc | 534 | #elif !defined(EC_LITTLE_ENDIAN) && defined(EC_BIG_ENDIAN) |
EasyCAT | 0:543d6784d4cc | 535 | |
EasyCAT | 0:543d6784d4cc | 536 | #define htoes(A) ((((uint16)(A) & 0xff00) >> 8) | \ |
EasyCAT | 0:543d6784d4cc | 537 | (((uint16)(A) & 0x00ff) << 8)) |
EasyCAT | 0:543d6784d4cc | 538 | #define htoel(A) ((((uint32)(A) & 0xff000000) >> 24) | \ |
EasyCAT | 0:543d6784d4cc | 539 | (((uint32)(A) & 0x00ff0000) >> 8) | \ |
EasyCAT | 0:543d6784d4cc | 540 | (((uint32)(A) & 0x0000ff00) << 8) | \ |
EasyCAT | 0:543d6784d4cc | 541 | (((uint32)(A) & 0x000000ff) << 24)) |
EasyCAT | 0:543d6784d4cc | 542 | #define htoell(A) ((((uint64)(A) & (uint64)0xff00000000000000ULL) >> 56) | \ |
EasyCAT | 0:543d6784d4cc | 543 | (((uint64)(A) & (uint64)0x00ff000000000000ULL) >> 40) | \ |
EasyCAT | 0:543d6784d4cc | 544 | (((uint64)(A) & (uint64)0x0000ff0000000000ULL) >> 24) | \ |
EasyCAT | 0:543d6784d4cc | 545 | (((uint64)(A) & (uint64)0x000000ff00000000ULL) >> 8) | \ |
EasyCAT | 0:543d6784d4cc | 546 | (((uint64)(A) & (uint64)0x00000000ff000000ULL) << 8) | \ |
EasyCAT | 0:543d6784d4cc | 547 | (((uint64)(A) & (uint64)0x0000000000ff0000ULL) << 24) | \ |
EasyCAT | 0:543d6784d4cc | 548 | (((uint64)(A) & (uint64)0x000000000000ff00ULL) << 40) | \ |
EasyCAT | 0:543d6784d4cc | 549 | (((uint64)(A) & (uint64)0x00000000000000ffULL) << 56)) |
EasyCAT | 0:543d6784d4cc | 550 | |
EasyCAT | 0:543d6784d4cc | 551 | #define etohs htoes |
EasyCAT | 0:543d6784d4cc | 552 | #define etohl htoel |
EasyCAT | 0:543d6784d4cc | 553 | #define etohll htoell |
EasyCAT | 0:543d6784d4cc | 554 | |
EasyCAT | 0:543d6784d4cc | 555 | #else |
EasyCAT | 0:543d6784d4cc | 556 | |
EasyCAT | 0:543d6784d4cc | 557 | #error "Must define one of EC_BIG_ENDIAN or EC_LITTLE_ENDIAN" |
EasyCAT | 0:543d6784d4cc | 558 | |
EasyCAT | 0:543d6784d4cc | 559 | #endif |
EasyCAT | 0:543d6784d4cc | 560 | |
EasyCAT | 0:543d6784d4cc | 561 | #ifdef __cplusplus |
EasyCAT | 0:543d6784d4cc | 562 | } |
EasyCAT | 0:543d6784d4cc | 563 | #endif |
EasyCAT | 0:543d6784d4cc | 564 | |
EasyCAT | 0:543d6784d4cc | 565 | #endif /* _EC_TYPE_H */ |