Mistake on this page?
Report an issue in GitHub or email us
scl_emac.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2020 Cypress Semiconductor Corporation
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 SCL_EMAC_H_
19 #define SCL_EMAC_H_
20 
21 /** @file
22  * Provides EMAC interface functions to be used with the SCL_EMAC object
23  *
24  */
25 #include "EMAC.h"
26 #include "EMACInterface.h"
27 #include "WiFiInterface.h"
28 #include "scl_common.h"
29 #include "rtos/Semaphore.h"
30 #include "rtos/Mutex.h"
31 #include "scl_wifi_api.h"
32 class SCL_EMAC : public EMAC {
33 public:
34  SCL_EMAC();
35  SCL_EMAC(scl_interface_role_t itype);
36 
37  /**
38  * Get the EMAC instance
39  *
40  * @return Reference to SCL_EMAC object.
41  */
42  static SCL_EMAC &get_instance();
43 
44  /**
45  * Get the EMAC instance
46  *
47  * @param role Interface type.
48  *
49  * @return Reference to SCL_EMAC object.
50  */
51  static SCL_EMAC &get_instance(scl_interface_role_t role);
52 
53  /**
54  * Returns the maximum transmission unit
55  *
56  * @return MTU in bytes.
57  */
58  virtual uint32_t get_mtu_size() const;
59 
60  /**
61  * Gets the memory buffer alignment preference
62  *
63  * Gets the preferred memory buffer alignment of the EMAC device. IP stack may or may not
64  * align with the link out memory buffer chains using the alignment.
65  *
66  * @return Memory alignment requirement in bytes.
67  */
68  virtual uint32_t get_align_preference() const;
69 
70  /**
71  * Returns the interface name
72  *
73  * @param name Pointer to the location where the name should be written.
74  * @param size Maximum number of characters to copy.
75  */
76  virtual void get_ifname(char *name, uint8_t size) const;
77 
78  /**
79  * Returns the size of the underlying interface HW address size.
80  *
81  * @return HW address size in bytes.
82  */
83  virtual uint8_t get_hwaddr_size() const;
84 
85  /**
86  * Returns the interface supplied HW address
87  * Copies the HW address to the provided memory
88  * @param addr HW address of the underlying interface. It must be of correct size. See @a get_hwaddr_size.
89  * @return True if HW address is available.
90  */
91  virtual bool get_hwaddr(uint8_t *addr) const;
92 
93  /**
94  * Set HW address for the interface
95  *
96  * Provided address must be of correct size. See @a get_hwaddr_size.
97  *
98  * Called to set the MAC address to be used - if @a get_hwaddr is provided
99  * the stack would normally use that, but it could be overridden for test
100  * purposes.
101  *
102  * @param addr Address to be set
103  */
104  virtual void set_hwaddr(const uint8_t *addr);
105 
106  /**
107  * Sends the packet over the link
108  *
109  * This cannot be called from an interrupt context.
110  *
111  * @param buf Packet to be sent.
112  * @return True if the packet was sent successfully. False otherwise.
113  */
114  virtual bool link_out(emac_mem_buf_t *buf);
115 
116  /**
117  * Initializes the HW
118  *
119  * @return True on success. False in case of an error.
120  */
121  virtual bool power_up();
122 
123  /**
124  * De-initializes the HW
125  */
126  virtual void power_down();
127 
128  /**
129  * Sets a callback that is called for packets received for a given interface
130  *
131  * @param input_cb Function to be registered as a callback.
132  */
133  virtual void set_link_input_cb(emac_link_input_cb_t input_cb);
134 
135  /**
136  * Sets a callback that is called on changes in the link status for a given interface
137  *
138  * @param state_cb Function to be registered as a callback.
139  */
140  virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb);
141 
142  /** Adds a device to a multicast group
143  *
144  * @param address A multicast group hardware address.
145  */
146  virtual void add_multicast_group(const uint8_t *address);
147 
148  /** Removes a device from a multicast group
149  *
150  * @param address A multicast group hardware address.
151  */
152  virtual void remove_multicast_group(const uint8_t *address);
153 
154  /** Requests reception of all multicast packets
155  *
156  * @param all True to receive all multicasts.
157  * False to receive only multicasts addressed to specified groups.
158  */
159  virtual void set_all_multicast(bool all);
160 
161  /** Sets memory manager used to handle memory buffers
162  *
163  * @param mem_mngr Pointer to memory manager.
164  */
165  virtual void set_memory_manager(EMACMemoryManager &mem_mngr);
166 
167  /** Sets callback to receive EMAC activity events
168  *
169  * @param activity_cb The callback for activity events.
170  */
171  virtual void set_activity_cb(mbed::Callback<void(bool is_tx_activity)> activity_cb);
172 
173  emac_link_input_cb_t emac_link_input_cb = NULL; /**< Callback for incoming data */
174  emac_link_state_change_cb_t emac_link_state_cb = NULL; /**< Callback for network connection status */
175  EMACMemoryManager *memory_manager; /**< Pointer to hold memory manager object */
176  bool powered_up = false; /**< Flag for Wi-Fi power on status */
177  bool link_state = false; /**< Flag for network connection status */
178  scl_interface_role_t interface_type; /**< Type of the interface */
179  scl_mac_t multicast_addr; /**< Multicast address */
180  mbed::Callback<void(bool)> activity_cb; /**< Callback for activity on network */
181 
182 };
183 /** Sends the change in network connection state to network stack
184 *
185 * @param state_up Connection status.
186 */
187 extern "C" void scl_emac_wifi_link_state_changed(bool state_up);
188 
189 #endif /* SCL_EMAC_H_ */
virtual void set_memory_manager(EMACMemoryManager &mem_mngr)
Sets memory manager used to handle memory buffers.
mbed::Callback< void(bool)> activity_cb
Callback for activity on network.
Definition: scl_emac.h:180
virtual void set_hwaddr(const uint8_t *addr)
Set HW address for the interface.
virtual void set_all_multicast(bool all)
Requests reception of all multicast packets.
virtual bool get_hwaddr(uint8_t *addr) const
Returns the interface supplied HW address Copies the HW address to the provided memory.
static SCL_EMAC & get_instance()
Get the EMAC instance.
void scl_emac_wifi_link_state_changed(bool state_up)
Sends the change in network connection state to network stack.
virtual bool link_out(emac_mem_buf_t *buf)
Sends the packet over the link.
bool powered_up
Flag for Wi-Fi power on status.
Definition: scl_emac.h:176
virtual void power_down()
De-initializes the HW.
emac_link_input_cb_t emac_link_input_cb
Callback for incoming data.
Definition: scl_emac.h:173
EMACMemoryManager * memory_manager
Pointer to hold memory manager object.
Definition: scl_emac.h:175
virtual uint32_t get_mtu_size() const
Returns the maximum transmission unit.
virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb)
Sets a callback that is called on changes in the link status for a given interface.
virtual bool power_up()
Initializes the HW.
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 remove_multicast_group(const uint8_t *address)
Removes a device from a multicast group.
virtual uint32_t get_align_preference() const
Gets the memory buffer alignment preference.
virtual uint8_t get_hwaddr_size() const
Returns the size of the underlying interface HW address size.
scl_mac_t multicast_addr
Multicast address.
Definition: scl_emac.h:179
scl_interface_role_t interface_type
Type of the interface.
Definition: scl_emac.h:178
virtual void set_activity_cb(mbed::Callback< void(bool is_tx_activity)> activity_cb)
Sets callback to receive EMAC activity events.
virtual void get_ifname(char *name, uint8_t size) const
Returns the interface name.
virtual void add_multicast_group(const uint8_t *address)
Adds a device to a multicast group.
This interface should be used to abstract low level access to networking hardware All operations rece...
Definition: EMAC.h:33
bool link_state
Flag for network connection status.
Definition: scl_emac.h:177
emac_link_state_change_cb_t emac_link_state_cb
Callback for network connection status.
Definition: scl_emac.h:174
virtual void set_link_input_cb(emac_link_input_cb_t input_cb)
Sets a callback that is called for packets received for a given interface.
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.