|
1 /****************************************************************************** |
|
2 * |
|
3 * $Id$ |
|
4 * |
|
5 * Copyright (C) 2006 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 |
|
10 * and/or modify it under the terms of the GNU General Public License |
|
11 * as published by the Free Software Foundation; either version 2 of the |
|
12 * License, or (at your option) any later version. |
|
13 * |
|
14 * The IgH EtherCAT Master is distributed in the hope that it will be |
|
15 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 * GNU General Public License for more details. |
|
18 * |
|
19 * You should have received a copy of the GNU General Public License |
|
20 * along with the IgH EtherCAT Master; if not, write to the Free Software |
|
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 * |
|
23 * The right to use EtherCAT Technology is granted and comes free of |
|
24 * charge under condition of compatibility of product made by |
|
25 * Licensee. People intending to distribute/sell products based on the |
|
26 * code, have to sign an agreement to guarantee that products using |
|
27 * software based on IgH EtherCAT master stay compatible with the actual |
|
28 * EtherCAT specification (which are released themselves as an open |
|
29 * standard) as the (only) precondition to have the right to use EtherCAT |
|
30 * Technology, IP and trade marks. |
|
31 * |
|
32 *****************************************************************************/ |
|
33 |
|
34 /** |
|
35 \file |
|
36 EtherCAT datagram structure. |
|
37 */ |
|
38 |
|
39 /*****************************************************************************/ |
|
40 |
|
41 #ifndef _EC_DATAGRAM_H_ |
|
42 #define _EC_DATAGRAM_H_ |
|
43 |
|
44 #include <linux/list.h> |
|
45 #include <linux/time.h> |
|
46 #include <linux/timex.h> |
|
47 |
|
48 #include "globals.h" |
|
49 |
|
50 /*****************************************************************************/ |
|
51 |
|
52 /** |
|
53 EtherCAT datagram type. |
|
54 */ |
|
55 |
|
56 typedef enum |
|
57 { |
|
58 EC_CMD_NONE = 0x00, /**< Dummy */ |
|
59 EC_CMD_APRD = 0x01, /**< Auto-increment physical read */ |
|
60 EC_CMD_APWR = 0x02, /**< Auto-increment physical write */ |
|
61 EC_CMD_NPRD = 0x04, /**< Node-addressed physical read */ |
|
62 EC_CMD_NPWR = 0x05, /**< Node-addressed physical write */ |
|
63 EC_CMD_BRD = 0x07, /**< Broadcast read */ |
|
64 EC_CMD_BWR = 0x08, /**< Broadcast write */ |
|
65 EC_CMD_LRW = 0x0C /**< Logical read/write */ |
|
66 } |
|
67 ec_datagram_type_t; |
|
68 |
|
69 /** |
|
70 EtherCAT datagram state. |
|
71 */ |
|
72 |
|
73 typedef enum |
|
74 { |
|
75 EC_CMD_INIT, /**< new datagram */ |
|
76 EC_CMD_QUEUED, /**< datagram queued by master */ |
|
77 EC_CMD_SENT, /**< datagram has been sent */ |
|
78 EC_CMD_RECEIVED, /**< datagram has been received */ |
|
79 EC_CMD_TIMEOUT, /**< datagram timed out */ |
|
80 EC_CMD_ERROR /**< error while sending/receiving */ |
|
81 } |
|
82 ec_datagram_state_t; |
|
83 |
|
84 /*****************************************************************************/ |
|
85 |
|
86 /** |
|
87 EtherCAT address. |
|
88 */ |
|
89 |
|
90 typedef union |
|
91 { |
|
92 struct |
|
93 { |
|
94 uint16_t slave; /**< configured or autoincrement address */ |
|
95 uint16_t mem; /**< physical memory address */ |
|
96 } |
|
97 physical; /**< physical address */ |
|
98 |
|
99 uint32_t logical; /**< logical address */ |
|
100 } |
|
101 ec_address_t; |
|
102 |
|
103 /*****************************************************************************/ |
|
104 |
|
105 /** |
|
106 EtherCAT datagram. |
|
107 */ |
|
108 |
|
109 typedef struct |
|
110 { |
|
111 struct list_head list; /**< needed by domain datagram lists */ |
|
112 struct list_head queue; /**< master datagram queue item */ |
|
113 ec_datagram_type_t type; /**< datagram type (APRD, BWR, etc) */ |
|
114 ec_address_t address; /**< receipient address */ |
|
115 uint8_t *data; /**< datagram data */ |
|
116 size_t mem_size; /**< datagram \a data memory size */ |
|
117 size_t data_size; /**< size of the data in \a data */ |
|
118 uint8_t index; /**< datagram index (set by master) */ |
|
119 uint16_t working_counter; /**< working counter */ |
|
120 ec_datagram_state_t state; /**< datagram state */ |
|
121 cycles_t t_sent; /**< time, the datagrams was sent */ |
|
122 } |
|
123 ec_datagram_t; |
|
124 |
|
125 /*****************************************************************************/ |
|
126 |
|
127 void ec_datagram_init(ec_datagram_t *); |
|
128 void ec_datagram_clear(ec_datagram_t *); |
|
129 int ec_datagram_prealloc(ec_datagram_t *, size_t); |
|
130 |
|
131 int ec_datagram_nprd(ec_datagram_t *, uint16_t, uint16_t, size_t); |
|
132 int ec_datagram_npwr(ec_datagram_t *, uint16_t, uint16_t, size_t); |
|
133 int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t); |
|
134 int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t); |
|
135 int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t); |
|
136 int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t); |
|
137 int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t); |
|
138 |
|
139 /*****************************************************************************/ |
|
140 |
|
141 #endif |