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 .

/media/uploads/EasyCAT/easycat_lab.jpg

/media/uploads/EasyCAT/components.jpg

config.h

Committer:
EasyCAT
Date:
2019-06-11
Revision:
2:7d4fd6354015
Parent:
0:7077d8f28b3e

File content as of revision 2:7d4fd6354015:

#ifndef config_H
#define config_H

#include "ethercat.h"


//------------------------------------------------------------------------------

#define LAB_1               1
#define LAB_2               2

#define SLAVE_NUM           2

//------------------------------------------------------------------------------


#define IO_MAP_SIZE 256



//------------------------------------------------------------------------------

typedef struct __attribute__((__packed__))
{
    uint8_t     Alarm;
}out_LAB_1t;

typedef struct __attribute__((__packed__))
{
    float       Temperature;
}in_LAB_1t;

//------------------------------------------------------------------------------

typedef struct __attribute__((__packed__))
{
    uint8_t     Segments;
}out_LAB_2t;

typedef struct __attribute__((__packed__))
{
    uint16_t    Potentiometer;    
    uint8_t     Buttons;
}in_LAB_2t;


out_LAB_1t    *out_LAB_1;
in_LAB_1t     *in_LAB_1;

out_LAB_2t    *out_LAB_2;
in_LAB_2t     *in_LAB_2;


//------------------------------------------------------------------------------

char IOmap[IO_MAP_SIZE];
char IOmapSafe[IO_MAP_SIZE];   


void MapLocalStructures (void)
{
    out_LAB_1 = (out_LAB_1t*)((char *)ec_slave[LAB_1].outputs - &IOmap[0] + &IOmapSafe[0]);
    in_LAB_1 =  (in_LAB_1t*)((char *)ec_slave[LAB_1].inputs - &IOmap[0] + &IOmapSafe[0]);                
    
    out_LAB_2 = (out_LAB_2t*)((char *)ec_slave[LAB_2].outputs - &IOmap[0] + &IOmapSafe[0]);
    in_LAB_2 =  (in_LAB_2t*)((char *)ec_slave[LAB_2].inputs - &IOmap[0] + &IOmapSafe[0]);                
}



//------------------------------------------------------------------------------

uint32_t network_configuration(void)
{

   if (ec_slavecount != SLAVE_NUM)                          // check if the number of slaves matches what we expect
      return 0;                                             
                                                            
   if (strcmp(ec_slave[LAB_1].name,"LAB_1"))                // verify slave by slave that the slave names are correct  
      return 0;
   
   else if (strcmp(ec_slave[LAB_2].name,"LAB_2"))
      return 0;
      
  return 1;
}


#endif