Yang Zhang / EasyCAT_lib
Committer:
neeyoo
Date:
Mon Oct 04 15:02:35 2021 +0000
Revision:
4:66867fae2256
Parent:
0:7816b38c99cc
11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EasyCAT 0:7816b38c99cc 1 //********************************************************************************************
EasyCAT 0:7816b38c99cc 2 // *
EasyCAT 0:7816b38c99cc 3 // AB&T Tecnologie Informatiche - Ivrea Italy *
EasyCAT 0:7816b38c99cc 4 // http://www.bausano.net *
EasyCAT 0:7816b38c99cc 5 // https://www.ethercat.org/en/products/791FFAA126AD43859920EA64384AD4FD.htm *
EasyCAT 0:7816b38c99cc 6 // *
EasyCAT 0:7816b38c99cc 7 //********************************************************************************************
EasyCAT 0:7816b38c99cc 8 // *
EasyCAT 0:7816b38c99cc 9 // This software is distributed as an example, in the hope that it could be useful, *
EasyCAT 0:7816b38c99cc 10 // WITHOUT ANY WARRANTY, even the implied warranty of FITNESS FOR A PARTICULAR PURPOSE *
EasyCAT 0:7816b38c99cc 11 // *
EasyCAT 0:7816b38c99cc 12 //********************************************************************************************
EasyCAT 0:7816b38c99cc 13
EasyCAT 0:7816b38c99cc 14
EasyCAT 0:7816b38c99cc 15 //----- EasyCAT library for mbed boards 170912 ----------------------------------------------
EasyCAT 0:7816b38c99cc 16 //----- Derived from the AB&T EasyCAT Arduino shield library V 1.5 --------------------------
EasyCAT 0:7816b38c99cc 17
EasyCAT 0:7816b38c99cc 18 //----- Tested with the STM32 NUCLEO-F767ZI board -------------------------------------------
EasyCAT 0:7816b38c99cc 19
EasyCAT 0:7816b38c99cc 20
EasyCAT 0:7816b38c99cc 21
EasyCAT 0:7816b38c99cc 22
EasyCAT 0:7816b38c99cc 23 #ifndef EasyCAT_H
EasyCAT 0:7816b38c99cc 24 #define EasyCAT_H
EasyCAT 0:7816b38c99cc 25
EasyCAT 0:7816b38c99cc 26
EasyCAT 0:7816b38c99cc 27
EasyCAT 0:7816b38c99cc 28
EasyCAT 0:7816b38c99cc 29 //****** PDO configuration parameters ********************************************************
EasyCAT 0:7816b38c99cc 30
EasyCAT 0:7816b38c99cc 31 // Here we can define how many I/O bytes our EasyCAT can exchange
EasyCAT 0:7816b38c99cc 32
EasyCAT 0:7816b38c99cc 33 // We can use STANDARD MODE or CUSTOM MODE
EasyCAT 0:7816b38c99cc 34 // !!! Warning: CUSTOM MODE is recommended only for advanced users !!!
EasyCAT 0:7816b38c99cc 35
EasyCAT 0:7816b38c99cc 36 // In STANDARD MODE the EasyCAT exchanges a fixed number of bytes
EasyCAT 0:7816b38c99cc 37 // in input and in output
EasyCAT 0:7816b38c99cc 38 // The number of bytes in input are equal to the number of bytes in output
EasyCAT 0:7816b38c99cc 39 // Valid values are 16, 32, 64, 128
EasyCAT 0:7816b38c99cc 40 //
EasyCAT 0:7816b38c99cc 41 // The configuration EEPROM on board of the EasyCAT must be
EasyCAT 0:7816b38c99cc 42 // loaded with the corresponding bin file, provided by AB&T
EasyCAT 0:7816b38c99cc 43 //
EasyCAT 0:7816b38c99cc 44 // The EasyCAT is shipped configured for 32+32 bytes I.E. with
EasyCAT 0:7816b38c99cc 45 // the "EasyCAT_32_32.bin" file loaded into the configuration EEPROM
EasyCAT 0:7816b38c99cc 46
EasyCAT 0:7816b38c99cc 47
EasyCAT 0:7816b38c99cc 48 //-- BYTE_NUM ----------- Byte exchanged ------ Config EEPROM file
EasyCAT 0:7816b38c99cc 49
EasyCAT 0:7816b38c99cc 50 //#define BYTE_NUM 16 // 16 + 16 EasyCAT_16_16.bin
neeyoo 4:66867fae2256 51 //#define BYTE_NUM 32 // 32 + 32 EasyCAT_32_32.bin
EasyCAT 0:7816b38c99cc 52 //#define BYTE_NUM 64 // 64 + 64 EasyCAT_64_64.bin
EasyCAT 0:7816b38c99cc 53 //#define BYTE_NUM 128 // 128 + 128 EasyCAT_128_128.bin
EasyCAT 0:7816b38c99cc 54
EasyCAT 0:7816b38c99cc 55
EasyCAT 0:7816b38c99cc 56
EasyCAT 0:7816b38c99cc 57 // In CUSTOM MODE, recommended only for advanced users, the EasyCAT exchanges
EasyCAT 0:7816b38c99cc 58 // a configurable number of bytes, between 0 and 128, in input and in output
EasyCAT 0:7816b38c99cc 59 // The number of bytes in input and in output can be different
EasyCAT 0:7816b38c99cc 60 //
EasyCAT 0:7816b38c99cc 61 // The configuration EEPROM on board of the EasyCAT must be
EasyCAT 0:7816b38c99cc 62 // loaded with a suitable bin file, provided by the user
EasyCAT 0:7816b38c99cc 63 // or with the "EasyCAT_configurable.bin" file provided by AB&T
EasyCAT 0:7816b38c99cc 64
EasyCAT 0:7816b38c99cc 65 // Comment all the above BYTE_NUM #define for the STANDARD MODE
EasyCAT 0:7816b38c99cc 66 // and define here the custom number of exchanged bytes
EasyCAT 0:7816b38c99cc 67
EasyCAT 0:7816b38c99cc 68 //----- CUSTOM_MODE example -------
EasyCAT 0:7816b38c99cc 69 //
neeyoo 4:66867fae2256 70 #define CUST_BYTE_NUM_OUT 0 // total number of bytes in output
neeyoo 4:66867fae2256 71 #define CUST_BYTE_NUM_IN 60 // total number of bytes in input
EasyCAT 0:7816b38c99cc 72
EasyCAT 0:7816b38c99cc 73 // We can also customize names and data types for the PDOs
EasyCAT 0:7816b38c99cc 74 // see the example in this file (look for tag "Custom data types example")
EasyCAT 0:7816b38c99cc 75
EasyCAT 0:7816b38c99cc 76 //*************************************************************************************
EasyCAT 0:7816b38c99cc 77
EasyCAT 0:7816b38c99cc 78
EasyCAT 0:7816b38c99cc 79
EasyCAT 0:7816b38c99cc 80 //-- the preprocessor calculates the parameters necessary to transfer out data ---
EasyCAT 0:7816b38c99cc 81
EasyCAT 0:7816b38c99cc 82 // define TOT_BYTE_NUM_OUT as the total
EasyCAT 0:7816b38c99cc 83 // number of byte you need to
EasyCAT 0:7816b38c99cc 84 // transfer in output (between 0 and 128)
EasyCAT 0:7816b38c99cc 85 // this must match your ESI XML
EasyCAT 0:7816b38c99cc 86
EasyCAT 0:7816b38c99cc 87 #ifdef BYTE_NUM
EasyCAT 0:7816b38c99cc 88 #define TOT_BYTE_NUM_OUT BYTE_NUM // bytes in output
EasyCAT 0:7816b38c99cc 89 #else
EasyCAT 0:7816b38c99cc 90 #define TOT_BYTE_NUM_OUT CUST_BYTE_NUM_OUT // any number between 0 and 128
EasyCAT 0:7816b38c99cc 91 #endif
EasyCAT 0:7816b38c99cc 92
EasyCAT 0:7816b38c99cc 93
EasyCAT 0:7816b38c99cc 94 #if ((TOT_BYTE_NUM_OUT & 0x03) != 0x00) // number of bytes in output
EasyCAT 0:7816b38c99cc 95 #define TOT_BYTE_NUM_ROUND_OUT ((TOT_BYTE_NUM_OUT | 0x03) + 1)
EasyCAT 0:7816b38c99cc 96 #else // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 97 #define TOT_BYTE_NUM_ROUND_OUT TOT_BYTE_NUM_OUT //
EasyCAT 0:7816b38c99cc 98 #endif //
EasyCAT 0:7816b38c99cc 99
EasyCAT 0:7816b38c99cc 100 #if TOT_BYTE_NUM_OUT > 64 // if we have more then 64 bytes
EasyCAT 0:7816b38c99cc 101 // we have to split the transfer in two
EasyCAT 0:7816b38c99cc 102
EasyCAT 0:7816b38c99cc 103 #define SEC_BYTE_NUM_OUT (TOT_BYTE_NUM_OUT - 64) // number of bytes of the second transfer
EasyCAT 0:7816b38c99cc 104
EasyCAT 0:7816b38c99cc 105 #if ((SEC_BYTE_NUM_OUT & 0x03) != 0x00) // number of bytes of the second transfer
EasyCAT 0:7816b38c99cc 106 #define SEC_BYTE_NUM_ROUND_OUT ((SEC_BYTE_NUM_OUT | 0x03) + 1)
EasyCAT 0:7816b38c99cc 107 #else // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 108 #define SEC_BYTE_NUM_ROUND_OUT SEC_BYTE_NUM_OUT//
EasyCAT 0:7816b38c99cc 109 #endif //
EasyCAT 0:7816b38c99cc 110
EasyCAT 0:7816b38c99cc 111 #define SEC_LONG_NUM_OUT SEC_BYTE_NUM_ROUND_OUT/4// number of long of the second transfer
EasyCAT 0:7816b38c99cc 112
EasyCAT 0:7816b38c99cc 113 #define FST_BYTE_NUM_OUT 64 // number of bytes of the first transfer
EasyCAT 0:7816b38c99cc 114 #define FST_BYTE_NUM_ROUND_OUT 64 // number of bytes of the first transfer
EasyCAT 0:7816b38c99cc 115 // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 116 #define FST_LONG_NUM_OUT 16 // number of long of the second transfer
EasyCAT 0:7816b38c99cc 117
EasyCAT 0:7816b38c99cc 118
EasyCAT 0:7816b38c99cc 119 #else // if we have 64 bytes max we tranfert
EasyCAT 0:7816b38c99cc 120 // them in just one round
EasyCAT 0:7816b38c99cc 121
EasyCAT 0:7816b38c99cc 122 #define FST_BYTE_NUM_OUT TOT_BYTE_NUM_OUT // number of bytes of the first and only transfer
EasyCAT 0:7816b38c99cc 123
EasyCAT 0:7816b38c99cc 124 #if ((FST_BYTE_NUM_OUT & 0x03) != 0x00) // number of bytes of the first and only transfer
EasyCAT 0:7816b38c99cc 125 #define FST_BYTE_NUM_ROUND_OUT ((FST_BYTE_NUM_OUT | 0x03) + 1)
EasyCAT 0:7816b38c99cc 126 #else // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 127 #define FST_BYTE_NUM_ROUND_OUT FST_BYTE_NUM_OUT
EasyCAT 0:7816b38c99cc 128 #endif
EasyCAT 0:7816b38c99cc 129
EasyCAT 0:7816b38c99cc 130 #define FST_LONG_NUM_OUT FST_BYTE_NUM_ROUND_OUT/4// number of long of the first and only transfer
EasyCAT 0:7816b38c99cc 131
EasyCAT 0:7816b38c99cc 132 #define SEC_BYTE_NUM_OUT 0 // we don't use the second round
EasyCAT 0:7816b38c99cc 133 #define SEC_BYTE_NUM_ROUND_OUT 0 //
EasyCAT 0:7816b38c99cc 134 #define SEC_LONG_NUM_OUT 0 //
EasyCAT 0:7816b38c99cc 135
EasyCAT 0:7816b38c99cc 136 #endif
EasyCAT 0:7816b38c99cc 137
EasyCAT 0:7816b38c99cc 138
EasyCAT 0:7816b38c99cc 139 //-- the preprocessor calculates the parameters necessary to transfer in data ---
EasyCAT 0:7816b38c99cc 140
EasyCAT 0:7816b38c99cc 141 // define TOT_BYTE_NUM_IN the total
EasyCAT 0:7816b38c99cc 142 // number of byte you need to
EasyCAT 0:7816b38c99cc 143 // transfer in input (between 0 and 128)
EasyCAT 0:7816b38c99cc 144
EasyCAT 0:7816b38c99cc 145 #ifdef BYTE_NUM
EasyCAT 0:7816b38c99cc 146 #define TOT_BYTE_NUM_IN BYTE_NUM // bytes in input
EasyCAT 0:7816b38c99cc 147 #else
EasyCAT 0:7816b38c99cc 148 #define TOT_BYTE_NUM_IN CUST_BYTE_NUM_IN // any number between 0 and 128
EasyCAT 0:7816b38c99cc 149 #endif
EasyCAT 0:7816b38c99cc 150
EasyCAT 0:7816b38c99cc 151
EasyCAT 0:7816b38c99cc 152 #if ((TOT_BYTE_NUM_IN & 0x03) != 0x00) // number of bytes in output
EasyCAT 0:7816b38c99cc 153 #define TOT_BYTE_NUM_ROUND_IN ((TOT_BYTE_NUM_IN | 0x03) + 1)
EasyCAT 0:7816b38c99cc 154 #else // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 155 #define TOT_BYTE_NUM_ROUND_IN TOT_BYTE_NUM_IN //
EasyCAT 0:7816b38c99cc 156 #endif //
EasyCAT 0:7816b38c99cc 157
EasyCAT 0:7816b38c99cc 158 #if TOT_BYTE_NUM_IN > 64 // if we have more then 64 bytes
EasyCAT 0:7816b38c99cc 159 // we have to split the transfer in two
EasyCAT 0:7816b38c99cc 160
EasyCAT 0:7816b38c99cc 161 #define SEC_BYTE_NUM_IN (TOT_BYTE_NUM_IN - 64) // number of bytes of the second transfer
EasyCAT 0:7816b38c99cc 162
EasyCAT 0:7816b38c99cc 163 #if ((SEC_BYTE_NUM_IN & 0x03) != 0x00) // number of bytes of the second transfer
EasyCAT 0:7816b38c99cc 164 #define SEC_BYTE_NUM_ROUND_IN ((SEC_BYTE_NUM_IN | 0x03) + 1)
EasyCAT 0:7816b38c99cc 165 #else // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 166 #define SEC_BYTE_NUM_ROUND_IN SEC_BYTE_NUM_IN //
EasyCAT 0:7816b38c99cc 167 #endif //
EasyCAT 0:7816b38c99cc 168
EasyCAT 0:7816b38c99cc 169 #define SEC_LONG_NUM_IN SEC_BYTE_NUM_ROUND_IN/4 // number of long of the second transfer
EasyCAT 0:7816b38c99cc 170
EasyCAT 0:7816b38c99cc 171 #define FST_BYTE_NUM_IN 64 // number of bytes of the first transfer
EasyCAT 0:7816b38c99cc 172 #define FST_BYTE_NUM_ROUND_IN 64 // number of bytes of the first transfer
EasyCAT 0:7816b38c99cc 173 // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 174 #define FST_LONG_NUM_IN 16 // number of long of the second transfer
EasyCAT 0:7816b38c99cc 175
EasyCAT 0:7816b38c99cc 176
EasyCAT 0:7816b38c99cc 177 #else // if we have 64 bytes max we tranfert
EasyCAT 0:7816b38c99cc 178 // them in just one round
EasyCAT 0:7816b38c99cc 179
EasyCAT 0:7816b38c99cc 180 #define FST_BYTE_NUM_IN TOT_BYTE_NUM_IN // number of bytes of the first and only transfer
EasyCAT 0:7816b38c99cc 181
EasyCAT 0:7816b38c99cc 182 #if ((FST_BYTE_NUM_IN & 0x03) != 0x00) // number of bytes of the first and only transfer
EasyCAT 0:7816b38c99cc 183 #define FST_BYTE_NUM_ROUND_IN ((FST_BYTE_NUM_IN | 0x03) + 1)
EasyCAT 0:7816b38c99cc 184 #else // rounded to 4 (long)
EasyCAT 0:7816b38c99cc 185 #define FST_BYTE_NUM_ROUND_IN FST_BYTE_NUM_IN
EasyCAT 0:7816b38c99cc 186 #endif
EasyCAT 0:7816b38c99cc 187
EasyCAT 0:7816b38c99cc 188 #define FST_LONG_NUM_IN FST_BYTE_NUM_ROUND_IN/4 // number of long of the first and only transfer
EasyCAT 0:7816b38c99cc 189
EasyCAT 0:7816b38c99cc 190 #define SEC_BYTE_NUM_IN 0 // we don't use the second round
EasyCAT 0:7816b38c99cc 191 #define SEC_BYTE_NUM_ROUND_IN 0 //
EasyCAT 0:7816b38c99cc 192 #define SEC_LONG_NUM_IN 0 //
EasyCAT 0:7816b38c99cc 193
EasyCAT 0:7816b38c99cc 194 #endif
EasyCAT 0:7816b38c99cc 195
EasyCAT 0:7816b38c99cc 196
EasyCAT 0:7816b38c99cc 197 //---------------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 198
EasyCAT 0:7816b38c99cc 199 //----------------- sanity check -------------------------------------------------------
EasyCAT 0:7816b38c99cc 200
EasyCAT 0:7816b38c99cc 201
EasyCAT 0:7816b38c99cc 202 #ifdef BYTE_NUM // STANDARD MODE and CUSTOM MODE
EasyCAT 0:7816b38c99cc 203 // cannot be defined at the same time
EasyCAT 0:7816b38c99cc 204 #ifdef CUST_BYTE_NUM_OUT
EasyCAT 0:7816b38c99cc 205 #error "BYTE_NUM and CUST_BYTE_NUM_OUT cannot be defined at the same time !!!!"
EasyCAT 0:7816b38c99cc 206 #error "define them correctly in file EasyCAT.h"
EasyCAT 0:7816b38c99cc 207 #endif
EasyCAT 0:7816b38c99cc 208
EasyCAT 0:7816b38c99cc 209 #ifdef CUST_BYTE_NUM_IN
EasyCAT 0:7816b38c99cc 210 #error "BYTE_NUM and CUST_BYTE_NUM_IN cannot be defined at the same time !!!!"
EasyCAT 0:7816b38c99cc 211 #error "define them correctly in file EasyCAT.h"
EasyCAT 0:7816b38c99cc 212 #endif
EasyCAT 0:7816b38c99cc 213 #endif
EasyCAT 0:7816b38c99cc 214
EasyCAT 0:7816b38c99cc 215 #ifdef BYTE_NUM //--- for BYTE_NUM we accept only 16 32 64 128 --
EasyCAT 0:7816b38c99cc 216
EasyCAT 0:7816b38c99cc 217 #if ((BYTE_NUM !=16) && (BYTE_NUM !=32) && (BYTE_NUM !=64) && (BYTE_NUM !=128))
EasyCAT 0:7816b38c99cc 218 #error "BYTE_NUM must be 16, 32, 64 or 128 !!! define it correctly in file EasyCAT.h"
EasyCAT 0:7816b38c99cc 219 #endif
EasyCAT 0:7816b38c99cc 220
EasyCAT 0:7816b38c99cc 221 #else
EasyCAT 0:7816b38c99cc 222 //--- CUST_BYTE_NUM_OUT and CUST_BYTE_NUM_IN --------
EasyCAT 0:7816b38c99cc 223 // must be max 128
EasyCAT 0:7816b38c99cc 224 #if (CUST_BYTE_NUM_OUT > 128)
EasyCAT 0:7816b38c99cc 225 #error "CUST_BYTE_NUM_OUT must be max 128 !!! define it correctly in file EasyCAT.h"
EasyCAT 0:7816b38c99cc 226 #endif
EasyCAT 0:7816b38c99cc 227
EasyCAT 0:7816b38c99cc 228 #if (CUST_BYTE_NUM_IN > 128)
EasyCAT 0:7816b38c99cc 229 #error "CUST_BYTE_NUM_IN must be max 128 !!! define it correctly in file EasyCAT.h"
EasyCAT 0:7816b38c99cc 230 #endif
EasyCAT 0:7816b38c99cc 231
EasyCAT 0:7816b38c99cc 232 #endif
EasyCAT 0:7816b38c99cc 233
EasyCAT 0:7816b38c99cc 234
EasyCAT 0:7816b38c99cc 235 //*************************************************************************************************
EasyCAT 0:7816b38c99cc 236
EasyCAT 0:7816b38c99cc 237
EasyCAT 0:7816b38c99cc 238
EasyCAT 0:7816b38c99cc 239
EasyCAT 0:7816b38c99cc 240 //---- LAN9252 registers --------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 241
EasyCAT 0:7816b38c99cc 242 //---- access to EtherCAT registers -------------------
EasyCAT 0:7816b38c99cc 243
EasyCAT 0:7816b38c99cc 244 #define ECAT_CSR_DATA 0x0300 // EtherCAT CSR Interface Data Register
EasyCAT 0:7816b38c99cc 245 #define ECAT_CSR_CMD 0x0304 // EtherCAT CSR Interface Command Register
EasyCAT 0:7816b38c99cc 246
EasyCAT 0:7816b38c99cc 247
EasyCAT 0:7816b38c99cc 248 //---- access to EtherCAT process RAM -----------------
EasyCAT 0:7816b38c99cc 249
EasyCAT 0:7816b38c99cc 250 #define ECAT_PRAM_RD_ADDR_LEN 0x0308 // EtherCAT Process RAM Read Address and Length Register
EasyCAT 0:7816b38c99cc 251 #define ECAT_PRAM_RD_CMD 0x030C // EtherCAT Process RAM Read Command Register
EasyCAT 0:7816b38c99cc 252 #define ECAT_PRAM_WR_ADDR_LEN 0x0310 // EtherCAT Process RAM Write Address and Length Register
EasyCAT 0:7816b38c99cc 253 #define ECAT_PRAM_WR_CMD 0x0314 // EtherCAT Process RAM Write Command Register
EasyCAT 0:7816b38c99cc 254
EasyCAT 0:7816b38c99cc 255 #define ECAT_PRAM_RD_DATA 0x0000 // EtherCAT Process RAM Read Data FIFO
EasyCAT 0:7816b38c99cc 256 #define ECAT_PRAM_WR_DATA 0x0020 // EtherCAT Process RAM Write Data FIFO
EasyCAT 0:7816b38c99cc 257
EasyCAT 0:7816b38c99cc 258 //---- EtherCAT registers -----------------------------
EasyCAT 0:7816b38c99cc 259
EasyCAT 0:7816b38c99cc 260 #define AL_STATUS 0x0130 // AL status
EasyCAT 0:7816b38c99cc 261 #define WDOG_STATUS 0x0440 // watch dog status
EasyCAT 0:7816b38c99cc 262 #define AL_EVENT_MASK 0x0204 // AL event interrupt mask
EasyCAT 0:7816b38c99cc 263
EasyCAT 0:7816b38c99cc 264 //---- LAN9252 registers ------------------------------
EasyCAT 0:7816b38c99cc 265
EasyCAT 0:7816b38c99cc 266 #define HW_CFG 0x0074 // hardware configuration register
EasyCAT 0:7816b38c99cc 267 #define BYTE_TEST 0x0064 // byte order test register
EasyCAT 0:7816b38c99cc 268 #define RESET_CTL 0x01F8 // reset register
EasyCAT 0:7816b38c99cc 269 #define ID_REV 0x0050 // chip ID and revision
EasyCAT 0:7816b38c99cc 270 #define IRQ_CFG 0x0054 // interrupt configuration
EasyCAT 0:7816b38c99cc 271 #define INT_EN 0x005C // interrupt enable
EasyCAT 0:7816b38c99cc 272
EasyCAT 0:7816b38c99cc 273
EasyCAT 0:7816b38c99cc 274 //---- LAN9252 flags ------------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 275
EasyCAT 0:7816b38c99cc 276 #define ECAT_CSR_BUSY 0x80
EasyCAT 0:7816b38c99cc 277
EasyCAT 0:7816b38c99cc 278 #define PRAM_ABORT 0x40000000
EasyCAT 0:7816b38c99cc 279
EasyCAT 0:7816b38c99cc 280 #define PRAM_BUSY 0x80
EasyCAT 0:7816b38c99cc 281
EasyCAT 0:7816b38c99cc 282 #define PRAM_AVAIL 0x01
EasyCAT 0:7816b38c99cc 283
EasyCAT 0:7816b38c99cc 284 #define READY 0x08
EasyCAT 0:7816b38c99cc 285
EasyCAT 0:7816b38c99cc 286 #define DIGITAL_RST 0x00000001
EasyCAT 0:7816b38c99cc 287
EasyCAT 0:7816b38c99cc 288
EasyCAT 0:7816b38c99cc 289 //---- EtherCAT flags -----------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 290
EasyCAT 0:7816b38c99cc 291 // EtherCAT state machine
EasyCAT 0:7816b38c99cc 292
EasyCAT 0:7816b38c99cc 293 #define ESM_INIT 0x01 // init
EasyCAT 0:7816b38c99cc 294 #define ESM_PREOP 0x02 // pre-operational
EasyCAT 0:7816b38c99cc 295 #define ESM_BOOT 0x03 // bootstrap
EasyCAT 0:7816b38c99cc 296 #define ESM_SAFEOP 0x04 // safe-operational
EasyCAT 0:7816b38c99cc 297 #define ESM_OP 0x08 // operational
EasyCAT 0:7816b38c99cc 298
EasyCAT 0:7816b38c99cc 299
EasyCAT 0:7816b38c99cc 300 //--- ESC commands --------------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 301
EasyCAT 0:7816b38c99cc 302 #define ESC_WRITE 0x80
EasyCAT 0:7816b38c99cc 303 #define ESC_READ 0xC0
EasyCAT 0:7816b38c99cc 304
EasyCAT 0:7816b38c99cc 305
EasyCAT 0:7816b38c99cc 306 //---- SPI ----------------------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 307
EasyCAT 0:7816b38c99cc 308 #define COMM_SPI_READ 0x03
EasyCAT 0:7816b38c99cc 309 #define COMM_SPI_WRITE 0x02
EasyCAT 0:7816b38c99cc 310
EasyCAT 0:7816b38c99cc 311 #define DUMMY_BYTE 0xFF
EasyCAT 0:7816b38c99cc 312
EasyCAT 0:7816b38c99cc 313
EasyCAT 0:7816b38c99cc 314
EasyCAT 0:7816b38c99cc 315 //---- typedef ------------------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 316
EasyCAT 0:7816b38c99cc 317 typedef union
EasyCAT 0:7816b38c99cc 318 {
EasyCAT 0:7816b38c99cc 319 unsigned short Word;
EasyCAT 0:7816b38c99cc 320 unsigned char Byte[2];
EasyCAT 0:7816b38c99cc 321 } UWORD;
EasyCAT 0:7816b38c99cc 322
EasyCAT 0:7816b38c99cc 323 typedef union
EasyCAT 0:7816b38c99cc 324 {
EasyCAT 0:7816b38c99cc 325 unsigned long Long;
EasyCAT 0:7816b38c99cc 326 unsigned short Word[2];
EasyCAT 0:7816b38c99cc 327 unsigned char Byte[4];
EasyCAT 0:7816b38c99cc 328 } ULONG;
EasyCAT 0:7816b38c99cc 329
EasyCAT 0:7816b38c99cc 330
EasyCAT 0:7816b38c99cc 331 typedef union //-- output buffer -----------------
EasyCAT 0:7816b38c99cc 332 { //
EasyCAT 0:7816b38c99cc 333 uint8_t Byte [TOT_BYTE_NUM_ROUND_OUT]; //
EasyCAT 0:7816b38c99cc 334
EasyCAT 0:7816b38c99cc 335 #if CUST_BYTE_NUM_OUT > 0 //----- Custom data types example -----
neeyoo 4:66867fae2256 336 //
EasyCAT 0:7816b38c99cc 337 struct // Here we can define our custom
EasyCAT 0:7816b38c99cc 338 { // data types and names for the outputs
EasyCAT 0:7816b38c99cc 339 //
EasyCAT 0:7816b38c99cc 340 uint8_t Control; // The total number of bytes declared
EasyCAT 0:7816b38c99cc 341 float PreZone1; // in this structure must be equal
EasyCAT 0:7816b38c99cc 342 float CommZone1; // to the value assigned to CUST_BYTE_NUM_OUT
EasyCAT 0:7816b38c99cc 343 float RampZone1; //
EasyCAT 0:7816b38c99cc 344 float PreZone2; // In this case 1+ 4+4+4+ 4+4+4+ 4+4+4+ 4+4+4 = 49
EasyCAT 0:7816b38c99cc 345 float CommZone2; //
EasyCAT 0:7816b38c99cc 346 float RampZone2; //
EasyCAT 0:7816b38c99cc 347 float PreZone3; //
EasyCAT 0:7816b38c99cc 348 float CommZone3; //
EasyCAT 0:7816b38c99cc 349 float RampZone3; //
EasyCAT 0:7816b38c99cc 350 float PreZone4; //
EasyCAT 0:7816b38c99cc 351 float CommZone4; //
EasyCAT 0:7816b38c99cc 352 float RampZone4; //
EasyCAT 0:7816b38c99cc 353 }Cust; //
neeyoo 4:66867fae2256 354 //
EasyCAT 0:7816b38c99cc 355 #endif //
EasyCAT 0:7816b38c99cc 356
EasyCAT 0:7816b38c99cc 357 } PROCBUFFER_OUT; //
EasyCAT 0:7816b38c99cc 358
EasyCAT 0:7816b38c99cc 359
EasyCAT 0:7816b38c99cc 360 typedef union //-- input buffer ------------------
EasyCAT 0:7816b38c99cc 361 { //
EasyCAT 0:7816b38c99cc 362 uint8_t Byte [TOT_BYTE_NUM_ROUND_IN]; //
EasyCAT 0:7816b38c99cc 363
EasyCAT 0:7816b38c99cc 364 #if CUST_BYTE_NUM_IN > 0 //----- Custom data types example ------
neeyoo 4:66867fae2256 365 //
EasyCAT 0:7816b38c99cc 366 struct // Here we can define our custom
EasyCAT 0:7816b38c99cc 367 { // data types and names for the inputs
neeyoo 4:66867fae2256 368 int32_t centerXL;
neeyoo 4:66867fae2256 369 int32_t centerYL;
neeyoo 4:66867fae2256 370 int32_t forceL;
neeyoo 4:66867fae2256 371 int32_t yawL;
neeyoo 4:66867fae2256 372 int32_t pitchL;
neeyoo 4:66867fae2256 373 int32_t rollL;
neeyoo 4:66867fae2256 374 int32_t centerXR;
neeyoo 4:66867fae2256 375 int32_t centerYR;
neeyoo 4:66867fae2256 376 int32_t forceR;
neeyoo 4:66867fae2256 377 int32_t yawR;
neeyoo 4:66867fae2256 378 int32_t pitchR;
neeyoo 4:66867fae2256 379 int32_t rollR;
neeyoo 4:66867fae2256 380 int32_t yawH;
neeyoo 4:66867fae2256 381 int32_t pitchH;
neeyoo 4:66867fae2256 382 int32_t rollH; //
neeyoo 4:66867fae2256 383
EasyCAT 0:7816b38c99cc 384 }Cust; //
neeyoo 4:66867fae2256 385 //
EasyCAT 0:7816b38c99cc 386 #endif //
EasyCAT 0:7816b38c99cc 387
EasyCAT 0:7816b38c99cc 388 } PROCBUFFER_IN; //
EasyCAT 0:7816b38c99cc 389
EasyCAT 0:7816b38c99cc 390
EasyCAT 0:7816b38c99cc 391 typedef enum
EasyCAT 0:7816b38c99cc 392 {
EasyCAT 0:7816b38c99cc 393 ASYNC,
EasyCAT 0:7816b38c99cc 394 DC_SYNC,
EasyCAT 0:7816b38c99cc 395 SM_SYNC
EasyCAT 0:7816b38c99cc 396 }SyncMode;
EasyCAT 0:7816b38c99cc 397
EasyCAT 0:7816b38c99cc 398
EasyCAT 0:7816b38c99cc 399
EasyCAT 0:7816b38c99cc 400 //-------------------------------------------------------------------------------------------------
EasyCAT 0:7816b38c99cc 401
EasyCAT 0:7816b38c99cc 402 class EasyCAT
EasyCAT 0:7816b38c99cc 403 {
EasyCAT 0:7816b38c99cc 404 public:
EasyCAT 0:7816b38c99cc 405 EasyCAT(); // default constructor
EasyCAT 0:7816b38c99cc 406 EasyCAT(PinName SCS);
EasyCAT 0:7816b38c99cc 407 EasyCAT(SyncMode Sync);
EasyCAT 0:7816b38c99cc 408 EasyCAT(PinName SCS, SyncMode Sync);
EasyCAT 0:7816b38c99cc 409
EasyCAT 0:7816b38c99cc 410
EasyCAT 0:7816b38c99cc 411 unsigned char MainTask(); // EtherCAT main task
EasyCAT 0:7816b38c99cc 412 // must be called cyclically by the application
EasyCAT 0:7816b38c99cc 413
EasyCAT 0:7816b38c99cc 414 bool Init(); // EasyCAT board initialization
EasyCAT 0:7816b38c99cc 415
EasyCAT 0:7816b38c99cc 416 PROCBUFFER_OUT BufferOut; // output process data buffer
EasyCAT 0:7816b38c99cc 417 PROCBUFFER_IN BufferIn; // input process data buffer
EasyCAT 0:7816b38c99cc 418
EasyCAT 0:7816b38c99cc 419
EasyCAT 0:7816b38c99cc 420 private:
EasyCAT 0:7816b38c99cc 421 void SPIWriteRegisterDirect (unsigned short Address, unsigned long DataOut);
EasyCAT 0:7816b38c99cc 422 unsigned long SPIReadRegisterDirect (unsigned short Address, unsigned char Len);
EasyCAT 0:7816b38c99cc 423
EasyCAT 0:7816b38c99cc 424 void SPIWriteRegisterIndirect (unsigned long DataOut, unsigned short Address, unsigned char Len);
EasyCAT 0:7816b38c99cc 425 unsigned long SPIReadRegisterIndirect (unsigned short Address, unsigned char Len);
EasyCAT 0:7816b38c99cc 426
EasyCAT 0:7816b38c99cc 427 void SPIReadProcRamFifo();
EasyCAT 0:7816b38c99cc 428 void SPIWriteProcRamFifo();
EasyCAT 0:7816b38c99cc 429
EasyCAT 0:7816b38c99cc 430 PinName SCS_;
EasyCAT 0:7816b38c99cc 431 SyncMode Sync_;
EasyCAT 0:7816b38c99cc 432 };
EasyCAT 0:7816b38c99cc 433
EasyCAT 0:7816b38c99cc 434 #endif