IgH EtherCAT Master  1.5.3
datagram.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with the IgH EtherCAT Master; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
35 /*****************************************************************************/
36 
37 #ifndef __EC_DATAGRAM_H__
38 #define __EC_DATAGRAM_H__
39 
40 #include <linux/list.h>
41 #include <linux/time.h>
42 #include <linux/timex.h>
43 
44 #include "globals.h"
45 
46 /*****************************************************************************/
47 
50 typedef enum {
58  EC_DATAGRAM_BRD = 0x07,
59  EC_DATAGRAM_BWR = 0x08,
60  EC_DATAGRAM_BRW = 0x09,
61  EC_DATAGRAM_LRD = 0x0A,
62  EC_DATAGRAM_LWR = 0x0B,
63  EC_DATAGRAM_LRW = 0x0C,
69 
70 /*****************************************************************************/
71 
74 typedef enum {
82 
83 /*****************************************************************************/
84 
87 typedef struct {
88  struct list_head queue;
89  struct list_head sent;
93  uint8_t address[EC_ADDR_LEN];
94  uint8_t *data;
96  size_t mem_size;
97  size_t data_size;
98  uint8_t index;
99  uint16_t working_counter;
101 #ifdef EC_HAVE_CYCLES
102  cycles_t cycles_sent;
103 #endif
104  unsigned long jiffies_sent;
105 #ifdef EC_HAVE_CYCLES
106  cycles_t cycles_received;
107 #endif
108  unsigned long jiffies_received;
110  unsigned int skip_count;
111  unsigned long stats_output_jiffies;
113 } ec_datagram_t;
114 
115 /*****************************************************************************/
116 
120 int ec_datagram_prealloc(ec_datagram_t *, size_t);
122 
123 int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
124 int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
125 int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
126 int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t);
127 int ec_datagram_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
128 int ec_datagram_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
129 int ec_datagram_fprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
130 int ec_datagram_frmw(ec_datagram_t *, uint16_t, uint16_t, size_t);
131 int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t);
132 int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t);
133 int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t);
134 int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t);
135 int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t);
136 int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t);
137 int ec_datagram_lrd_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
138 int ec_datagram_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
139 int ec_datagram_lrw_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
140 
144 const char *ec_datagram_type_string(const ec_datagram_t *);
145 
146 /*****************************************************************************/
147 
148 #endif
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
Definition: datagram.h:104
Auto Increment Physical Read Multiple Write.
Definition: datagram.h:64
#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:273
Auto Increment Physical ReadWrite.
Definition: datagram.h:54
size_t data_size
Size of the data in data.
Definition: datagram.h:97
Broadcast ReadWrite.
Definition: datagram.h:60
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:543
unsigned long stats_output_jiffies
Last statistics output.
Definition: datagram.h:111
ec_origin_t data_origin
Origin of the data memory.
Definition: datagram.h:95
EtherCAT datagram.
Definition: datagram.h:87
Logical Read.
Definition: datagram.h:61
uint16_t working_counter
Working counter.
Definition: datagram.h:99
Sent (still in the queue).
Definition: datagram.h:77
Configured Address Physical Read.
Definition: datagram.h:55
int ec_datagram_prealloc(ec_datagram_t *, size_t)
Allocates internal payload memory.
Definition: datagram.c:150
ec_datagram_type_t type
Datagram type (APRD, BWR, etc.).
Definition: datagram.h:92
Global definitions and macros.
Logical Write.
Definition: datagram.h:62
Initial state of a new datagram.
Definition: datagram.h:75
void ec_datagram_clear(ec_datagram_t *)
Destructor.
Definition: datagram.c:118
int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRD datagram.
Definition: datagram.c:189
void ec_datagram_zero(ec_datagram_t *)
Fills the datagram payload memory with zeros.
Definition: datagram.c:178
ec_datagram_state_t state
State.
Definition: datagram.h:100
void ec_datagram_print_state(const ec_datagram_t *)
Prints the state of a datagram.
Definition: datagram.c:565
const char * ec_datagram_type_string(const ec_datagram_t *)
Returns a string describing the datagram type.
Definition: datagram.c:645
ec_device_index_t
Master devices.
Definition: globals.h:189
int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LWR datagram.
Definition: datagram.c:452
int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BWR datagram.
Definition: datagram.c:393
unsigned int skip_count
Number of requeues when not yet received.
Definition: datagram.h:110
int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT ARMW datagram.
Definition: datagram.c:252
ec_datagram_state_t
EtherCAT datagram state.
Definition: datagram.h:74
Auto Increment Physical Read.
Definition: datagram.h:52
int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRW datagram.
Definition: datagram.c:471
int ec_datagram_fprw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPRW datagram.
Definition: datagram.c:323
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:518
Broadcast Write.
Definition: datagram.h:59
ec_device_index_t device_index
Device via which the datagram shall be / was sent.
Definition: datagram.h:90
void ec_datagram_unqueue(ec_datagram_t *)
Unqueue datagram.
Definition: datagram.c:132
Configured Address Physical Read Multiple Write.
Definition: datagram.h:66
int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BRW datagram.
Definition: datagram.c:413
Queued for sending.
Definition: datagram.h:76
Logical ReadWrite.
Definition: datagram.h:63
Timed out (dequeued).
Definition: datagram.h:79
Broadcast Read.
Definition: datagram.h:58
int ec_datagram_frmw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FRMW datagram.
Definition: datagram.c:348
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:493
ec_origin_t
Origin type.
Definition: globals.h:294
uint8_t * data
Datagram payload.
Definition: datagram.h:94
Configured Address Physical ReadWrite.
Definition: datagram.h:57
void ec_datagram_print_wc_error(const ec_datagram_t *)
Evaluates the working counter of a single-cast datagram.
Definition: datagram.c:602
int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BRD datagram.
Definition: datagram.c:373
int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APWR datagram.
Definition: datagram.c:210
int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRD datagram.
Definition: datagram.c:433
size_t mem_size
Datagram data memory size.
Definition: datagram.h:96
Error while sending/receiving (dequeued).
Definition: datagram.h:80
Auto Increment Physical Write.
Definition: datagram.h:53
void ec_datagram_output_stats(ec_datagram_t *)
Outputs datagram statistics at most every second.
Definition: datagram.c:622
Received (dequeued).
Definition: datagram.h:78
ec_datagram_type_t
EtherCAT datagram type.
Definition: datagram.h:50
Configured Address Physical Write.
Definition: datagram.h:56
uint8_t index
Index (set by master).
Definition: datagram.h:98
unsigned long jiffies_received
Jiffies, when the datagram was received.
Definition: datagram.h:108
void ec_datagram_init(ec_datagram_t *)
Constructor.
Definition: datagram.c:88
int ec_datagram_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPWR datagram.
Definition: datagram.c:298
int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRW datagram.
Definition: datagram.c:231