EasyCAT LAB - EtherCAT master legacy example
Dependencies: SOEM SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts
config.h
00001 #ifndef config_H 00002 #define config_H 00003 00004 #include "ethercat.h" 00005 00006 00007 //------------------------------------------------------------------------------ 00008 00009 #define LAB_1 1 00010 #define LAB_2 2 00011 00012 #define SLAVE_NUM 2 00013 00014 //------------------------------------------------------------------------------ 00015 00016 00017 #define IO_MAP_SIZE 256 00018 00019 00020 00021 //------------------------------------------------------------------------------ 00022 00023 typedef struct __attribute__((__packed__)) 00024 { 00025 uint8_t Alarm; 00026 }out_LAB_1t; 00027 00028 typedef struct __attribute__((__packed__)) 00029 { 00030 float Temperature; 00031 }in_LAB_1t; 00032 00033 //------------------------------------------------------------------------------ 00034 00035 typedef struct __attribute__((__packed__)) 00036 { 00037 uint8_t Segments; 00038 }out_LAB_2t; 00039 00040 typedef struct __attribute__((__packed__)) 00041 { 00042 uint16_t Potentiometer; 00043 uint8_t Buttons; 00044 }in_LAB_2t; 00045 00046 00047 out_LAB_1t *out_LAB_1; 00048 in_LAB_1t *in_LAB_1; 00049 00050 out_LAB_2t *out_LAB_2; 00051 in_LAB_2t *in_LAB_2; 00052 00053 00054 //------------------------------------------------------------------------------ 00055 00056 char IOmap[IO_MAP_SIZE]; 00057 char IOmapSafe[IO_MAP_SIZE]; 00058 00059 00060 void MapLocalStructures (void) 00061 { 00062 out_LAB_1 = (out_LAB_1t*)((char *)ec_slave[LAB_1].outputs - &IOmap[0] + &IOmapSafe[0]); 00063 in_LAB_1 = (in_LAB_1t*)((char *)ec_slave[LAB_1].inputs - &IOmap[0] + &IOmapSafe[0]); 00064 00065 out_LAB_2 = (out_LAB_2t*)((char *)ec_slave[LAB_2].outputs - &IOmap[0] + &IOmapSafe[0]); 00066 in_LAB_2 = (in_LAB_2t*)((char *)ec_slave[LAB_2].inputs - &IOmap[0] + &IOmapSafe[0]); 00067 } 00068 00069 00070 00071 //------------------------------------------------------------------------------ 00072 00073 uint32_t network_configuration(void) 00074 { 00075 00076 if (ec_slavecount != SLAVE_NUM) // check if the number of slaves matches what we expect 00077 return 0; 00078 00079 if (strcmp(ec_slave[LAB_1].name,"LAB_1")) // verify slave by slave that the slave names are correct 00080 return 0; 00081 00082 else if (strcmp(ec_slave[LAB_2].name,"LAB_2")) 00083 return 0; 00084 00085 return 1; 00086 } 00087 00088 00089 #endif
Generated on Thu Oct 26 2023 12:29:59 by 1.7.2