libethercat - an embeddable realtime EtherCAT-master library
Communicate with EtherCAT slaves attached to a Network interface.
Loading...
Searching...
No Matches
mbx.h
Go to the documentation of this file.
1
12/*
13 * This file is part of libethercat.
14 *
15 * libethercat is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 3 of the License, or (at your option) any later version.
19 *
20 * libethercat is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with libethercat (LICENSE.LGPL-V3); if not, write
27 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
28 * Floor, Boston, MA 02110-1301, USA.
29 *
30 * Please note that the use of the EtherCAT technology, the EtherCAT
31 * brand name and the EtherCAT logo is only permitted if the property
32 * rights of Beckhoff Automation GmbH are observed. For further
33 * information please contact Beckhoff Automation GmbH & Co. KG,
34 * Hülshorstweg 20, D-33415 Verl, Germany (www.beckhoff.com) or the
35 * EtherCAT Technology Group, Ostendstraße 196, D-90482 Nuremberg,
36 * Germany (ETG, www.ethercat.org).
37 *
38 */
39
40#ifndef LIBETHERCAT_MBX_H
41#define LIBETHERCAT_MBX_H
42
43#include <libosal/types.h>
44#include <libosal/osal.h>
45
46#include "libethercat/common.h"
47
48#if LIBETHERCAT_MBX_SUPPORT_COE == 1
49#include "libethercat/coe.h"
50#endif
51
52#if LIBETHERCAT_MBX_SUPPORT_SOE == 1
53#include "libethercat/soe.h"
54#endif
55
56#if LIBETHERCAT_MBX_SUPPORT_FOE == 1
57#include "libethercat/foe.h"
58#endif
59
60#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
61#include "libethercat/eoe.h"
62#endif
63
64#include "libethercat/pool.h"
66
74#define MAILBOX_WRITE (osal_uint16_t)(0u)
75#define MAILBOX_READ (osal_uint16_t)(1u)
76
77// forward declarations
78struct ec;
79typedef struct ec ec_t;
80
81#define MESSAGE_POOL_DEBUG(type) {}
82
83/*
84#define N_MESSAGE_POOL_DEBUG(type) \
85{ \
86 int avail = 0; \
87 sem_getvalue(&slv->mbx.message_pool_ ## type->avail_cnt, &avail); \
88 ec_log(10, __func__, "slave %d: " #type " pool avail %d\n", slave, avail); \
89}
90*/
92enum {
93 EC_MBX_ERR = 0x00,
99 EC_MBX_VOE = 0x0f
101
103typedef struct PACKED ec_mbx_header {
104 osal_uint16_t length;
105 osal_uint16_t address;
106 osal_uint8_t priority;
107 osal_uint8_t mbxtype : 4;
108 osal_uint8_t counter : 4;
110
112typedef struct PACKED ec_mbx_buffer {
114 ec_data_t mbx_data;
116
117typedef struct ec_mbx {
118 osal_uint32_t handler_flags;
119 osal_mutex_t sync_mutex;
120 osal_binary_semaphore_t sync_sem;
121
128 int slave;
133 osal_task_t handler_tid;
134
135 osal_mutex_t lock;
143
145
146#if LIBETHERCAT_MBX_SUPPORT_COE == 1
147 ec_coe_t coe;
148#endif
149
150#if LIBETHERCAT_MBX_SUPPORT_SOE == 1
151 ec_soe_t soe;
152#endif
153
154#if LIBETHERCAT_MBX_SUPPORT_FOE == 1
155 ec_foe_t foe;
156#endif
157
158#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
159 ec_eoe_t eoe;
160#endif
161
162 osal_uint32_t sm_state_bitno;
163 osal_uint8_t *sm_state;
171 osal_uint8_t mbx_state;
172} ec_mbx_t;
173
174#ifdef __cplusplus
175extern "C" {
176#endif
177
179
186void ec_mbx_init(ec_t *pec, osal_uint16_t slave);
187
189
196void ec_mbx_deinit(ec_t *pec, osal_uint16_t slave);
197
199
207void ec_mbx_enqueue_head(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_entry);
208
210
218void ec_mbx_enqueue_tail(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_entry);
219
221
228void ec_mbx_sched_read(ec_t *pec, osal_uint16_t slave);
229
231
247int ec_mbx_check(ec_t *pec, int slave, osal_uint16_t mbx_flag);
248
250
260int ec_mbx_next_counter(ec_t *pec, int slave, int *seq_counter);
261
262#define ec_mbx_get_free_recv_buffer(pec, slave, entry, timeout, lock) \
263 pool_get(&(pec)->mbx_message_pool_recv_free, &(entry), (timeout))
264
265#define ec_mbx_get_free_send_buffer_old(pec, slave, entry, timeout, lock) \
266 pool_get(&(pec)->mbx_message_pool_send_free, &(entry), (timeout))
267
269
281int ec_mbx_get_free_send_buffer(ec_t *pec, osal_uint16_t slave, pool_entry_t **pp_entry, osal_timer_t *timeout);
282
283#define ec_mbx_return_free_send_buffer(pec, slave, entry) \
284 pool_put(&(pec)->mbx_message_pool_send_free, (entry))
285
286#define ec_mbx_return_free_recv_buffer(pec, slave, entry) \
287 pool_put(&(pec)->mbx_message_pool_recv_free, (entry))
288
289
290#ifdef __cplusplus
291}
292#endif
293
296#endif // LIBETHERCAT_MBX_H
297
EtherCAT coe functions.
ethercat master common stuff
ethercat datagram
EtherCAT eoe functions.
file over ethercat fuctions
int ec_mbx_next_counter(ec_t *pec, int slave, int *seq_counter)
Get next sequence counter.
void ec_mbx_deinit(ec_t *pec, osal_uint16_t slave)
Deinit mailbox structure.
struct PACKED ec_mbx_buffer ec_mbx_buffer_t
ethercat mailbox data
void ec_mbx_enqueue_head(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_entry)
Enqueue mailbox message to send queue.
void ec_mbx_sched_read(ec_t *pec, osal_uint16_t slave)
Trigger read of mailbox.
int ec_mbx_get_free_send_buffer(ec_t *pec, osal_uint16_t slave, pool_entry_t **pp_entry, osal_timer_t *timeout)
Get free mailbox send buffer from slaves send message pool.
void ec_mbx_init(ec_t *pec, osal_uint16_t slave)
Initialize mailbox structure.
int ec_mbx_check(ec_t *pec, int slave, osal_uint16_t mbx_flag)
Checks if mailbox protocol is supported by slave.
void ec_mbx_enqueue_tail(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_entry)
Enqueue mailbox message to send queue.
struct PACKED ec_mbx_header ec_mbx_header_t
ethercat mailbox header
@ EC_MBX_ERR
error mailbox
Definition mbx.h:93
@ EC_MBX_EOE
Ethernet over EtherCAT mailbox.
Definition mbx.h:95
@ EC_MBX_AOE
ADS over EtherCAT mailbox.
Definition mbx.h:94
@ EC_MBX_COE
CANopen over EtherCAT mailbox.
Definition mbx.h:96
@ EC_MBX_VOE
Vendor over EtherCAT mailbox.
Definition mbx.h:99
@ EC_MBX_SOE
Servo over EtherCAT mailbox.
Definition mbx.h:98
@ EC_MBX_FOE
File over EtherCAT mailbox.
Definition mbx.h:97
Data pool implementation.
EtherCAT SoE functions.
Definition coe.h:65
Definition eoe.h:74
Definition foe.h:57
ethercat mailbox data
Definition mbx.h:112
ec_mbx_header_t mbx_hdr
mailbox header
Definition mbx.h:113
ec_data_t mbx_data
mailbox data
Definition mbx.h:114
ethercat mailbox header
Definition mbx.h:103
osal_uint16_t length
mailbox length
Definition mbx.h:104
osal_uint8_t mbxtype
mailbox type
Definition mbx.h:107
osal_uint8_t priority
priority
Definition mbx.h:106
osal_uint8_t counter
counter
Definition mbx.h:108
osal_uint16_t address
mailbox address
Definition mbx.h:105
Definition mbx.h:117
int handler_running
Mailbox handler thread running flag.
Definition mbx.h:122
osal_mutex_t sync_mutex
Sync mutex for handler flags.
Definition mbx.h:119
osal_uint8_t mbx_state
State if not mapped.
Definition mbx.h:171
osal_mutex_t lock
mailbox lock
Definition mbx.h:135
ec_t * pec
Pointer to ethercat master structure.
Definition mbx.h:123
pool_t message_pool_send_queued
Pool with mailbox buffers ready to be sent.
Definition mbx.h:144
osal_uint8_t * sm_state
Sync manager state of read mailbox.
Definition mbx.h:163
osal_uint32_t handler_flags
Flags signalling handler recv of send action.
Definition mbx.h:118
int seq_counter
mailbox sequence counter
Definition mbx.h:142
osal_binary_semaphore_t sync_sem
Mailbox sync semaphore.
Definition mbx.h:120
osal_task_t handler_tid
Mailbox handler thread handle.
Definition mbx.h:133
int slave
Number of EtherCAT slave.
Definition mbx.h:128
Definition soe.h:56
ethercat master structure
Definition ec.h:188
Pool queue entry.
Definition pool.h:67
the datagram pool itself
Definition pool.h:81