Jinbuhm Kim
/
W5500_Driver
Wiznet W5500 driver and TCP/UDP loopback
Embed:
(wiki syntax)
Show/hide line numbers
wizchip_conf.h
00001 /* Wiznet W5500 Library 00002 * Copyright (c) 2013, WIZnet Co., LTD. 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 /** 00018 * @defgroup extra_functions 2. WIZnet Extra Functions 00019 * 00020 * @brief These functions is optional function. It could be replaced at WIZCHIP I/O function because they were made by WIZCHIP I/O functions. 00021 * @details There are functions of configuring WIZCHIP, network, interrupt, phy, network information and timer. \n 00022 * 00023 */ 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 #ifndef _WIZCHIP_CONF_H_ 00029 #define _WIZCHIP_CONF_H_ 00030 00031 #include <stdint.h> 00032 #include "W5500/w5500.h" 00033 00034 #define _WIZCHIP_SOCK_NUM_ 8 ///< The count of independant socket of @b WIZCHIP 00035 00036 00037 /******************************************************** 00038 * WIZCHIP BASIC IF functions for SPI, SDIO, I2C , ETC. 00039 *********************************************************/ 00040 /** 00041 * @ingroup DATA_TYPE 00042 * @brief The set of callback functions for W5500:@ref WIZCHIP_IO_Functions W5200:@ref WIZCHIP_IO_Functions_W5200 00043 */ 00044 typedef struct __WIZCHIP 00045 { 00046 /** 00047 * The set of critical section callback func. 00048 */ 00049 struct _CRIS 00050 { 00051 void (*_enter) (void); ///< crtical section enter 00052 void (*_exit) (void); ///< critial section exit 00053 }CRIS; 00054 /** 00055 * The set of @ref\_WIZCHIP_ select control callback func. 00056 */ 00057 struct _CS 00058 { 00059 void (*_select) (void); ///< @ref \_WIZCHIP_ selected 00060 void (*_deselect)(void); ///< @ref \_WIZCHIP_ deselected 00061 }CS; 00062 /** 00063 * The set of interface IO callback func. 00064 */ 00065 union _IF 00066 { 00067 /** 00068 * For SPI interface IO 00069 */ 00070 struct 00071 { 00072 uint8_t (*_read_byte) (void); 00073 void (*_write_byte) (uint8_t wb); 00074 }SPI; 00075 }IF; 00076 }_WIZCHIP; 00077 00078 extern _WIZCHIP WIZCHIP; 00079 00080 /** 00081 * @ingroup DATA_TYPE 00082 * WIZCHIP control type enumration used in @ref ctlwizchip(). 00083 */ 00084 typedef enum 00085 { 00086 CW_RESET_WIZCHIP, ///< Resets WIZCHIP by softly 00087 CW_INIT_WIZCHIP, ///< Inializes to WIZCHIP with SOCKET buffer size 2 or 1 dimension array typed uint8_t. 00088 CW_GET_INTERRUPT, ///< Get Interrupt status of WIZCHIP 00089 CW_CLR_INTERRUPT, ///< Clears interrupt 00090 CW_SET_INTRMASK, ///< Masks interrupt 00091 CW_GET_INTRMASK, ///< Get interrupt mask 00092 CW_SET_INTRTIME, ///< Set interval time between the current and next interrupt. 00093 CW_GET_INTRTIME, ///< Set interval time between the current and next interrupt. 00094 CW_GET_ID, ///< Gets WIZCHIP name. 00095 00096 CW_RESET_PHY, ///< Resets internal PHY. Valid Only W5000 00097 CW_SET_PHYCONF, ///< When PHY configured by interal register, PHY operation mode (Manual/Auto, 10/100, Half/Full). Valid Only W5000 00098 CW_GET_PHYCONF, ///< Get PHY operation mode in interal register. Valid Only W5000 00099 CW_GET_PHYSTATUS, ///< Get real PHY status on operating. Valid Only W5000 00100 CW_SET_PHYPOWMODE, ///< Set PHY power mode as noraml and down when PHYSTATUS.OPMD == 1. Valid Only W5000 00101 00102 CW_GET_PHYPOWMODE, ///< Get PHY Power mode as down or normal 00103 CW_GET_PHYLINK ///< Get PHY Link status 00104 }ctlwizchip_type; 00105 00106 /** 00107 * @ingroup DATA_TYPE 00108 * Network control type enumration used in @ref ctlnetwork(). 00109 */ 00110 typedef enum 00111 { 00112 CN_SET_NETINFO, ///< Set Network with @ref wiz_NetInfo 00113 CN_GET_NETINFO, ///< Get Network with @ref wiz_NetInfo 00114 CN_SET_NETMODE, ///< Set network mode as WOL, PPPoE, Ping Block, and Force ARP mode 00115 CN_GET_NETMODE, ///< Get network mode as WOL, PPPoE, Ping Block, and Force ARP mode 00116 CN_SET_TIMEOUT, ///< Set network timeout as retry count and time. 00117 CN_GET_TIMEOUT, ///< Get network timeout as retry count and time. 00118 }ctlnetwork_type; 00119 00120 /** 00121 * @ingroup DATA_TYPE 00122 * Interrupt kind when CW_SET_INTRRUPT, CW_GET_INTERRUPT, CW_SET_INTRMASK 00123 * and CW_GET_INTRMASK is used in @ref ctlnetwork(). 00124 * It can be used with OR operation. 00125 */ 00126 typedef enum 00127 { 00128 IK_WOL = (1 << 4), ///< Wake On Lan by receiving the magic packet. Valid in W500. 00129 00130 IK_PPPOE_TERMINATED = (1 << 5), ///< PPPoE Disconnected 00131 00132 IK_DEST_UNREACH = (1 << 6), ///< Destination IP & Port Unreable, No use in W5200 00133 00134 IK_IP_CONFLICT = (1 << 7), ///< IP conflict occurred 00135 00136 IK_SOCK_0 = (1 << 8), ///< Socket 0 interrupt 00137 IK_SOCK_1 = (1 << 9), ///< Socket 1 interrupt 00138 IK_SOCK_2 = (1 << 10), ///< Socket 2 interrupt 00139 IK_SOCK_3 = (1 << 11), ///< Socket 3 interrupt 00140 IK_SOCK_4 = (1 << 12), ///< Socket 4 interrupt, No use in 5100 00141 IK_SOCK_5 = (1 << 13), ///< Socket 5 interrupt, No use in 5100 00142 IK_SOCK_6 = (1 << 14), ///< Socket 6 interrupt, No use in 5100 00143 IK_SOCK_7 = (1 << 15), ///< Socket 7 interrupt, No use in 5100 00144 00145 IK_SOCK_ALL = (0xFF << 8) ///< All Socket interrpt 00146 }intr_kind; 00147 00148 #define PHY_CONFBY_HW 0 ///< Configured PHY operation mode by HW pin 00149 #define PHY_CONFBY_SW 1 ///< Configured PHY operation mode by SW register 00150 #define PHY_MODE_MANUAL 0 ///< Configured PHY operation mode with user setting. 00151 #define PHY_MODE_AUTONEGO 1 ///< Configured PHY operation mode with auto-negotiation 00152 #define PHY_SPEED_10 0 ///< Link Speed 10 00153 #define PHY_SPEED_100 1 ///< Link Speed 100 00154 #define PHY_DUPLEX_HALF 0 ///< Link Half-Duplex 00155 #define PHY_DUPLEX_FULL 1 ///< Link Full-Duplex 00156 #define PHY_LINK_OFF 0 ///< Link Off 00157 #define PHY_LINK_ON 1 ///< Link On 00158 #define PHY_POWER_NORM 0 ///< PHY power normal mode 00159 #define PHY_POWER_DOWN 1 ///< PHY power down mode 00160 00161 00162 /** 00163 * @ingroup DATA_TYPE 00164 * It configures PHY configuration when CW_SET PHYCONF or CW_GET_PHYCONF in W5500, 00165 * and it indicates the real PHY status configured by HW or SW in all WIZCHIP. \n 00166 * Valid only in W5500. 00167 */ 00168 typedef struct wiz_PhyConf_t 00169 { 00170 uint8_t by; ///< set by @ref PHY_CONFBY_HW or @ref PHY_CONFBY_SW 00171 uint8_t mode; ///< set by @ref PHY_MODE_MANUAL or @ref PHY_MODE_AUTONEGO 00172 uint8_t speed; ///< set by @ref PHY_SPEED_10 or @ref PHY_SPEED_100 00173 uint8_t duplex; ///< set by @ref PHY_DUPLEX_HALF @ref PHY_DUPLEX_FULL 00174 //uint8_t power; ///< set by @ref PHY_POWER_NORM or @ref PHY_POWER_DOWN 00175 //uint8_t link; ///< Valid only in CW_GET_PHYSTATUS. set by @ref PHY_LINK_ON or PHY_DUPLEX_OFF 00176 }wiz_PhyConf; 00177 00178 /** 00179 * @ingroup DATA_TYPE 00180 * It used in setting dhcp_mode of @ref wiz_NetInfo. 00181 */ 00182 typedef enum 00183 { 00184 NETINFO_STATIC = 1, ///< Static IP configuration by manually. 00185 NETINFO_DHCP ///< Dynamic IP configruation from a DHCP sever 00186 }dhcp_mode; 00187 00188 /** 00189 * @ingroup DATA_TYPE 00190 * Network Information for WIZCHIP 00191 */ 00192 typedef struct wiz_NetInfo_t 00193 { 00194 uint8_t mac[6]; ///< Source Mac Address 00195 uint8_t ip[4]; ///< Source IP Address 00196 uint8_t sn[4]; ///< Subnet Mask 00197 uint8_t gw[4]; ///< Gateway IP Address 00198 uint8_t dns[4]; ///< DNS server IP Address 00199 dhcp_mode dhcp; ///< 1 - Static, 2 - DHCP 00200 }wiz_NetInfo; 00201 00202 /** 00203 * @ingroup DATA_TYPE 00204 * Network mode 00205 */ 00206 typedef enum 00207 { 00208 NM_FORCEARP = (1<<1), ///< Force to APP send whenever udp data is sent. Valid only in W5500 00209 NM_WAKEONLAN = (1<<5), ///< Wake On Lan 00210 NM_PINGBLOCK = (1<<4), ///< Block ping-request 00211 NM_PPPOE = (1<<3), ///< PPPoE mode 00212 }netmode_type; 00213 00214 /** 00215 * @ingroup DATA_TYPE 00216 * Used in CN_SET_TIMEOUT or CN_GET_TIMEOUT of @ref ctlwizchip() for timeout configruation. 00217 */ 00218 typedef struct wiz_NetTimeout_t 00219 { 00220 uint8_t retry_cnt; ///< retry count 00221 uint16_t time_100us; ///< time unit 100us 00222 }wiz_NetTimeout; 00223 00224 /** 00225 *@brief Registers call back function for critical section of I/O functions such as 00226 *\ref WIZCHIP_READ, @ref WIZCHIP_WRITE, @ref WIZCHIP_READ_BUF and @ref WIZCHIP_WRITE_BUF. 00227 *@param cris_en : callback function for critical section enter. 00228 *@param cris_ex : callback function for critical section exit. 00229 *@todo Describe @ref WIZCHIP_CRITICAL_ENTER and @ref WIZCHIP_CRITICAL_EXIT marco or register your functions. 00230 *@note If you do not describe or register, default functions(@ref wizchip_cris_enter & @ref wizchip_cris_exit) is called. 00231 */ 00232 void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void)); 00233 00234 00235 /** 00236 *@brief Registers call back function for WIZCHIP select & deselect. 00237 *@param cs_sel : callback function for WIZCHIP select 00238 *@param cs_desel : callback fucntion for WIZCHIP deselect 00239 *@todo Describe @ref wizchip_cs_select and @ref wizchip_cs_deselect function or register your functions. 00240 *@note If you do not describe or register, null function is called. 00241 */ 00242 void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void)); 00243 00244 /** 00245 *@brief Registers call back function for SPI interface. 00246 *@param spi_rb : callback function to read byte usig SPI 00247 *@param spi_wb : callback function to write byte usig SPI 00248 *@todo Describe \ref wizchip_spi_readbyte and \ref wizchip_spi_writebyte function 00249 *or register your functions. 00250 *@note If you do not describe or register, null function is called. 00251 */ 00252 void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb)); 00253 00254 /** 00255 * @ingroup extra_functions 00256 * @brief Controls to the WIZCHIP. 00257 * @details Resets WIZCHIP & internal PHY, Configures PHY mode, Monitor PHY(Link,Speed,Half/Full/Auto), 00258 * controls interrupt & mask and so on. 00259 * @param cwtype : Decides to the control type 00260 * @param arg : arg type is dependent on cwtype. 00261 * @return 0 : Success \n 00262 * -1 : Fail because of invalid \ref ctlwizchip_type or unsupported \ref ctlwizchip_type in WIZCHIP 00263 */ 00264 int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg); 00265 00266 /** 00267 * @ingroup extra_functions 00268 * @brief Controls to network. 00269 * @details Controls to network environment, mode, timeout and so on. 00270 * @param cntype : Input. Decides to the control type 00271 * @param arg : Inout. arg type is dependent on cntype. 00272 * @return -1 : Fail because of invalid \ref ctlnetwork_type or unsupported \ref ctlnetwork_type in WIZCHIP \n 00273 * 0 : Success 00274 */ 00275 int8_t ctlnetwork(ctlnetwork_type cntype, void* arg); 00276 00277 00278 /* 00279 * The following functions are implemented for internal use. 00280 * but You can call these functions for code size reduction instead of ctlwizchip() and ctlnetwork(). 00281 */ 00282 00283 /** 00284 * @ingroup extra_functions 00285 * @brief Reset WIZCHIP by softly. 00286 */ 00287 void wizchip_sw_reset(void); 00288 00289 /** 00290 * @ingroup extra_functions 00291 * @brief Initializes WIZCHIP with socket buffer size 00292 * @param txsize Socket tx buffer sizes. If null, initialized the default size 2KB. 00293 * @param rxsize Socket rx buffer sizes. If null, initialized the default size 2KB. 00294 * @return 0 : succcess \n 00295 * -1 : fail. Invalid buffer size 00296 */ 00297 int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize); 00298 00299 /** 00300 * @ingroup extra_functions 00301 * @brief Clear Interrupt of WIZCHIP. 00302 * @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t. 00303 */ 00304 void wizchip_clrinterrupt(intr_kind intr); 00305 00306 /** 00307 * @ingroup extra_functions 00308 * @brief Get Interrupt of WIZCHIP. 00309 * @return @ref intr_kind value operated OR. It can type-cast to uint16_t. 00310 */ 00311 intr_kind wizchip_getinterrupt(void); 00312 00313 /** 00314 * @ingroup extra_functions 00315 * @brief Mask or Unmask Interrupt of WIZCHIP. 00316 * @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t. 00317 */ 00318 void wizchip_setinterruptmask(intr_kind intr); 00319 00320 /** 00321 * @ingroup extra_functions 00322 * @brief Get Interrupt mask of WIZCHIP. 00323 * @return : The operated OR vaule of @ref intr_kind. It can type-cast to uint16_t. 00324 */ 00325 intr_kind wizchip_getinterruptmask(void); 00326 00327 int8_t wizphy_getphylink(void); ///< get the link status of phy in WIZCHIP. No use in W5100 00328 int8_t wizphy_getphypmode(void); ///< get the power mode of PHY in WIZCHIP. No use in W5100 00329 00330 void wizphy_reset(void); ///< Reset phy. Vailid only in W5500 00331 /** 00332 * @ingroup extra_functions 00333 * @brief Set the phy information for WIZCHIP without power mode 00334 * @param phyconf : @ref wiz_PhyConf 00335 */ 00336 void wizphy_setphyconf(wiz_PhyConf* phyconf); 00337 /** 00338 * @ingroup extra_functions 00339 * @brief Get phy configuration information. 00340 * @param phyconf : @ref wiz_PhyConf 00341 */ 00342 void wizphy_getphyconf(wiz_PhyConf* phyconf); 00343 /** 00344 * @ingroup extra_functions 00345 * @brief Get phy status. 00346 * @param phyconf : @ref wiz_PhyConf 00347 */ 00348 void wizphy_getphystat(wiz_PhyConf* phyconf); 00349 /** 00350 * @ingroup extra_functions 00351 * @brief set the power mode of phy inside WIZCHIP. Refer to @ref PHYCFGR in W5500, @ref PHYSTATUS in W5200 00352 * @param pmode Settig value of power down mode. 00353 */ 00354 int8_t wizphy_setphypmode(uint8_t pmode); 00355 00356 /** 00357 * @ingroup extra_functions 00358 * @brief Set the network information for WIZCHIP 00359 * @param pnetinfo : @ref wizNetInfo 00360 */ 00361 void wizchip_setnetinfo(wiz_NetInfo* pnetinfo); 00362 00363 /** 00364 * @ingroup extra_functions 00365 * @brief Get the network information for WIZCHIP 00366 * @param pnetinfo : @ref wizNetInfo 00367 */ 00368 void wizchip_getnetinfo(wiz_NetInfo* pnetinfo); 00369 00370 /** 00371 * @ingroup extra_functions 00372 * @brief Set the network mode such WOL, PPPoE, Ping Block, and etc. 00373 * @param pnetinfo Value of network mode. Refer to @ref netmode_type. 00374 */ 00375 int8_t wizchip_setnetmode(netmode_type netmode); 00376 00377 /** 00378 * @ingroup extra_functions 00379 * @brief Get the network mode such WOL, PPPoE, Ping Block, and etc. 00380 * @return Value of network mode. Refer to @ref netmode_type. 00381 */ 00382 netmode_type wizchip_getnetmode(void); 00383 00384 /** 00385 * @ingroup extra_functions 00386 * @brief Set retry time value(@ref RTR) and retry count(@ref RCR). 00387 * @details @ref RTR configures the retransmission timeout period and @ref RCR configures the number of time of retransmission. 00388 * @param nettime @ref RTR value and @ref RCR value. Refer to @ref wiz_NetTimeout. 00389 */ 00390 void wizchip_settimeout(wiz_NetTimeout* nettime); 00391 00392 /** 00393 * @ingroup extra_functions 00394 * @brief Get retry time value(@ref RTR) and retry count(@ref RCR). 00395 * @details @ref RTR configures the retransmission timeout period and @ref RCR configures the number of time of retransmission. 00396 * @param nettime @ref RTR value and @ref RCR value. Refer to @ref wiz_NetTimeout. 00397 */ 00398 void wizchip_gettimeout(wiz_NetTimeout* nettime); 00399 00400 #endif // _WIZCHIP_CONF_H_ 00401 00402 #ifdef __cplusplus 00403 } 00404 #endif
Generated on Tue Jul 12 2022 18:48:22 by 1.7.2