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.
Dependents: MQTT_Hello MQTT_HelloENC28J60
enc28j60_emac.h
00001 /* 00002 * Copyright (c) 2019 Tobias Jaster 00003 * 00004 * Modified by Zoltan Hudak 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #ifndef ENC28J60_EMAC_H_ 00019 #define ENC28J60_EMAC_H_ 00020 00021 #include <ctype.h> 00022 #include <stdio.h> 00023 #include <string.h> 00024 #include <stdlib.h> 00025 #include <stdint.h> 00026 #include "mbed.h" 00027 #include "EMAC.h" 00028 #include "rtos.h" 00029 #include "enc28j60_reg.h" 00030 #include "enc28j60.h" 00031 #include "enc28j60_emac_config.h" 00032 00033 class ENC28J60_EMAC : 00034 public EMAC 00035 { 00036 public: 00037 ENC28J60_EMAC(); 00038 00039 /** Return the ENC28J60 EMAC 00040 * 00041 * Returns the default on-board EMAC - this will be target-specific, and 00042 * may not be available on all targets. 00043 */ 00044 static ENC28J60_EMAC& get_instance(void); 00045 00046 /** 00047 * Return maximum transmission unit 00048 * 00049 * @return MTU in bytes 00050 */ 00051 virtual uint32_t get_mtu_size(void) const; 00052 00053 /** 00054 * Gets memory buffer alignment preference 00055 * 00056 * Gets preferred memory buffer alignment of the Emac device. IP stack may 00057 * or may not align link out memory buffer chains using the alignment. 00058 * 00059 * @return Memory alignment requirement in bytes 00060 */ 00061 virtual uint32_t get_align_preference(void) const; 00062 00063 /** 00064 * Return interface name 00065 * 00066 * @param name Pointer to where the name should be written 00067 * @param size Maximum number of character to copy 00068 */ 00069 virtual void get_ifname(char* name, uint8_t size) const; 00070 00071 /** 00072 * Returns size of the underlying interface HW address size. 00073 * 00074 * @return HW address size in bytes 00075 */ 00076 virtual uint8_t get_hwaddr_size(void) const; 00077 00078 /** 00079 * Return interface-supplied HW address 00080 * 00081 * Copies HW address to provided memory, @param addr has to be of correct 00082 * size see @a get_hwaddr_size 00083 * 00084 * HW address need not be provided if this interface does not have its own 00085 * HW address configuration; stack will choose address from central system 00086 * configuration if the function returns false and does not write to addr. 00087 * 00088 * @param addr HW address for underlying interface 00089 * @return true if HW address is available 00090 */ 00091 virtual bool get_hwaddr(uint8_t* addr) const; 00092 00093 /** 00094 * Set HW address for interface 00095 * 00096 * Provided address has to be of correct size, see @a get_hwaddr_size 00097 * 00098 * Called to set the MAC address to actually use - if @a get_hwaddr is 00099 * provided the stack would normally use that, but it could be overridden, 00100 * eg for test purposes. 00101 * 00102 * @param addr Address to be set 00103 */ 00104 virtual void set_hwaddr(const uint8_t* addr); 00105 00106 /** 00107 * Sends the packet over the link 00108 * 00109 * That can not be called from an interrupt context. 00110 * 00111 * @param buf Packet to be send 00112 * @return True if the packet was send successfully, False otherwise 00113 */ 00114 virtual bool link_out(emac_mem_buf_t* buf); 00115 00116 /** 00117 * Initializes the HW 00118 * 00119 * @return True on success, False in case of an error. 00120 */ 00121 virtual bool power_up(void); 00122 00123 /** 00124 * Deinitializes the HW 00125 * 00126 */ 00127 virtual void power_down(void); 00128 00129 /** 00130 * Sets a callback that needs to be called for packets received for that 00131 * interface 00132 * 00133 * @param input_cb Function to be register as a callback 00134 */ 00135 virtual void set_link_input_cb(emac_link_input_cb_t input_cb); 00136 00137 /** 00138 * Sets a callback that needs to be called on link status changes for given 00139 * interface 00140 * 00141 * @param state_cb Function to be register as a callback 00142 */ 00143 virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb); 00144 00145 /** Add device to a multicast group 00146 * 00147 * @param address A multicast group hardware address 00148 */ 00149 virtual void add_multicast_group(const uint8_t* address); 00150 00151 /** Remove device from a multicast group 00152 * 00153 * @param address A multicast group hardware address 00154 */ 00155 virtual void remove_multicast_group(const uint8_t* address); 00156 00157 /** Request reception of all multicast packets 00158 * 00159 * @param all True to receive all multicasts 00160 * False to receive only multicasts addressed to specified groups 00161 */ 00162 virtual void set_all_multicast(bool all); 00163 00164 /** Sets memory manager that is used to handle memory buffers 00165 * 00166 * @param mem_mngr Pointer to memory manager 00167 */ 00168 virtual void set_memory_manager(EMACMemoryManager& mem_mngr); 00169 private: 00170 void link_status_task(); 00171 void receive_task(); 00172 bool low_level_init_successful(); 00173 emac_mem_buf_t* low_level_input(); 00174 00175 ENC28J60* _enc28j60; 00176 bool _prev_link_status_up; 00177 int _link_status_task_handle; 00178 int _receive_task_handle; 00179 EMACMemoryManager* _memory_manager; 00180 Mutex _ethLockMutex; 00181 uint8_t _hwaddr[ENC28J60_HWADDR_SIZE]; 00182 00183 emac_link_input_cb_t _emac_link_input_cb; 00184 emac_link_state_change_cb_t _emac_link_state_cb; 00185 }; 00186 #endif /* ENC28J60_EMAC_H_ */
Generated on Wed Jul 13 2022 10:47:04 by
1.7.2