EasyCAT LAB - EtherCAT master legacy example

Dependencies:   SPI_STMPE610 TFT_fonts SPI_TFT_ILI9341 SOEM

The EasyCAT LAB is a complete educational and experimental EtherCAT® system, composed of one master and two slaves .

/media/uploads/EasyCAT/easycat_lab.jpg

/media/uploads/EasyCAT/components.jpg

Committer:
sulymarco
Date:
Fri May 28 09:40:12 2021 +0000
Revision:
6:4b39b4dee215
Parent:
2:7d4fd6354015
Added clarification about the TFT

Who changed what in which revision?

UserRevisionLine numberNew 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 #define SLAVE_NUM 2
sulymarco 0:7077d8f28b3e 13
sulymarco 0:7077d8f28b3e 14 //------------------------------------------------------------------------------
sulymarco 0:7077d8f28b3e 15
sulymarco 0:7077d8f28b3e 16
sulymarco 0:7077d8f28b3e 17 #define IO_MAP_SIZE 256
sulymarco 0:7077d8f28b3e 18
sulymarco 0:7077d8f28b3e 19
sulymarco 0:7077d8f28b3e 20
sulymarco 0:7077d8f28b3e 21 //------------------------------------------------------------------------------
sulymarco 0:7077d8f28b3e 22
sulymarco 0:7077d8f28b3e 23 typedef struct __attribute__((__packed__))
sulymarco 0:7077d8f28b3e 24 {
sulymarco 0:7077d8f28b3e 25 uint8_t Alarm;
sulymarco 0:7077d8f28b3e 26 }out_LAB_1t;
sulymarco 0:7077d8f28b3e 27
sulymarco 0:7077d8f28b3e 28 typedef struct __attribute__((__packed__))
sulymarco 0:7077d8f28b3e 29 {
sulymarco 0:7077d8f28b3e 30 float Temperature;
sulymarco 0:7077d8f28b3e 31 }in_LAB_1t;
sulymarco 0:7077d8f28b3e 32
sulymarco 0:7077d8f28b3e 33 //------------------------------------------------------------------------------
sulymarco 0:7077d8f28b3e 34
sulymarco 0:7077d8f28b3e 35 typedef struct __attribute__((__packed__))
sulymarco 0:7077d8f28b3e 36 {
sulymarco 0:7077d8f28b3e 37 uint8_t Segments;
sulymarco 0:7077d8f28b3e 38 }out_LAB_2t;
sulymarco 0:7077d8f28b3e 39
sulymarco 0:7077d8f28b3e 40 typedef struct __attribute__((__packed__))
sulymarco 0:7077d8f28b3e 41 {
sulymarco 0:7077d8f28b3e 42 uint16_t Potentiometer;
sulymarco 0:7077d8f28b3e 43 uint8_t Buttons;
sulymarco 0:7077d8f28b3e 44 }in_LAB_2t;
sulymarco 0:7077d8f28b3e 45
sulymarco 0:7077d8f28b3e 46
sulymarco 0:7077d8f28b3e 47 out_LAB_1t *out_LAB_1;
sulymarco 0:7077d8f28b3e 48 in_LAB_1t *in_LAB_1;
sulymarco 0:7077d8f28b3e 49
sulymarco 0:7077d8f28b3e 50 out_LAB_2t *out_LAB_2;
sulymarco 0:7077d8f28b3e 51 in_LAB_2t *in_LAB_2;
sulymarco 0:7077d8f28b3e 52
sulymarco 0:7077d8f28b3e 53
sulymarco 0:7077d8f28b3e 54 //------------------------------------------------------------------------------
sulymarco 0:7077d8f28b3e 55
sulymarco 0:7077d8f28b3e 56 char IOmap[IO_MAP_SIZE];
sulymarco 0:7077d8f28b3e 57 char IOmapSafe[IO_MAP_SIZE];
sulymarco 0:7077d8f28b3e 58
sulymarco 0:7077d8f28b3e 59
sulymarco 0:7077d8f28b3e 60 void MapLocalStructures (void)
sulymarco 0:7077d8f28b3e 61 {
sulymarco 0:7077d8f28b3e 62 out_LAB_1 = (out_LAB_1t*)((char *)ec_slave[LAB_1].outputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:7077d8f28b3e 63 in_LAB_1 = (in_LAB_1t*)((char *)ec_slave[LAB_1].inputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:7077d8f28b3e 64
sulymarco 0:7077d8f28b3e 65 out_LAB_2 = (out_LAB_2t*)((char *)ec_slave[LAB_2].outputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:7077d8f28b3e 66 in_LAB_2 = (in_LAB_2t*)((char *)ec_slave[LAB_2].inputs - &IOmap[0] + &IOmapSafe[0]);
sulymarco 0:7077d8f28b3e 67 }
sulymarco 0:7077d8f28b3e 68
sulymarco 0:7077d8f28b3e 69
sulymarco 0:7077d8f28b3e 70
sulymarco 0:7077d8f28b3e 71 //------------------------------------------------------------------------------
sulymarco 0:7077d8f28b3e 72
sulymarco 0:7077d8f28b3e 73 uint32_t network_configuration(void)
sulymarco 0:7077d8f28b3e 74 {
sulymarco 0:7077d8f28b3e 75
sulymarco 0:7077d8f28b3e 76 if (ec_slavecount != SLAVE_NUM) // check if the number of slaves matches what we expect
sulymarco 0:7077d8f28b3e 77 return 0;
sulymarco 0:7077d8f28b3e 78
sulymarco 0:7077d8f28b3e 79 if (strcmp(ec_slave[LAB_1].name,"LAB_1")) // verify slave by slave that the slave names are correct
sulymarco 0:7077d8f28b3e 80 return 0;
sulymarco 0:7077d8f28b3e 81
sulymarco 0:7077d8f28b3e 82 else if (strcmp(ec_slave[LAB_2].name,"LAB_2"))
sulymarco 0:7077d8f28b3e 83 return 0;
sulymarco 0:7077d8f28b3e 84
sulymarco 0:7077d8f28b3e 85 return 1;
sulymarco 0:7077d8f28b3e 86 }
sulymarco 0:7077d8f28b3e 87
sulymarco 0:7077d8f28b3e 88
sulymarco 0:7077d8f28b3e 89 #endif