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