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.
config.h@0:7077d8f28b3e, 2019-06-11 (annotated)
- Committer:
- sulymarco
- Date:
- Tue Jun 11 10:19:08 2019 +0000
- Revision:
- 0:7077d8f28b3e
- Child:
- 2:7d4fd6354015
Added SPI speed parameter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sulymarco | 0:7077d8f28b3e | 1 | #ifndef config_H |
sulymarco | 0:7077d8f28b3e | 2 | #define config_H |
sulymarco | 0:7077d8f28b3e | 3 | |
sulymarco | 0:7077d8f28b3e | 4 | #include "ethercat.h" |
sulymarco | 0:7077d8f28b3e | 5 | |
sulymarco | 0:7077d8f28b3e | 6 | |
sulymarco | 0:7077d8f28b3e | 7 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 8 | |
sulymarco | 0:7077d8f28b3e | 9 | #define LAB_1 1 |
sulymarco | 0:7077d8f28b3e | 10 | #define LAB_2 2 |
sulymarco | 0:7077d8f28b3e | 11 | |
sulymarco | 0:7077d8f28b3e | 12 | /* |
sulymarco | 0:7077d8f28b3e | 13 | #define EK1100 3 |
sulymarco | 0:7077d8f28b3e | 14 | #define EL2004 4 |
sulymarco | 0:7077d8f28b3e | 15 | #define EL1014 5 |
sulymarco | 0:7077d8f28b3e | 16 | */ |
sulymarco | 0:7077d8f28b3e | 17 | |
sulymarco | 0:7077d8f28b3e | 18 | #define SLAVE_NUM 2 |
sulymarco | 0:7077d8f28b3e | 19 | //#define SLAVE_NUM 5 |
sulymarco | 0:7077d8f28b3e | 20 | |
sulymarco | 0:7077d8f28b3e | 21 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 22 | |
sulymarco | 0:7077d8f28b3e | 23 | |
sulymarco | 0:7077d8f28b3e | 24 | #define IO_MAP_SIZE 256 |
sulymarco | 0:7077d8f28b3e | 25 | |
sulymarco | 0:7077d8f28b3e | 26 | |
sulymarco | 0:7077d8f28b3e | 27 | |
sulymarco | 0:7077d8f28b3e | 28 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 29 | |
sulymarco | 0:7077d8f28b3e | 30 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:7077d8f28b3e | 31 | { |
sulymarco | 0:7077d8f28b3e | 32 | uint8_t Alarm; |
sulymarco | 0:7077d8f28b3e | 33 | }out_LAB_1t; |
sulymarco | 0:7077d8f28b3e | 34 | |
sulymarco | 0:7077d8f28b3e | 35 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:7077d8f28b3e | 36 | { |
sulymarco | 0:7077d8f28b3e | 37 | float Temperature; |
sulymarco | 0:7077d8f28b3e | 38 | }in_LAB_1t; |
sulymarco | 0:7077d8f28b3e | 39 | |
sulymarco | 0:7077d8f28b3e | 40 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 41 | |
sulymarco | 0:7077d8f28b3e | 42 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:7077d8f28b3e | 43 | { |
sulymarco | 0:7077d8f28b3e | 44 | uint8_t Segments; |
sulymarco | 0:7077d8f28b3e | 45 | }out_LAB_2t; |
sulymarco | 0:7077d8f28b3e | 46 | |
sulymarco | 0:7077d8f28b3e | 47 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:7077d8f28b3e | 48 | { |
sulymarco | 0:7077d8f28b3e | 49 | uint16_t Potentiometer; |
sulymarco | 0:7077d8f28b3e | 50 | uint8_t Buttons; |
sulymarco | 0:7077d8f28b3e | 51 | }in_LAB_2t; |
sulymarco | 0:7077d8f28b3e | 52 | |
sulymarco | 0:7077d8f28b3e | 53 | /* |
sulymarco | 0:7077d8f28b3e | 54 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 55 | |
sulymarco | 0:7077d8f28b3e | 56 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:7077d8f28b3e | 57 | { |
sulymarco | 0:7077d8f28b3e | 58 | uint8_t Out_0:1; |
sulymarco | 0:7077d8f28b3e | 59 | uint8_t Out_1:1; |
sulymarco | 0:7077d8f28b3e | 60 | uint8_t Out_2:1; |
sulymarco | 0:7077d8f28b3e | 61 | uint8_t Out_3:1; |
sulymarco | 0:7077d8f28b3e | 62 | uint8_t PAD:4; |
sulymarco | 0:7077d8f28b3e | 63 | }out_EL2004t; |
sulymarco | 0:7077d8f28b3e | 64 | |
sulymarco | 0:7077d8f28b3e | 65 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 66 | |
sulymarco | 0:7077d8f28b3e | 67 | typedef struct __attribute__((__packed__)) |
sulymarco | 0:7077d8f28b3e | 68 | { |
sulymarco | 0:7077d8f28b3e | 69 | uint8_t In_0:1; |
sulymarco | 0:7077d8f28b3e | 70 | uint8_t In_1:1; |
sulymarco | 0:7077d8f28b3e | 71 | uint8_t In_2:1; |
sulymarco | 0:7077d8f28b3e | 72 | uint8_t In_3:1; |
sulymarco | 0:7077d8f28b3e | 73 | uint8_t PAD:4; |
sulymarco | 0:7077d8f28b3e | 74 | }in_EL1014t; |
sulymarco | 0:7077d8f28b3e | 75 | |
sulymarco | 0:7077d8f28b3e | 76 | |
sulymarco | 0:7077d8f28b3e | 77 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 78 | */ |
sulymarco | 0:7077d8f28b3e | 79 | |
sulymarco | 0:7077d8f28b3e | 80 | out_LAB_1t *out_LAB_1; |
sulymarco | 0:7077d8f28b3e | 81 | in_LAB_1t *in_LAB_1; |
sulymarco | 0:7077d8f28b3e | 82 | |
sulymarco | 0:7077d8f28b3e | 83 | out_LAB_2t *out_LAB_2; |
sulymarco | 0:7077d8f28b3e | 84 | in_LAB_2t *in_LAB_2; |
sulymarco | 0:7077d8f28b3e | 85 | |
sulymarco | 0:7077d8f28b3e | 86 | /* |
sulymarco | 0:7077d8f28b3e | 87 | out_EL2004t *out_EL2004; |
sulymarco | 0:7077d8f28b3e | 88 | |
sulymarco | 0:7077d8f28b3e | 89 | in_EL1014t *in_EL1014; |
sulymarco | 0:7077d8f28b3e | 90 | */ |
sulymarco | 0:7077d8f28b3e | 91 | |
sulymarco | 0:7077d8f28b3e | 92 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 93 | |
sulymarco | 0:7077d8f28b3e | 94 | char IOmap[IO_MAP_SIZE]; |
sulymarco | 0:7077d8f28b3e | 95 | char IOmapSafe[IO_MAP_SIZE]; |
sulymarco | 0:7077d8f28b3e | 96 | |
sulymarco | 0:7077d8f28b3e | 97 | |
sulymarco | 0:7077d8f28b3e | 98 | void MapLocalStructures (void) |
sulymarco | 0:7077d8f28b3e | 99 | { |
sulymarco | 0:7077d8f28b3e | 100 | out_LAB_1 = (out_LAB_1t*)((char *)ec_slave[LAB_1].outputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:7077d8f28b3e | 101 | in_LAB_1 = (in_LAB_1t*)((char *)ec_slave[LAB_1].inputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:7077d8f28b3e | 102 | |
sulymarco | 0:7077d8f28b3e | 103 | out_LAB_2 = (out_LAB_2t*)((char *)ec_slave[LAB_2].outputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:7077d8f28b3e | 104 | in_LAB_2 = (in_LAB_2t*)((char *)ec_slave[LAB_2].inputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:7077d8f28b3e | 105 | |
sulymarco | 0:7077d8f28b3e | 106 | /* |
sulymarco | 0:7077d8f28b3e | 107 | out_EL2004 = (out_EL2004t*)((char *)ec_slave[EL2004].outputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:7077d8f28b3e | 108 | |
sulymarco | 0:7077d8f28b3e | 109 | in_EL1014 = (in_EL1014t*)((char *)ec_slave[EL1014].inputs - &IOmap[0] + &IOmapSafe[0]); |
sulymarco | 0:7077d8f28b3e | 110 | */ |
sulymarco | 0:7077d8f28b3e | 111 | } |
sulymarco | 0:7077d8f28b3e | 112 | |
sulymarco | 0:7077d8f28b3e | 113 | |
sulymarco | 0:7077d8f28b3e | 114 | |
sulymarco | 0:7077d8f28b3e | 115 | //------------------------------------------------------------------------------ |
sulymarco | 0:7077d8f28b3e | 116 | |
sulymarco | 0:7077d8f28b3e | 117 | uint32_t network_configuration(void) |
sulymarco | 0:7077d8f28b3e | 118 | { |
sulymarco | 0:7077d8f28b3e | 119 | |
sulymarco | 0:7077d8f28b3e | 120 | if (ec_slavecount != SLAVE_NUM) // check if the number of slaves matches what we expect |
sulymarco | 0:7077d8f28b3e | 121 | return 0; |
sulymarco | 0:7077d8f28b3e | 122 | |
sulymarco | 0:7077d8f28b3e | 123 | if (strcmp(ec_slave[LAB_1].name,"LAB_1")) // verify slave by slave that the slave names are correct |
sulymarco | 0:7077d8f28b3e | 124 | return 0; |
sulymarco | 0:7077d8f28b3e | 125 | |
sulymarco | 0:7077d8f28b3e | 126 | else if (strcmp(ec_slave[LAB_2].name,"LAB_2")) |
sulymarco | 0:7077d8f28b3e | 127 | return 0; |
sulymarco | 0:7077d8f28b3e | 128 | |
sulymarco | 0:7077d8f28b3e | 129 | /* |
sulymarco | 0:7077d8f28b3e | 130 | else if (strcmp(ec_slave[EK1100].name,"EK1100")) |
sulymarco | 0:7077d8f28b3e | 131 | return 0; |
sulymarco | 0:7077d8f28b3e | 132 | |
sulymarco | 0:7077d8f28b3e | 133 | else if (strcmp(ec_slave[EL2004].name,"EL2004")) |
sulymarco | 0:7077d8f28b3e | 134 | return 0; |
sulymarco | 0:7077d8f28b3e | 135 | |
sulymarco | 0:7077d8f28b3e | 136 | else if (strcmp(ec_slave[EL1014].name,"EL1014")) |
sulymarco | 0:7077d8f28b3e | 137 | return 0; |
sulymarco | 0:7077d8f28b3e | 138 | */ |
sulymarco | 0:7077d8f28b3e | 139 | |
sulymarco | 0:7077d8f28b3e | 140 | return 1; |
sulymarco | 0:7077d8f28b3e | 141 | } |
sulymarco | 0:7077d8f28b3e | 142 | |
sulymarco | 0:7077d8f28b3e | 143 | |
sulymarco | 0:7077d8f28b3e | 144 | #endif |