|
1 /****************************************************************************** |
|
2 * |
|
3 * c o m m a n d . h |
|
4 * |
|
5 * Struktur für ein EtherCAT-Kommando. |
|
6 * |
|
7 * $Id$ |
|
8 * |
|
9 *****************************************************************************/ |
|
10 |
|
11 #ifndef _EC_COMMAND_H_ |
|
12 #define _EC_COMMAND_H_ |
|
13 |
|
14 #include <linux/list.h> |
|
15 |
|
16 #include "globals.h" |
|
17 |
|
18 /*****************************************************************************/ |
|
19 |
|
20 /** |
|
21 EtherCAT-Kommando-Typ. |
|
22 */ |
|
23 |
|
24 typedef enum |
|
25 { |
|
26 EC_CMD_NONE = 0x00, /**< Dummy */ |
|
27 EC_CMD_APRD = 0x01, /**< Auto-increment physical read */ |
|
28 EC_CMD_APWR = 0x02, /**< Auto-increment physical write */ |
|
29 EC_CMD_NPRD = 0x04, /**< Node-addressed physical read */ |
|
30 EC_CMD_NPWR = 0x05, /**< Node-addressed physical write */ |
|
31 EC_CMD_BRD = 0x07, /**< Broadcast read */ |
|
32 EC_CMD_BWR = 0x08, /**< Broadcast write */ |
|
33 EC_CMD_LRW = 0x0C /**< Logical read/write */ |
|
34 } |
|
35 ec_command_type_t; |
|
36 |
|
37 /** |
|
38 EtherCAT-Kommando-Zustand. |
|
39 */ |
|
40 |
|
41 typedef enum |
|
42 { |
|
43 EC_CMD_INIT, /**< Neues Kommando */ |
|
44 EC_CMD_QUEUED, /**< Kommando in Warteschlange */ |
|
45 EC_CMD_SENT, /**< Kommando gesendet */ |
|
46 EC_CMD_RECEIVED, /**< Kommando empfangen */ |
|
47 EC_CMD_TIMEOUT, /**< Zeitgrenze überschritten */ |
|
48 EC_CMD_ERROR /**< Fehler beim Senden oder Empfangen */ |
|
49 } |
|
50 ec_command_state_t; |
|
51 |
|
52 /*****************************************************************************/ |
|
53 |
|
54 /** |
|
55 EtherCAT-Adresse. |
|
56 |
|
57 Im EtherCAT-Kommando sind 4 Bytes für die Adresse reserviert, die je nach |
|
58 Kommandotyp, eine andere Bedeutung haben können: Bei Autoinkrementbefehlen |
|
59 sind die ersten zwei Bytes die (negative) Autoinkrement-Adresse, bei Knoten- |
|
60 adressierten Befehlen entsprechen sie der Knotenadresse. Das dritte und |
|
61 vierte Byte entspricht in diesen Fällen der physikalischen Speicheradresse |
|
62 auf dem Slave. Bei einer logischen Adressierung entsprechen alle vier Bytes |
|
63 der logischen Adresse. |
|
64 */ |
|
65 |
|
66 typedef union |
|
67 { |
|
68 struct |
|
69 { |
|
70 uint16_t slave; /**< Adresse des Slaves (Ringposition oder Knoten) */ |
|
71 uint16_t mem; /**< Physikalische Speicheradresse im Slave */ |
|
72 } |
|
73 physical; /**< Physikalische Adresse */ |
|
74 |
|
75 uint32_t logical; /**< Logische Adresse */ |
|
76 } |
|
77 ec_address_t; |
|
78 |
|
79 /*****************************************************************************/ |
|
80 |
|
81 /** |
|
82 EtherCAT-Kommando. |
|
83 */ |
|
84 |
|
85 typedef struct |
|
86 { |
|
87 struct list_head list; /**< Nötig für Liste */ |
|
88 ec_command_type_t type; /**< Typ des Kommandos (APRD, NPWR, etc) */ |
|
89 ec_address_t address; /**< Adresse des/der Empfänger */ |
|
90 uint8_t data[EC_MAX_DATA_SIZE]; /**< Kommandodaten */ |
|
91 size_t data_size; /**< Länge der zu sendenden und/oder empfangenen Daten */ |
|
92 uint8_t index; /**< Kommando-Index, wird vom Master beim Senden gesetzt. */ |
|
93 uint16_t working_counter; /**< Working-Counter */ |
|
94 ec_command_state_t state; /**< Zustand */ |
|
95 } |
|
96 ec_command_t; |
|
97 |
|
98 /*****************************************************************************/ |
|
99 |
|
100 void ec_command_init_nprd(ec_command_t *, uint16_t, uint16_t, size_t); |
|
101 void ec_command_init_npwr(ec_command_t *, uint16_t, uint16_t, size_t, |
|
102 const uint8_t *); |
|
103 void ec_command_init_aprd(ec_command_t *, uint16_t, uint16_t, size_t); |
|
104 void ec_command_init_apwr(ec_command_t *, uint16_t, uint16_t, size_t, |
|
105 const uint8_t *); |
|
106 void ec_command_init_brd(ec_command_t *, uint16_t, size_t); |
|
107 void ec_command_init_bwr(ec_command_t *, uint16_t, size_t, const uint8_t *); |
|
108 void ec_command_init_lrw(ec_command_t *, uint32_t, size_t, uint8_t *); |
|
109 |
|
110 /*****************************************************************************/ |
|
111 |
|
112 #endif |
|
113 |
|
114 /* Emacs-Konfiguration |
|
115 ;;; Local Variables: *** |
|
116 ;;; c-basic-offset:4 *** |
|
117 ;;; End: *** |
|
118 */ |