EasyCAT LAB - EtherCAT master simple example
Dependencies: SOEM SPI_TFT_ILI9341 TFT_fonts
- This repository contains a simple example 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.
- It uses the SOEM (Simple Open EtherCAT® Master) library by rt-labs, that has been ported in the ecosystem by AB&T Tecnologie Informatiche.
- The slaves are based on the EasyCAT SHIELD and the Arduino UNO.
Note
- This example uses two LAB 2 slaves.
Note
- In this example only two bytes of data are exchanged between the slaves and are also visualized on the TFT display.
soem_start.cpp@0:13be39911caf, 2019-07-08 (annotated)
- Committer:
- sulymarco
- Date:
- Mon Jul 08 17:44:47 2019 +0000
- Revision:
- 0:13be39911caf
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sulymarco | 0:13be39911caf | 1 | |
sulymarco | 0:13be39911caf | 2 | #include "soem_start.h" |
sulymarco | 0:13be39911caf | 3 | #include "ethercat.h" |
sulymarco | 0:13be39911caf | 4 | #include "string.h" |
sulymarco | 0:13be39911caf | 5 | #include "oshw.h" |
sulymarco | 0:13be39911caf | 6 | |
sulymarco | 0:13be39911caf | 7 | #include "mbed.h" |
sulymarco | 0:13be39911caf | 8 | |
sulymarco | 0:13be39911caf | 9 | #include <inttypes.h> |
sulymarco | 0:13be39911caf | 10 | |
sulymarco | 0:13be39911caf | 11 | #include "SPI_TFT_ILI9341.h" |
sulymarco | 0:13be39911caf | 12 | |
sulymarco | 0:13be39911caf | 13 | extern SPI_TFT_ILI9341 TFT; |
sulymarco | 0:13be39911caf | 14 | |
sulymarco | 0:13be39911caf | 15 | boolean printSDO = TRUE; |
sulymarco | 0:13be39911caf | 16 | boolean printMAP = TRUE; |
sulymarco | 0:13be39911caf | 17 | |
sulymarco | 0:13be39911caf | 18 | ec_ODlistt ODlist; |
sulymarco | 0:13be39911caf | 19 | ec_OElistt OElist; |
sulymarco | 0:13be39911caf | 20 | char usdo[128]; |
sulymarco | 0:13be39911caf | 21 | char hstr[1024]; |
sulymarco | 0:13be39911caf | 22 | |
sulymarco | 0:13be39911caf | 23 | char extern IOmap[]; |
sulymarco | 0:13be39911caf | 24 | |
sulymarco | 0:13be39911caf | 25 | uint32_t error_counter = 0; |
sulymarco | 0:13be39911caf | 26 | |
sulymarco | 0:13be39911caf | 27 | |
sulymarco | 0:13be39911caf | 28 | char* dtype2string(uint16 dtype); |
sulymarco | 0:13be39911caf | 29 | char* SDO2string(uint16 slave, uint16 index, uint8 subidx, uint16 dtype); |
sulymarco | 0:13be39911caf | 30 | int si_PDOassign(uint16 slave, uint16 PDOassign, int mapoffset, int bitoffset); |
sulymarco | 0:13be39911caf | 31 | void si_sdo(int cnt); |
sulymarco | 0:13be39911caf | 32 | int si_map_sdo(int slave); |
sulymarco | 0:13be39911caf | 33 | int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset); |
sulymarco | 0:13be39911caf | 34 | bool network_scanning(void); |
sulymarco | 0:13be39911caf | 35 | |
sulymarco | 0:13be39911caf | 36 | |
sulymarco | 0:13be39911caf | 37 | |
sulymarco | 0:13be39911caf | 38 | //---- convert Ethercat types to string ---------------------------------------- |
sulymarco | 0:13be39911caf | 39 | |
sulymarco | 0:13be39911caf | 40 | |
sulymarco | 0:13be39911caf | 41 | char* dtype2string(uint16 dtype) |
sulymarco | 0:13be39911caf | 42 | { |
sulymarco | 0:13be39911caf | 43 | switch(dtype) |
sulymarco | 0:13be39911caf | 44 | { |
sulymarco | 0:13be39911caf | 45 | case ECT_BOOLEAN: |
sulymarco | 0:13be39911caf | 46 | sprintf(hstr, "BOOLEAN"); |
sulymarco | 0:13be39911caf | 47 | break; |
sulymarco | 0:13be39911caf | 48 | case ECT_INTEGER8: |
sulymarco | 0:13be39911caf | 49 | sprintf(hstr, "INTEGER8"); |
sulymarco | 0:13be39911caf | 50 | break; |
sulymarco | 0:13be39911caf | 51 | case ECT_INTEGER16: |
sulymarco | 0:13be39911caf | 52 | sprintf(hstr, "INTEGER16"); |
sulymarco | 0:13be39911caf | 53 | break; |
sulymarco | 0:13be39911caf | 54 | case ECT_INTEGER32: |
sulymarco | 0:13be39911caf | 55 | sprintf(hstr, "INTEGER32"); |
sulymarco | 0:13be39911caf | 56 | break; |
sulymarco | 0:13be39911caf | 57 | case ECT_INTEGER24: |
sulymarco | 0:13be39911caf | 58 | sprintf(hstr, "INTEGER24"); |
sulymarco | 0:13be39911caf | 59 | break; |
sulymarco | 0:13be39911caf | 60 | case ECT_INTEGER64: |
sulymarco | 0:13be39911caf | 61 | sprintf(hstr, "INTEGER64"); |
sulymarco | 0:13be39911caf | 62 | break; |
sulymarco | 0:13be39911caf | 63 | case ECT_UNSIGNED8: |
sulymarco | 0:13be39911caf | 64 | sprintf(hstr, "UNSIGNED8"); |
sulymarco | 0:13be39911caf | 65 | break; |
sulymarco | 0:13be39911caf | 66 | case ECT_UNSIGNED16: |
sulymarco | 0:13be39911caf | 67 | sprintf(hstr, "UNSIGNED16"); |
sulymarco | 0:13be39911caf | 68 | break; |
sulymarco | 0:13be39911caf | 69 | case ECT_UNSIGNED32: |
sulymarco | 0:13be39911caf | 70 | sprintf(hstr, "UNSIGNED32"); |
sulymarco | 0:13be39911caf | 71 | break; |
sulymarco | 0:13be39911caf | 72 | case ECT_UNSIGNED24: |
sulymarco | 0:13be39911caf | 73 | sprintf(hstr, "UNSIGNED24"); |
sulymarco | 0:13be39911caf | 74 | break; |
sulymarco | 0:13be39911caf | 75 | case ECT_UNSIGNED64: |
sulymarco | 0:13be39911caf | 76 | sprintf(hstr, "UNSIGNED64"); |
sulymarco | 0:13be39911caf | 77 | break; |
sulymarco | 0:13be39911caf | 78 | case ECT_REAL32: |
sulymarco | 0:13be39911caf | 79 | sprintf(hstr, "REAL32"); |
sulymarco | 0:13be39911caf | 80 | break; |
sulymarco | 0:13be39911caf | 81 | case ECT_REAL64: |
sulymarco | 0:13be39911caf | 82 | sprintf(hstr, "REAL64"); |
sulymarco | 0:13be39911caf | 83 | break; |
sulymarco | 0:13be39911caf | 84 | case ECT_BIT1: |
sulymarco | 0:13be39911caf | 85 | sprintf(hstr, "BIT1"); |
sulymarco | 0:13be39911caf | 86 | break; |
sulymarco | 0:13be39911caf | 87 | case ECT_BIT2: |
sulymarco | 0:13be39911caf | 88 | sprintf(hstr, "BIT2"); |
sulymarco | 0:13be39911caf | 89 | break; |
sulymarco | 0:13be39911caf | 90 | case ECT_BIT3: |
sulymarco | 0:13be39911caf | 91 | sprintf(hstr, "BIT3"); |
sulymarco | 0:13be39911caf | 92 | break; |
sulymarco | 0:13be39911caf | 93 | case ECT_BIT4: |
sulymarco | 0:13be39911caf | 94 | sprintf(hstr, "BIT4"); |
sulymarco | 0:13be39911caf | 95 | break; |
sulymarco | 0:13be39911caf | 96 | case ECT_BIT5: |
sulymarco | 0:13be39911caf | 97 | sprintf(hstr, "BIT5"); |
sulymarco | 0:13be39911caf | 98 | break; |
sulymarco | 0:13be39911caf | 99 | case ECT_BIT6: |
sulymarco | 0:13be39911caf | 100 | sprintf(hstr, "BIT6"); |
sulymarco | 0:13be39911caf | 101 | break; |
sulymarco | 0:13be39911caf | 102 | case ECT_BIT7: |
sulymarco | 0:13be39911caf | 103 | sprintf(hstr, "BIT7"); |
sulymarco | 0:13be39911caf | 104 | break; |
sulymarco | 0:13be39911caf | 105 | case ECT_BIT8: |
sulymarco | 0:13be39911caf | 106 | sprintf(hstr, "BIT8"); |
sulymarco | 0:13be39911caf | 107 | break; |
sulymarco | 0:13be39911caf | 108 | case ECT_VISIBLE_STRING: |
sulymarco | 0:13be39911caf | 109 | sprintf(hstr, "VISIBLE_STRING"); |
sulymarco | 0:13be39911caf | 110 | break; |
sulymarco | 0:13be39911caf | 111 | case ECT_OCTET_STRING: |
sulymarco | 0:13be39911caf | 112 | sprintf(hstr, "OCTET_STRING"); |
sulymarco | 0:13be39911caf | 113 | break; |
sulymarco | 0:13be39911caf | 114 | default: |
sulymarco | 0:13be39911caf | 115 | sprintf(hstr, "Type 0x%4.4X", dtype); |
sulymarco | 0:13be39911caf | 116 | } |
sulymarco | 0:13be39911caf | 117 | return hstr; |
sulymarco | 0:13be39911caf | 118 | } |
sulymarco | 0:13be39911caf | 119 | |
sulymarco | 0:13be39911caf | 120 | |
sulymarco | 0:13be39911caf | 121 | //------------------------------------------------------------------------------ |
sulymarco | 0:13be39911caf | 122 | |
sulymarco | 0:13be39911caf | 123 | char* SDO2string(uint16 slave, uint16 index, uint8 subidx, uint16 dtype) |
sulymarco | 0:13be39911caf | 124 | { |
sulymarco | 0:13be39911caf | 125 | int l = sizeof(usdo) - 1, i; |
sulymarco | 0:13be39911caf | 126 | uint8 *u8; |
sulymarco | 0:13be39911caf | 127 | int8 *i8; |
sulymarco | 0:13be39911caf | 128 | uint16 *u16; |
sulymarco | 0:13be39911caf | 129 | int16 *i16; |
sulymarco | 0:13be39911caf | 130 | uint32 *u32; |
sulymarco | 0:13be39911caf | 131 | int32 *i32; |
sulymarco | 0:13be39911caf | 132 | uint64 *u64; |
sulymarco | 0:13be39911caf | 133 | int64 *i64; |
sulymarco | 0:13be39911caf | 134 | float *sr; |
sulymarco | 0:13be39911caf | 135 | double *dr; |
sulymarco | 0:13be39911caf | 136 | char es[32]; |
sulymarco | 0:13be39911caf | 137 | |
sulymarco | 0:13be39911caf | 138 | memset(&usdo, 0, 128); |
sulymarco | 0:13be39911caf | 139 | ec_SDOread(slave, index, subidx, FALSE, &l, &usdo, EC_TIMEOUTRXM); |
sulymarco | 0:13be39911caf | 140 | if (EcatError) |
sulymarco | 0:13be39911caf | 141 | { |
sulymarco | 0:13be39911caf | 142 | return ec_elist2string(); |
sulymarco | 0:13be39911caf | 143 | } |
sulymarco | 0:13be39911caf | 144 | else |
sulymarco | 0:13be39911caf | 145 | { |
sulymarco | 0:13be39911caf | 146 | switch(dtype) |
sulymarco | 0:13be39911caf | 147 | { |
sulymarco | 0:13be39911caf | 148 | case ECT_BOOLEAN: |
sulymarco | 0:13be39911caf | 149 | u8 = (uint8*) &usdo[0]; |
sulymarco | 0:13be39911caf | 150 | if (*u8) sprintf(hstr, "TRUE"); |
sulymarco | 0:13be39911caf | 151 | else sprintf(hstr, "FALSE"); |
sulymarco | 0:13be39911caf | 152 | break; |
sulymarco | 0:13be39911caf | 153 | case ECT_INTEGER8: |
sulymarco | 0:13be39911caf | 154 | i8 = (int8*) &usdo[0]; |
sulymarco | 0:13be39911caf | 155 | sprintf(hstr, "0x%2.2x %d", *i8, *i8); |
sulymarco | 0:13be39911caf | 156 | break; |
sulymarco | 0:13be39911caf | 157 | case ECT_INTEGER16: |
sulymarco | 0:13be39911caf | 158 | i16 = (int16*) &usdo[0]; |
sulymarco | 0:13be39911caf | 159 | sprintf(hstr, "0x%4.4x %d", *i16, *i16); |
sulymarco | 0:13be39911caf | 160 | break; |
sulymarco | 0:13be39911caf | 161 | case ECT_INTEGER32: |
sulymarco | 0:13be39911caf | 162 | case ECT_INTEGER24: |
sulymarco | 0:13be39911caf | 163 | i32 = (int32*) &usdo[0]; |
sulymarco | 0:13be39911caf | 164 | sprintf(hstr, "0x%8.8x %d", *i32, *i32); |
sulymarco | 0:13be39911caf | 165 | break; |
sulymarco | 0:13be39911caf | 166 | case ECT_INTEGER64: |
sulymarco | 0:13be39911caf | 167 | i64 = (int64*) &usdo[0]; |
sulymarco | 0:13be39911caf | 168 | sprintf(hstr, "0x%16.16"PRIx64" %"PRId64, *i64, *i64); |
sulymarco | 0:13be39911caf | 169 | break; |
sulymarco | 0:13be39911caf | 170 | case ECT_UNSIGNED8: |
sulymarco | 0:13be39911caf | 171 | u8 = (uint8*) &usdo[0]; |
sulymarco | 0:13be39911caf | 172 | sprintf(hstr, "0x%2.2x %u", *u8, *u8); |
sulymarco | 0:13be39911caf | 173 | break; |
sulymarco | 0:13be39911caf | 174 | case ECT_UNSIGNED16: |
sulymarco | 0:13be39911caf | 175 | u16 = (uint16*) &usdo[0]; |
sulymarco | 0:13be39911caf | 176 | sprintf(hstr, "0x%4.4x %u", *u16, *u16); |
sulymarco | 0:13be39911caf | 177 | break; |
sulymarco | 0:13be39911caf | 178 | case ECT_UNSIGNED32: |
sulymarco | 0:13be39911caf | 179 | case ECT_UNSIGNED24: |
sulymarco | 0:13be39911caf | 180 | u32 = (uint32*) &usdo[0]; |
sulymarco | 0:13be39911caf | 181 | sprintf(hstr, "0x%8.8x %u", *u32, *u32); |
sulymarco | 0:13be39911caf | 182 | break; |
sulymarco | 0:13be39911caf | 183 | case ECT_UNSIGNED64: |
sulymarco | 0:13be39911caf | 184 | u64 = (uint64*) &usdo[0]; |
sulymarco | 0:13be39911caf | 185 | sprintf(hstr, "0x%16.16"PRIx64" %"PRIu64, *u64, *u64); |
sulymarco | 0:13be39911caf | 186 | break; |
sulymarco | 0:13be39911caf | 187 | case ECT_REAL32: |
sulymarco | 0:13be39911caf | 188 | sr = (float*) &usdo[0]; |
sulymarco | 0:13be39911caf | 189 | sprintf(hstr, "%f", *sr); |
sulymarco | 0:13be39911caf | 190 | break; |
sulymarco | 0:13be39911caf | 191 | case ECT_REAL64: |
sulymarco | 0:13be39911caf | 192 | dr = (double*) &usdo[0]; |
sulymarco | 0:13be39911caf | 193 | sprintf(hstr, "%f", *dr); |
sulymarco | 0:13be39911caf | 194 | break; |
sulymarco | 0:13be39911caf | 195 | case ECT_BIT1: |
sulymarco | 0:13be39911caf | 196 | case ECT_BIT2: |
sulymarco | 0:13be39911caf | 197 | case ECT_BIT3: |
sulymarco | 0:13be39911caf | 198 | case ECT_BIT4: |
sulymarco | 0:13be39911caf | 199 | case ECT_BIT5: |
sulymarco | 0:13be39911caf | 200 | case ECT_BIT6: |
sulymarco | 0:13be39911caf | 201 | case ECT_BIT7: |
sulymarco | 0:13be39911caf | 202 | case ECT_BIT8: |
sulymarco | 0:13be39911caf | 203 | u8 = (uint8*) &usdo[0]; |
sulymarco | 0:13be39911caf | 204 | sprintf(hstr, "0x%x", *u8); |
sulymarco | 0:13be39911caf | 205 | break; |
sulymarco | 0:13be39911caf | 206 | case ECT_VISIBLE_STRING: |
sulymarco | 0:13be39911caf | 207 | strcpy(hstr, usdo); |
sulymarco | 0:13be39911caf | 208 | break; |
sulymarco | 0:13be39911caf | 209 | case ECT_OCTET_STRING: |
sulymarco | 0:13be39911caf | 210 | hstr[0] = 0x00; |
sulymarco | 0:13be39911caf | 211 | for (i = 0 ; i < l ; i++) |
sulymarco | 0:13be39911caf | 212 | { |
sulymarco | 0:13be39911caf | 213 | sprintf(es, "0x%2.2x ", usdo[i]); |
sulymarco | 0:13be39911caf | 214 | strcat( hstr, es); |
sulymarco | 0:13be39911caf | 215 | } |
sulymarco | 0:13be39911caf | 216 | break; |
sulymarco | 0:13be39911caf | 217 | default: |
sulymarco | 0:13be39911caf | 218 | sprintf(hstr, "Unknown type"); |
sulymarco | 0:13be39911caf | 219 | } |
sulymarco | 0:13be39911caf | 220 | return hstr; |
sulymarco | 0:13be39911caf | 221 | } |
sulymarco | 0:13be39911caf | 222 | } |
sulymarco | 0:13be39911caf | 223 | |
sulymarco | 0:13be39911caf | 224 | |
sulymarco | 0:13be39911caf | 225 | //----- read PDO assign structure ---------------------------------------------- |
sulymarco | 0:13be39911caf | 226 | |
sulymarco | 0:13be39911caf | 227 | int si_PDOassign(uint16 slave, uint16 PDOassign, int mapoffset, int bitoffset) |
sulymarco | 0:13be39911caf | 228 | { |
sulymarco | 0:13be39911caf | 229 | uint16 idxloop, nidx, subidxloop, rdat, idx, subidx; |
sulymarco | 0:13be39911caf | 230 | uint8 subcnt; |
sulymarco | 0:13be39911caf | 231 | int wkc, bsize = 0, rdl; |
sulymarco | 0:13be39911caf | 232 | int32 rdat2; |
sulymarco | 0:13be39911caf | 233 | uint8 bitlen, obj_subidx; |
sulymarco | 0:13be39911caf | 234 | uint16 obj_idx; |
sulymarco | 0:13be39911caf | 235 | int abs_offset, abs_bit; |
sulymarco | 0:13be39911caf | 236 | |
sulymarco | 0:13be39911caf | 237 | rdl = sizeof(rdat); rdat = 0; |
sulymarco | 0:13be39911caf | 238 | // read PDO assign subindex 0 (= number of PDO's) |
sulymarco | 0:13be39911caf | 239 | wkc = ec_SDOread(slave, PDOassign, 0x00, FALSE, &rdl, &rdat, EC_TIMEOUTRXM); |
sulymarco | 0:13be39911caf | 240 | rdat = etohs(rdat); |
sulymarco | 0:13be39911caf | 241 | |
sulymarco | 0:13be39911caf | 242 | if ((wkc > 0) && (rdat > 0)) // positive result from slave? |
sulymarco | 0:13be39911caf | 243 | { |
sulymarco | 0:13be39911caf | 244 | nidx = rdat; // number of available sub indexes |
sulymarco | 0:13be39911caf | 245 | bsize = 0; |
sulymarco | 0:13be39911caf | 246 | |
sulymarco | 0:13be39911caf | 247 | for (idxloop = 1; idxloop <= nidx; idxloop++) // read all PDO's |
sulymarco | 0:13be39911caf | 248 | { |
sulymarco | 0:13be39911caf | 249 | rdl = sizeof(rdat); rdat = 0; |
sulymarco | 0:13be39911caf | 250 | // read PDO assign |
sulymarco | 0:13be39911caf | 251 | wkc = ec_SDOread(slave, PDOassign, (uint8)idxloop, FALSE, &rdl, &rdat, EC_TIMEOUTRXM); |
sulymarco | 0:13be39911caf | 252 | |
sulymarco | 0:13be39911caf | 253 | idx = etohl(rdat); // result is index of PDO |
sulymarco | 0:13be39911caf | 254 | if (idx > 0) |
sulymarco | 0:13be39911caf | 255 | { |
sulymarco | 0:13be39911caf | 256 | rdl = sizeof(subcnt); subcnt = 0; |
sulymarco | 0:13be39911caf | 257 | // read number of subindexes of PDO |
sulymarco | 0:13be39911caf | 258 | wkc = ec_SDOread(slave,idx, 0x00, FALSE, &rdl, &subcnt, EC_TIMEOUTRXM); |
sulymarco | 0:13be39911caf | 259 | subidx = subcnt; |
sulymarco | 0:13be39911caf | 260 | // for each subindex |
sulymarco | 0:13be39911caf | 261 | for (subidxloop = 1; subidxloop <= subidx; subidxloop++) |
sulymarco | 0:13be39911caf | 262 | { |
sulymarco | 0:13be39911caf | 263 | rdl = sizeof(rdat2); rdat2 = 0; |
sulymarco | 0:13be39911caf | 264 | // read SDO that is mapped in PDO |
sulymarco | 0:13be39911caf | 265 | wkc = ec_SDOread(slave, idx, (uint8)subidxloop, FALSE, &rdl, &rdat2, EC_TIMEOUTRXM); |
sulymarco | 0:13be39911caf | 266 | rdat2 = etohl(rdat2); |
sulymarco | 0:13be39911caf | 267 | |
sulymarco | 0:13be39911caf | 268 | bitlen = LO_BYTE(rdat2); // extract bitlength of SDO |
sulymarco | 0:13be39911caf | 269 | bsize += bitlen; |
sulymarco | 0:13be39911caf | 270 | obj_idx = (uint16)(rdat2 >> 16); |
sulymarco | 0:13be39911caf | 271 | obj_subidx = (uint8)((rdat2 >> 8) & 0x000000ff); |
sulymarco | 0:13be39911caf | 272 | abs_offset = mapoffset + (bitoffset / 8); |
sulymarco | 0:13be39911caf | 273 | abs_bit = bitoffset % 8; |
sulymarco | 0:13be39911caf | 274 | ODlist.Slave = slave; |
sulymarco | 0:13be39911caf | 275 | ODlist.Index[0] = obj_idx; |
sulymarco | 0:13be39911caf | 276 | OElist.Entries = 0; |
sulymarco | 0:13be39911caf | 277 | wkc = 0; |
sulymarco | 0:13be39911caf | 278 | |
sulymarco | 0:13be39911caf | 279 | if(obj_idx || obj_subidx) // read object entry from dictionary if not a filler (0x0000:0x00) |
sulymarco | 0:13be39911caf | 280 | wkc = ec_readOEsingle(0, obj_subidx, &ODlist, &OElist); |
sulymarco | 0:13be39911caf | 281 | printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen); |
sulymarco | 0:13be39911caf | 282 | |
sulymarco | 0:13be39911caf | 283 | if((wkc > 0) && OElist.Entries) |
sulymarco | 0:13be39911caf | 284 | { |
sulymarco | 0:13be39911caf | 285 | printf(" %-12s %s\n", dtype2string(OElist.DataType[obj_subidx]), OElist.Name[obj_subidx]); |
sulymarco | 0:13be39911caf | 286 | } |
sulymarco | 0:13be39911caf | 287 | else |
sulymarco | 0:13be39911caf | 288 | printf("\n"); |
sulymarco | 0:13be39911caf | 289 | bitoffset += bitlen; |
sulymarco | 0:13be39911caf | 290 | }; |
sulymarco | 0:13be39911caf | 291 | }; |
sulymarco | 0:13be39911caf | 292 | }; |
sulymarco | 0:13be39911caf | 293 | }; |
sulymarco | 0:13be39911caf | 294 | |
sulymarco | 0:13be39911caf | 295 | return bsize; // return total found bitlength (PDO) |
sulymarco | 0:13be39911caf | 296 | } |
sulymarco | 0:13be39911caf | 297 | |
sulymarco | 0:13be39911caf | 298 | |
sulymarco | 0:13be39911caf | 299 | //---- PDO mapping according to CoE -------------------------------------------- |
sulymarco | 0:13be39911caf | 300 | |
sulymarco | 0:13be39911caf | 301 | int si_map_sdo(int slave) |
sulymarco | 0:13be39911caf | 302 | { |
sulymarco | 0:13be39911caf | 303 | int wkc, rdl; |
sulymarco | 0:13be39911caf | 304 | int retVal = 0; |
sulymarco | 0:13be39911caf | 305 | uint8 nSM, iSM, tSM; |
sulymarco | 0:13be39911caf | 306 | int Tsize, outputs_bo, inputs_bo; |
sulymarco | 0:13be39911caf | 307 | uint8 SMt_bug_add; |
sulymarco | 0:13be39911caf | 308 | |
sulymarco | 0:13be39911caf | 309 | printf("PDO mapping according to CoE :\n\n"); |
sulymarco | 0:13be39911caf | 310 | SMt_bug_add = 0; |
sulymarco | 0:13be39911caf | 311 | outputs_bo = 0; |
sulymarco | 0:13be39911caf | 312 | inputs_bo = 0; |
sulymarco | 0:13be39911caf | 313 | rdl = sizeof(nSM); nSM = 0; |
sulymarco | 0:13be39911caf | 314 | // read SyncManager Communication Type object count |
sulymarco | 0:13be39911caf | 315 | wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, 0x00, FALSE, &rdl, &nSM, EC_TIMEOUTRXM); |
sulymarco | 0:13be39911caf | 316 | |
sulymarco | 0:13be39911caf | 317 | if ((wkc > 0) && (nSM > 2)) // positive result from slave ? |
sulymarco | 0:13be39911caf | 318 | { |
sulymarco | 0:13be39911caf | 319 | nSM--; // make nSM equal to number of defined SM |
sulymarco | 0:13be39911caf | 320 | |
sulymarco | 0:13be39911caf | 321 | if (nSM > EC_MAXSM) // limit to maximum number of SM defined, |
sulymarco | 0:13be39911caf | 322 | nSM = EC_MAXSM; // if true the slave can't be configured |
sulymarco | 0:13be39911caf | 323 | |
sulymarco | 0:13be39911caf | 324 | for (iSM = 2 ; iSM <= nSM ; iSM++) // iterate for every SM type defined |
sulymarco | 0:13be39911caf | 325 | { |
sulymarco | 0:13be39911caf | 326 | rdl = sizeof(tSM); tSM = 0; |
sulymarco | 0:13be39911caf | 327 | // read SyncManager Communication Type |
sulymarco | 0:13be39911caf | 328 | wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, iSM + 1, FALSE, &rdl, &tSM, EC_TIMEOUTRXM); |
sulymarco | 0:13be39911caf | 329 | if (wkc > 0) |
sulymarco | 0:13be39911caf | 330 | { |
sulymarco | 0:13be39911caf | 331 | if((iSM == 2) && (tSM == 2)) // SM2 has type 2 == mailbox out, this is a bug in the slave! |
sulymarco | 0:13be39911caf | 332 | { |
sulymarco | 0:13be39911caf | 333 | SMt_bug_add = 1; // try to correct, this works if the types are 0 1 2 3 and should be 1 2 3 4 |
sulymarco | 0:13be39911caf | 334 | printf("Activated SM type workaround, possible incorrect mapping.\n"); |
sulymarco | 0:13be39911caf | 335 | } |
sulymarco | 0:13be39911caf | 336 | |
sulymarco | 0:13be39911caf | 337 | if(tSM) // only add if SMt > 0 |
sulymarco | 0:13be39911caf | 338 | tSM += SMt_bug_add; |
sulymarco | 0:13be39911caf | 339 | |
sulymarco | 0:13be39911caf | 340 | if (tSM == 3) // outputs |
sulymarco | 0:13be39911caf | 341 | { // read the assign RXPDO |
sulymarco | 0:13be39911caf | 342 | |
sulymarco | 0:13be39911caf | 343 | printf(" SM%1d outputs\n addr b index: sub bitl data_type name\n", iSM); |
sulymarco | 0:13be39911caf | 344 | Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].outputs - (uint8 *)&IOmap[0]), outputs_bo ); |
sulymarco | 0:13be39911caf | 345 | outputs_bo += Tsize; |
sulymarco | 0:13be39911caf | 346 | } |
sulymarco | 0:13be39911caf | 347 | |
sulymarco | 0:13be39911caf | 348 | if (tSM == 4) // inputs |
sulymarco | 0:13be39911caf | 349 | { // read the assign TXPDO |
sulymarco | 0:13be39911caf | 350 | |
sulymarco | 0:13be39911caf | 351 | printf(" SM%1d inputs\n addr b index: sub bitl data_type name\n", iSM); |
sulymarco | 0:13be39911caf | 352 | Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].inputs - (uint8 *)&IOmap[0]), inputs_bo ); |
sulymarco | 0:13be39911caf | 353 | inputs_bo += Tsize; |
sulymarco | 0:13be39911caf | 354 | } |
sulymarco | 0:13be39911caf | 355 | } |
sulymarco | 0:13be39911caf | 356 | } |
sulymarco | 0:13be39911caf | 357 | } |
sulymarco | 0:13be39911caf | 358 | |
sulymarco | 0:13be39911caf | 359 | if ((outputs_bo > 0) || (inputs_bo > 0)) // found some I/O bits? |
sulymarco | 0:13be39911caf | 360 | retVal = 1; |
sulymarco | 0:13be39911caf | 361 | return retVal; |
sulymarco | 0:13be39911caf | 362 | } |
sulymarco | 0:13be39911caf | 363 | |
sulymarco | 0:13be39911caf | 364 | |
sulymarco | 0:13be39911caf | 365 | //---- CoE objects description ------------------------------------------------- |
sulymarco | 0:13be39911caf | 366 | |
sulymarco | 0:13be39911caf | 367 | void si_sdo(int cnt) |
sulymarco | 0:13be39911caf | 368 | { |
sulymarco | 0:13be39911caf | 369 | int i, j; |
sulymarco | 0:13be39911caf | 370 | |
sulymarco | 0:13be39911caf | 371 | ODlist.Entries = 0; |
sulymarco | 0:13be39911caf | 372 | memset(&ODlist, 0, sizeof(ODlist)); |
sulymarco | 0:13be39911caf | 373 | if( ec_readODlist(cnt, &ODlist)) |
sulymarco | 0:13be39911caf | 374 | { |
sulymarco | 0:13be39911caf | 375 | printf(" CoE Object Description found, %d entries.\n",ODlist.Entries); |
sulymarco | 0:13be39911caf | 376 | for( i = 0 ; i < ODlist.Entries ; i++) |
sulymarco | 0:13be39911caf | 377 | { |
sulymarco | 0:13be39911caf | 378 | ec_readODdescription(i, &ODlist); |
sulymarco | 0:13be39911caf | 379 | while(EcatError) printf("%s", ec_elist2string()); |
sulymarco | 0:13be39911caf | 380 | printf(" Index: %4.4x Datatype: %4.4x Objectcode: %2.2x Name: %s\n", |
sulymarco | 0:13be39911caf | 381 | ODlist.Index[i], ODlist.DataType[i], ODlist.ObjectCode[i], ODlist.Name[i]); |
sulymarco | 0:13be39911caf | 382 | memset(&OElist, 0, sizeof(OElist)); |
sulymarco | 0:13be39911caf | 383 | ec_readOE(i, &ODlist, &OElist); |
sulymarco | 0:13be39911caf | 384 | while(EcatError) printf("%s", ec_elist2string()); |
sulymarco | 0:13be39911caf | 385 | for( j = 0 ; j < ODlist.MaxSub[i]+1 ; j++) |
sulymarco | 0:13be39911caf | 386 | { |
sulymarco | 0:13be39911caf | 387 | if ((OElist.DataType[j] > 0) && (OElist.BitLength[j] > 0)) |
sulymarco | 0:13be39911caf | 388 | { |
sulymarco | 0:13be39911caf | 389 | printf(" Sub: %2.2x Datatype: %4.4x Bitlength: %4.4x Obj.access: %4.4x Name: %s\n", |
sulymarco | 0:13be39911caf | 390 | j, OElist.DataType[j], OElist.BitLength[j], OElist.ObjAccess[j], OElist.Name[j]); |
sulymarco | 0:13be39911caf | 391 | if ((OElist.ObjAccess[j] & 0x0007)) |
sulymarco | 0:13be39911caf | 392 | { |
sulymarco | 0:13be39911caf | 393 | printf(" Value :%s\n", SDO2string(cnt, ODlist.Index[i], j, OElist.DataType[j])); |
sulymarco | 0:13be39911caf | 394 | } |
sulymarco | 0:13be39911caf | 395 | } |
sulymarco | 0:13be39911caf | 396 | } |
sulymarco | 0:13be39911caf | 397 | } |
sulymarco | 0:13be39911caf | 398 | } |
sulymarco | 0:13be39911caf | 399 | else |
sulymarco | 0:13be39911caf | 400 | { |
sulymarco | 0:13be39911caf | 401 | while(EcatError) printf("%s", ec_elist2string()); |
sulymarco | 0:13be39911caf | 402 | } |
sulymarco | 0:13be39911caf | 403 | } |
sulymarco | 0:13be39911caf | 404 | |
sulymarco | 0:13be39911caf | 405 | |
sulymarco | 0:13be39911caf | 406 | //---- PDO mapping according to SII -------------------------------------------- |
sulymarco | 0:13be39911caf | 407 | |
sulymarco | 0:13be39911caf | 408 | int si_map_sii(int slave) |
sulymarco | 0:13be39911caf | 409 | { |
sulymarco | 0:13be39911caf | 410 | int retVal = 0; |
sulymarco | 0:13be39911caf | 411 | int Tsize, outputs_bo, inputs_bo; |
sulymarco | 0:13be39911caf | 412 | |
sulymarco | 0:13be39911caf | 413 | printf("\nPDO mapping according to SII :\n\n"); |
sulymarco | 0:13be39911caf | 414 | |
sulymarco | 0:13be39911caf | 415 | outputs_bo = 0; |
sulymarco | 0:13be39911caf | 416 | inputs_bo = 0; |
sulymarco | 0:13be39911caf | 417 | // read the assign RXPDOs |
sulymarco | 0:13be39911caf | 418 | Tsize = si_siiPDO(slave, 1, (int)(ec_slave[slave].outputs - (uint8*)&IOmap), outputs_bo ); |
sulymarco | 0:13be39911caf | 419 | outputs_bo += Tsize; |
sulymarco | 0:13be39911caf | 420 | // read the assign TXPDOs |
sulymarco | 0:13be39911caf | 421 | Tsize = si_siiPDO(slave, 0, (int)(ec_slave[slave].inputs - (uint8*)&IOmap), inputs_bo ); |
sulymarco | 0:13be39911caf | 422 | inputs_bo += Tsize; |
sulymarco | 0:13be39911caf | 423 | |
sulymarco | 0:13be39911caf | 424 | if ((outputs_bo > 0) || (inputs_bo > 0)) // found some I/O bits ? |
sulymarco | 0:13be39911caf | 425 | retVal = 1; |
sulymarco | 0:13be39911caf | 426 | return retVal; |
sulymarco | 0:13be39911caf | 427 | } |
sulymarco | 0:13be39911caf | 428 | |
sulymarco | 0:13be39911caf | 429 | |
sulymarco | 0:13be39911caf | 430 | //------------------------------------------------------------------------------ |
sulymarco | 0:13be39911caf | 431 | |
sulymarco | 0:13be39911caf | 432 | int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset) |
sulymarco | 0:13be39911caf | 433 | { |
sulymarco | 0:13be39911caf | 434 | uint16 a , w, c, e, er, Size; |
sulymarco | 0:13be39911caf | 435 | uint8 eectl; |
sulymarco | 0:13be39911caf | 436 | uint16 obj_idx; |
sulymarco | 0:13be39911caf | 437 | uint8 obj_subidx; |
sulymarco | 0:13be39911caf | 438 | uint8 obj_name; |
sulymarco | 0:13be39911caf | 439 | uint8 obj_datatype; |
sulymarco | 0:13be39911caf | 440 | uint8 bitlen; |
sulymarco | 0:13be39911caf | 441 | int totalsize; |
sulymarco | 0:13be39911caf | 442 | ec_eepromPDOt eepPDO; |
sulymarco | 0:13be39911caf | 443 | ec_eepromPDOt *PDO; |
sulymarco | 0:13be39911caf | 444 | int abs_offset, abs_bit; |
sulymarco | 0:13be39911caf | 445 | char str_name[EC_MAXNAME + 1]; |
sulymarco | 0:13be39911caf | 446 | |
sulymarco | 0:13be39911caf | 447 | eectl = ec_slave[slave].eep_pdi; |
sulymarco | 0:13be39911caf | 448 | Size = 0; |
sulymarco | 0:13be39911caf | 449 | totalsize = 0; |
sulymarco | 0:13be39911caf | 450 | PDO = &eepPDO; |
sulymarco | 0:13be39911caf | 451 | PDO->nPDO = 0; |
sulymarco | 0:13be39911caf | 452 | PDO->Length = 0; |
sulymarco | 0:13be39911caf | 453 | PDO->Index[1] = 0; |
sulymarco | 0:13be39911caf | 454 | |
sulymarco | 0:13be39911caf | 455 | for (c = 0 ; c < EC_MAXSM ; c++) |
sulymarco | 0:13be39911caf | 456 | PDO->SMbitsize[c] = 0; |
sulymarco | 0:13be39911caf | 457 | |
sulymarco | 0:13be39911caf | 458 | if (t > 1) |
sulymarco | 0:13be39911caf | 459 | t = 1; |
sulymarco | 0:13be39911caf | 460 | |
sulymarco | 0:13be39911caf | 461 | PDO->Startpos = ec_siifind(slave, ECT_SII_PDO + t); |
sulymarco | 0:13be39911caf | 462 | |
sulymarco | 0:13be39911caf | 463 | if (PDO->Startpos > 0) |
sulymarco | 0:13be39911caf | 464 | { |
sulymarco | 0:13be39911caf | 465 | a = PDO->Startpos; |
sulymarco | 0:13be39911caf | 466 | w = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 467 | w += (ec_siigetbyte(slave, a++) << 8); |
sulymarco | 0:13be39911caf | 468 | PDO->Length = w; |
sulymarco | 0:13be39911caf | 469 | c = 1; |
sulymarco | 0:13be39911caf | 470 | |
sulymarco | 0:13be39911caf | 471 | do // traverse through all PDOs |
sulymarco | 0:13be39911caf | 472 | { |
sulymarco | 0:13be39911caf | 473 | PDO->nPDO++; |
sulymarco | 0:13be39911caf | 474 | PDO->Index[PDO->nPDO] = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 475 | PDO->Index[PDO->nPDO] += (ec_siigetbyte(slave, a++) << 8); |
sulymarco | 0:13be39911caf | 476 | PDO->BitSize[PDO->nPDO] = 0; |
sulymarco | 0:13be39911caf | 477 | c++; |
sulymarco | 0:13be39911caf | 478 | |
sulymarco | 0:13be39911caf | 479 | e = ec_siigetbyte(slave, a++); // number of entries in PDO |
sulymarco | 0:13be39911caf | 480 | PDO->SyncM[PDO->nPDO] = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 481 | a++; |
sulymarco | 0:13be39911caf | 482 | obj_name = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 483 | a += 2; |
sulymarco | 0:13be39911caf | 484 | c += 2; |
sulymarco | 0:13be39911caf | 485 | |
sulymarco | 0:13be39911caf | 486 | if (PDO->SyncM[PDO->nPDO] < EC_MAXSM) // active and in range SM? |
sulymarco | 0:13be39911caf | 487 | { |
sulymarco | 0:13be39911caf | 488 | str_name[0] = 0; |
sulymarco | 0:13be39911caf | 489 | if(obj_name) |
sulymarco | 0:13be39911caf | 490 | ec_siistring(str_name, slave, obj_name); |
sulymarco | 0:13be39911caf | 491 | |
sulymarco | 0:13be39911caf | 492 | if (t) |
sulymarco | 0:13be39911caf | 493 | printf(" SM%1d RXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name); |
sulymarco | 0:13be39911caf | 494 | else |
sulymarco | 0:13be39911caf | 495 | printf(" SM%1d TXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name); |
sulymarco | 0:13be39911caf | 496 | |
sulymarco | 0:13be39911caf | 497 | printf(" addr b index: sub bitl data_type name\n"); |
sulymarco | 0:13be39911caf | 498 | |
sulymarco | 0:13be39911caf | 499 | for (er = 1; er <= e; er++) // read all entries defined in PDO |
sulymarco | 0:13be39911caf | 500 | { |
sulymarco | 0:13be39911caf | 501 | c += 4; |
sulymarco | 0:13be39911caf | 502 | obj_idx = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 503 | obj_idx += (ec_siigetbyte(slave, a++) << 8); |
sulymarco | 0:13be39911caf | 504 | obj_subidx = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 505 | obj_name = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 506 | obj_datatype = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 507 | bitlen = ec_siigetbyte(slave, a++); |
sulymarco | 0:13be39911caf | 508 | abs_offset = mapoffset + (bitoffset / 8); |
sulymarco | 0:13be39911caf | 509 | abs_bit = bitoffset % 8; |
sulymarco | 0:13be39911caf | 510 | |
sulymarco | 0:13be39911caf | 511 | PDO->BitSize[PDO->nPDO] += bitlen; |
sulymarco | 0:13be39911caf | 512 | a += 2; |
sulymarco | 0:13be39911caf | 513 | |
sulymarco | 0:13be39911caf | 514 | if(obj_idx || obj_subidx) // skip entry if filler (0x0000:0x00) |
sulymarco | 0:13be39911caf | 515 | { |
sulymarco | 0:13be39911caf | 516 | str_name[0] = 0; |
sulymarco | 0:13be39911caf | 517 | if(obj_name) |
sulymarco | 0:13be39911caf | 518 | ec_siistring(str_name, slave, obj_name); |
sulymarco | 0:13be39911caf | 519 | |
sulymarco | 0:13be39911caf | 520 | printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen); |
sulymarco | 0:13be39911caf | 521 | printf(" %-12s %s\n", dtype2string(obj_datatype), str_name); |
sulymarco | 0:13be39911caf | 522 | } |
sulymarco | 0:13be39911caf | 523 | bitoffset += bitlen; |
sulymarco | 0:13be39911caf | 524 | totalsize += bitlen; |
sulymarco | 0:13be39911caf | 525 | } |
sulymarco | 0:13be39911caf | 526 | PDO->SMbitsize[ PDO->SyncM[PDO->nPDO] ] += PDO->BitSize[PDO->nPDO]; |
sulymarco | 0:13be39911caf | 527 | Size += PDO->BitSize[PDO->nPDO]; |
sulymarco | 0:13be39911caf | 528 | c++; |
sulymarco | 0:13be39911caf | 529 | } |
sulymarco | 0:13be39911caf | 530 | |
sulymarco | 0:13be39911caf | 531 | else // PDO deactivated because SM is 0xff or > EC_MAXSM |
sulymarco | 0:13be39911caf | 532 | { |
sulymarco | 0:13be39911caf | 533 | c += 4 * e; |
sulymarco | 0:13be39911caf | 534 | a += 8 * e; |
sulymarco | 0:13be39911caf | 535 | c++; |
sulymarco | 0:13be39911caf | 536 | } |
sulymarco | 0:13be39911caf | 537 | // limit number of PDO entries in buffer |
sulymarco | 0:13be39911caf | 538 | if (PDO->nPDO >= (EC_MAXEEPDO - 1)) c = PDO->Length; |
sulymarco | 0:13be39911caf | 539 | } |
sulymarco | 0:13be39911caf | 540 | while (c < PDO->Length); |
sulymarco | 0:13be39911caf | 541 | } |
sulymarco | 0:13be39911caf | 542 | |
sulymarco | 0:13be39911caf | 543 | if (eectl) |
sulymarco | 0:13be39911caf | 544 | ec_eeprom2pdi(slave); // if eeprom control was previously pdi then restore |
sulymarco | 0:13be39911caf | 545 | |
sulymarco | 0:13be39911caf | 546 | return totalsize; |
sulymarco | 0:13be39911caf | 547 | } |
sulymarco | 0:13be39911caf | 548 | |
sulymarco | 0:13be39911caf | 549 | |
sulymarco | 0:13be39911caf | 550 | //------------------------------------------------------------------------------ |
sulymarco | 0:13be39911caf | 551 | |
sulymarco | 0:13be39911caf | 552 | bool network_scanning(void) |
sulymarco | 0:13be39911caf | 553 | |
sulymarco | 0:13be39911caf | 554 | { |
sulymarco | 0:13be39911caf | 555 | int expectedWKC; |
sulymarco | 0:13be39911caf | 556 | int cnt, i, j, nSM; |
sulymarco | 0:13be39911caf | 557 | uint16 ssigen; |
sulymarco | 0:13be39911caf | 558 | |
sulymarco | 0:13be39911caf | 559 | if ( ec_config(FALSE, &IOmap) > 0 ) // find and configure the slaves |
sulymarco | 0:13be39911caf | 560 | { |
sulymarco | 0:13be39911caf | 561 | ec_configdc(); |
sulymarco | 0:13be39911caf | 562 | while(EcatError) printf("%s", ec_elist2string()); |
sulymarco | 0:13be39911caf | 563 | |
sulymarco | 0:13be39911caf | 564 | printf("%d slaves found and configured.\n",ec_slavecount); |
sulymarco | 0:13be39911caf | 565 | TFT.printf("%d slaves found and configured.\n\n",ec_slavecount); |
sulymarco | 0:13be39911caf | 566 | |
sulymarco | 0:13be39911caf | 567 | expectedWKC = (ec_group[0].outputsWKC * 2) + ec_group[0].inputsWKC; |
sulymarco | 0:13be39911caf | 568 | printf("Calculated workcounter %d\n", expectedWKC); |
sulymarco | 0:13be39911caf | 569 | // wait for all slaves to reach SAFE_OP state |
sulymarco | 0:13be39911caf | 570 | ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 3); |
sulymarco | 0:13be39911caf | 571 | |
sulymarco | 0:13be39911caf | 572 | if (ec_slave[0].state != EC_STATE_SAFE_OP ) |
sulymarco | 0:13be39911caf | 573 | { |
sulymarco | 0:13be39911caf | 574 | printf("Not all slaves reached safe operational state.\n"); |
sulymarco | 0:13be39911caf | 575 | ec_readstate(); |
sulymarco | 0:13be39911caf | 576 | for(i = 1; i<=ec_slavecount ; i++) |
sulymarco | 0:13be39911caf | 577 | { |
sulymarco | 0:13be39911caf | 578 | if(ec_slave[i].state != EC_STATE_SAFE_OP) |
sulymarco | 0:13be39911caf | 579 | { |
sulymarco | 0:13be39911caf | 580 | printf("Slave %d State=%2x StatusCode=%4x : %s\n", |
sulymarco | 0:13be39911caf | 581 | i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode)); |
sulymarco | 0:13be39911caf | 582 | } |
sulymarco | 0:13be39911caf | 583 | } |
sulymarco | 0:13be39911caf | 584 | } |
sulymarco | 0:13be39911caf | 585 | |
sulymarco | 0:13be39911caf | 586 | ec_readstate(); |
sulymarco | 0:13be39911caf | 587 | |
sulymarco | 0:13be39911caf | 588 | for( cnt = 1 ; cnt <= ec_slavecount ; cnt++) |
sulymarco | 0:13be39911caf | 589 | { |
sulymarco | 0:13be39911caf | 590 | printf("\nSlave:%d -------------------------------------------------\nName:%s\n Output size: %dbits\n Input size: %dbits\n State: %d\n Delay: %d[ns]\n Has DC: %d\n", |
sulymarco | 0:13be39911caf | 591 | cnt, ec_slave[cnt].name, ec_slave[cnt].Obits, ec_slave[cnt].Ibits, |
sulymarco | 0:13be39911caf | 592 | ec_slave[cnt].state, ec_slave[cnt].pdelay, ec_slave[cnt].hasdc); |
sulymarco | 0:13be39911caf | 593 | |
sulymarco | 0:13be39911caf | 594 | int Line = cnt-1; |
sulymarco | 0:13be39911caf | 595 | |
sulymarco | 0:13be39911caf | 596 | TFT.foreground(Green); // print Name, Manufacturer, ID and Revision |
sulymarco | 0:13be39911caf | 597 | TFT.locate(0, 12*(((Line % 6)*3)+3)); // of the slaves found on the TFT |
sulymarco | 0:13be39911caf | 598 | TFT.printf("Slave %d ", cnt); // |
sulymarco | 0:13be39911caf | 599 | TFT.foreground(Yellow); // |
sulymarco | 0:13be39911caf | 600 | // |
sulymarco | 0:13be39911caf | 601 | TFT.foreground(Magenta); // |
sulymarco | 0:13be39911caf | 602 | TFT.locate(60, 12*(((Line % 6)*3)+3)); // |
sulymarco | 0:13be39911caf | 603 | TFT.printf("Name"); // |
sulymarco | 0:13be39911caf | 604 | TFT.foreground(Yellow); // |
sulymarco | 0:13be39911caf | 605 | TFT.locate(104, 12*(((Line % 6)*3)+3)); // |
sulymarco | 0:13be39911caf | 606 | TFT.printf("%.14s", ec_slave[cnt].name); // |
sulymarco | 0:13be39911caf | 607 | // |
sulymarco | 0:13be39911caf | 608 | TFT.foreground(Magenta); // |
sulymarco | 0:13be39911caf | 609 | TFT.locate(220, 12*(((Line % 6)*3)+3)); // |
sulymarco | 0:13be39911caf | 610 | TFT.printf("Man"); // |
sulymarco | 0:13be39911caf | 611 | TFT.foreground(Yellow); // |
sulymarco | 0:13be39911caf | 612 | TFT.locate(250, 12*(((Line % 6)*3)+3)); // |
sulymarco | 0:13be39911caf | 613 | TFT.printf("%8.8X", (int)ec_slave[cnt].eep_man);// |
sulymarco | 0:13be39911caf | 614 | // |
sulymarco | 0:13be39911caf | 615 | TFT.foreground(Magenta); // |
sulymarco | 0:13be39911caf | 616 | TFT.locate(60, 12*(((Line % 6)*3)+4)); // |
sulymarco | 0:13be39911caf | 617 | TFT.printf("ID"); // |
sulymarco | 0:13be39911caf | 618 | TFT.foreground(Yellow); // |
sulymarco | 0:13be39911caf | 619 | TFT.locate(104, 12*(((Line % 6)*3)+4)); // |
sulymarco | 0:13be39911caf | 620 | TFT.printf("%8.8X", (int)ec_slave[cnt].eep_id); // |
sulymarco | 0:13be39911caf | 621 | // |
sulymarco | 0:13be39911caf | 622 | TFT.foreground(Magenta); // |
sulymarco | 0:13be39911caf | 623 | TFT.locate(220, 12*(((Line % 6)*3)+4)); // |
sulymarco | 0:13be39911caf | 624 | TFT.printf("Rev "); // |
sulymarco | 0:13be39911caf | 625 | TFT.foreground(Yellow); // |
sulymarco | 0:13be39911caf | 626 | TFT.locate(250, 12*(((Line % 6)*3)+4)); // |
sulymarco | 0:13be39911caf | 627 | TFT.printf("%8.8X", (int)ec_slave[cnt].eep_rev);// |
sulymarco | 0:13be39911caf | 628 | |
sulymarco | 0:13be39911caf | 629 | |
sulymarco | 0:13be39911caf | 630 | if (ec_slave[cnt].hasdc) printf(" DCParentport:%d\n", ec_slave[cnt].parentport); |
sulymarco | 0:13be39911caf | 631 | printf(" Activeports:%d.%d.%d.%d\n", (ec_slave[cnt].activeports & 0x01) > 0 , |
sulymarco | 0:13be39911caf | 632 | (ec_slave[cnt].activeports & 0x02) > 0 , |
sulymarco | 0:13be39911caf | 633 | (ec_slave[cnt].activeports & 0x04) > 0 , |
sulymarco | 0:13be39911caf | 634 | (ec_slave[cnt].activeports & 0x08) > 0 ); |
sulymarco | 0:13be39911caf | 635 | |
sulymarco | 0:13be39911caf | 636 | printf(" Configured address: %4.4X\n", ec_slave[cnt].configadr); |
sulymarco | 0:13be39911caf | 637 | printf(" Outputs address: %X\n", ec_slave[cnt].outputs); |
sulymarco | 0:13be39911caf | 638 | printf(" Inputs address: %X\n", ec_slave[cnt].inputs); |
sulymarco | 0:13be39911caf | 639 | |
sulymarco | 0:13be39911caf | 640 | printf(" Man: %8.8x ID: %8.8x Rev: %8.8x\n", (int)ec_slave[cnt].eep_man, (int)ec_slave[cnt].eep_id, (int)ec_slave[cnt].eep_rev); |
sulymarco | 0:13be39911caf | 641 | for(nSM = 0 ; nSM < EC_MAXSM ; nSM++) |
sulymarco | 0:13be39911caf | 642 | { |
sulymarco | 0:13be39911caf | 643 | if(ec_slave[cnt].SM[nSM].StartAddr > 0) |
sulymarco | 0:13be39911caf | 644 | printf(" SM%1d A:%4.4x L:%4d F:%8.8x Type:%d\n",nSM, ec_slave[cnt].SM[nSM].StartAddr, ec_slave[cnt].SM[nSM].SMlength, |
sulymarco | 0:13be39911caf | 645 | (int)ec_slave[cnt].SM[nSM].SMflags, ec_slave[cnt].SMtype[nSM]); |
sulymarco | 0:13be39911caf | 646 | } |
sulymarco | 0:13be39911caf | 647 | for(j = 0 ; j < ec_slave[cnt].FMMUunused ; j++) |
sulymarco | 0:13be39911caf | 648 | { |
sulymarco | 0:13be39911caf | 649 | printf(" FMMU%1d Ls:%8.8x Ll:%4d Lsb:%d Leb:%d Ps:%4.4x Psb:%d Ty:%2.2x Act:%2.2x\n", j, |
sulymarco | 0:13be39911caf | 650 | (int)ec_slave[cnt].FMMU[j].LogStart, ec_slave[cnt].FMMU[j].LogLength, ec_slave[cnt].FMMU[j].LogStartbit, |
sulymarco | 0:13be39911caf | 651 | ec_slave[cnt].FMMU[j].LogEndbit, ec_slave[cnt].FMMU[j].PhysStart, ec_slave[cnt].FMMU[j].PhysStartBit, |
sulymarco | 0:13be39911caf | 652 | ec_slave[cnt].FMMU[j].FMMUtype, ec_slave[cnt].FMMU[j].FMMUactive); |
sulymarco | 0:13be39911caf | 653 | } |
sulymarco | 0:13be39911caf | 654 | printf(" FMMUfunc 0:%d 1:%d 2:%d 3:%d\n", |
sulymarco | 0:13be39911caf | 655 | ec_slave[cnt].FMMU0func, ec_slave[cnt].FMMU1func, ec_slave[cnt].FMMU2func, ec_slave[cnt].FMMU3func); |
sulymarco | 0:13be39911caf | 656 | printf(" MBX length wr: %d rd: %d MBX protocols : %2.2x\n", ec_slave[cnt].mbx_l, ec_slave[cnt].mbx_rl, ec_slave[cnt].mbx_proto); |
sulymarco | 0:13be39911caf | 657 | ssigen = ec_siifind(cnt, ECT_SII_GENERAL); |
sulymarco | 0:13be39911caf | 658 | |
sulymarco | 0:13be39911caf | 659 | if (ssigen) // SII general section |
sulymarco | 0:13be39911caf | 660 | { |
sulymarco | 0:13be39911caf | 661 | ec_slave[cnt].CoEdetails = ec_siigetbyte(cnt, ssigen + 0x07); |
sulymarco | 0:13be39911caf | 662 | ec_slave[cnt].FoEdetails = ec_siigetbyte(cnt, ssigen + 0x08); |
sulymarco | 0:13be39911caf | 663 | ec_slave[cnt].EoEdetails = ec_siigetbyte(cnt, ssigen + 0x09); |
sulymarco | 0:13be39911caf | 664 | ec_slave[cnt].SoEdetails = ec_siigetbyte(cnt, ssigen + 0x0a); |
sulymarco | 0:13be39911caf | 665 | if((ec_siigetbyte(cnt, ssigen + 0x0d) & 0x02) > 0) |
sulymarco | 0:13be39911caf | 666 | { |
sulymarco | 0:13be39911caf | 667 | ec_slave[cnt].blockLRW = 1; |
sulymarco | 0:13be39911caf | 668 | ec_slave[0].blockLRW++; |
sulymarco | 0:13be39911caf | 669 | } |
sulymarco | 0:13be39911caf | 670 | ec_slave[cnt].Ebuscurrent = ec_siigetbyte(cnt, ssigen + 0x0e); |
sulymarco | 0:13be39911caf | 671 | ec_slave[cnt].Ebuscurrent += ec_siigetbyte(cnt, ssigen + 0x0f) << 8; |
sulymarco | 0:13be39911caf | 672 | ec_slave[0].Ebuscurrent += ec_slave[cnt].Ebuscurrent; |
sulymarco | 0:13be39911caf | 673 | } |
sulymarco | 0:13be39911caf | 674 | printf(" CoE details: %2.2x FoE details: %2.2x EoE details: %2.2x SoE details: %2.2x\n", |
sulymarco | 0:13be39911caf | 675 | ec_slave[cnt].CoEdetails, ec_slave[cnt].FoEdetails, ec_slave[cnt].EoEdetails, ec_slave[cnt].SoEdetails); |
sulymarco | 0:13be39911caf | 676 | printf(" Ebus current: %d[mA]\n only LRD/LWR:%d\n", |
sulymarco | 0:13be39911caf | 677 | ec_slave[cnt].Ebuscurrent, ec_slave[cnt].blockLRW); |
sulymarco | 0:13be39911caf | 678 | |
sulymarco | 0:13be39911caf | 679 | if ((ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE) && printSDO) |
sulymarco | 0:13be39911caf | 680 | si_sdo(cnt); |
sulymarco | 0:13be39911caf | 681 | |
sulymarco | 0:13be39911caf | 682 | if(printMAP) |
sulymarco | 0:13be39911caf | 683 | { |
sulymarco | 0:13be39911caf | 684 | if (ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE) |
sulymarco | 0:13be39911caf | 685 | si_map_sdo(cnt); |
sulymarco | 0:13be39911caf | 686 | else |
sulymarco | 0:13be39911caf | 687 | si_map_sii(cnt); |
sulymarco | 0:13be39911caf | 688 | } |
sulymarco | 0:13be39911caf | 689 | } |
sulymarco | 0:13be39911caf | 690 | return 1; |
sulymarco | 0:13be39911caf | 691 | } |
sulymarco | 0:13be39911caf | 692 | |
sulymarco | 0:13be39911caf | 693 | else |
sulymarco | 0:13be39911caf | 694 | { |
sulymarco | 0:13be39911caf | 695 | // ec_close(); //******// |
sulymarco | 0:13be39911caf | 696 | |
sulymarco | 0:13be39911caf | 697 | return 0; // no slaves found |
sulymarco | 0:13be39911caf | 698 | } |
sulymarco | 0:13be39911caf | 699 | } |
sulymarco | 0:13be39911caf | 700 | |
sulymarco | 0:13be39911caf | 701 | |
sulymarco | 0:13be39911caf | 702 | |
sulymarco | 0:13be39911caf | 703 | |
sulymarco | 0:13be39911caf | 704 | |
sulymarco | 0:13be39911caf | 705 |