IgH EtherCAT Master  1.6.2
datagram.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
4  *
5  * This file is part of the IgH EtherCAT Master.
6  *
7  * The IgH EtherCAT Master is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version 2, as
9  * published by the Free Software Foundation.
10  *
11  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with the IgH EtherCAT Master; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  ****************************************************************************/
21 
27 /****************************************************************************/
28 
29 #ifndef __EC_DATAGRAM_H__
30 #define __EC_DATAGRAM_H__
31 
32 #include <linux/list.h>
33 #include <linux/time.h>
34 #include <linux/timex.h>
35 
36 #include "globals.h"
37 
38 /****************************************************************************/
39 
42 typedef enum {
50  EC_DATAGRAM_BRD = 0x07,
51  EC_DATAGRAM_BWR = 0x08,
52  EC_DATAGRAM_BRW = 0x09,
53  EC_DATAGRAM_LRD = 0x0A,
54  EC_DATAGRAM_LWR = 0x0B,
55  EC_DATAGRAM_LRW = 0x0C,
61 
62 /****************************************************************************/
63 
66 typedef enum {
74 
75 /****************************************************************************/
76 
79 typedef struct {
80  struct list_head queue;
82  struct list_head ext_queue;
83  struct list_head sent;
87  uint8_t address[EC_ADDR_LEN];
88  uint8_t *data;
90  size_t mem_size;
91  size_t data_size;
92  uint8_t index;
93  uint16_t working_counter;
95 #ifdef EC_HAVE_CYCLES
96  cycles_t cycles_sent;
97 #endif
98  unsigned long jiffies_sent;
99 #ifdef EC_HAVE_CYCLES
100  cycles_t cycles_received;
101 #endif
102  unsigned long jiffies_received;
104  unsigned int skip_count;
105  unsigned long stats_output_jiffies;
107 } ec_datagram_t;
108 
109 /****************************************************************************/
110 
114 int ec_datagram_prealloc(ec_datagram_t *, size_t);
116 
117 int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
118 int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
119 int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
120 int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t);
121 int ec_datagram_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
122 int ec_datagram_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
123 int ec_datagram_fprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
124 int ec_datagram_frmw(ec_datagram_t *, uint16_t, uint16_t, size_t);
125 int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t);
126 int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t);
127 int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t);
128 int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t);
129 int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t);
130 int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t);
131 int ec_datagram_lrd_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
132 int ec_datagram_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
133 int ec_datagram_lrw_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
134 
138 const char *ec_datagram_type_string(const ec_datagram_t *);
139 
140 /****************************************************************************/
141 
142 #endif
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
Definition: datagram.h:98
Auto Increment Physical Read Multiple Write.
Definition: datagram.h:56
#define EC_ADDR_LEN
Size of the EtherCAT address field.
Definition: globals.h:76
#define EC_DATAGRAM_NAME_SIZE
Size of the datagram description string.
Definition: globals.h:104
int ec_datagram_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPRD datagram.
Definition: datagram.c:265
Auto Increment Physical ReadWrite.
Definition: datagram.h:46
size_t data_size
Size of the data in data.
Definition: datagram.h:91
Broadcast ReadWrite.
Definition: datagram.h:52
int ec_datagram_lrw_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *)
Initializes an EtherCAT LRW datagram with external memory.
Definition: datagram.c:535
unsigned long stats_output_jiffies
Last statistics output.
Definition: datagram.h:105
ec_origin_t data_origin
Origin of the data memory.
Definition: datagram.h:89
EtherCAT datagram.
Definition: datagram.h:79
Logical Read.
Definition: datagram.h:53
uint16_t working_counter
Working counter.
Definition: datagram.h:93
Sent (still in the queue).
Definition: datagram.h:69
Configured Address Physical Read.
Definition: datagram.h:47
int ec_datagram_prealloc(ec_datagram_t *, size_t)
Allocates internal payload memory.
Definition: datagram.c:142
ec_datagram_type_t type
Datagram type (APRD, BWR, etc.).
Definition: datagram.h:86
Global definitions and macros.
Logical Write.
Definition: datagram.h:54
Initial state of a new datagram.
Definition: datagram.h:67
void ec_datagram_clear(ec_datagram_t *)
Destructor.
Definition: datagram.c:110
int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRD datagram.
Definition: datagram.c:181
void ec_datagram_zero(ec_datagram_t *)
Fills the datagram payload memory with zeros.
Definition: datagram.c:170
ec_datagram_state_t state
State.
Definition: datagram.h:94
void ec_datagram_print_state(const ec_datagram_t *)
Prints the state of a datagram.
Definition: datagram.c:557
const char * ec_datagram_type_string(const ec_datagram_t *)
Returns a string describing the datagram type.
Definition: datagram.c:637
ec_device_index_t
Master devices.
Definition: globals.h:198
int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LWR datagram.
Definition: datagram.c:444
int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BWR datagram.
Definition: datagram.c:385
unsigned int skip_count
Number of requeues when not yet received.
Definition: datagram.h:104
int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT ARMW datagram.
Definition: datagram.c:244
ec_datagram_state_t
EtherCAT datagram state.
Definition: datagram.h:66
Auto Increment Physical Read.
Definition: datagram.h:44
int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRW datagram.
Definition: datagram.c:463
int ec_datagram_fprw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPRW datagram.
Definition: datagram.c:315
int ec_datagram_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *)
Initializes an EtherCAT LWR datagram with external memory.
Definition: datagram.c:510
Broadcast Write.
Definition: datagram.h:51
ec_device_index_t device_index
Device via which the datagram shall be / was sent.
Definition: datagram.h:84
void ec_datagram_unqueue(ec_datagram_t *)
Unqueue datagram.
Definition: datagram.c:124
Configured Address Physical Read Multiple Write.
Definition: datagram.h:58
int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BRW datagram.
Definition: datagram.c:405
Queued for sending.
Definition: datagram.h:68
Logical ReadWrite.
Definition: datagram.h:55
Timed out (dequeued).
Definition: datagram.h:71
Broadcast Read.
Definition: datagram.h:50
int ec_datagram_frmw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FRMW datagram.
Definition: datagram.c:340
int ec_datagram_lrd_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *)
Initializes an EtherCAT LRD datagram with external memory.
Definition: datagram.c:485
ec_origin_t
Origin type.
Definition: globals.h:303
uint8_t * data
Datagram payload.
Definition: datagram.h:88
Configured Address Physical ReadWrite.
Definition: datagram.h:49
void ec_datagram_print_wc_error(const ec_datagram_t *)
Evaluates the working counter of a single-cast datagram.
Definition: datagram.c:594
int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BRD datagram.
Definition: datagram.c:365
int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APWR datagram.
Definition: datagram.c:202
int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRD datagram.
Definition: datagram.c:425
size_t mem_size
Datagram data memory size.
Definition: datagram.h:90
Error while sending/receiving (dequeued).
Definition: datagram.h:72
Auto Increment Physical Write.
Definition: datagram.h:45
void ec_datagram_output_stats(ec_datagram_t *)
Outputs datagram statistics at most every second.
Definition: datagram.c:614
Received (dequeued).
Definition: datagram.h:70
ec_datagram_type_t
EtherCAT datagram type.
Definition: datagram.h:42
Configured Address Physical Write.
Definition: datagram.h:48
uint8_t index
Index (set by master).
Definition: datagram.h:92
unsigned long jiffies_received
Jiffies, when the datagram was received.
Definition: datagram.h:102
void ec_datagram_init(ec_datagram_t *)
Constructor.
Definition: datagram.c:80
int ec_datagram_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPWR datagram.
Definition: datagram.c:290
int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRW datagram.
Definition: datagram.c:223