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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.