IgH EtherCAT Master  1.5.2
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
50typedef enum {
64 EC_DATAGRAM_ARMW = 0x0D,
66 EC_DATAGRAM_FRMW = 0x0E,
69
70/*****************************************************************************/
71
74typedef enum {
82
83/*****************************************************************************/
84
87typedef 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;
114
115/*****************************************************************************/
116
122
123int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
124int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
125int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
126int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t);
127int ec_datagram_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
128int ec_datagram_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
129int ec_datagram_fprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
130int ec_datagram_frmw(ec_datagram_t *, uint16_t, uint16_t, size_t);
131int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t);
132int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t);
133int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t);
134int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t);
135int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t);
136int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t);
137int ec_datagram_lrd_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
138int ec_datagram_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
139int ec_datagram_lrw_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
140
144const char *ec_datagram_type_string(const ec_datagram_t *);
145
146/*****************************************************************************/
147
148#endif
ec_datagram_type_t
EtherCAT datagram type.
Definition: datagram.h:50
@ EC_DATAGRAM_FPWR
Configured Address Physical Write.
Definition: datagram.h:56
@ EC_DATAGRAM_APRW
Auto Increment Physical ReadWrite.
Definition: datagram.h:54
@ EC_DATAGRAM_ARMW
Auto Increment Physical Read Multiple Write.
Definition: datagram.h:64
@ EC_DATAGRAM_FPRD
Configured Address Physical Read.
Definition: datagram.h:55
@ EC_DATAGRAM_NONE
Dummy.
Definition: datagram.h:51
@ EC_DATAGRAM_APRD
Auto Increment Physical Read.
Definition: datagram.h:52
@ EC_DATAGRAM_BRD
Broadcast Read.
Definition: datagram.h:58
@ EC_DATAGRAM_LRW
Logical ReadWrite.
Definition: datagram.h:63
@ EC_DATAGRAM_BRW
Broadcast ReadWrite.
Definition: datagram.h:60
@ EC_DATAGRAM_LWR
Logical Write.
Definition: datagram.h:62
@ EC_DATAGRAM_FRMW
Configured Address Physical Read Multiple Write.
Definition: datagram.h:66
@ EC_DATAGRAM_FPRW
Configured Address Physical ReadWrite.
Definition: datagram.h:57
@ EC_DATAGRAM_BWR
Broadcast Write.
Definition: datagram.h:59
@ EC_DATAGRAM_APWR
Auto Increment Physical Write.
Definition: datagram.h:53
@ EC_DATAGRAM_LRD
Logical Read.
Definition: datagram.h:61
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_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPRD datagram.
Definition: datagram.c:273
int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRW datagram.
Definition: datagram.c:231
const char * ec_datagram_type_string(const ec_datagram_t *)
Returns a string describing the datagram type.
Definition: datagram.c:645
int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BWR datagram.
Definition: datagram.c:393
int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRD datagram.
Definition: datagram.c:189
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_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *)
Initializes an EtherCAT LWR datagram with external memory.
Definition: datagram.c:518
void ec_datagram_unqueue(ec_datagram_t *)
Unqueue datagram.
Definition: datagram.c:132
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_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPWR datagram.
Definition: datagram.c:298
void ec_datagram_output_stats(ec_datagram_t *)
Outputs datagram statistics at most every second.
Definition: datagram.c:622
void ec_datagram_init(ec_datagram_t *)
Constructor.
Definition: datagram.c:88
int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT ARMW datagram.
Definition: datagram.c:252
int ec_datagram_prealloc(ec_datagram_t *, size_t)
Allocates internal payload memory.
Definition: datagram.c:150
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
int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BRW datagram.
Definition: datagram.c:413
int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRD datagram.
Definition: datagram.c:433
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
void ec_datagram_clear(ec_datagram_t *)
Destructor.
Definition: datagram.c:118
ec_datagram_state_t
EtherCAT datagram state.
Definition: datagram.h:74
@ EC_DATAGRAM_INIT
Initial state of a new datagram.
Definition: datagram.h:75
@ EC_DATAGRAM_RECEIVED
Received (dequeued).
Definition: datagram.h:78
@ EC_DATAGRAM_TIMED_OUT
Timed out (dequeued).
Definition: datagram.h:79
@ EC_DATAGRAM_SENT
Sent (still in the queue).
Definition: datagram.h:77
@ EC_DATAGRAM_QUEUED
Queued for sending.
Definition: datagram.h:76
@ EC_DATAGRAM_ERROR
Error while sending/receiving (dequeued).
Definition: datagram.h:80
void ec_datagram_print_state(const ec_datagram_t *)
Prints the state of a datagram.
Definition: datagram.c:565
void ec_datagram_zero(ec_datagram_t *)
Fills the datagram payload memory with zeros.
Definition: datagram.c:178
int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LWR datagram.
Definition: datagram.c:452
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
int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRW datagram.
Definition: datagram.c:471
Global definitions and macros.
#define EC_ADDR_LEN
Size of the EtherCAT address field.
Definition: globals.h:76
ec_origin_t
Origin type.
Definition: globals.h:294
#define EC_DATAGRAM_NAME_SIZE
Size of the datagram description string.
Definition: globals.h:104
ec_device_index_t
Master devices.
Definition: globals.h:189
EtherCAT datagram.
Definition: datagram.h:87
size_t mem_size
Datagram data memory size.
Definition: datagram.h:96
uint16_t working_counter
Working counter.
Definition: datagram.h:99
size_t data_size
Size of the data in data.
Definition: datagram.h:97
unsigned long jiffies_received
Jiffies, when the datagram was received.
Definition: datagram.h:108
ec_datagram_type_t type
Datagram type (APRD, BWR, etc.).
Definition: datagram.h:92
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
Definition: datagram.h:104
uint8_t index
Index (set by master).
Definition: datagram.h:98
ec_datagram_state_t state
State.
Definition: datagram.h:100
ec_device_index_t device_index
Device via which the datagram shall be / was sent.
Definition: datagram.h:90
unsigned long stats_output_jiffies
Last statistics output.
Definition: datagram.h:111
uint8_t * data
Datagram payload.
Definition: datagram.h:94
ec_origin_t data_origin
Origin of the data memory.
Definition: datagram.h:95
unsigned int skip_count
Number of requeues when not yet received.
Definition: datagram.h:110