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