52 /** size of the datagram description string */ |
52 /** size of the datagram description string */ |
53 #define EC_DATAGRAM_NAME_SIZE 20 |
53 #define EC_DATAGRAM_NAME_SIZE 20 |
54 |
54 |
55 /*****************************************************************************/ |
55 /*****************************************************************************/ |
56 |
56 |
57 /** |
57 /** EtherCAT datagram type. |
58 EtherCAT datagram type. |
58 */ |
59 */ |
59 typedef enum { |
60 |
60 EC_DATAGRAM_NONE = 0x00, /**< Dummy. */ |
61 typedef enum |
61 EC_DATAGRAM_APRD = 0x01, /**< Auto-increment physical read. */ |
62 { |
62 EC_DATAGRAM_APWR = 0x02, /**< Auto-increment physical write. */ |
63 EC_DATAGRAM_NONE = 0x00, /**< Dummy */ |
63 EC_DATAGRAM_NPRD = 0x04, /**< Node-addressed physical read. */ |
64 EC_DATAGRAM_APRD = 0x01, /**< Auto-increment physical read */ |
64 EC_DATAGRAM_NPWR = 0x05, /**< Node-addressed physical write. */ |
65 EC_DATAGRAM_APWR = 0x02, /**< Auto-increment physical write */ |
65 EC_DATAGRAM_BRD = 0x07, /**< Broadcast read. */ |
66 EC_DATAGRAM_NPRD = 0x04, /**< Node-addressed physical read */ |
66 EC_DATAGRAM_BWR = 0x08, /**< Broadcast write. */ |
67 EC_DATAGRAM_NPWR = 0x05, /**< Node-addressed physical write */ |
67 EC_DATAGRAM_LRW = 0x0C /**< Logical read/write. */ |
68 EC_DATAGRAM_BRD = 0x07, /**< Broadcast read */ |
68 } ec_datagram_type_t; |
69 EC_DATAGRAM_BWR = 0x08, /**< Broadcast write */ |
|
70 EC_DATAGRAM_LRW = 0x0C /**< Logical read/write */ |
|
71 } |
|
72 ec_datagram_type_t; |
|
73 |
|
74 /** |
|
75 EtherCAT datagram state. |
|
76 */ |
|
77 |
|
78 typedef enum |
|
79 { |
|
80 EC_DATAGRAM_INIT, /**< new datagram */ |
|
81 EC_DATAGRAM_QUEUED, /**< datagram queued for sending */ |
|
82 EC_DATAGRAM_SENT, /**< datagram has been sent (still in the queue) */ |
|
83 EC_DATAGRAM_RECEIVED, /**< datagram has been received (dequeued) */ |
|
84 EC_DATAGRAM_TIMED_OUT, /**< datagram timed out (dequeued) */ |
|
85 EC_DATAGRAM_ERROR /**< error while sending/receiving (dequeued) */ |
|
86 } |
|
87 ec_datagram_state_t; |
|
88 |
69 |
89 /*****************************************************************************/ |
70 /*****************************************************************************/ |
90 |
71 |
91 /** |
72 /** EtherCAT datagram state. |
92 EtherCAT datagram. |
73 */ |
93 */ |
74 typedef enum { |
|
75 EC_DATAGRAM_INIT, /**< Initial state of a new datagram. */ |
|
76 EC_DATAGRAM_QUEUED, /**< Queued for sending. */ |
|
77 EC_DATAGRAM_SENT, /**< Sent (still in the queue). */ |
|
78 EC_DATAGRAM_RECEIVED, /**< Received (dequeued). */ |
|
79 EC_DATAGRAM_TIMED_OUT, /**< Timed out (dequeued). */ |
|
80 EC_DATAGRAM_ERROR /**< Error while sending/receiving (dequeued). */ |
|
81 } ec_datagram_state_t; |
94 |
82 |
95 typedef struct |
83 /*****************************************************************************/ |
96 { |
84 |
97 struct list_head list; /**< needed by domain datagram lists */ |
85 /** EtherCAT datagram. |
98 struct list_head queue; /**< master datagram queue item */ |
86 */ |
99 struct list_head sent; /**< master list item for sent datagrams */ |
87 typedef struct { |
100 ec_datagram_type_t type; /**< datagram type (APRD, BWR, etc) */ |
88 struct list_head list; /**< Needed by domain datagram lists. */ |
101 uint8_t address[EC_ADDR_LEN]; /**< recipient address */ |
89 struct list_head queue; /**< Master datagram queue item. */ |
102 uint8_t *data; /**< datagram data */ |
90 struct list_head sent; /**< Master list item for sent datagrams. */ |
103 size_t mem_size; /**< datagram \a data memory size */ |
91 ec_datagram_type_t type; /**< Datagram type (APRD, BWR, etc.). */ |
104 size_t data_size; /**< size of the data in \a data */ |
92 uint8_t address[EC_ADDR_LEN]; /**< Recipient address. */ |
105 uint8_t index; /**< datagram index (set by master) */ |
93 uint8_t *data; /**< Datagram payload. */ |
106 uint16_t working_counter; /**< working counter */ |
94 ec_origin_t data_origin; /**< Origin of the \a data memory. */ |
107 ec_datagram_state_t state; /**< datagram state */ |
95 size_t mem_size; /**< Datagram \a data memory size. */ |
108 cycles_t cycles_sent; /**< time, the datagram was sent */ |
96 size_t data_size; /**< Size of the data in \a data. */ |
109 unsigned long jiffies_sent; /**< jiffies, when the datagram was sent */ |
97 uint8_t index; /**< Index (set by master). */ |
110 cycles_t cycles_received; /**< time, when the datagram was received */ |
98 uint16_t working_counter; /**< Working counter. */ |
111 unsigned long jiffies_received; /**< jiffies the datagram was received */ |
99 ec_datagram_state_t state; /**< State. */ |
112 unsigned int skip_count; /**< number of requeues when not yet received */ |
100 cycles_t cycles_sent; /**< Time, when the datagram was sent. */ |
113 unsigned long stats_output_jiffies; /**< last statistics output */ |
101 unsigned long jiffies_sent; /**< Jiffies, when the datagram was sent. */ |
114 char name[EC_DATAGRAM_NAME_SIZE]; /**< description of the datagram */ |
102 cycles_t cycles_received; /**< Time, when the datagram was received. */ |
115 } |
103 unsigned long jiffies_received; /**< Jiffies, when the datagram was |
116 ec_datagram_t; |
104 received. */ |
|
105 unsigned int skip_count; /**< Number of requeues when not yet received. */ |
|
106 unsigned long stats_output_jiffies; /**< Last statistics output. */ |
|
107 char name[EC_DATAGRAM_NAME_SIZE]; /**< Description of the datagram. */ |
|
108 } ec_datagram_t; |
117 |
109 |
118 /*****************************************************************************/ |
110 /*****************************************************************************/ |
119 |
111 |
120 void ec_datagram_init(ec_datagram_t *); |
112 void ec_datagram_init(ec_datagram_t *); |
121 void ec_datagram_clear(ec_datagram_t *); |
113 void ec_datagram_clear(ec_datagram_t *); |
125 int ec_datagram_npwr(ec_datagram_t *, uint16_t, uint16_t, size_t); |
117 int ec_datagram_npwr(ec_datagram_t *, uint16_t, uint16_t, size_t); |
126 int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t); |
118 int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t); |
127 int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t); |
119 int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t); |
128 int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t); |
120 int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t); |
129 int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t); |
121 int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t); |
130 int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t); |
122 int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t, uint8_t *); |
131 |
123 |
132 void ec_datagram_print_wc_error(const ec_datagram_t *); |
124 void ec_datagram_print_wc_error(const ec_datagram_t *); |
133 void ec_datagram_output_stats(ec_datagram_t *datagram); |
125 void ec_datagram_output_stats(ec_datagram_t *datagram); |
134 |
126 |
135 /*****************************************************************************/ |
127 /*****************************************************************************/ |