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 command structure. |
|
37 */ |
|
38 |
|
39 /*****************************************************************************/ |
|
40 |
|
41 #ifndef _EC_COMMAND_H_ |
|
42 #define _EC_COMMAND_H_ |
|
43 |
|
44 #include <linux/list.h> |
|
45 #include <linux/timex.h> |
|
46 |
|
47 #include "globals.h" |
|
48 |
|
49 /*****************************************************************************/ |
|
50 |
|
51 /** |
|
52 EtherCAT command type. |
|
53 */ |
|
54 |
|
55 typedef enum |
|
56 { |
|
57 EC_CMD_NONE = 0x00, /**< Dummy */ |
|
58 EC_CMD_APRD = 0x01, /**< Auto-increment physical read */ |
|
59 EC_CMD_APWR = 0x02, /**< Auto-increment physical write */ |
|
60 EC_CMD_NPRD = 0x04, /**< Node-addressed physical read */ |
|
61 EC_CMD_NPWR = 0x05, /**< Node-addressed physical write */ |
|
62 EC_CMD_BRD = 0x07, /**< Broadcast read */ |
|
63 EC_CMD_BWR = 0x08, /**< Broadcast write */ |
|
64 EC_CMD_LRW = 0x0C /**< Logical read/write */ |
|
65 } |
|
66 ec_command_type_t; |
|
67 |
|
68 /** |
|
69 EtherCAT command state. |
|
70 */ |
|
71 |
|
72 typedef enum |
|
73 { |
|
74 EC_CMD_INIT, /**< new command */ |
|
75 EC_CMD_QUEUED, /**< command queued by master */ |
|
76 EC_CMD_SENT, /**< command has been sent */ |
|
77 EC_CMD_RECEIVED, /**< command has been received */ |
|
78 EC_CMD_TIMEOUT, /**< command timed out */ |
|
79 EC_CMD_ERROR /**< error while sending/receiving */ |
|
80 } |
|
81 ec_command_state_t; |
|
82 |
|
83 /*****************************************************************************/ |
|
84 |
|
85 /** |
|
86 EtherCAT address. |
|
87 */ |
|
88 |
|
89 typedef union |
|
90 { |
|
91 struct |
|
92 { |
|
93 uint16_t slave; /**< configured or autoincrement address */ |
|
94 uint16_t mem; /**< physical memory address */ |
|
95 } |
|
96 physical; /**< physical address */ |
|
97 |
|
98 uint32_t logical; /**< logical address */ |
|
99 } |
|
100 ec_address_t; |
|
101 |
|
102 /*****************************************************************************/ |
|
103 |
|
104 /** |
|
105 EtherCAT command. |
|
106 */ |
|
107 |
|
108 typedef struct |
|
109 { |
|
110 struct list_head list; /**< needed by domain command lists */ |
|
111 struct list_head queue; /**< master command queue item */ |
|
112 ec_command_type_t type; /**< command type (APRD, BWR, etc) */ |
|
113 ec_address_t address; /**< receipient address */ |
|
114 uint8_t *data; /**< command data */ |
|
115 size_t mem_size; /**< command \a data memory size */ |
|
116 size_t data_size; /**< size of the data in \a data */ |
|
117 uint8_t index; /**< command index (set by master) */ |
|
118 uint16_t working_counter; /**< working counter */ |
|
119 ec_command_state_t state; /**< command state */ |
|
120 cycles_t t_sent; /**< time, the commands was sent */ |
|
121 } |
|
122 ec_command_t; |
|
123 |
|
124 /*****************************************************************************/ |
|
125 |
|
126 void ec_command_init(ec_command_t *); |
|
127 void ec_command_clear(ec_command_t *); |
|
128 int ec_command_prealloc(ec_command_t *, size_t); |
|
129 |
|
130 int ec_command_nprd(ec_command_t *, uint16_t, uint16_t, size_t); |
|
131 int ec_command_npwr(ec_command_t *, uint16_t, uint16_t, size_t); |
|
132 int ec_command_aprd(ec_command_t *, uint16_t, uint16_t, size_t); |
|
133 int ec_command_apwr(ec_command_t *, uint16_t, uint16_t, size_t); |
|
134 int ec_command_brd(ec_command_t *, uint16_t, size_t); |
|
135 int ec_command_bwr(ec_command_t *, uint16_t, size_t); |
|
136 int ec_command_lrw(ec_command_t *, uint32_t, size_t); |
|
137 |
|
138 /*****************************************************************************/ |
|
139 |
|
140 #endif |
|