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