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