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