Mistake on this page?
Report an issue in GitHub or email us
EMW3080B_EMAC.h
1 /*
2  * Copyright (c) STMicroelectronics 2021
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 EMW3080B_EMAC_H_
19 #define EMW3080B_EMAC_H_
20 
21 #include <inttypes.h>
22 
23 #include "mbed.h"
24 #include "mbed_debug.h"
25 #include "EMACInterface.h"
26 #include "WiFiInterface.h"
27 #include "mx_wifi.h"
28 
29 extern EMACMemoryManager *emac3080b_global_memory_manager ;
30 
31 
32 class EMW3080B_EMAC : public EMAC {
33 public:
34  EMW3080B_EMAC();
35 
36  static EMW3080B_EMAC &get_instance();
37 
38  /**
39  * Return maximum transmission unit
40  *
41  * @return MTU in bytes
42  */
43  virtual uint32_t get_mtu_size() const;
44 
45  /**
46  * Gets memory buffer alignment preference
47  *
48  * Gets preferred memory buffer alignment of the Emac device. IP stack may or may not
49  * align link out memory buffer chains using the alignment.
50  *
51  * @return Memory alignment requirement in bytes
52  */
53  virtual uint32_t get_align_preference() const;
54 
55  /**
56  * Return interface name
57  *
58  * @param name Pointer to where the name should be written
59  * @param size Maximum number of character to copy
60  */
61  virtual void get_ifname(char *name, uint8_t size) const;
62 
63  /**
64  * Returns size of the underlying interface HW address size.
65  *
66  * @return HW address size in bytes
67  */
68  virtual uint8_t get_hwaddr_size() const;
69 
70  /**
71  * Return interface-supplied HW address
72  *
73  * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size
74  *
75  * HW address need not be provided if this interface does not have its own HW
76  * address configuration; stack will choose address from central system
77  * configuration if the function returns false and does not write to addr.
78  *
79  * @param addr HW address for underlying interface
80  * @return true if HW address is available
81  */
82  virtual bool get_hwaddr(uint8_t *addr) const;
83 
84  /**
85  * Set HW address for interface
86  *
87  * Provided address has to be of correct size, see @a get_hwaddr_size
88  *
89  * Called to set the MAC address to actually use - if @a get_hwaddr is provided
90  * the stack would normally use that, but it could be overridden, eg for test
91  * purposes.
92  *
93  * @param addr Address to be set
94  */
95  virtual void set_hwaddr(const uint8_t *addr);
96 
97  /**
98  * Sends the packet over the link
99  *
100  * That can not be called from an interrupt context.
101  *
102  * @param buf Packet to be send
103  * @return True if the packet was send successfully, False otherwise
104  */
105  virtual bool link_out(emac_mem_buf_t *buf);
106 
107  /**
108  * Initializes the HW
109  *
110  * @return True on success, False in case of an error.
111  */
112  virtual bool power_up();
113 
114  /**
115  * Deinitializes the HW
116  *
117  */
118  virtual void power_down();
119 
120  /**
121  * Sets a callback that needs to be called for packets received for that interface
122  *
123  * @param input_cb Function to be register as a callback
124  */
125  virtual void set_link_input_cb(emac_link_input_cb_t input_cb);
126 
127  /**
128  * Sets a callback that needs to be called on link status changes for given interface
129  *
130  * @param state_cb Function to be register as a callback
131  */
132  virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb);
133 
134  /** Add device to a multicast group
135  *
136  * @param address A multicast group hardware address
137  */
138  virtual void add_multicast_group(const uint8_t *address);
139 
140  /** Remove device from a multicast group
141  *
142  * @param address A multicast group hardware address
143  */
144  virtual void remove_multicast_group(const uint8_t *address);
145 
146  /** Request reception of all multicast packets
147  *
148  * @param all True to receive all multicasts
149  * False to receive only multicasts addressed to specified groups
150  */
151  virtual void set_all_multicast(bool all);
152 
153  /** Sets memory manager that is used to handle memory buffers
154  *
155  * @param mem_mngr Pointer to memory manager
156  */
157  virtual void set_memory_manager(EMACMemoryManager &mem_mngr);
158 
159  void mx_wifi_status_changed(uint8_t cate, uint8_t status, void *arg);
160  void mx_wifi_netlink_input_callback(mx_buf_t *buffer);
161 
162 #define EMW3080B_HWADDR_SIZE 6
163 
164  emac_link_input_cb_t _emac_link_input_cb; /**< Callback for incoming data */
165  emac_link_state_change_cb_t _emac_link_state_cb;
166  emac_link_input_cb_t _emac_input_data_cb;
167  EMACMemoryManager *_memory_manager;
168  uint8_t _mac_addr[EMW3080B_HWADDR_SIZE];
169 
170  uint8_t _debug_level;
171 };
172 
173 #endif /* EMW3080B_EMAC_H_ */
virtual uint32_t get_mtu_size() const
Return maximum transmission unit.
virtual void remove_multicast_group(const uint8_t *address)
Remove device from a multicast group.
virtual void set_memory_manager(EMACMemoryManager &mem_mngr)
Sets memory manager that is used to handle memory buffers.
virtual void set_all_multicast(bool all)
Request reception of all multicast packets.
virtual void set_hwaddr(const uint8_t *addr)
Set HW address for interface.
virtual void set_link_input_cb(emac_link_input_cb_t input_cb)
Sets a callback that needs to be called for packets received for that interface.
virtual bool get_hwaddr(uint8_t *addr) const
Return interface-supplied HW address.
virtual void power_down()
Deinitializes the HW.
virtual bool link_out(emac_mem_buf_t *buf)
Sends the packet over the link.
virtual void get_ifname(char *name, uint8_t size) const
Return interface name.
virtual uint8_t get_hwaddr_size() const
Returns size of the underlying interface HW address size.
Header for mx_wifi.c module.
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
virtual bool power_up()
Initializes the HW.
virtual void add_multicast_group(const uint8_t *address)
Add device to a multicast group.
emac_link_input_cb_t _emac_link_input_cb
Callback for incoming data.
virtual uint32_t get_align_preference() const
Gets memory buffer alignment preference.
virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb)
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:33
Callback class based on template specialization.
Definition: Callback.h:53
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.