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