|
| 1 | +<<<<<<< HEAD |
1 | 2 | /* mbed Microcontroller Library
|
2 | 3 | * Copyright (c) 2018 Gigadevice Semiconductor Inc.
|
3 | 4 | *
|
@@ -172,3 +173,179 @@ class GD32_EMAC : public EMAC {
|
172 | 173 | };
|
173 | 174 |
|
174 | 175 | #endif /* GD32_EMAC_H_ */
|
| 176 | +======= |
| 177 | +/* mbed Microcontroller Library |
| 178 | + * Copyright (c) 2018 Gigadevice Semiconductor Inc. |
| 179 | + * |
| 180 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 181 | + * you may not use this file except in compliance with the License. |
| 182 | + * You may obtain a copy of the License at |
| 183 | + * |
| 184 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 185 | + * |
| 186 | + * Unless required by applicable law or agreed to in writing, software |
| 187 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 188 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 189 | + * See the License for the specific language governing permissions and |
| 190 | + * limitations under the License. |
| 191 | + */ |
| 192 | + |
| 193 | +#ifndef GD32_EMAC_H_ |
| 194 | +#define GD32_EMAC_H_ |
| 195 | + |
| 196 | +#include "EMAC.h" |
| 197 | +#include "rtos/Semaphore.h" |
| 198 | +#include "rtos/Mutex.h" |
| 199 | + |
| 200 | +class GD32_EMAC : public EMAC { |
| 201 | +public: |
| 202 | + GD32_EMAC(); |
| 203 | + |
| 204 | + static GD32_EMAC &get_instance(); |
| 205 | + |
| 206 | + /** |
| 207 | + * Return maximum transmission unit |
| 208 | + * |
| 209 | + * @return MTU in bytes |
| 210 | + */ |
| 211 | + virtual uint32_t get_mtu_size() const; |
| 212 | + |
| 213 | + /** |
| 214 | + * Gets memory buffer alignment preference |
| 215 | + * |
| 216 | + * Gets preferred memory buffer alignment of the Emac device. IP stack may or may not |
| 217 | + * align link out memory buffer chains using the alignment. |
| 218 | + * |
| 219 | + * @return Memory alignment requirement in bytes |
| 220 | + */ |
| 221 | + virtual uint32_t get_align_preference() const; |
| 222 | + |
| 223 | + /** |
| 224 | + * Return interface name |
| 225 | + * |
| 226 | + * @param name Pointer to where the name should be written |
| 227 | + * @param size Maximum number of character to copy |
| 228 | + */ |
| 229 | + virtual void get_ifname(char *name, uint8_t size) const; |
| 230 | + |
| 231 | + /** |
| 232 | + * Returns size of the underlying interface HW address size. |
| 233 | + * |
| 234 | + * @return HW address size in bytes |
| 235 | + */ |
| 236 | + virtual uint8_t get_hwaddr_size() const; |
| 237 | + |
| 238 | + /** |
| 239 | + * Return interface-supplied HW address |
| 240 | + * |
| 241 | + * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size |
| 242 | + * |
| 243 | + * HW address need not be provided if this interface does not have its own HW |
| 244 | + * address configuration; stack will choose address from central system |
| 245 | + * configuration if the function returns false and does not write to addr. |
| 246 | + * |
| 247 | + * @param addr HW address for underlying interface |
| 248 | + * @return true if HW address is available |
| 249 | + */ |
| 250 | + virtual bool get_hwaddr(uint8_t *addr) const; |
| 251 | + |
| 252 | + /** |
| 253 | + * Set HW address for interface |
| 254 | + * |
| 255 | + * Provided address has to be of correct size, see @a get_hwaddr_size |
| 256 | + * |
| 257 | + * Called to set the MAC address to actually use - if @a get_hwaddr is provided |
| 258 | + * the stack would normally use that, but it could be overridden, eg for test |
| 259 | + * purposes. |
| 260 | + * |
| 261 | + * @param addr Address to be set |
| 262 | + */ |
| 263 | + virtual void set_hwaddr(const uint8_t *addr); |
| 264 | + |
| 265 | + /** |
| 266 | + * Sends the packet over the link |
| 267 | + * |
| 268 | + * That can not be called from an interrupt context. |
| 269 | + * |
| 270 | + * @param buf Packet to be send |
| 271 | + * @return True if the packet was send successfully, False otherwise |
| 272 | + */ |
| 273 | + virtual bool link_out(emac_mem_buf_t *buf); |
| 274 | + |
| 275 | + /** |
| 276 | + * Initializes the HW |
| 277 | + * |
| 278 | + * @return True on success, False in case of an error. |
| 279 | + */ |
| 280 | + virtual bool power_up(); |
| 281 | + |
| 282 | + /** |
| 283 | + * Deinitializes the HW |
| 284 | + * |
| 285 | + */ |
| 286 | + virtual void power_down(); |
| 287 | + |
| 288 | + /** |
| 289 | + * Sets a callback that needs to be called for packets received for that interface |
| 290 | + * |
| 291 | + * @param input_cb Function to be register as a callback |
| 292 | + */ |
| 293 | + virtual void set_link_input_cb(emac_link_input_cb_t input_cb); |
| 294 | + |
| 295 | + /** |
| 296 | + * Sets a callback that needs to be called on link status changes for given interface |
| 297 | + * |
| 298 | + * @param state_cb Function to be register as a callback |
| 299 | + */ |
| 300 | + virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb); |
| 301 | + |
| 302 | + /** Add device to a multicast group |
| 303 | + * |
| 304 | + * @param address A multicast group hardware address |
| 305 | + */ |
| 306 | + virtual void add_multicast_group(const uint8_t *address); |
| 307 | + |
| 308 | + /** Remove device from a multicast group |
| 309 | + * |
| 310 | + * @param address A multicast group hardware address |
| 311 | + */ |
| 312 | + virtual void remove_multicast_group(const uint8_t *address); |
| 313 | + |
| 314 | + /** Request reception of all multicast packets |
| 315 | + * |
| 316 | + * @param all True to receive all multicasts |
| 317 | + * False to receive only multicasts addressed to specified groups |
| 318 | + */ |
| 319 | + virtual void set_all_multicast(bool all); |
| 320 | + |
| 321 | + /** Sets memory manager that is used to handle memory buffers |
| 322 | + * |
| 323 | + * @param mem_mngr Pointer to memory manager |
| 324 | + */ |
| 325 | + virtual void set_memory_manager(EMACMemoryManager &mem_mngr); |
| 326 | + |
| 327 | + /* Called from driver functions */ |
| 328 | + osThreadId_t rx_thread; /**< Processing rx thread */ |
| 329 | + |
| 330 | +private: |
| 331 | + bool low_level_init(); |
| 332 | + void packet_rx(); |
| 333 | + emac_mem_buf_t *low_level_input(void); |
| 334 | + static void thread_function(void *pvParameters); |
| 335 | + void phy_task(); |
| 336 | + void eth_arch_enable_interrupts(); |
| 337 | + void eth_arch_disable_interrupts(); |
| 338 | + |
| 339 | + mbed_rtos_storage_thread_t rx_thread_cb; |
| 340 | + |
| 341 | + rtos::Mutex TXLockMutex;/**< TX critical section mutex */ |
| 342 | + emac_link_input_cb_t emac_link_input_cb; /**< Callback for incoming data */ |
| 343 | + emac_link_state_change_cb_t emac_link_state_cb; /**< Link state change callback */ |
| 344 | + EMACMemoryManager *memory_manager; /**< Memory manager */ |
| 345 | + |
| 346 | + uint32_t phy_status; |
| 347 | + int phy_task_handle; /**< Handle for phy task event */ |
| 348 | +}; |
| 349 | + |
| 350 | +#endif /* GD32_EMAC_H_ */ |
| 351 | +>>>>>>> Update licence |
0 commit comments