Mbed OS Reference
Loading...
Searching...
No Matches
EMAC.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2016 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef EMAC_H
19#define EMAC_H
20
21#include <stdbool.h>
22#include "Callback.h"
23#include "EMACMemoryManager.h"
24
25// Nuvoton platform headers define EMAC - avoid the collision
26#undef EMAC
27
28/**
29 * This interface should be used to abstract low level access to networking hardware
30 * All operations receive a `void *` hardware pointer which an EMAC device provides when
31 * it is registered with a stack.
32 */
33class EMAC {
34public:
35
36 /** Return the default on-board EMAC
37 *
38 * Returns the default on-board EMAC - this will be target-specific, and
39 * may not be available on all targets.
40 */
42
43 /**
44 * Callback to be register with EMAC interface and to be called for received packets
45 *
46 * <br>
47 * \c buf : Received data
48 */
49 typedef mbed::Callback<void (emac_mem_buf_t *buf)> emac_link_input_cb_t;
50
51 /**
52 * Callback to be register with EMAC interface and to be called for link status changes
53 *
54 * <br>
55 * \c up : Link status
56 */
58
59 /**
60 * Return maximum transmission unit
61 *
62 * @return MTU in bytes
63 */
64 virtual uint32_t get_mtu_size() const = 0;
65
66 /**
67 * Gets memory buffer alignment preference
68 *
69 * Gets preferred memory buffer alignment of the EMAC device. IP stack may or may not
70 * align link out memory buffer chains using the alignment.
71 *
72 * @return Memory alignment requirement in bytes
73 */
74 virtual uint32_t get_align_preference() const = 0;
75
76 /**
77 * Return interface name
78 *
79 * @param name Pointer to where the name should be written
80 * @param size Maximum number of character to copy
81 */
82 virtual void get_ifname(char *name, uint8_t size) const = 0;
83
84 /**
85 * Returns size of the underlying interface HW address size.
86 *
87 * @return HW address size in bytes
88 */
89 virtual uint8_t get_hwaddr_size() const = 0;
90
91 /**
92 * Return interface-supplied HW address
93 *
94 * Copies HW address to provided memory, \c addr has to be of correct size see #get_hwaddr_size
95 *
96 * HW address need not be provided if this interface does not have its own HW
97 * address configuration; stack will choose address from central system
98 * configuration if the function returns false and does not write to addr.
99 *
100 * @param addr HW address for underlying interface
101 * @return true if HW address is available
102 */
103 virtual bool get_hwaddr(uint8_t *addr) const = 0;
104
105 /**
106 * Set HW address for interface
107 *
108 * Provided address has to be of correct size, see @a get_hwaddr_size
109 *
110 * Called to set the MAC address to actually use - if @a get_hwaddr is provided
111 * the stack would normally use that, but it could be overridden, for example for test
112 * purposes.
113 *
114 * @param addr Address to be set
115 */
116 virtual void set_hwaddr(const uint8_t *addr) = 0;
117
118 /**
119 * Sends the packet over the link
120 *
121 * That can not be called from an interrupt context.
122 *
123 * @param buf Packet to be send
124 * @return True if the packet was send successfully, False otherwise
125 */
126 virtual bool link_out(emac_mem_buf_t *buf) = 0;
127
128 /**
129 * Initializes the HW
130 *
131 * @return True on success, False in case of an error.
132 */
133 virtual bool power_up() = 0;
134
135 /**
136 * Deinitializes the HW
137 *
138 */
139 virtual void power_down() = 0;
140
141 /**
142 * Sets a callback that needs to be called for packets received for that interface
143 *
144 * @param input_cb Function to be register as a callback
145 */
146 virtual void set_link_input_cb(emac_link_input_cb_t input_cb) = 0;
147
148 /**
149 * Sets a callback that needs to be called on link status changes for given interface
150 *
151 * @param state_cb Function to be register as a callback
152 */
154
155 /** Add device to a multicast group
156 *
157 * @param address A multicast group hardware address
158 */
159 virtual void add_multicast_group(const uint8_t *address) = 0;
160
161 /** Remove device from a multicast group
162 *
163 * @param address A multicast group hardware address
164 */
165 virtual void remove_multicast_group(const uint8_t *address) = 0;
166
167 /** Request reception of all multicast packets
168 *
169 * @param all True to receive all multicasts
170 * False to receive only multicasts addressed to specified groups
171 */
172 virtual void set_all_multicast(bool all) = 0;
173
174 /** Sets memory manager that is used to handle memory buffers
175 *
176 * @param mem_mngr Pointer to memory manager
177 */
178 virtual void set_memory_manager(EMACMemoryManager &mem_mngr) = 0;
179};
180
181
182/** These need to be defined by targets wishing to provide an Ethernet driver using EMAC interface. It will
183 * be used by the EMACInterface class's default constructor to initialize the networking subsystem.
184 */
185//extern const emac_interface_ops_t mbed_emac_eth_ops_default;
186//extern void *mbed_emac_eth_hw_default;
187
188#endif /* EMAC_H */
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: EMAC.h:33
virtual void set_all_multicast(bool all)=0
Request reception of all multicast packets.
virtual uint8_t get_hwaddr_size() const =0
Returns size of the underlying interface HW address size.
mbed::Callback< void(bool up)> emac_link_state_change_cb_t
Callback to be register with EMAC interface and to be called for link status changes.
Definition: EMAC.h:57
mbed::Callback< void(emac_mem_buf_t *buf)> emac_link_input_cb_t
Callback to be register with EMAC interface and to be called for received packets.
Definition: EMAC.h:49
virtual void set_hwaddr(const uint8_t *addr)=0
Set HW address for interface.
virtual bool power_up()=0
Initializes the HW.
static EMAC & get_default_instance()
Return the default on-board EMAC.
virtual void set_memory_manager(EMACMemoryManager &mem_mngr)=0
Sets memory manager that is used to handle memory buffers.
virtual bool get_hwaddr(uint8_t *addr) const =0
Return interface-supplied HW address.
virtual void get_ifname(char *name, uint8_t size) const =0
Return interface name.
virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb)=0
Sets a callback that needs to be called on link status changes for given interface.
virtual uint32_t get_align_preference() const =0
Gets memory buffer alignment preference.
virtual bool link_out(emac_mem_buf_t *buf)=0
Sends the packet over the link.
virtual uint32_t get_mtu_size() const =0
Return maximum transmission unit.
virtual void remove_multicast_group(const uint8_t *address)=0
Remove device from a multicast group.
virtual void set_link_input_cb(emac_link_input_cb_t input_cb)=0
Sets a callback that needs to be called for packets received for that interface.
virtual void power_down()=0
Deinitializes the HW.
virtual void add_multicast_group(const uint8_t *address)=0
Add device to a multicast group.
Callback class based on template specialization.
Definition: Callback.h:53