SOEM EtherCAT Master library for STM Nucleo F767ZI

Dependents:   EasyCAT_LAB_simple EasyCAT_LAB_very_simple EasyCAT_LAB

  • It has been developed for the EasyCAT LAB , a complete educational and experimental EtherCAT® system, composed of one master and two slaves .

Warning

/media/uploads/EasyCAT/easycat_lab.jpg

Committer:
EasyCAT
Date:
Tue Jun 11 10:29:09 2019 +0000
Revision:
0:543d6784d4cc
SOEM EtherCAT Master Library for STM Nucleo F767ZI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EasyCAT 0:543d6784d4cc 1 /*
EasyCAT 0:543d6784d4cc 2 * Licensed under the GNU General Public License version 2 with exceptions. See
EasyCAT 0:543d6784d4cc 3 * LICENSE file in the project root for full license information
EasyCAT 0:543d6784d4cc 4 */
EasyCAT 0:543d6784d4cc 5
EasyCAT 0:543d6784d4cc 6 /** \file
EasyCAT 0:543d6784d4cc 7 * \brief
EasyCAT 0:543d6784d4cc 8 * Headerfile for nicdrv.c
EasyCAT 0:543d6784d4cc 9 */
EasyCAT 0:543d6784d4cc 10
EasyCAT 0:543d6784d4cc 11 #ifndef _nicdrvh_
EasyCAT 0:543d6784d4cc 12 #define _nicdrvh_
EasyCAT 0:543d6784d4cc 13
EasyCAT 0:543d6784d4cc 14 /** pointer structure to Tx and Rx stacks */
EasyCAT 0:543d6784d4cc 15 typedef struct
EasyCAT 0:543d6784d4cc 16 {
EasyCAT 0:543d6784d4cc 17 /** socket connection used */
EasyCAT 0:543d6784d4cc 18 int *sock;
EasyCAT 0:543d6784d4cc 19 /** tx buffer */
EasyCAT 0:543d6784d4cc 20 ec_bufT (*txbuf)[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 21 /** tx buffer lengths */
EasyCAT 0:543d6784d4cc 22 int (*txbuflength)[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 23 /** temporary receive buffer */
EasyCAT 0:543d6784d4cc 24 ec_bufT *tempbuf;
EasyCAT 0:543d6784d4cc 25 /** rx buffers */
EasyCAT 0:543d6784d4cc 26 ec_bufT (*rxbuf)[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 27 /** rx buffer status fields */
EasyCAT 0:543d6784d4cc 28 int (*rxbufstat)[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 29 /** received MAC source address (middle word) */
EasyCAT 0:543d6784d4cc 30 int (*rxsa)[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 31 } ec_stackT;
EasyCAT 0:543d6784d4cc 32
EasyCAT 0:543d6784d4cc 33 /** pointer structure to buffers for redundant port */
EasyCAT 0:543d6784d4cc 34 typedef struct
EasyCAT 0:543d6784d4cc 35 {
EasyCAT 0:543d6784d4cc 36 ec_stackT stack;
EasyCAT 0:543d6784d4cc 37 int sockhandle;
EasyCAT 0:543d6784d4cc 38 /** rx buffers */
EasyCAT 0:543d6784d4cc 39 ec_bufT rxbuf[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 40 /** rx buffer status */
EasyCAT 0:543d6784d4cc 41 int rxbufstat[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 42 /** rx MAC source address */
EasyCAT 0:543d6784d4cc 43 int rxsa[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 44 /** temporary rx buffer */
EasyCAT 0:543d6784d4cc 45 ec_bufT tempinbuf;
EasyCAT 0:543d6784d4cc 46 } ecx_redportt;
EasyCAT 0:543d6784d4cc 47
EasyCAT 0:543d6784d4cc 48 /** pointer structure to buffers, vars and mutexes for port instantiation */
EasyCAT 0:543d6784d4cc 49 typedef struct
EasyCAT 0:543d6784d4cc 50 {
EasyCAT 0:543d6784d4cc 51 ec_stackT stack;
EasyCAT 0:543d6784d4cc 52 int sockhandle;
EasyCAT 0:543d6784d4cc 53 /** rx buffers */
EasyCAT 0:543d6784d4cc 54 ec_bufT rxbuf[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 55 /** rx buffer status */
EasyCAT 0:543d6784d4cc 56 int rxbufstat[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 57 /** rx MAC source address */
EasyCAT 0:543d6784d4cc 58 int rxsa[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 59 /** temporary rx buffer */
EasyCAT 0:543d6784d4cc 60 ec_bufT tempinbuf;
EasyCAT 0:543d6784d4cc 61 /** temporary rx buffer status */
EasyCAT 0:543d6784d4cc 62 int tempinbufs;
EasyCAT 0:543d6784d4cc 63 /** transmit buffers */
EasyCAT 0:543d6784d4cc 64 ec_bufT txbuf[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 65 /** transmit buffer lengths */
EasyCAT 0:543d6784d4cc 66 int txbuflength[EC_MAXBUF];
EasyCAT 0:543d6784d4cc 67 /** temporary tx buffer */
EasyCAT 0:543d6784d4cc 68 ec_bufT txbuf2;
EasyCAT 0:543d6784d4cc 69 /** temporary tx buffer length */
EasyCAT 0:543d6784d4cc 70 int txbuflength2;
EasyCAT 0:543d6784d4cc 71 /** last used frame index */
EasyCAT 0:543d6784d4cc 72 int lastidx;
EasyCAT 0:543d6784d4cc 73 /** current redundancy state */
EasyCAT 0:543d6784d4cc 74 int redstate;
EasyCAT 0:543d6784d4cc 75 /** pointer to redundancy port and buffers */
EasyCAT 0:543d6784d4cc 76 ecx_redportt *redport;
EasyCAT 0:543d6784d4cc 77 //mtx_t * getindex_mutex; //******//
EasyCAT 0:543d6784d4cc 78 //mtx_t * tx_mutex; //******//
EasyCAT 0:543d6784d4cc 79 //mtx_t * rx_mutex; //******//
EasyCAT 0:543d6784d4cc 80 } ecx_portt;
EasyCAT 0:543d6784d4cc 81
EasyCAT 0:543d6784d4cc 82 extern const uint16 priMAC[3];
EasyCAT 0:543d6784d4cc 83 extern const uint16 secMAC[3];
EasyCAT 0:543d6784d4cc 84
EasyCAT 0:543d6784d4cc 85 #ifdef EC_VER1
EasyCAT 0:543d6784d4cc 86 extern ecx_portt ecx_port;
EasyCAT 0:543d6784d4cc 87 extern ecx_redportt ecx_redport;
EasyCAT 0:543d6784d4cc 88
EasyCAT 0:543d6784d4cc 89 int ec_setupnic(const char * ifname, int secondary);
EasyCAT 0:543d6784d4cc 90 int ec_closenic(void);
EasyCAT 0:543d6784d4cc 91 void ec_setbufstat(int idx, int bufstat);
EasyCAT 0:543d6784d4cc 92 int ec_getindex(void);
EasyCAT 0:543d6784d4cc 93 int ec_outframe(int idx, int stacknumber);
EasyCAT 0:543d6784d4cc 94 int ec_outframe_red(int idx);
EasyCAT 0:543d6784d4cc 95 int ec_waitinframe(int idx, int timeout);
EasyCAT 0:543d6784d4cc 96 int ec_srconfirm(int idx,int timeout);
EasyCAT 0:543d6784d4cc 97 #endif
EasyCAT 0:543d6784d4cc 98
EasyCAT 0:543d6784d4cc 99 void ec_setupheader(void *p);
EasyCAT 0:543d6784d4cc 100
EasyCAT 0:543d6784d4cc 101 int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary);
EasyCAT 0:543d6784d4cc 102 int ecx_closenic(ecx_portt *port);
EasyCAT 0:543d6784d4cc 103 void ecx_setbufstat(ecx_portt *port, int idx, int bufstat);
EasyCAT 0:543d6784d4cc 104 int ecx_getindex(ecx_portt *port);
EasyCAT 0:543d6784d4cc 105 int ecx_outframe(ecx_portt *port, int idx, int stacknumber);
EasyCAT 0:543d6784d4cc 106 int ecx_outframe_red(ecx_portt *port, int idx);
EasyCAT 0:543d6784d4cc 107 int ecx_waitinframe(ecx_portt *port, int idx, int timeout);
EasyCAT 0:543d6784d4cc 108 int ecx_srconfirm(ecx_portt *port, int idx,int timeout);
EasyCAT 0:543d6784d4cc 109
EasyCAT 0:543d6784d4cc 110 #endif