Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
EMAC.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2016 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef EMAC_H 00018 #define EMAC_H 00019 00020 #include <stdbool.h> 00021 #include "Callback.h" 00022 #include "EMACMemoryManager.h" 00023 00024 // Nuvoton platform headers define EMAC - avoid the collision 00025 #undef EMAC 00026 00027 /** 00028 * This interface should be used to abstract low level access to networking hardware 00029 * All operations receive a `void *` hw pointer which an emac device provides when 00030 * it is registered with a stack. 00031 */ 00032 class EMAC { 00033 public: 00034 00035 /** Return the default on-board EMAC 00036 * 00037 * Returns the default on-board EMAC - this will be target-specific, and 00038 * may not be available on all targets. 00039 */ 00040 static EMAC &get_default_instance(); 00041 00042 /** 00043 * Callback to be register with Emac interface and to be called for received packets 00044 * 00045 * @param buf Received data 00046 */ 00047 //typedef void (*emac_link_input_fn)(void *data, emac_mem_buf_t *buf); 00048 typedef mbed::Callback<void (emac_mem_buf_t *buf)> emac_link_input_cb_t; 00049 00050 /** 00051 * Callback to be register with Emac interface and to be called for link status changes 00052 * 00053 * @param up Link status 00054 */ 00055 //typedef void (*emac_link_state_change_fn)(void *data, bool up); 00056 typedef mbed::Callback<void (bool up)> emac_link_state_change_cb_t; 00057 00058 /** 00059 * Return maximum transmission unit 00060 * 00061 * @return MTU in bytes 00062 */ 00063 virtual uint32_t get_mtu_size() const = 0; 00064 00065 /** 00066 * Gets memory buffer alignment preference 00067 * 00068 * Gets preferred memory buffer alignment of the Emac device. IP stack may or may not 00069 * align link out memory buffer chains using the alignment. 00070 * 00071 * @return Memory alignment requirement in bytes 00072 */ 00073 virtual uint32_t get_align_preference() const = 0; 00074 00075 /** 00076 * Return interface name 00077 * 00078 * @param name Pointer to where the name should be written 00079 * @param size Maximum number of character to copy 00080 */ 00081 virtual void get_ifname(char *name, uint8_t size) const = 0; 00082 00083 /** 00084 * Returns size of the underlying interface HW address size. 00085 * 00086 * @return HW address size in bytes 00087 */ 00088 virtual uint8_t get_hwaddr_size() const = 0; 00089 00090 /** 00091 * Return interface-supplied HW address 00092 * 00093 * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size 00094 * 00095 * HW address need not be provided if this interface does not have its own HW 00096 * address configuration; stack will choose address from central system 00097 * configuration if the function returns false and does not write to addr. 00098 * 00099 * @param addr HW address for underlying interface 00100 * @return true if HW address is available 00101 */ 00102 virtual bool get_hwaddr(uint8_t *addr) const = 0; 00103 00104 /** 00105 * Set HW address for interface 00106 * 00107 * Provided address has to be of correct size, see @a get_hwaddr_size 00108 * 00109 * Called to set the MAC address to actually use - if @a get_hwaddr is provided 00110 * the stack would normally use that, but it could be overridden, eg for test 00111 * purposes. 00112 * 00113 * @param addr Address to be set 00114 */ 00115 virtual void set_hwaddr(const uint8_t *addr) = 0; 00116 00117 /** 00118 * Sends the packet over the link 00119 * 00120 * That can not be called from an interrupt context. 00121 * 00122 * @param buf Packet to be send 00123 * @return True if the packet was send successfully, False otherwise 00124 */ 00125 virtual bool link_out(emac_mem_buf_t *buf) = 0; 00126 00127 /** 00128 * Initializes the HW 00129 * 00130 * @return True on success, False in case of an error. 00131 */ 00132 virtual bool power_up() = 0; 00133 00134 /** 00135 * Deinitializes the HW 00136 * 00137 */ 00138 virtual void power_down() = 0; 00139 00140 /** 00141 * Sets a callback that needs to be called for packets received for that interface 00142 * 00143 * @param input_cb Function to be register as a callback 00144 */ 00145 virtual void set_link_input_cb(emac_link_input_cb_t input_cb) = 0; 00146 00147 /** 00148 * Sets a callback that needs to be called on link status changes for given interface 00149 * 00150 * @param state_cb Function to be register as a callback 00151 */ 00152 virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb) = 0; 00153 00154 /** Add device to a multicast group 00155 * 00156 * @param address A multicast group hardware address 00157 */ 00158 virtual void add_multicast_group(const uint8_t *address) = 0; 00159 00160 /** Remove device from a multicast group 00161 * 00162 * @param address A multicast group hardware address 00163 */ 00164 virtual void remove_multicast_group(const uint8_t *address) = 0; 00165 00166 /** Request reception of all multicast packets 00167 * 00168 * @param all True to receive all multicasts 00169 * False to receive only multicasts addressed to specified groups 00170 */ 00171 virtual void set_all_multicast(bool all) = 0; 00172 00173 /** Sets memory manager that is used to handle memory buffers 00174 * 00175 * @param mem_mngr Pointer to memory manager 00176 */ 00177 virtual void set_memory_manager(EMACMemoryManager &mem_mngr) = 0; 00178 }; 00179 00180 00181 /** These need to be defined by targets wishing to provide an Ethernet driver using EMAC interface. It will 00182 * be used by the EMACInterface class's default constructor to initialise the networking subsystem. 00183 */ 00184 //extern const emac_interface_ops_t mbed_emac_eth_ops_default; 00185 //extern void *mbed_emac_eth_hw_default; 00186 00187 #endif /* EMAC_H */
Generated on Tue Jul 12 2022 12:43:52 by
