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#include <libosal/task.h>
46
47#include "libethercat/common.h"
48
49#if LIBETHERCAT_MBX_SUPPORT_COE == 1
50#include "libethercat/coe.h"
51#endif
52
53#if LIBETHERCAT_MBX_SUPPORT_SOE == 1
54#include "libethercat/soe.h"
55#endif
56
57#if LIBETHERCAT_MBX_SUPPORT_FOE == 1
58#include "libethercat/foe.h"
59#endif
60
61#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
62#include "libethercat/eoe.h"
63#endif
64
65#include "libethercat/pool.h"
67
75#define MAILBOX_WRITE (osal_uint16_t)(0u)
76#define MAILBOX_READ (osal_uint16_t)(1u)
77
78// forward declarations
79struct ec;
80typedef struct ec ec_t;
81
82#define MESSAGE_POOL_DEBUG(type) {}
83
84/*
85#define N_MESSAGE_POOL_DEBUG(type) \
86{ \
87 int avail = 0; \
88 sem_getvalue(&slv->mbx.message_pool_ ## type->avail_cnt, &avail); \
89 ec_log(10, __func__, "slave %d: " #type " pool avail %d\n", slave, avail); \
90}
91*/
93enum {
94 EC_MBX_ERR = 0x00,
100 EC_MBX_VOE = 0x0f
102
104typedef struct PACKED ec_mbx_header {
105 osal_uint16_t length;
106 osal_uint16_t address;
107 osal_uint8_t priority;
108 osal_uint8_t mbxtype : 4;
109 osal_uint8_t counter : 4;
111
113typedef struct PACKED ec_mbx_buffer {
115 ec_data_t mbx_data;
117
118typedef struct ec_mbx {
119 osal_uint32_t handler_flags;
120 osal_mutex_t sync_mutex;
121 osal_binary_semaphore_t sync_sem;
122
129 int slave;
134 osal_task_t handler_tid;
135
136 osal_mutex_t lock;
144
146
147#if LIBETHERCAT_MBX_SUPPORT_COE == 1
148 ec_coe_t coe;
149#endif
150
151#if LIBETHERCAT_MBX_SUPPORT_SOE == 1
152 ec_soe_t soe;
153#endif
154
155#if LIBETHERCAT_MBX_SUPPORT_FOE == 1
156 ec_foe_t foe;
157#endif
158
159#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
160 ec_eoe_t eoe;
161#endif
162
163 osal_uint32_t sm_state_bitno;
164 osal_uint8_t *sm_state;
172 osal_uint8_t mbx_state;
173} ec_mbx_t;
174
175#ifdef __cplusplus
176extern "C" {
177#endif
178
180
187void ec_mbx_init(ec_t *pec, osal_uint16_t slave);
188
190
197void ec_mbx_deinit(ec_t *pec, osal_uint16_t slave);
198
200
208void ec_mbx_enqueue_head(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_entry);
209
211
219void ec_mbx_enqueue_tail(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_entry);
220
222
229void ec_mbx_sched_read(ec_t *pec, osal_uint16_t slave);
230
232
248int ec_mbx_check(ec_t *pec, int slave, osal_uint16_t mbx_flag);
249
251
261int ec_mbx_next_counter(ec_t *pec, int slave, int *seq_counter);
262
263#define ec_mbx_get_free_recv_buffer(pec, slave, entry, timeout, lock) \
264 pool_get(&(pec)->mbx_message_pool_recv_free, &(entry), (timeout))
265
266#define ec_mbx_get_free_send_buffer_old(pec, slave, entry, timeout, lock) \
267 pool_get(&(pec)->mbx_message_pool_send_free, &(entry), (timeout))
268
270
282int ec_mbx_get_free_send_buffer(ec_t *pec, osal_uint16_t slave, pool_entry_t **pp_entry, osal_timer_t *timeout);
283
284#define ec_mbx_return_free_send_buffer(pec, slave, entry) \
285 pool_put(&(pec)->mbx_message_pool_send_free, (entry))
286
287#define ec_mbx_return_free_recv_buffer(pec, slave, entry) \
288 pool_put(&(pec)->mbx_message_pool_recv_free, (entry))
289
291
300void ec_mbx_do_handle(ec_t *pec, uint16_t slave);
301
302#ifdef __cplusplus
303}
304#endif
305
308#endif // LIBETHERCAT_MBX_H
309
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.
void ec_mbx_do_handle(ec_t *pec, uint16_t slave)
Handle slaves mailbox.
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:94
@ EC_MBX_EOE
Ethernet over EtherCAT mailbox.
Definition mbx.h:96
@ EC_MBX_AOE
ADS over EtherCAT mailbox.
Definition mbx.h:95
@ EC_MBX_COE
CANopen over EtherCAT mailbox.
Definition mbx.h:97
@ EC_MBX_VOE
Vendor over EtherCAT mailbox.
Definition mbx.h:100
@ EC_MBX_SOE
Servo over EtherCAT mailbox.
Definition mbx.h:99
@ EC_MBX_FOE
File over EtherCAT mailbox.
Definition mbx.h:98
Data pool implementation.
EtherCAT SoE functions.
Definition coe.h:65
Definition eoe.h:75
Definition foe.h:58
ethercat mailbox data
Definition mbx.h:113
ec_mbx_header_t mbx_hdr
mailbox header
Definition mbx.h:114
ec_data_t mbx_data
mailbox data
Definition mbx.h:115
ethercat mailbox header
Definition mbx.h:104
osal_uint16_t length
mailbox length
Definition mbx.h:105
osal_uint8_t mbxtype
mailbox type
Definition mbx.h:108
osal_uint8_t priority
priority
Definition mbx.h:107
osal_uint8_t counter
counter
Definition mbx.h:109
osal_uint16_t address
mailbox address
Definition mbx.h:106
Definition mbx.h:118
int handler_running
Mailbox handler thread running flag.
Definition mbx.h:123
osal_mutex_t sync_mutex
Sync mutex for handler flags.
Definition mbx.h:120
osal_uint8_t mbx_state
State if not mapped.
Definition mbx.h:172
osal_mutex_t lock
mailbox lock
Definition mbx.h:136
ec_t * pec
Pointer to ethercat master structure.
Definition mbx.h:124
pool_t message_pool_send_queued
Pool with mailbox buffers ready to be sent.
Definition mbx.h:145
osal_uint8_t * sm_state
Sync manager state of read mailbox.
Definition mbx.h:164
osal_uint32_t handler_flags
Flags signalling handler recv of send action.
Definition mbx.h:119
int seq_counter
mailbox sequence counter
Definition mbx.h:143
osal_binary_semaphore_t sync_sem
Mailbox sync semaphore.
Definition mbx.h:121
osal_task_t handler_tid
Mailbox handler thread handle.
Definition mbx.h:134
int slave
Number of EtherCAT slave.
Definition mbx.h:129
Definition soe.h:56
ethercat master structure
Definition ec.h:192
Pool queue entry.
Definition pool.h:67
the datagram pool itself
Definition pool.h:84