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