IgH EtherCAT Master  1.6.9
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
26
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
61
62/****************************************************************************/
63
74
75/****************************************************************************/
76
79typedef struct {
80 struct list_head queue;
82 struct list_head ext_queue;
83 struct list_head sent;
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;
108
109/****************************************************************************/
110
116
117int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
118int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
119int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
120int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t);
121int ec_datagram_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
122int ec_datagram_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
123int ec_datagram_fprw(ec_datagram_t *, uint16_t, uint16_t, size_t);
124int ec_datagram_frmw(ec_datagram_t *, uint16_t, uint16_t, size_t);
125int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t);
126int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t);
127int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t);
128int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t);
129int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t);
130int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t);
131int ec_datagram_lrd_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
132int ec_datagram_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
133int ec_datagram_lrw_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *);
134
138const char *ec_datagram_type_string(const ec_datagram_t *);
139
140/****************************************************************************/
141
142#endif
ec_datagram_type_t
EtherCAT datagram type.
Definition datagram.h:42
@ EC_DATAGRAM_FPWR
Configured Address Physical Write.
Definition datagram.h:48
@ EC_DATAGRAM_APRW
Auto Increment Physical ReadWrite.
Definition datagram.h:46
@ EC_DATAGRAM_ARMW
Auto Increment Physical Read Multiple Write.
Definition datagram.h:56
@ EC_DATAGRAM_FPRD
Configured Address Physical Read.
Definition datagram.h:47
@ EC_DATAGRAM_NONE
Dummy.
Definition datagram.h:43
@ EC_DATAGRAM_APRD
Auto Increment Physical Read.
Definition datagram.h:44
@ EC_DATAGRAM_BRD
Broadcast Read.
Definition datagram.h:50
@ EC_DATAGRAM_LRW
Logical ReadWrite.
Definition datagram.h:55
@ EC_DATAGRAM_BRW
Broadcast ReadWrite.
Definition datagram.h:52
@ EC_DATAGRAM_LWR
Logical Write.
Definition datagram.h:54
@ EC_DATAGRAM_FRMW
Configured Address Physical Read Multiple Write.
Definition datagram.h:58
@ EC_DATAGRAM_FPRW
Configured Address Physical ReadWrite.
Definition datagram.h:49
@ EC_DATAGRAM_BWR
Broadcast Write.
Definition datagram.h:51
@ EC_DATAGRAM_APWR
Auto Increment Physical Write.
Definition datagram.h:45
@ EC_DATAGRAM_LRD
Logical Read.
Definition datagram.h:53
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_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPRD datagram.
Definition datagram.c:265
int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRW datagram.
Definition datagram.c:223
const char * ec_datagram_type_string(const ec_datagram_t *)
Returns a string describing the datagram type.
Definition datagram.c:637
int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BWR datagram.
Definition datagram.c:385
int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT APRD datagram.
Definition datagram.c:181
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_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *)
Initializes an EtherCAT LWR datagram with external memory.
Definition datagram.c:510
void ec_datagram_unqueue(ec_datagram_t *)
Unqueue datagram.
Definition datagram.c:124
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_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT FPWR datagram.
Definition datagram.c:290
void ec_datagram_output_stats(ec_datagram_t *)
Outputs datagram statistics at most every second.
Definition datagram.c:614
void ec_datagram_init(ec_datagram_t *)
Constructor.
Definition datagram.c:80
int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t)
Initializes an EtherCAT ARMW datagram.
Definition datagram.c:244
int ec_datagram_prealloc(ec_datagram_t *, size_t)
Allocates internal payload memory.
Definition datagram.c:142
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
int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t)
Initializes an EtherCAT BRW datagram.
Definition datagram.c:405
int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRD datagram.
Definition datagram.c:425
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
void ec_datagram_clear(ec_datagram_t *)
Destructor.
Definition datagram.c:110
ec_datagram_state_t
EtherCAT datagram state.
Definition datagram.h:66
@ EC_DATAGRAM_INIT
Initial state of a new datagram.
Definition datagram.h:67
@ EC_DATAGRAM_RECEIVED
Received (dequeued).
Definition datagram.h:70
@ EC_DATAGRAM_TIMED_OUT
Timed out (dequeued).
Definition datagram.h:71
@ EC_DATAGRAM_SENT
Sent (still in the queue).
Definition datagram.h:69
@ EC_DATAGRAM_QUEUED
Queued for sending.
Definition datagram.h:68
@ EC_DATAGRAM_ERROR
Error while sending/receiving (dequeued).
Definition datagram.h:72
void ec_datagram_print_state(const ec_datagram_t *)
Prints the state of a datagram.
Definition datagram.c:557
void ec_datagram_zero(ec_datagram_t *)
Fills the datagram payload memory with zeros.
Definition datagram.c:170
int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LWR datagram.
Definition datagram.c:444
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
int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t)
Initializes an EtherCAT LRW datagram.
Definition datagram.c:463
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:303
#define EC_DATAGRAM_NAME_SIZE
Size of the datagram description string.
Definition globals.h:104
ec_device_index_t
Master devices.
Definition globals.h:198
EtherCAT datagram.
Definition datagram.h:79
size_t mem_size
Datagram data memory size.
Definition datagram.h:90
uint16_t working_counter
Working counter.
Definition datagram.h:93
size_t data_size
Size of the data in data.
Definition datagram.h:91
struct list_head ext_queue
External datagram queue item, protected by ext_queue_sem.
Definition datagram.h:82
unsigned long jiffies_received
Jiffies, when the datagram was received.
Definition datagram.h:102
ec_datagram_type_t type
Datagram type (APRD, BWR, etc.).
Definition datagram.h:86
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
Definition datagram.h:98
struct list_head queue
Master datagram queue item, protected by user-supplied mutex.
Definition datagram.h:80
uint8_t index
Index (set by master).
Definition datagram.h:92
ec_datagram_state_t state
State.
Definition datagram.h:94
ec_device_index_t device_index
Device via which the datagram shall be / was sent.
Definition datagram.h:84
unsigned long stats_output_jiffies
Last statistics output.
Definition datagram.h:105
struct list_head sent
Master list item for sent datagrams.
Definition datagram.h:83
uint8_t address[EC_ADDR_LEN]
Recipient address.
Definition datagram.h:87
uint8_t * data
Datagram payload.
Definition datagram.h:88
ec_origin_t data_origin
Origin of the data memory.
Definition datagram.h:89
char name[EC_DATAGRAM_NAME_SIZE]
Description of the datagram.
Definition datagram.h:106
unsigned int skip_count
Number of requeues when not yet received.
Definition datagram.h:104