petfeeder st ver

Fork of WIZnetInterface by WIZnet

Committer:
Soohwan Kim
Date:
Mon Jun 15 22:12:21 2015 +0900
Revision:
4:4930f81bbe98
Parent:
3:f8c6efc8bf83
Child:
5:f432ae8f8708
fixed W5500.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Soohwan Kim 0:6f28332c466f 1 /* Copyright (C) 2012 mbed.org, MIT License
Soohwan Kim 0:6f28332c466f 2 *
Soohwan Kim 0:6f28332c466f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Soohwan Kim 0:6f28332c466f 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Soohwan Kim 0:6f28332c466f 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Soohwan Kim 0:6f28332c466f 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Soohwan Kim 0:6f28332c466f 7 * furnished to do so, subject to the following conditions:
Soohwan Kim 0:6f28332c466f 8 *
Soohwan Kim 0:6f28332c466f 9 * The above copyright notice and this permission notice shall be included in all copies or
Soohwan Kim 0:6f28332c466f 10 * substantial portions of the Software.
Soohwan Kim 0:6f28332c466f 11 *
Soohwan Kim 0:6f28332c466f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Soohwan Kim 0:6f28332c466f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Soohwan Kim 0:6f28332c466f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Soohwan Kim 0:6f28332c466f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Soohwan Kim 0:6f28332c466f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Soohwan Kim 0:6f28332c466f 17 *
Soohwan Kim 0:6f28332c466f 18 */
Soohwan Kim 0:6f28332c466f 19
Soohwan Kim 0:6f28332c466f 20 #pragma once
Soohwan Kim 0:6f28332c466f 21
Soohwan Kim 0:6f28332c466f 22 #include "mbed.h"
Soohwan Kim 0:6f28332c466f 23 #include "mbed_debug.h"
Soohwan Kim 0:6f28332c466f 24
Soohwan Kim 0:6f28332c466f 25 #define TEST_ASSERT(A) while(!(A)){debug("\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
Soohwan Kim 0:6f28332c466f 26
Soohwan Kim 0:6f28332c466f 27 #define DEFAULT_WAIT_RESP_TIMEOUT 500
Soohwan Kim 0:6f28332c466f 28
Soohwan Kim 0:6f28332c466f 29
Soohwan Kim 0:6f28332c466f 30
Soohwan Kim 4:4930f81bbe98 31 #define SOCK_OK 1 ///< Result is OK about socket process.
Soohwan Kim 4:4930f81bbe98 32 #define SOCK_BUSY 0 ///< Socket is busy on processing the operation. Valid only Non-block IO Mode.
Soohwan Kim 4:4930f81bbe98 33 #define SOCK_FATAL -1000 ///< Result is fatal error about socket process.
Soohwan Kim 4:4930f81bbe98 34
Soohwan Kim 4:4930f81bbe98 35 #define SOCK_ERROR 0
Soohwan Kim 4:4930f81bbe98 36 #define SOCKERR_SOCKNUM (SOCK_ERROR - 1) ///< Invalid socket number
Soohwan Kim 4:4930f81bbe98 37 #define SOCKERR_SOCKOPT (SOCK_ERROR - 2) ///< Invalid socket option
Soohwan Kim 4:4930f81bbe98 38 #define SOCKERR_SOCKINIT (SOCK_ERROR - 3) ///< Socket is not initialized
Soohwan Kim 4:4930f81bbe98 39 #define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4) ///< Socket unexpectedly closed.
Soohwan Kim 4:4930f81bbe98 40 #define SOCKERR_SOCKMODE (SOCK_ERROR - 5) ///< Invalid socket mode for socket operation.
Soohwan Kim 4:4930f81bbe98 41 #define SOCKERR_SOCKFLAG (SOCK_ERROR - 6) ///< Invalid socket flag
Soohwan Kim 4:4930f81bbe98 42 #define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7) ///< Invalid socket status for socket operation.
Soohwan Kim 4:4930f81bbe98 43 #define SOCKERR_ARG (SOCK_ERROR - 10) ///< Invalid argrument.
Soohwan Kim 4:4930f81bbe98 44 #define SOCKERR_PORTZERO (SOCK_ERROR - 11) ///< Port number is zero
Soohwan Kim 4:4930f81bbe98 45 #define SOCKERR_IPINVALID (SOCK_ERROR - 12) ///< Invalid IP address
Soohwan Kim 4:4930f81bbe98 46 #define SOCKERR_TIMEOUT (SOCK_ERROR - 13) ///< Timeout occurred
Soohwan Kim 4:4930f81bbe98 47 #define SOCKERR_DATALEN (SOCK_ERROR - 14) ///< Data length is zero or greater than buffer max size.
Soohwan Kim 4:4930f81bbe98 48 #define SOCKERR_BUFFER (SOCK_ERROR - 15) ///< Socket buffer is not enough for data communication.
Soohwan Kim 4:4930f81bbe98 49
Soohwan Kim 4:4930f81bbe98 50 #define SOCK_ANY_PORT_NUM 0xC000;
Soohwan Kim 4:4930f81bbe98 51
Soohwan Kim 0:6f28332c466f 52
Soohwan Kim 0:6f28332c466f 53 #define MAX_SOCK_NUM 8
Soohwan Kim 0:6f28332c466f 54
Soohwan Kim 0:6f28332c466f 55 #define MR 0x0000
Soohwan Kim 0:6f28332c466f 56 #define GAR 0x0001
Soohwan Kim 0:6f28332c466f 57 #define SUBR 0x0005
Soohwan Kim 0:6f28332c466f 58 #define SHAR 0x0009
Soohwan Kim 0:6f28332c466f 59 #define SIPR 0x000f
Soohwan Kim 4:4930f81bbe98 60 #define INTLEVEL 0x0013
Soohwan Kim 4:4930f81bbe98 61 #define IR 0x0015
Soohwan Kim 4:4930f81bbe98 62 #define IMR 0x0016
Soohwan Kim 4:4930f81bbe98 63 #define SIR 0x0017
Soohwan Kim 4:4930f81bbe98 64 #define SIMR 0x0018
Soohwan Kim 4:4930f81bbe98 65 #define RTR 0x0019
Soohwan Kim 4:4930f81bbe98 66 #define RCR 0x001b
Soohwan Kim 4:4930f81bbe98 67 #define PTIMER 0x001c
Soohwan Kim 4:4930f81bbe98 68 #define PMAGIC 0x001d
Soohwan Kim 4:4930f81bbe98 69 #define PHAR 0x001e
Soohwan Kim 4:4930f81bbe98 70 #define PSID 0x0024
Soohwan Kim 4:4930f81bbe98 71 #define PMRU 0x0026
Soohwan Kim 4:4930f81bbe98 72 #define UIPR 0x0028
Soohwan Kim 4:4930f81bbe98 73 #define UPORTR 0x002c
Soohwan Kim 4:4930f81bbe98 74 #define PHYCFGR 0x002e
Soohwan Kim 4:4930f81bbe98 75 #define VERSIONR 0x0039
Soohwan Kim 0:6f28332c466f 76
Soohwan Kim 0:6f28332c466f 77 // W5500 socket register
Soohwan Kim 0:6f28332c466f 78 #define Sn_MR 0x0000
Soohwan Kim 0:6f28332c466f 79 #define Sn_CR 0x0001
Soohwan Kim 0:6f28332c466f 80 #define Sn_IR 0x0002
Soohwan Kim 0:6f28332c466f 81 #define Sn_SR 0x0003
Soohwan Kim 0:6f28332c466f 82 #define Sn_PORT 0x0004
Soohwan Kim 4:4930f81bbe98 83 #define Sn_DHAR 0x0006
Soohwan Kim 0:6f28332c466f 84 #define Sn_DIPR 0x000c
Soohwan Kim 0:6f28332c466f 85 #define Sn_DPORT 0x0010
Soohwan Kim 4:4930f81bbe98 86 #define Sn_MSSR 0x0012
Soohwan Kim 4:4930f81bbe98 87 #define Sn_TOS 0x0015
Soohwan Kim 4:4930f81bbe98 88 #define Sn_TTL 0x0016
Soohwan Kim 0:6f28332c466f 89 #define Sn_RXBUF_SIZE 0x001e
Soohwan Kim 0:6f28332c466f 90 #define Sn_TXBUF_SIZE 0x001f
Soohwan Kim 0:6f28332c466f 91 #define Sn_TX_FSR 0x0020
Soohwan Kim 4:4930f81bbe98 92 #define Sn_TX_RD 0x0022
Soohwan Kim 0:6f28332c466f 93 #define Sn_TX_WR 0x0024
Soohwan Kim 0:6f28332c466f 94 #define Sn_RX_RSR 0x0026
Soohwan Kim 0:6f28332c466f 95 #define Sn_RX_RD 0x0028
Soohwan Kim 4:4930f81bbe98 96 #define Sn_RX_WR 0x002a
Soohwan Kim 4:4930f81bbe98 97 #define Sn_IMR 0x002c
Soohwan Kim 4:4930f81bbe98 98 #define Sn_FRAG 0x002d
Soohwan Kim 4:4930f81bbe98 99 #define Sn_KPALVTR 0x002f
Soohwan Kim 4:4930f81bbe98 100
Soohwan Kim 4:4930f81bbe98 101 //define for Mode Register option value
Soohwan Kim 4:4930f81bbe98 102 #define MR_PPPOE 0x08
Soohwan Kim 4:4930f81bbe98 103 #define MR_RST 0x80
Soohwan Kim 4:4930f81bbe98 104
Soohwan Kim 4:4930f81bbe98 105 //Define for Socket Command register option value
Soohwan Kim 4:4930f81bbe98 106 #define Sn_CR_OPEN 0x01
Soohwan Kim 4:4930f81bbe98 107 #define Sn_CR_LISTEN 0x02
Soohwan Kim 4:4930f81bbe98 108 #define Sn_CR_CONNECT 0x04
Soohwan Kim 4:4930f81bbe98 109 #define Sn_CR_DISCON 0x08
Soohwan Kim 4:4930f81bbe98 110 #define Sn_CR_CLOSE 0x10
Soohwan Kim 4:4930f81bbe98 111 #define Sn_CR_SEND 0x20
Soohwan Kim 4:4930f81bbe98 112 #define Sn_CR_SEND_MAC 0x21
Soohwan Kim 4:4930f81bbe98 113 #define Sn_CR_SEND_KEEP 0x22
Soohwan Kim 4:4930f81bbe98 114 #define Sn_CR_RECV 0x40
Soohwan Kim 4:4930f81bbe98 115
Soohwan Kim 4:4930f81bbe98 116
Soohwan Kim 4:4930f81bbe98 117 //Define for Socket Mode register option value
Soohwan Kim 4:4930f81bbe98 118 #define Sn_MR_CLOSE 0x00
Soohwan Kim 4:4930f81bbe98 119 #define Sn_MR_TCP 0x01
Soohwan Kim 4:4930f81bbe98 120 #define Sn_MR_UDP 0x02
Soohwan Kim 4:4930f81bbe98 121 #define Sn_MR_MACRAW 0x04
Soohwan Kim 4:4930f81bbe98 122 #define Sn_MR_UCASTB 0x10
Soohwan Kim 4:4930f81bbe98 123 #define Sn_MR_ND 0x20
Soohwan Kim 4:4930f81bbe98 124 #define Sn_MR_BCASTB 0x40
Soohwan Kim 4:4930f81bbe98 125 #define Sn_MR_MULTI 0x80
Soohwan Kim 4:4930f81bbe98 126
Soohwan Kim 4:4930f81bbe98 127 #define Sn_IR_SENDOK 0x10
Soohwan Kim 4:4930f81bbe98 128
Soohwan Kim 4:4930f81bbe98 129 //Sn_IR values
Soohwan Kim 4:4930f81bbe98 130
Soohwan Kim 4:4930f81bbe98 131 #define Sn_IR_TIMEOUT 0x08
Soohwan Kim 4:4930f81bbe98 132 #define Sn_IR_RECV 0x04
Soohwan Kim 4:4930f81bbe98 133 #define Sn_IR_DISCON 0x02
Soohwan Kim 4:4930f81bbe98 134 #define Sn_IR_CON 0x01
Soohwan Kim 4:4930f81bbe98 135
Soohwan Kim 4:4930f81bbe98 136 /*
Soohwan Kim 4:4930f81bbe98 137 * SOCKET FLAG
Soohwan Kim 4:4930f81bbe98 138 */
Soohwan Kim 4:4930f81bbe98 139 #define SF_ETHER_OWN (Sn_MR_MFEN) ///< In \ref Sn_MR_MACRAW, Receive only the packet as broadcast, multicast and own packet
Soohwan Kim 4:4930f81bbe98 140 #define SF_IGMP_VER2 (Sn_MR_ND) ///< In \ref Sn_MR_UDP with \ref SF_MULTI_ENABLE, Select IGMP version 2.
Soohwan Kim 4:4930f81bbe98 141 #define SF_TCP_NODELAY (Sn_MR_ND) ///< In \ref Sn_MR_TCP, Use to nodelayed ack.
Soohwan Kim 4:4930f81bbe98 142 #define SF_MULTI_ENABLE (Sn_MR_MULTI) ///< In \ref Sn_MR_UDP, Enable multicast mode.
Soohwan Kim 4:4930f81bbe98 143 #define SF_IO_NONBLOCK 0x01 ///< Socket nonblock io mode. It used parameter in \ref socket().
Soohwan Kim 4:4930f81bbe98 144 #define SF_BROAD_BLOCK (Sn_MR_BCASTB) ///< In \ref Sn_MR_UDP or \ref Sn_MR_MACRAW, Block broadcast packet. Valid only in W5500
Soohwan Kim 4:4930f81bbe98 145 #define SF_MULTI_BLOCK (Sn_MR_MMB) ///< In \ref Sn_MR_MACRAW, Block multicast packet. Valid only in W5500
Soohwan Kim 4:4930f81bbe98 146 #define SF_IPv6_BLOCK (Sn_MR_MIP6B) ///< In \ref Sn_MR_MACRAW, Block IPv6 packet. Valid only in W5500
Soohwan Kim 4:4930f81bbe98 147 #define SF_UNI_BLOCK (Sn_MR_UCASTB) ///< In \ref Sn_MR_UDP with \ref SF_MULTI_ENABLE. Valid only in W5500
Soohwan Kim 4:4930f81bbe98 148
Soohwan Kim 4:4930f81bbe98 149 #define SOCK_MACRAW 0x42
Soohwan Kim 4:4930f81bbe98 150
Soohwan Kim 4:4930f81bbe98 151
Soohwan Kim 4:4930f81bbe98 152 /* PHYCFGR register value */
Soohwan Kim 4:4930f81bbe98 153 #define PHYCFGR_RST ~(1<<7) //< For PHY reset, must operate AND mask.
Soohwan Kim 4:4930f81bbe98 154 #define PHYCFGR_OPMD (1<<6) // Configre PHY with OPMDC value
Soohwan Kim 4:4930f81bbe98 155 #define PHYCFGR_OPMDC_ALLA (7<<3)
Soohwan Kim 4:4930f81bbe98 156 #define PHYCFGR_OPMDC_PDOWN (6<<3)
Soohwan Kim 4:4930f81bbe98 157 #define PHYCFGR_OPMDC_NA (5<<3)
Soohwan Kim 4:4930f81bbe98 158 #define PHYCFGR_OPMDC_100FA (4<<3)
Soohwan Kim 4:4930f81bbe98 159 #define PHYCFGR_OPMDC_100F (3<<3)
Soohwan Kim 4:4930f81bbe98 160 #define PHYCFGR_OPMDC_100H (2<<3)
Soohwan Kim 4:4930f81bbe98 161 #define PHYCFGR_OPMDC_10F (1<<3)
Soohwan Kim 4:4930f81bbe98 162 #define PHYCFGR_OPMDC_10H (0<<3)
Soohwan Kim 4:4930f81bbe98 163 #define PHYCFGR_DPX_FULL (1<<2)
Soohwan Kim 4:4930f81bbe98 164 #define PHYCFGR_DPX_HALF (0<<2)
Soohwan Kim 4:4930f81bbe98 165 #define PHYCFGR_SPD_100 (1<<1)
Soohwan Kim 4:4930f81bbe98 166 #define PHYCFGR_SPD_10 (0<<1)
Soohwan Kim 4:4930f81bbe98 167 #define PHYCFGR_LNK_ON (1<<0)
Soohwan Kim 4:4930f81bbe98 168 #define PHYCFGR_LNK_OFF (0<<0)
Soohwan Kim 4:4930f81bbe98 169
Soohwan Kim 4:4930f81bbe98 170 //PHY status define
Soohwan Kim 4:4930f81bbe98 171 #define PHY_CONFBY_HW 0 ///< Configured PHY operation mode by HW pin
Soohwan Kim 4:4930f81bbe98 172 #define PHY_CONFBY_SW 1 ///< Configured PHY operation mode by SW register
Soohwan Kim 4:4930f81bbe98 173 #define PHY_MODE_MANUAL 0 ///< Configured PHY operation mode with user setting.
Soohwan Kim 4:4930f81bbe98 174 #define PHY_MODE_AUTONEGO 1 ///< Configured PHY operation mode with auto-negotiation
Soohwan Kim 4:4930f81bbe98 175 #define PHY_SPEED_10 0 ///< Link Speed 10
Soohwan Kim 4:4930f81bbe98 176 #define PHY_SPEED_100 1 ///< Link Speed 100
Soohwan Kim 4:4930f81bbe98 177 #define PHY_DUPLEX_HALF 0 ///< Link Half-Duplex
Soohwan Kim 4:4930f81bbe98 178 #define PHY_DUPLEX_FULL 1 ///< Link Full-Duplex
Soohwan Kim 4:4930f81bbe98 179 #define PHY_LINK_OFF 0 ///< Link Off
Soohwan Kim 4:4930f81bbe98 180 #define PHY_LINK_ON 1 ///< Link On
Soohwan Kim 4:4930f81bbe98 181 #define PHY_POWER_NORM 0 ///< PHY power normal mode
Soohwan Kim 4:4930f81bbe98 182 #define PHY_POWER_DOWN 1 ///< PHY power down mode
Soohwan Kim 0:6f28332c466f 183
Soohwan Kim 0:6f28332c466f 184 class WIZnet_Chip {
Soohwan Kim 0:6f28332c466f 185 public:
embeddist 3:f8c6efc8bf83 186 enum Protocol {
embeddist 3:f8c6efc8bf83 187 CLOSED = 0,
embeddist 3:f8c6efc8bf83 188 TCP = 1,
embeddist 3:f8c6efc8bf83 189 UDP = 2,
embeddist 3:f8c6efc8bf83 190 };
embeddist 3:f8c6efc8bf83 191
embeddist 3:f8c6efc8bf83 192 enum Command {
embeddist 3:f8c6efc8bf83 193 OPEN = 0x01,
embeddist 3:f8c6efc8bf83 194 LISTEN = 0x02,
embeddist 3:f8c6efc8bf83 195 CONNECT = 0x04,
embeddist 3:f8c6efc8bf83 196 DISCON = 0x08,
embeddist 3:f8c6efc8bf83 197 CLOSE = 0x10,
embeddist 3:f8c6efc8bf83 198 SEND = 0x20,
embeddist 3:f8c6efc8bf83 199 SEND_MAC = 0x21,
embeddist 3:f8c6efc8bf83 200 SEND_KEEP = 0x22,
embeddist 3:f8c6efc8bf83 201 RECV = 0x40,
embeddist 3:f8c6efc8bf83 202
embeddist 3:f8c6efc8bf83 203 };
embeddist 3:f8c6efc8bf83 204
embeddist 3:f8c6efc8bf83 205 enum Interrupt {
embeddist 3:f8c6efc8bf83 206 INT_CON = 0x01,
embeddist 3:f8c6efc8bf83 207 INT_DISCON = 0x02,
embeddist 3:f8c6efc8bf83 208 INT_RECV = 0x04,
embeddist 3:f8c6efc8bf83 209 INT_TIMEOUT = 0x08,
embeddist 3:f8c6efc8bf83 210 INT_SEND_OK = 0x10,
embeddist 3:f8c6efc8bf83 211 };
embeddist 3:f8c6efc8bf83 212
Soohwan Kim 4:4930f81bbe98 213
Soohwan Kim 4:4930f81bbe98 214 uint16_t sock_any_port;
Soohwan Kim 4:4930f81bbe98 215
Soohwan Kim 0:6f28332c466f 216 /*
Soohwan Kim 0:6f28332c466f 217 * Constructor
Soohwan Kim 0:6f28332c466f 218 *
Soohwan Kim 0:6f28332c466f 219 * @param spi spi class
Soohwan Kim 0:6f28332c466f 220 * @param cs cs of the W5500
Soohwan Kim 0:6f28332c466f 221 * @param reset reset pin of the W5500
Soohwan Kim 0:6f28332c466f 222 */
Soohwan Kim 4:4930f81bbe98 223 WIZnet_Chip(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset);
Soohwan Kim 4:4930f81bbe98 224 WIZnet_Chip(SPI* spi, PinName cs, PinName reset);
Soohwan Kim 0:6f28332c466f 225
Soohwan Kim 0:6f28332c466f 226 /*
Soohwan Kim 4:4930f81bbe98 227 * Set MAC Address to W5500
Soohwan Kim 4:4930f81bbe98 228 *
Soohwan Kim 4:4930f81bbe98 229 * @return true if connected, false otherwise
Soohwan Kim 4:4930f81bbe98 230 */
Soohwan Kim 4:4930f81bbe98 231 bool setmac();
Soohwan Kim 4:4930f81bbe98 232
Soohwan Kim 4:4930f81bbe98 233 /*
Soohwan Kim 4:4930f81bbe98 234 * Set Network Informations (SrcIP, Netmask, Gataway)
Soohwan Kim 0:6f28332c466f 235 *
Soohwan Kim 0:6f28332c466f 236 * @return true if connected, false otherwise
Soohwan Kim 0:6f28332c466f 237 */
Soohwan Kim 0:6f28332c466f 238 bool setip();
Soohwan Kim 0:6f28332c466f 239
Soohwan Kim 0:6f28332c466f 240 /*
Soohwan Kim 4:4930f81bbe98 241 * Get Link Status
Soohwan Kim 4:4930f81bbe98 242 *
Soohwan Kim 4:4930f81bbe98 243 * @return true if Link up, false Link down
Soohwan Kim 4:4930f81bbe98 244 */
Soohwan Kim 4:4930f81bbe98 245 bool linkstatus();
Soohwan Kim 4:4930f81bbe98 246
Soohwan Kim 4:4930f81bbe98 247 /*
Soohwan Kim 0:6f28332c466f 248 * Disconnect the connection
Soohwan Kim 0:6f28332c466f 249 *
Soohwan Kim 0:6f28332c466f 250 * @ returns true
Soohwan Kim 0:6f28332c466f 251 */
Soohwan Kim 0:6f28332c466f 252 bool disconnect();
Soohwan Kim 0:6f28332c466f 253
Soohwan Kim 0:6f28332c466f 254 /*
Soohwan Kim 0:6f28332c466f 255 * Open a tcp connection with the specified host on the specified port
Soohwan Kim 0:6f28332c466f 256 *
Soohwan Kim 0:6f28332c466f 257 * @param host host (can be either an ip address or a name. If a name is provided, a dns request will be established)
Soohwan Kim 0:6f28332c466f 258 * @param port port
Soohwan Kim 0:6f28332c466f 259 * @ returns true if successful
Soohwan Kim 0:6f28332c466f 260 */
Soohwan Kim 0:6f28332c466f 261 bool connect(int socket, const char * host, int port, int timeout_ms = 10*1000);
Soohwan Kim 0:6f28332c466f 262
Soohwan Kim 0:6f28332c466f 263 /*
Soohwan Kim 0:6f28332c466f 264 * Set the protocol (UDP or TCP)
Soohwan Kim 0:6f28332c466f 265 *
Soohwan Kim 0:6f28332c466f 266 * @param p protocol
Soohwan Kim 0:6f28332c466f 267 * @ returns true if successful
Soohwan Kim 0:6f28332c466f 268 */
Soohwan Kim 0:6f28332c466f 269 bool setProtocol(int socket, Protocol p);
Soohwan Kim 0:6f28332c466f 270
Soohwan Kim 0:6f28332c466f 271 /*
Soohwan Kim 0:6f28332c466f 272 * Reset the W5500
Soohwan Kim 0:6f28332c466f 273 */
Soohwan Kim 0:6f28332c466f 274 void reset();
Soohwan Kim 0:6f28332c466f 275
Soohwan Kim 0:6f28332c466f 276 int wait_readable(int socket, int wait_time_ms, int req_size = 0);
Soohwan Kim 0:6f28332c466f 277
Soohwan Kim 0:6f28332c466f 278 int wait_writeable(int socket, int wait_time_ms, int req_size = 0);
Soohwan Kim 0:6f28332c466f 279
Soohwan Kim 0:6f28332c466f 280 /*
Soohwan Kim 0:6f28332c466f 281 * Check if a tcp link is active
Soohwan Kim 0:6f28332c466f 282 *
Soohwan Kim 0:6f28332c466f 283 * @returns true if successful
Soohwan Kim 0:6f28332c466f 284 */
Soohwan Kim 0:6f28332c466f 285 bool is_connected(int socket);
Soohwan Kim 0:6f28332c466f 286
Soohwan Kim 0:6f28332c466f 287 /*
Soohwan Kim 0:6f28332c466f 288 * Close a tcp connection
Soohwan Kim 0:6f28332c466f 289 *
Soohwan Kim 0:6f28332c466f 290 * @ returns true if successful
Soohwan Kim 0:6f28332c466f 291 */
Soohwan Kim 0:6f28332c466f 292 bool close(int socket);
Soohwan Kim 0:6f28332c466f 293
Soohwan Kim 0:6f28332c466f 294 /*
Soohwan Kim 0:6f28332c466f 295 * @param str string to be sent
Soohwan Kim 0:6f28332c466f 296 * @param len string length
Soohwan Kim 0:6f28332c466f 297 */
Soohwan Kim 0:6f28332c466f 298 int send(int socket, const char * str, int len);
Soohwan Kim 0:6f28332c466f 299
Soohwan Kim 0:6f28332c466f 300 int recv(int socket, char* buf, int len);
Soohwan Kim 0:6f28332c466f 301
Soohwan Kim 0:6f28332c466f 302 /*
Soohwan Kim 0:6f28332c466f 303 * Return true if the module is using dhcp
Soohwan Kim 0:6f28332c466f 304 *
Soohwan Kim 0:6f28332c466f 305 * @returns true if the module is using dhcp
Soohwan Kim 0:6f28332c466f 306 */
Soohwan Kim 0:6f28332c466f 307 bool isDHCP() {
Soohwan Kim 0:6f28332c466f 308 return dhcp;
Soohwan Kim 0:6f28332c466f 309 }
Soohwan Kim 0:6f28332c466f 310
Soohwan Kim 0:6f28332c466f 311 bool gethostbyname(const char* host, uint32_t* ip);
Soohwan Kim 0:6f28332c466f 312
Soohwan Kim 0:6f28332c466f 313 static WIZnet_Chip * getInstance() {
Soohwan Kim 0:6f28332c466f 314 return inst;
Soohwan Kim 0:6f28332c466f 315 };
Soohwan Kim 0:6f28332c466f 316
Soohwan Kim 0:6f28332c466f 317 int new_socket();
Soohwan Kim 0:6f28332c466f 318 uint16_t new_port();
Soohwan Kim 0:6f28332c466f 319 void scmd(int socket, Command cmd);
Soohwan Kim 0:6f28332c466f 320
Soohwan Kim 0:6f28332c466f 321 template<typename T>
Soohwan Kim 0:6f28332c466f 322 void sreg(int socket, uint16_t addr, T data) {
Soohwan Kim 0:6f28332c466f 323 reg_wr<T>(addr, (0x0C + (socket << 5)), data);
Soohwan Kim 0:6f28332c466f 324 }
Soohwan Kim 0:6f28332c466f 325
Soohwan Kim 0:6f28332c466f 326 template<typename T>
Soohwan Kim 0:6f28332c466f 327 T sreg(int socket, uint16_t addr) {
Soohwan Kim 0:6f28332c466f 328 return reg_rd<T>(addr, (0x08 + (socket << 5)));
Soohwan Kim 0:6f28332c466f 329 }
Soohwan Kim 0:6f28332c466f 330
Soohwan Kim 0:6f28332c466f 331 template<typename T>
Soohwan Kim 0:6f28332c466f 332 void reg_wr(uint16_t addr, T data) {
Soohwan Kim 0:6f28332c466f 333 return reg_wr(addr, 0x04, data);
Soohwan Kim 0:6f28332c466f 334 }
Soohwan Kim 0:6f28332c466f 335
Soohwan Kim 0:6f28332c466f 336 template<typename T>
Soohwan Kim 0:6f28332c466f 337 void reg_wr(uint16_t addr, uint8_t cb, T data) {
Soohwan Kim 0:6f28332c466f 338 uint8_t buf[sizeof(T)];
Soohwan Kim 0:6f28332c466f 339 *reinterpret_cast<T*>(buf) = data;
Soohwan Kim 0:6f28332c466f 340 for(int i = 0; i < sizeof(buf)/2; i++) { // Little Endian to Big Endian
Soohwan Kim 0:6f28332c466f 341 uint8_t t = buf[i];
Soohwan Kim 0:6f28332c466f 342 buf[i] = buf[sizeof(buf)-1-i];
Soohwan Kim 0:6f28332c466f 343 buf[sizeof(buf)-1-i] = t;
Soohwan Kim 0:6f28332c466f 344 }
Soohwan Kim 0:6f28332c466f 345 spi_write(addr, cb, buf, sizeof(buf));
Soohwan Kim 0:6f28332c466f 346 }
Soohwan Kim 0:6f28332c466f 347
Soohwan Kim 0:6f28332c466f 348 template<typename T>
Soohwan Kim 0:6f28332c466f 349 T reg_rd(uint16_t addr) {
Soohwan Kim 0:6f28332c466f 350 return reg_rd<T>(addr, 0x00);
Soohwan Kim 0:6f28332c466f 351 }
Soohwan Kim 0:6f28332c466f 352
Soohwan Kim 0:6f28332c466f 353 template<typename T>
Soohwan Kim 0:6f28332c466f 354 T reg_rd(uint16_t addr, uint8_t cb) {
Soohwan Kim 0:6f28332c466f 355 uint8_t buf[sizeof(T)];
Soohwan Kim 0:6f28332c466f 356 spi_read(addr, cb, buf, sizeof(buf));
Soohwan Kim 0:6f28332c466f 357 for(int i = 0; i < sizeof(buf)/2; i++) { // Big Endian to Little Endian
Soohwan Kim 0:6f28332c466f 358 uint8_t t = buf[i];
Soohwan Kim 0:6f28332c466f 359 buf[i] = buf[sizeof(buf)-1-i];
Soohwan Kim 0:6f28332c466f 360 buf[sizeof(buf)-1-i] = t;
Soohwan Kim 0:6f28332c466f 361 }
Soohwan Kim 0:6f28332c466f 362 return *reinterpret_cast<T*>(buf);
Soohwan Kim 0:6f28332c466f 363 }
Soohwan Kim 0:6f28332c466f 364
Soohwan Kim 0:6f28332c466f 365 void reg_rd_mac(uint16_t addr, uint8_t* data) {
Soohwan Kim 0:6f28332c466f 366 spi_read(addr, 0x00, data, 6);
Soohwan Kim 0:6f28332c466f 367 }
Soohwan Kim 0:6f28332c466f 368
Soohwan Kim 0:6f28332c466f 369 void reg_wr_ip(uint16_t addr, uint8_t cb, const char* ip) {
Soohwan Kim 0:6f28332c466f 370 uint8_t buf[4];
Soohwan Kim 0:6f28332c466f 371 char* p = (char*)ip;
Soohwan Kim 0:6f28332c466f 372 for(int i = 0; i < 4; i++) {
Soohwan Kim 0:6f28332c466f 373 buf[i] = atoi(p);
Soohwan Kim 0:6f28332c466f 374 p = strchr(p, '.');
Soohwan Kim 0:6f28332c466f 375 if (p == NULL) {
Soohwan Kim 0:6f28332c466f 376 break;
Soohwan Kim 0:6f28332c466f 377 }
Soohwan Kim 0:6f28332c466f 378 p++;
Soohwan Kim 0:6f28332c466f 379 }
Soohwan Kim 0:6f28332c466f 380 spi_write(addr, cb, buf, sizeof(buf));
Soohwan Kim 0:6f28332c466f 381 }
Soohwan Kim 4:4930f81bbe98 382
Soohwan Kim 0:6f28332c466f 383 void sreg_ip(int socket, uint16_t addr, const char* ip) {
Soohwan Kim 0:6f28332c466f 384 reg_wr_ip(addr, (0x0C + (socket << 5)), ip);
Soohwan Kim 0:6f28332c466f 385 }
Soohwan Kim 4:4930f81bbe98 386
Soohwan Kim 4:4930f81bbe98 387 void reg_rd_ip_byte(uint16_t addr, uint8_t* data) {
Soohwan Kim 4:4930f81bbe98 388 spi_read(addr, 0x00, data, 4);
Soohwan Kim 4:4930f81bbe98 389 }
Soohwan Kim 4:4930f81bbe98 390
Soohwan Kim 4:4930f81bbe98 391 void reg_wr_ip_byte(uint16_t addr, uint8_t* data) {
Soohwan Kim 4:4930f81bbe98 392 spi_write(addr, 0x04, data, 4);
Soohwan Kim 4:4930f81bbe98 393 }
Soohwan Kim 4:4930f81bbe98 394
Soohwan Kim 4:4930f81bbe98 395 /////////////////////////////////
Soohwan Kim 4:4930f81bbe98 396 // Common Register I/O function //
Soohwan Kim 4:4930f81bbe98 397 /////////////////////////////////
Soohwan Kim 4:4930f81bbe98 398 /**
Soohwan Kim 4:4930f81bbe98 399 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 400 * @brief Set Mode Register
Soohwan Kim 4:4930f81bbe98 401 * @param (uint8_t)mr The value to be set.
Soohwan Kim 4:4930f81bbe98 402 * @sa getMR()
Soohwan Kim 4:4930f81bbe98 403 */
Soohwan Kim 4:4930f81bbe98 404 void setMR(uint8_t mr) {
Soohwan Kim 4:4930f81bbe98 405 reg_wr<uint8_t>(MR,mr);
Soohwan Kim 4:4930f81bbe98 406 }
Soohwan Kim 4:4930f81bbe98 407
Soohwan Kim 4:4930f81bbe98 408
Soohwan Kim 4:4930f81bbe98 409 /**
Soohwan Kim 4:4930f81bbe98 410 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 411 * @brief Get Mode Register
Soohwan Kim 4:4930f81bbe98 412 * @return uint8_t. The value of Mode register.
Soohwan Kim 4:4930f81bbe98 413 * @sa setMR()
Soohwan Kim 4:4930f81bbe98 414 */
Soohwan Kim 4:4930f81bbe98 415 uint8_t getMR() {
Soohwan Kim 4:4930f81bbe98 416 return reg_rd<uint8_t>(MR);
Soohwan Kim 4:4930f81bbe98 417 }
Soohwan Kim 4:4930f81bbe98 418
Soohwan Kim 4:4930f81bbe98 419 /**
Soohwan Kim 4:4930f81bbe98 420 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 421 * @brief Set gateway IP address
Soohwan Kim 4:4930f81bbe98 422 * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 423 * @sa getGAR()
Soohwan Kim 4:4930f81bbe98 424 */
Soohwan Kim 4:4930f81bbe98 425 void setGAR(uint8_t * gar) {
Soohwan Kim 4:4930f81bbe98 426 reg_wr_ip_byte(GAR,gar);
Soohwan Kim 4:4930f81bbe98 427 }
Soohwan Kim 4:4930f81bbe98 428
Soohwan Kim 4:4930f81bbe98 429 /**
Soohwan Kim 4:4930f81bbe98 430 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 431 * @brief Get gateway IP address
Soohwan Kim 4:4930f81bbe98 432 * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 433 * @sa setGAR()
Soohwan Kim 4:4930f81bbe98 434 */
Soohwan Kim 4:4930f81bbe98 435 void getGAR(uint8_t * gar) {
Soohwan Kim 4:4930f81bbe98 436 reg_rd_ip_byte(GAR,gar);
Soohwan Kim 4:4930f81bbe98 437 }
Soohwan Kim 4:4930f81bbe98 438
Soohwan Kim 4:4930f81bbe98 439 /**
Soohwan Kim 4:4930f81bbe98 440 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 441 * @brief Set subnet mask address
Soohwan Kim 4:4930f81bbe98 442 * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 443 * @sa getSUBR()
Soohwan Kim 4:4930f81bbe98 444 */
Soohwan Kim 4:4930f81bbe98 445 void setSUBR(uint8_t * subr) {
Soohwan Kim 4:4930f81bbe98 446 reg_wr_ip_byte(SUBR, subr);
Soohwan Kim 4:4930f81bbe98 447 }
Soohwan Kim 4:4930f81bbe98 448
Soohwan Kim 4:4930f81bbe98 449
Soohwan Kim 4:4930f81bbe98 450 /**
Soohwan Kim 4:4930f81bbe98 451 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 452 * @brief Get subnet mask address
Soohwan Kim 4:4930f81bbe98 453 * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 454 * @sa setSUBR()
Soohwan Kim 4:4930f81bbe98 455 */
Soohwan Kim 4:4930f81bbe98 456 void getSUBR(uint8_t * subr) {
Soohwan Kim 4:4930f81bbe98 457 reg_rd_ip_byte(SUBR, subr);
Soohwan Kim 4:4930f81bbe98 458 }
Soohwan Kim 4:4930f81bbe98 459
Soohwan Kim 4:4930f81bbe98 460 /**
Soohwan Kim 4:4930f81bbe98 461 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 462 * @brief Set local MAC address
Soohwan Kim 4:4930f81bbe98 463 * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes.
Soohwan Kim 4:4930f81bbe98 464 * @sa getSHAR()
Soohwan Kim 4:4930f81bbe98 465 */
Soohwan Kim 4:4930f81bbe98 466 void setSHAR(uint8_t * shar) {
Soohwan Kim 4:4930f81bbe98 467 reg_wr_mac(SHAR, shar);
Soohwan Kim 4:4930f81bbe98 468 }
Soohwan Kim 4:4930f81bbe98 469
Soohwan Kim 4:4930f81bbe98 470 /**
Soohwan Kim 4:4930f81bbe98 471 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 472 * @brief Get local MAC address
Soohwan Kim 4:4930f81bbe98 473 * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes.
Soohwan Kim 4:4930f81bbe98 474 * @sa setSHAR()
Soohwan Kim 4:4930f81bbe98 475 */
Soohwan Kim 4:4930f81bbe98 476 void getSHAR(uint8_t * shar) {
Soohwan Kim 4:4930f81bbe98 477 reg_rd_mac(SHAR, shar);
Soohwan Kim 4:4930f81bbe98 478 }
Soohwan Kim 4:4930f81bbe98 479
Soohwan Kim 4:4930f81bbe98 480 /**
Soohwan Kim 4:4930f81bbe98 481 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 482 * @brief Set local IP address
Soohwan Kim 4:4930f81bbe98 483 * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 484 * @sa getSIPR()
Soohwan Kim 4:4930f81bbe98 485 */
Soohwan Kim 4:4930f81bbe98 486 void setSIPR(uint8_t * sipr) {
Soohwan Kim 4:4930f81bbe98 487 reg_wr_ip_byte(SIPR, sipr);
Soohwan Kim 4:4930f81bbe98 488 }
Soohwan Kim 4:4930f81bbe98 489
Soohwan Kim 4:4930f81bbe98 490 /**
Soohwan Kim 4:4930f81bbe98 491 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 492 * @brief Get local IP address
Soohwan Kim 4:4930f81bbe98 493 * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 494 * @sa setSIPR()
Soohwan Kim 4:4930f81bbe98 495 */
Soohwan Kim 4:4930f81bbe98 496 void getSIPR(uint8_t * sipr) {
Soohwan Kim 4:4930f81bbe98 497 reg_rd_ip_byte(SIPR, sipr);
Soohwan Kim 4:4930f81bbe98 498 }
Soohwan Kim 4:4930f81bbe98 499
Soohwan Kim 4:4930f81bbe98 500 /**
Soohwan Kim 4:4930f81bbe98 501 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 502 * @brief Set INTLEVEL register
Soohwan Kim 4:4930f81bbe98 503 * @param (uint16_t)intlevel Value to set @ref INTLEVEL register.
Soohwan Kim 4:4930f81bbe98 504 * @sa getINTLEVEL()
Soohwan Kim 4:4930f81bbe98 505 */
Soohwan Kim 4:4930f81bbe98 506 void setINTLEVEL(uint16_t intlevel) {
Soohwan Kim 4:4930f81bbe98 507 reg_wr<uint16_t>(INTLEVEL, intlevel);
Soohwan Kim 4:4930f81bbe98 508 }
Soohwan Kim 4:4930f81bbe98 509
Soohwan Kim 4:4930f81bbe98 510
Soohwan Kim 4:4930f81bbe98 511 /**
Soohwan Kim 4:4930f81bbe98 512 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 513 * @brief Get INTLEVEL register
Soohwan Kim 4:4930f81bbe98 514 * @return uint16_t. Value of @ref INTLEVEL register.
Soohwan Kim 4:4930f81bbe98 515 * @sa setINTLEVEL()
Soohwan Kim 4:4930f81bbe98 516 */
Soohwan Kim 4:4930f81bbe98 517 uint16_t getINTLEVEL() {
Soohwan Kim 4:4930f81bbe98 518 return reg_rd<uint16_t>(INTLEVEL);
Soohwan Kim 4:4930f81bbe98 519 }
Soohwan Kim 4:4930f81bbe98 520
Soohwan Kim 4:4930f81bbe98 521 /**
Soohwan Kim 4:4930f81bbe98 522 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 523 * @brief Set @ref IR register
Soohwan Kim 4:4930f81bbe98 524 * @param (uint8_t)ir Value to set @ref IR register.
Soohwan Kim 4:4930f81bbe98 525 * @sa getIR()
Soohwan Kim 4:4930f81bbe98 526 */
Soohwan Kim 4:4930f81bbe98 527 void setIR(uint8_t ir) {
Soohwan Kim 4:4930f81bbe98 528 reg_wr<uint8_t>(IR, (ir & 0xF0));
Soohwan Kim 4:4930f81bbe98 529 }
Soohwan Kim 4:4930f81bbe98 530
Soohwan Kim 4:4930f81bbe98 531 /**
Soohwan Kim 4:4930f81bbe98 532 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 533 * @brief Get @ref IR register
Soohwan Kim 4:4930f81bbe98 534 * @return uint8_t. Value of @ref IR register.
Soohwan Kim 4:4930f81bbe98 535 * @sa setIR()
Soohwan Kim 4:4930f81bbe98 536 */
Soohwan Kim 4:4930f81bbe98 537 uint8_t getIR() {
Soohwan Kim 4:4930f81bbe98 538 return reg_rd<uint8_t>(IR & 0xF0);
Soohwan Kim 4:4930f81bbe98 539 }
Soohwan Kim 4:4930f81bbe98 540
Soohwan Kim 4:4930f81bbe98 541 /**
Soohwan Kim 4:4930f81bbe98 542 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 543 * @brief Set @ref IMR register
Soohwan Kim 4:4930f81bbe98 544 * @param (uint8_t)imr Value to set @ref IMR register.
Soohwan Kim 4:4930f81bbe98 545 * @sa getIMR()
Soohwan Kim 4:4930f81bbe98 546 */
Soohwan Kim 4:4930f81bbe98 547 void setIMR(uint8_t imr) {
Soohwan Kim 4:4930f81bbe98 548 reg_wr<uint8_t>(IMR, imr);
Soohwan Kim 4:4930f81bbe98 549 }
Soohwan Kim 4:4930f81bbe98 550
Soohwan Kim 4:4930f81bbe98 551 /**
Soohwan Kim 4:4930f81bbe98 552 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 553 * @brief Get @ref IMR register
Soohwan Kim 4:4930f81bbe98 554 * @return uint8_t. Value of @ref IMR register.
Soohwan Kim 4:4930f81bbe98 555 * @sa setIMR()
Soohwan Kim 4:4930f81bbe98 556 */
Soohwan Kim 4:4930f81bbe98 557 uint8_t getIMR() {
Soohwan Kim 4:4930f81bbe98 558 return reg_rd<uint8_t>(IMR);
Soohwan Kim 4:4930f81bbe98 559 }
Soohwan Kim 4:4930f81bbe98 560
Soohwan Kim 4:4930f81bbe98 561
Soohwan Kim 4:4930f81bbe98 562 /**
Soohwan Kim 4:4930f81bbe98 563 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 564 * @brief Set @ref SIR register
Soohwan Kim 4:4930f81bbe98 565 * @param (uint8_t)sir Value to set @ref SIR register.
Soohwan Kim 4:4930f81bbe98 566 * @sa getSIR()
Soohwan Kim 4:4930f81bbe98 567 */
Soohwan Kim 4:4930f81bbe98 568 void setSIR(uint8_t sir) {
Soohwan Kim 4:4930f81bbe98 569 reg_wr<uint8_t>(SIR, sir);
Soohwan Kim 4:4930f81bbe98 570 }
Soohwan Kim 4:4930f81bbe98 571
Soohwan Kim 4:4930f81bbe98 572 /**
Soohwan Kim 4:4930f81bbe98 573 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 574 * @brief Get @ref SIR register
Soohwan Kim 4:4930f81bbe98 575 * @return uint8_t. Value of @ref SIR register.
Soohwan Kim 4:4930f81bbe98 576 * @sa setSIR()
Soohwan Kim 4:4930f81bbe98 577 */
Soohwan Kim 4:4930f81bbe98 578 uint8_t getSIR() {
Soohwan Kim 4:4930f81bbe98 579 return reg_rd<uint8_t>(SIR);
Soohwan Kim 4:4930f81bbe98 580 }
Soohwan Kim 4:4930f81bbe98 581 /**
Soohwan Kim 4:4930f81bbe98 582 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 583 * @brief Set @ref SIMR register
Soohwan Kim 4:4930f81bbe98 584 * @param (uint8_t)simr Value to set @ref SIMR register.
Soohwan Kim 4:4930f81bbe98 585 * @sa getSIMR()
Soohwan Kim 4:4930f81bbe98 586 */
Soohwan Kim 4:4930f81bbe98 587 void setSIMR(uint8_t simr) {
Soohwan Kim 4:4930f81bbe98 588 reg_wr<uint8_t>(SIMR, simr);
Soohwan Kim 4:4930f81bbe98 589 }
Soohwan Kim 4:4930f81bbe98 590
Soohwan Kim 4:4930f81bbe98 591 /**
Soohwan Kim 4:4930f81bbe98 592 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 593 * @brief Get @ref SIMR register
Soohwan Kim 4:4930f81bbe98 594 * @return uint8_t. Value of @ref SIMR register.
Soohwan Kim 4:4930f81bbe98 595 * @sa setSIMR()
Soohwan Kim 4:4930f81bbe98 596 */
Soohwan Kim 4:4930f81bbe98 597 uint8_t getSIMR() {
Soohwan Kim 4:4930f81bbe98 598 return reg_rd<uint8_t>(SIMR);
Soohwan Kim 4:4930f81bbe98 599 }
Soohwan Kim 4:4930f81bbe98 600
Soohwan Kim 4:4930f81bbe98 601 /**
Soohwan Kim 4:4930f81bbe98 602 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 603 * @brief Set @ref RTR register
Soohwan Kim 4:4930f81bbe98 604 * @param (uint16_t)rtr Value to set @ref RTR register.
Soohwan Kim 4:4930f81bbe98 605 * @sa getRTR()
Soohwan Kim 4:4930f81bbe98 606 */
Soohwan Kim 4:4930f81bbe98 607 void setRTR(uint16_t rtr) {
Soohwan Kim 4:4930f81bbe98 608 reg_wr<uint16_t>(RTR, rtr);
Soohwan Kim 4:4930f81bbe98 609 }
Soohwan Kim 4:4930f81bbe98 610
Soohwan Kim 4:4930f81bbe98 611 /**
Soohwan Kim 4:4930f81bbe98 612 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 613 * @brief Get @ref RTR register
Soohwan Kim 4:4930f81bbe98 614 * @return uint16_t. Value of @ref RTR register.
Soohwan Kim 4:4930f81bbe98 615 * @sa setRTR()
Soohwan Kim 4:4930f81bbe98 616 */
Soohwan Kim 4:4930f81bbe98 617 uint16_t getRTR() {
Soohwan Kim 4:4930f81bbe98 618 return reg_rd<uint16_t>(RTR);
Soohwan Kim 4:4930f81bbe98 619 }
Soohwan Kim 4:4930f81bbe98 620
Soohwan Kim 4:4930f81bbe98 621 /**
Soohwan Kim 4:4930f81bbe98 622 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 623 * @brief Set @ref RCR register
Soohwan Kim 4:4930f81bbe98 624 * @param (uint8_t)rcr Value to set @ref RCR register.
Soohwan Kim 4:4930f81bbe98 625 * @sa getRCR()
Soohwan Kim 4:4930f81bbe98 626 */
Soohwan Kim 4:4930f81bbe98 627 void setRCR(uint8_t rcr) {
Soohwan Kim 4:4930f81bbe98 628 reg_wr<uint8_t>(RCR, rcr);
Soohwan Kim 4:4930f81bbe98 629 }
Soohwan Kim 4:4930f81bbe98 630
Soohwan Kim 4:4930f81bbe98 631 /**
Soohwan Kim 4:4930f81bbe98 632 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 633 * @brief Get @ref RCR register
Soohwan Kim 4:4930f81bbe98 634 * @return uint8_t. Value of @ref RCR register.
Soohwan Kim 4:4930f81bbe98 635 * @sa setRCR()
Soohwan Kim 4:4930f81bbe98 636 */
Soohwan Kim 4:4930f81bbe98 637 uint8_t getRCR() {
Soohwan Kim 4:4930f81bbe98 638 return reg_rd<uint8_t>(RCR);
Soohwan Kim 4:4930f81bbe98 639 }
Soohwan Kim 4:4930f81bbe98 640
Soohwan Kim 4:4930f81bbe98 641 //================================================== test done ===========================================================
Soohwan Kim 4:4930f81bbe98 642
Soohwan Kim 4:4930f81bbe98 643 /**
Soohwan Kim 4:4930f81bbe98 644 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 645 * @brief Set @ref PTIMER register
Soohwan Kim 4:4930f81bbe98 646 * @param (uint8_t)ptimer Value to set @ref PTIMER register.
Soohwan Kim 4:4930f81bbe98 647 * @sa getPTIMER()
Soohwan Kim 4:4930f81bbe98 648 */
Soohwan Kim 4:4930f81bbe98 649 void setPTIMER(uint8_t ptimer) {
Soohwan Kim 4:4930f81bbe98 650 reg_wr<uint8_t>(PTIMER, ptimer);
Soohwan Kim 4:4930f81bbe98 651 }
Soohwan Kim 4:4930f81bbe98 652
Soohwan Kim 4:4930f81bbe98 653 /**
Soohwan Kim 4:4930f81bbe98 654 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 655 * @brief Get @ref PTIMER register
Soohwan Kim 4:4930f81bbe98 656 * @return uint8_t. Value of @ref PTIMER register.
Soohwan Kim 4:4930f81bbe98 657 * @sa setPTIMER()
Soohwan Kim 4:4930f81bbe98 658 */
Soohwan Kim 4:4930f81bbe98 659 uint8_t getPTIMER() {
Soohwan Kim 4:4930f81bbe98 660 return reg_rd<uint8_t>(PTIMER);
Soohwan Kim 4:4930f81bbe98 661 }
Soohwan Kim 4:4930f81bbe98 662
Soohwan Kim 4:4930f81bbe98 663 /**
Soohwan Kim 4:4930f81bbe98 664 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 665 * @brief Set @ref PMAGIC register
Soohwan Kim 4:4930f81bbe98 666 * @param (uint8_t)pmagic Value to set @ref PMAGIC register.
Soohwan Kim 4:4930f81bbe98 667 * @sa getPMAGIC()
Soohwan Kim 4:4930f81bbe98 668 */
Soohwan Kim 4:4930f81bbe98 669 /*
Soohwan Kim 4:4930f81bbe98 670 #define setPMAGIC(pmagic) \
Soohwan Kim 4:4930f81bbe98 671 WIZCHIP_WRITE(PMAGIC, pmagic)
Soohwan Kim 4:4930f81bbe98 672 */
Soohwan Kim 4:4930f81bbe98 673 void setPMAGIC(uint8_t pmagic) {
Soohwan Kim 4:4930f81bbe98 674 reg_wr<uint8_t>(PMAGIC, pmagic );
Soohwan Kim 4:4930f81bbe98 675 }
Soohwan Kim 4:4930f81bbe98 676 /**
Soohwan Kim 4:4930f81bbe98 677 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 678 * @brief Get @ref PMAGIC register
Soohwan Kim 4:4930f81bbe98 679 * @return uint8_t. Value of @ref PMAGIC register.
Soohwan Kim 4:4930f81bbe98 680 * @sa setPMAGIC()
Soohwan Kim 4:4930f81bbe98 681 */
Soohwan Kim 4:4930f81bbe98 682 /*
Soohwan Kim 4:4930f81bbe98 683 #define getPMAGIC() \
Soohwan Kim 4:4930f81bbe98 684 WIZCHIP_READ(PMAGIC)
Soohwan Kim 4:4930f81bbe98 685 */
Soohwan Kim 4:4930f81bbe98 686 uint8_t getPMAGIC(uint8_t pmagic) {
Soohwan Kim 4:4930f81bbe98 687 return reg_rd<uint8_t>(PMAGIC, pmagic);
Soohwan Kim 4:4930f81bbe98 688 }
Soohwan Kim 4:4930f81bbe98 689 /**
Soohwan Kim 4:4930f81bbe98 690 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 691 * @brief Set PHAR address
Soohwan Kim 4:4930f81bbe98 692 * @param (uint8_t*)phar Pointer variable to set PPP destination MAC register address. It should be allocated 6 bytes.
Soohwan Kim 4:4930f81bbe98 693 * @sa getPHAR()
Soohwan Kim 4:4930f81bbe98 694 */
Soohwan Kim 4:4930f81bbe98 695 void setPHAR(uint8_t * phar) {
Soohwan Kim 4:4930f81bbe98 696 reg_wr_mac(PHAR, phar);
Soohwan Kim 4:4930f81bbe98 697 }
Soohwan Kim 4:4930f81bbe98 698
Soohwan Kim 4:4930f81bbe98 699 /**
Soohwan Kim 4:4930f81bbe98 700 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 701 * @brief Get local IP address
Soohwan Kim 4:4930f81bbe98 702 * @param (uint8_t*)phar Pointer variable to PPP destination MAC register address. It should be allocated 6 bytes.
Soohwan Kim 4:4930f81bbe98 703 * @sa setPHAR()
Soohwan Kim 4:4930f81bbe98 704 */
Soohwan Kim 4:4930f81bbe98 705 void getPHAR(uint8_t * phar) {
Soohwan Kim 4:4930f81bbe98 706 reg_rd_mac(PHAR, phar);
Soohwan Kim 4:4930f81bbe98 707 }
Soohwan Kim 4:4930f81bbe98 708
Soohwan Kim 4:4930f81bbe98 709 /**
Soohwan Kim 4:4930f81bbe98 710 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 711 * @brief Set @ref PSID register
Soohwan Kim 4:4930f81bbe98 712 * @param (uint16_t)psid Value to set @ref PSID register.
Soohwan Kim 4:4930f81bbe98 713 * @sa getPSID()
Soohwan Kim 4:4930f81bbe98 714 */
Soohwan Kim 4:4930f81bbe98 715 void setPSID(uint16_t psid) {
Soohwan Kim 4:4930f81bbe98 716 reg_wr<uint16_t>(PSID, psid );
Soohwan Kim 4:4930f81bbe98 717 }
Soohwan Kim 4:4930f81bbe98 718
Soohwan Kim 4:4930f81bbe98 719 /**
Soohwan Kim 4:4930f81bbe98 720 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 721 * @brief Get @ref PSID register
Soohwan Kim 4:4930f81bbe98 722 * @return uint16_t. Value of @ref PSID register.
Soohwan Kim 4:4930f81bbe98 723 * @sa setPSID()
Soohwan Kim 4:4930f81bbe98 724 */
Soohwan Kim 4:4930f81bbe98 725 //uint16_t getPSID(void);
Soohwan Kim 4:4930f81bbe98 726 uint16_t getPSID() {
Soohwan Kim 4:4930f81bbe98 727 return reg_rd<uint16_t>(PSID);
Soohwan Kim 4:4930f81bbe98 728 }
Soohwan Kim 4:4930f81bbe98 729
Soohwan Kim 4:4930f81bbe98 730 /**
Soohwan Kim 4:4930f81bbe98 731 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 732 * @brief Set @ref PMRU register
Soohwan Kim 4:4930f81bbe98 733 * @param (uint16_t)pmru Value to set @ref PMRU register.
Soohwan Kim 4:4930f81bbe98 734 * @sa getPMRU()
Soohwan Kim 4:4930f81bbe98 735 */
Soohwan Kim 4:4930f81bbe98 736 void setPMRU(uint16_t pmru) {
Soohwan Kim 4:4930f81bbe98 737 reg_wr<uint16_t>(PMRU, pmru);
Soohwan Kim 4:4930f81bbe98 738 }
Soohwan Kim 4:4930f81bbe98 739
Soohwan Kim 4:4930f81bbe98 740 /**
Soohwan Kim 4:4930f81bbe98 741 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 742 * @brief Get @ref PMRU register
Soohwan Kim 4:4930f81bbe98 743 * @return uint16_t. Value of @ref PMRU register.
Soohwan Kim 4:4930f81bbe98 744 * @sa setPMRU()
Soohwan Kim 4:4930f81bbe98 745 */
Soohwan Kim 4:4930f81bbe98 746 uint16_t getPMRU() {
Soohwan Kim 4:4930f81bbe98 747 return reg_rd<uint16_t>(PMRU);
Soohwan Kim 4:4930f81bbe98 748 }
Soohwan Kim 4:4930f81bbe98 749
Soohwan Kim 4:4930f81bbe98 750 /**
Soohwan Kim 4:4930f81bbe98 751 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 752 * @brief Get unreachable IP address
Soohwan Kim 4:4930f81bbe98 753 * @param (uint8_t*)uipr Pointer variable to get unreachable IP address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 754 */
Soohwan Kim 4:4930f81bbe98 755 void getUIPR(uint8_t * uipr) {
Soohwan Kim 4:4930f81bbe98 756 reg_rd_ip_byte(UIPR,uipr);
Soohwan Kim 4:4930f81bbe98 757 }
Soohwan Kim 4:4930f81bbe98 758
Soohwan Kim 4:4930f81bbe98 759 /**
Soohwan Kim 4:4930f81bbe98 760 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 761 * @brief Get @ref UPORTR register
Soohwan Kim 4:4930f81bbe98 762 * @return uint16_t. Value of @ref UPORTR register.
Soohwan Kim 4:4930f81bbe98 763 */
Soohwan Kim 4:4930f81bbe98 764 uint16_t getUPORTR() {
Soohwan Kim 4:4930f81bbe98 765 return reg_rd<uint16_t>(UPORTR);
Soohwan Kim 4:4930f81bbe98 766 }
Soohwan Kim 4:4930f81bbe98 767
Soohwan Kim 4:4930f81bbe98 768 /**
Soohwan Kim 4:4930f81bbe98 769 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 770 * @brief Set @ref PHYCFGR register
Soohwan Kim 4:4930f81bbe98 771 * @param (uint8_t)phycfgr Value to set @ref PHYCFGR register.
Soohwan Kim 4:4930f81bbe98 772 * @sa getPHYCFGR()
Soohwan Kim 4:4930f81bbe98 773 */
Soohwan Kim 4:4930f81bbe98 774 void setPHYCFGR(uint8_t phycfgr) {
Soohwan Kim 4:4930f81bbe98 775 reg_wr<uint8_t>(PHYCFGR, phycfgr);
Soohwan Kim 4:4930f81bbe98 776 }
Soohwan Kim 4:4930f81bbe98 777
Soohwan Kim 4:4930f81bbe98 778 /**
Soohwan Kim 4:4930f81bbe98 779 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 780 * @brief Get @ref PHYCFGR register
Soohwan Kim 4:4930f81bbe98 781 * @return uint8_t. Value of @ref PHYCFGR register.
Soohwan Kim 4:4930f81bbe98 782 * @sa setPHYCFGR()
Soohwan Kim 4:4930f81bbe98 783 */
Soohwan Kim 4:4930f81bbe98 784 uint8_t getPHYCFGR() {
Soohwan Kim 4:4930f81bbe98 785 return reg_rd<uint8_t>(PHYCFGR);
Soohwan Kim 4:4930f81bbe98 786 }
Soohwan Kim 4:4930f81bbe98 787
Soohwan Kim 4:4930f81bbe98 788 /**
Soohwan Kim 4:4930f81bbe98 789 * @ingroup Common_register_access_function
Soohwan Kim 4:4930f81bbe98 790 * @brief Get @ref VERSIONR register
Soohwan Kim 4:4930f81bbe98 791 * @return uint8_t. Value of @ref VERSIONR register.
Soohwan Kim 4:4930f81bbe98 792 */
Soohwan Kim 4:4930f81bbe98 793 uint8_t getVERSIONR() {
Soohwan Kim 4:4930f81bbe98 794 return reg_rd<uint8_t>(VERSIONR);
Soohwan Kim 4:4930f81bbe98 795 }
Soohwan Kim 4:4930f81bbe98 796
Soohwan Kim 4:4930f81bbe98 797 /////////////////////////////////////
Soohwan Kim 4:4930f81bbe98 798
Soohwan Kim 4:4930f81bbe98 799 ///////////////////////////////////
Soohwan Kim 4:4930f81bbe98 800 // Socket N register I/O function //
Soohwan Kim 4:4930f81bbe98 801 ///////////////////////////////////
Soohwan Kim 4:4930f81bbe98 802 /**
Soohwan Kim 4:4930f81bbe98 803 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 804 * @brief Set @ref Sn_MR register
Soohwan Kim 4:4930f81bbe98 805 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 806 * @param (uint8_t)mr Value to set @ref Sn_MR
Soohwan Kim 4:4930f81bbe98 807 * @sa getSn_MR()
Soohwan Kim 4:4930f81bbe98 808 */
Soohwan Kim 4:4930f81bbe98 809 void setSn_MR(uint8_t sn, uint8_t mr) {
Soohwan Kim 4:4930f81bbe98 810 sreg<uint8_t>(sn, MR, mr);
Soohwan Kim 4:4930f81bbe98 811 }
Soohwan Kim 4:4930f81bbe98 812
Soohwan Kim 4:4930f81bbe98 813 /**
Soohwan Kim 4:4930f81bbe98 814 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 815 * @brief Get @ref Sn_MR register
Soohwan Kim 4:4930f81bbe98 816 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 817 * @return uint8_t. Value of @ref Sn_MR.
Soohwan Kim 4:4930f81bbe98 818 * @sa setSn_MR()
Soohwan Kim 4:4930f81bbe98 819 */
Soohwan Kim 4:4930f81bbe98 820 uint8_t getSn_MR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 821 return sreg<uint8_t>(sn, Sn_MR);
Soohwan Kim 4:4930f81bbe98 822 }
Soohwan Kim 4:4930f81bbe98 823
Soohwan Kim 4:4930f81bbe98 824 /**
Soohwan Kim 4:4930f81bbe98 825 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 826 * @brief Set @ref Sn_CR register
Soohwan Kim 4:4930f81bbe98 827 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 828 * @param (uint8_t)cr Value to set @ref Sn_CR
Soohwan Kim 4:4930f81bbe98 829 * @sa getSn_CR()
Soohwan Kim 4:4930f81bbe98 830 */
Soohwan Kim 4:4930f81bbe98 831 void setSn_CR(uint8_t sn, uint8_t cr) {
Soohwan Kim 4:4930f81bbe98 832 sreg<uint8_t>(sn, Sn_CR, cr);
Soohwan Kim 4:4930f81bbe98 833 }
Soohwan Kim 4:4930f81bbe98 834
Soohwan Kim 4:4930f81bbe98 835 /**
Soohwan Kim 4:4930f81bbe98 836 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 837 * @brief Get @ref Sn_CR register
Soohwan Kim 4:4930f81bbe98 838 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 839 * @return uint8_t. Value of @ref Sn_CR.
Soohwan Kim 4:4930f81bbe98 840 * @sa setSn_CR()
Soohwan Kim 4:4930f81bbe98 841 */
Soohwan Kim 4:4930f81bbe98 842 uint8_t getSn_CR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 843 return sreg<uint8_t>(sn, Sn_CR);
Soohwan Kim 4:4930f81bbe98 844 }
Soohwan Kim 4:4930f81bbe98 845
Soohwan Kim 4:4930f81bbe98 846 /**
Soohwan Kim 4:4930f81bbe98 847 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 848 * @brief Set @ref Sn_IR register
Soohwan Kim 4:4930f81bbe98 849 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 850 * @param (uint8_t)ir Value to set @ref Sn_IR
Soohwan Kim 4:4930f81bbe98 851 * @sa getSn_IR()
Soohwan Kim 4:4930f81bbe98 852 */
Soohwan Kim 4:4930f81bbe98 853 void setSn_IR(uint8_t sn, uint8_t ir) {
Soohwan Kim 4:4930f81bbe98 854 sreg<uint8_t>(sn, Sn_IR, (ir & 0x1F));
Soohwan Kim 4:4930f81bbe98 855 }
Soohwan Kim 4:4930f81bbe98 856
Soohwan Kim 4:4930f81bbe98 857 /**
Soohwan Kim 4:4930f81bbe98 858 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 859 * @brief Get @ref Sn_IR register
Soohwan Kim 4:4930f81bbe98 860 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 861 * @return uint8_t. Value of @ref Sn_IR.
Soohwan Kim 4:4930f81bbe98 862 * @sa setSn_IR()
Soohwan Kim 4:4930f81bbe98 863 */
Soohwan Kim 4:4930f81bbe98 864 uint8_t getSn_IR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 865 return (sreg<uint8_t>(sn, Sn_IR)) & 0x1F;
Soohwan Kim 4:4930f81bbe98 866 }
Soohwan Kim 4:4930f81bbe98 867
Soohwan Kim 4:4930f81bbe98 868 /**
Soohwan Kim 4:4930f81bbe98 869 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 870 * @brief Set @ref Sn_IMR register
Soohwan Kim 4:4930f81bbe98 871 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 872 * @param (uint8_t)imr Value to set @ref Sn_IMR
Soohwan Kim 4:4930f81bbe98 873 * @sa getSn_IMR()
Soohwan Kim 4:4930f81bbe98 874 */
Soohwan Kim 4:4930f81bbe98 875 void setSn_IMR(uint8_t sn, uint8_t imr) {
Soohwan Kim 4:4930f81bbe98 876 sreg<uint8_t>(sn, Sn_IMR, (imr & 0x1F));
Soohwan Kim 4:4930f81bbe98 877 }
Soohwan Kim 4:4930f81bbe98 878
Soohwan Kim 4:4930f81bbe98 879 /**
Soohwan Kim 4:4930f81bbe98 880 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 881 * @brief Get @ref Sn_IMR register
Soohwan Kim 4:4930f81bbe98 882 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 883 * @return uint8_t. Value of @ref Sn_IMR.
Soohwan Kim 4:4930f81bbe98 884 * @sa setSn_IMR()
Soohwan Kim 4:4930f81bbe98 885 */
Soohwan Kim 4:4930f81bbe98 886 uint8_t getSn_IMR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 887 return (sreg<uint8_t>(sn, Sn_IMR)) & 0x1F;
Soohwan Kim 4:4930f81bbe98 888 }
Soohwan Kim 4:4930f81bbe98 889
Soohwan Kim 4:4930f81bbe98 890 /**
Soohwan Kim 4:4930f81bbe98 891 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 892 * @brief Get @ref Sn_SR register
Soohwan Kim 4:4930f81bbe98 893 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 894 * @return uint8_t. Value of @ref Sn_SR.
Soohwan Kim 4:4930f81bbe98 895 */
Soohwan Kim 4:4930f81bbe98 896 uint8_t getSn_SR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 897 return sreg<uint8_t>(sn, Sn_SR);
Soohwan Kim 4:4930f81bbe98 898 }
Soohwan Kim 4:4930f81bbe98 899
Soohwan Kim 4:4930f81bbe98 900 /**
Soohwan Kim 4:4930f81bbe98 901 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 902 * @brief Set @ref Sn_PORT register
Soohwan Kim 4:4930f81bbe98 903 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 904 * @param (uint16_t)port Value to set @ref Sn_PORT.
Soohwan Kim 4:4930f81bbe98 905 * @sa getSn_PORT()
Soohwan Kim 4:4930f81bbe98 906 */
Soohwan Kim 4:4930f81bbe98 907 void setSn_PORT(uint8_t sn, uint16_t port) {
Soohwan Kim 4:4930f81bbe98 908 sreg<uint16_t>(sn, Sn_PORT, port );
Soohwan Kim 4:4930f81bbe98 909 }
Soohwan Kim 4:4930f81bbe98 910
Soohwan Kim 4:4930f81bbe98 911 /**
Soohwan Kim 4:4930f81bbe98 912 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 913 * @brief Get @ref Sn_PORT register
Soohwan Kim 4:4930f81bbe98 914 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 915 * @return uint16_t. Value of @ref Sn_PORT.
Soohwan Kim 4:4930f81bbe98 916 * @sa setSn_PORT()
Soohwan Kim 4:4930f81bbe98 917 */
Soohwan Kim 4:4930f81bbe98 918 uint16_t getSn_PORT(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 919 return sreg<uint16_t>(sn, Sn_PORT);
Soohwan Kim 4:4930f81bbe98 920 }
Soohwan Kim 4:4930f81bbe98 921
Soohwan Kim 4:4930f81bbe98 922 /**
Soohwan Kim 4:4930f81bbe98 923 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 924 * @brief Set @ref Sn_DHAR register
Soohwan Kim 4:4930f81bbe98 925 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 926 * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes.
Soohwan Kim 4:4930f81bbe98 927 * @sa getSn_DHAR()
Soohwan Kim 4:4930f81bbe98 928 */
Soohwan Kim 4:4930f81bbe98 929 void setSn_DHAR(uint8_t sn, uint8_t * dhar) {
Soohwan Kim 4:4930f81bbe98 930 spi_write(Sn_DHAR, (0x0C + (sn << 5)), dhar, 6);
Soohwan Kim 4:4930f81bbe98 931 }
Soohwan Kim 4:4930f81bbe98 932
Soohwan Kim 4:4930f81bbe98 933 /**
Soohwan Kim 4:4930f81bbe98 934 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 935 * @brief Get @ref Sn_MR register
Soohwan Kim 4:4930f81bbe98 936 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 937 * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes.
Soohwan Kim 4:4930f81bbe98 938 * @sa setSn_DHAR()
Soohwan Kim 4:4930f81bbe98 939 */
Soohwan Kim 4:4930f81bbe98 940 void getSn_DHAR(uint8_t sn, uint8_t * dhar) {
Soohwan Kim 4:4930f81bbe98 941 spi_read(Sn_DHAR, (0x08 + (sn << 5)), dhar, 6);
Soohwan Kim 4:4930f81bbe98 942 }
Soohwan Kim 4:4930f81bbe98 943
Soohwan Kim 4:4930f81bbe98 944 /**
Soohwan Kim 4:4930f81bbe98 945 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 946 * @brief Set @ref Sn_DIPR register
Soohwan Kim 4:4930f81bbe98 947 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 948 * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 949 * @sa getSn_DIPR()
Soohwan Kim 4:4930f81bbe98 950 */
Soohwan Kim 4:4930f81bbe98 951 void setSn_DIPR(uint8_t sn, uint8_t * dipr) {
Soohwan Kim 4:4930f81bbe98 952 spi_write(Sn_DIPR, (0x0C + (sn << 5)), dipr, 4);
Soohwan Kim 4:4930f81bbe98 953 }
Soohwan Kim 4:4930f81bbe98 954
Soohwan Kim 4:4930f81bbe98 955 /**
Soohwan Kim 4:4930f81bbe98 956 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 957 * @brief Get @ref Sn_DIPR register
Soohwan Kim 4:4930f81bbe98 958 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 959 * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes.
Soohwan Kim 4:4930f81bbe98 960 * @sa SetSn_DIPR()
Soohwan Kim 4:4930f81bbe98 961 */
Soohwan Kim 4:4930f81bbe98 962 void getSn_DIPR(uint8_t sn, uint8_t * dipr) {
Soohwan Kim 4:4930f81bbe98 963 spi_read(Sn_DIPR, (0x08 + (sn << 5)), dipr, 4);
Soohwan Kim 4:4930f81bbe98 964 }
Soohwan Kim 4:4930f81bbe98 965
Soohwan Kim 4:4930f81bbe98 966 /**
Soohwan Kim 4:4930f81bbe98 967 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 968 * @brief Set @ref Sn_DPORT register
Soohwan Kim 4:4930f81bbe98 969 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 970 * @param (uint16_t)dport Value to set @ref Sn_DPORT
Soohwan Kim 4:4930f81bbe98 971 * @sa getSn_DPORT()
Soohwan Kim 4:4930f81bbe98 972 */
Soohwan Kim 4:4930f81bbe98 973 void setSn_DPORT(uint8_t sn, uint16_t dport) {
Soohwan Kim 4:4930f81bbe98 974 sreg<uint16_t>(sn, Sn_DPORT, dport);
Soohwan Kim 4:4930f81bbe98 975 }
Soohwan Kim 4:4930f81bbe98 976
Soohwan Kim 4:4930f81bbe98 977 /**
Soohwan Kim 4:4930f81bbe98 978 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 979 * @brief Get @ref Sn_DPORT register
Soohwan Kim 4:4930f81bbe98 980 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 981 * @return uint16_t. Value of @ref Sn_DPORT.
Soohwan Kim 4:4930f81bbe98 982 * @sa setSn_DPORT()
Soohwan Kim 4:4930f81bbe98 983 */
Soohwan Kim 4:4930f81bbe98 984 uint16_t getSn_DPORT(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 985 return sreg<uint16_t>(sn, Sn_DPORT);
Soohwan Kim 4:4930f81bbe98 986 }
Soohwan Kim 4:4930f81bbe98 987
Soohwan Kim 4:4930f81bbe98 988 /**
Soohwan Kim 4:4930f81bbe98 989 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 990 * @brief Set @ref Sn_MSSR register
Soohwan Kim 4:4930f81bbe98 991 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 992 * @param (uint16_t)mss Value to set @ref Sn_MSSR
Soohwan Kim 4:4930f81bbe98 993 * @sa setSn_MSSR()
Soohwan Kim 4:4930f81bbe98 994 */
Soohwan Kim 4:4930f81bbe98 995 void setSn_MSSR(uint8_t sn, uint16_t mss) {
Soohwan Kim 4:4930f81bbe98 996 sreg<uint16_t>(sn, Sn_MSSR, mss);
Soohwan Kim 4:4930f81bbe98 997 }
Soohwan Kim 4:4930f81bbe98 998
Soohwan Kim 4:4930f81bbe98 999 /**
Soohwan Kim 4:4930f81bbe98 1000 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1001 * @brief Get @ref Sn_MSSR register
Soohwan Kim 4:4930f81bbe98 1002 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1003 * @return uint16_t. Value of @ref Sn_MSSR.
Soohwan Kim 4:4930f81bbe98 1004 * @sa setSn_MSSR()
Soohwan Kim 4:4930f81bbe98 1005 */
Soohwan Kim 4:4930f81bbe98 1006 uint16_t getSn_MSSR(uint16_t sn) {
Soohwan Kim 4:4930f81bbe98 1007 return sreg<uint16_t>(sn, Sn_MSSR);
Soohwan Kim 4:4930f81bbe98 1008 }
Soohwan Kim 4:4930f81bbe98 1009
Soohwan Kim 4:4930f81bbe98 1010 /**
Soohwan Kim 4:4930f81bbe98 1011 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1012 * @brief Set @ref Sn_TOS register
Soohwan Kim 4:4930f81bbe98 1013 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1014 * @param (uint8_t)tos Value to set @ref Sn_TOS
Soohwan Kim 4:4930f81bbe98 1015 * @sa getSn_TOS()
Soohwan Kim 4:4930f81bbe98 1016 */
Soohwan Kim 4:4930f81bbe98 1017 void setSn_TOS(uint8_t sn, uint8_t tos) {
Soohwan Kim 4:4930f81bbe98 1018 sreg<uint8_t>(sn, Sn_TOS, tos);
Soohwan Kim 4:4930f81bbe98 1019 }
Soohwan Kim 4:4930f81bbe98 1020
Soohwan Kim 4:4930f81bbe98 1021 /**
Soohwan Kim 4:4930f81bbe98 1022 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1023 * @brief Get @ref Sn_TOS register
Soohwan Kim 4:4930f81bbe98 1024 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1025 * @return uint8_t. Value of Sn_TOS.
Soohwan Kim 4:4930f81bbe98 1026 * @sa setSn_TOS()
Soohwan Kim 4:4930f81bbe98 1027 */
Soohwan Kim 4:4930f81bbe98 1028 uint8_t getSn_TOS(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1029 return sreg<uint8_t>(sn, Sn_TOS);
Soohwan Kim 4:4930f81bbe98 1030 }
Soohwan Kim 4:4930f81bbe98 1031
Soohwan Kim 4:4930f81bbe98 1032 /**
Soohwan Kim 4:4930f81bbe98 1033 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1034 * @brief Set @ref Sn_TTL register
Soohwan Kim 4:4930f81bbe98 1035 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1036 * @param (uint8_t)ttl Value to set @ref Sn_TTL
Soohwan Kim 4:4930f81bbe98 1037 * @sa getSn_TTL()
Soohwan Kim 4:4930f81bbe98 1038 */
Soohwan Kim 4:4930f81bbe98 1039 void setSn_TTL(uint8_t sn, uint8_t ttl) {
Soohwan Kim 4:4930f81bbe98 1040 sreg<uint8_t>(sn, Sn_TTL, ttl);
Soohwan Kim 4:4930f81bbe98 1041 }
Soohwan Kim 4:4930f81bbe98 1042
Soohwan Kim 4:4930f81bbe98 1043
Soohwan Kim 4:4930f81bbe98 1044 /**
Soohwan Kim 4:4930f81bbe98 1045 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1046 * @brief Get @ref Sn_TTL register
Soohwan Kim 4:4930f81bbe98 1047 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1048 * @return uint8_t. Value of @ref Sn_TTL.
Soohwan Kim 4:4930f81bbe98 1049 * @sa setSn_TTL()
Soohwan Kim 4:4930f81bbe98 1050 */
Soohwan Kim 4:4930f81bbe98 1051 uint8_t getSn_TTL(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1052 return sreg<uint8_t>(sn, Sn_TTL);
Soohwan Kim 4:4930f81bbe98 1053 }
Soohwan Kim 4:4930f81bbe98 1054
Soohwan Kim 4:4930f81bbe98 1055
Soohwan Kim 4:4930f81bbe98 1056 /**
Soohwan Kim 4:4930f81bbe98 1057 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1058 * @brief Set @ref Sn_RXBUF_SIZE register
Soohwan Kim 4:4930f81bbe98 1059 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1060 * @param (uint8_t)rxbufsize Value to set @ref Sn_RXBUF_SIZE
Soohwan Kim 4:4930f81bbe98 1061 * @sa getSn_RXBUF_SIZE()
Soohwan Kim 4:4930f81bbe98 1062 */
Soohwan Kim 4:4930f81bbe98 1063 void setSn_RXBUF_SIZE(uint8_t sn, uint8_t rxbufsize) {
Soohwan Kim 4:4930f81bbe98 1064 sreg<uint8_t>(sn, Sn_RXBUF_SIZE ,rxbufsize);
Soohwan Kim 4:4930f81bbe98 1065 }
Soohwan Kim 4:4930f81bbe98 1066
Soohwan Kim 4:4930f81bbe98 1067
Soohwan Kim 4:4930f81bbe98 1068 /**
Soohwan Kim 4:4930f81bbe98 1069 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1070 * @brief Get @ref Sn_RXBUF_SIZE register
Soohwan Kim 4:4930f81bbe98 1071 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1072 * @return uint8_t. Value of @ref Sn_RXBUF_SIZE.
Soohwan Kim 4:4930f81bbe98 1073 * @sa setSn_RXBUF_SIZE()
Soohwan Kim 4:4930f81bbe98 1074 */
Soohwan Kim 4:4930f81bbe98 1075 uint8_t getSn_RXBUF_SIZE(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1076 return sreg<uint8_t>(sn, Sn_RXBUF_SIZE);
Soohwan Kim 4:4930f81bbe98 1077 }
Soohwan Kim 4:4930f81bbe98 1078
Soohwan Kim 4:4930f81bbe98 1079 /**
Soohwan Kim 4:4930f81bbe98 1080 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1081 * @brief Set @ref Sn_TXBUF_SIZE register
Soohwan Kim 4:4930f81bbe98 1082 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1083 * @param (uint8_t)txbufsize Value to set @ref Sn_TXBUF_SIZE
Soohwan Kim 4:4930f81bbe98 1084 * @sa getSn_TXBUF_SIZE()
Soohwan Kim 4:4930f81bbe98 1085 */
Soohwan Kim 4:4930f81bbe98 1086 void setSn_TXBUF_SIZE(uint8_t sn, uint8_t txbufsize) {
Soohwan Kim 4:4930f81bbe98 1087 sreg<uint8_t>(sn, Sn_TXBUF_SIZE, txbufsize);
Soohwan Kim 4:4930f81bbe98 1088 }
Soohwan Kim 4:4930f81bbe98 1089
Soohwan Kim 4:4930f81bbe98 1090 /**
Soohwan Kim 4:4930f81bbe98 1091 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1092 * @brief Get @ref Sn_TXBUF_SIZE register
Soohwan Kim 4:4930f81bbe98 1093 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1094 * @return uint8_t. Value of @ref Sn_TXBUF_SIZE.
Soohwan Kim 4:4930f81bbe98 1095 * @sa setSn_TXBUF_SIZE()
Soohwan Kim 4:4930f81bbe98 1096 */
Soohwan Kim 4:4930f81bbe98 1097 uint8_t getSn_TXBUF_SIZE(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1098 return sreg<uint8_t>(sn, Sn_TXBUF_SIZE);
Soohwan Kim 4:4930f81bbe98 1099 }
Soohwan Kim 4:4930f81bbe98 1100
Soohwan Kim 4:4930f81bbe98 1101 /**
Soohwan Kim 4:4930f81bbe98 1102 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1103 * @brief Get @ref Sn_TX_FSR register
Soohwan Kim 4:4930f81bbe98 1104 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1105 * @return uint16_t. Value of @ref Sn_TX_FSR.
Soohwan Kim 4:4930f81bbe98 1106 */
Soohwan Kim 4:4930f81bbe98 1107 uint16_t getSn_TX_FSR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1108 return sreg<uint16_t>(sn, Sn_TX_FSR);
Soohwan Kim 4:4930f81bbe98 1109 }
Soohwan Kim 4:4930f81bbe98 1110
Soohwan Kim 4:4930f81bbe98 1111
Soohwan Kim 4:4930f81bbe98 1112 /**
Soohwan Kim 4:4930f81bbe98 1113 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1114 * @brief Get @ref Sn_TX_RD register
Soohwan Kim 4:4930f81bbe98 1115 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1116 * @return uint16_t. Value of @ref Sn_TX_RD.
Soohwan Kim 4:4930f81bbe98 1117 */
Soohwan Kim 4:4930f81bbe98 1118 uint16_t getSn_TX_RD(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1119 return sreg<uint16_t>(sn, Sn_TX_RD);
Soohwan Kim 4:4930f81bbe98 1120 }
Soohwan Kim 4:4930f81bbe98 1121
Soohwan Kim 4:4930f81bbe98 1122 /**
Soohwan Kim 4:4930f81bbe98 1123 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1124 * @brief Set @ref Sn_TX_WR register
Soohwan Kim 4:4930f81bbe98 1125 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1126 * @param (uint16_t)txwr Value to set @ref Sn_TX_WR
Soohwan Kim 4:4930f81bbe98 1127 * @sa GetSn_TX_WR()
Soohwan Kim 4:4930f81bbe98 1128 */
Soohwan Kim 4:4930f81bbe98 1129 void setSn_TX_WR(uint8_t sn, uint16_t txwr) {
Soohwan Kim 4:4930f81bbe98 1130 sreg<uint16_t>(sn, Sn_TX_WR, txwr);
Soohwan Kim 4:4930f81bbe98 1131 }
Soohwan Kim 4:4930f81bbe98 1132
Soohwan Kim 4:4930f81bbe98 1133 /**
Soohwan Kim 4:4930f81bbe98 1134 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1135 * @brief Get @ref Sn_TX_WR register
Soohwan Kim 4:4930f81bbe98 1136 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1137 * @return uint16_t. Value of @ref Sn_TX_WR.
Soohwan Kim 4:4930f81bbe98 1138 * @sa setSn_TX_WR()
Soohwan Kim 4:4930f81bbe98 1139 */
Soohwan Kim 4:4930f81bbe98 1140 uint16_t getSn_TX_WR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1141 return sreg<uint16_t>(sn, Sn_TX_WR);
Soohwan Kim 4:4930f81bbe98 1142 }
Soohwan Kim 4:4930f81bbe98 1143
Soohwan Kim 4:4930f81bbe98 1144
Soohwan Kim 4:4930f81bbe98 1145 /**
Soohwan Kim 4:4930f81bbe98 1146 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1147 * @brief Get @ref Sn_RX_RSR register
Soohwan Kim 4:4930f81bbe98 1148 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1149 * @return uint16_t. Value of @ref Sn_RX_RSR.
Soohwan Kim 4:4930f81bbe98 1150 */
Soohwan Kim 4:4930f81bbe98 1151 uint16_t getSn_RX_RSR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1152 return sreg<uint16_t>(sn, Sn_RX_RSR);
Soohwan Kim 4:4930f81bbe98 1153 }
Soohwan Kim 4:4930f81bbe98 1154
Soohwan Kim 4:4930f81bbe98 1155
Soohwan Kim 4:4930f81bbe98 1156 /**
Soohwan Kim 4:4930f81bbe98 1157 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1158 * @brief Set @ref Sn_RX_RD register
Soohwan Kim 4:4930f81bbe98 1159 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1160 * @param (uint16_t)rxrd Value to set @ref Sn_RX_RD
Soohwan Kim 4:4930f81bbe98 1161 * @sa getSn_RX_RD()
Soohwan Kim 4:4930f81bbe98 1162 */
Soohwan Kim 4:4930f81bbe98 1163 void setSn_RX_RD(uint8_t sn, uint16_t rxrd) {
Soohwan Kim 4:4930f81bbe98 1164 sreg<uint16_t>(sn, Sn_RX_RD, rxrd);
Soohwan Kim 4:4930f81bbe98 1165 }
Soohwan Kim 4:4930f81bbe98 1166
Soohwan Kim 4:4930f81bbe98 1167 /**
Soohwan Kim 4:4930f81bbe98 1168 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1169 * @brief Get @ref Sn_RX_RD register
Soohwan Kim 4:4930f81bbe98 1170 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1171 * @regurn uint16_t. Value of @ref Sn_RX_RD.
Soohwan Kim 4:4930f81bbe98 1172 * @sa setSn_RX_RD()
Soohwan Kim 4:4930f81bbe98 1173 */
Soohwan Kim 4:4930f81bbe98 1174 uint16_t getSn_RX_RD(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1175 return sreg<uint16_t>(sn, Sn_RX_RD);
Soohwan Kim 4:4930f81bbe98 1176 }
Soohwan Kim 4:4930f81bbe98 1177
Soohwan Kim 4:4930f81bbe98 1178 /**
Soohwan Kim 4:4930f81bbe98 1179 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1180 * @brief Get @ref Sn_RX_WR register
Soohwan Kim 4:4930f81bbe98 1181 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1182 * @return uint16_t. Value of @ref Sn_RX_WR.
Soohwan Kim 4:4930f81bbe98 1183 */
Soohwan Kim 4:4930f81bbe98 1184 uint16_t getSn_RX_WR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1185 return sreg<uint16_t>(sn, Sn_RX_WR);
Soohwan Kim 4:4930f81bbe98 1186 }
Soohwan Kim 4:4930f81bbe98 1187
Soohwan Kim 4:4930f81bbe98 1188
Soohwan Kim 4:4930f81bbe98 1189 /**
Soohwan Kim 4:4930f81bbe98 1190 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1191 * @brief Set @ref Sn_FRAG register
Soohwan Kim 4:4930f81bbe98 1192 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1193 * @param (uint16_t)frag Value to set @ref Sn_FRAG
Soohwan Kim 4:4930f81bbe98 1194 * @sa getSn_FRAD()
Soohwan Kim 4:4930f81bbe98 1195 */
Soohwan Kim 4:4930f81bbe98 1196 void setSn_FRAG(uint8_t sn, uint16_t frag) {
Soohwan Kim 4:4930f81bbe98 1197 sreg<uint16_t>(sn, Sn_FRAG, frag );
Soohwan Kim 4:4930f81bbe98 1198 }
Soohwan Kim 4:4930f81bbe98 1199
Soohwan Kim 4:4930f81bbe98 1200 /**
Soohwan Kim 4:4930f81bbe98 1201 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1202 * @brief Get @ref Sn_FRAG register
Soohwan Kim 4:4930f81bbe98 1203 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1204 * @return uint16_t. Value of @ref Sn_FRAG.
Soohwan Kim 4:4930f81bbe98 1205 * @sa setSn_FRAG()
Soohwan Kim 4:4930f81bbe98 1206 */
Soohwan Kim 4:4930f81bbe98 1207 uint16_t getSn_FRAG(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1208 return sreg<uint16_t>(sn, Sn_FRAG);
Soohwan Kim 4:4930f81bbe98 1209 }
Soohwan Kim 4:4930f81bbe98 1210
Soohwan Kim 4:4930f81bbe98 1211 /**
Soohwan Kim 4:4930f81bbe98 1212 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1213 * @brief Set @ref Sn_KPALVTR register
Soohwan Kim 4:4930f81bbe98 1214 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1215 * @param (uint8_t)kpalvt Value to set @ref Sn_KPALVTR
Soohwan Kim 4:4930f81bbe98 1216 * @sa getSn_KPALVTR()
Soohwan Kim 4:4930f81bbe98 1217 */
Soohwan Kim 4:4930f81bbe98 1218 void setSn_KPALVTR(uint8_t sn, uint8_t kpalvt) {
Soohwan Kim 4:4930f81bbe98 1219 sreg<uint8_t>(sn, Sn_KPALVTR, kpalvt);
Soohwan Kim 4:4930f81bbe98 1220 }
Soohwan Kim 4:4930f81bbe98 1221
Soohwan Kim 4:4930f81bbe98 1222 /**
Soohwan Kim 4:4930f81bbe98 1223 * @ingroup Socket_register_access_function
Soohwan Kim 4:4930f81bbe98 1224 * @brief Get @ref Sn_KPALVTR register
Soohwan Kim 4:4930f81bbe98 1225 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1226 * @return uint8_t. Value of @ref Sn_KPALVTR.
Soohwan Kim 4:4930f81bbe98 1227 * @sa setSn_KPALVTR()
Soohwan Kim 4:4930f81bbe98 1228 */
Soohwan Kim 4:4930f81bbe98 1229 uint8_t getSn_KPALVTR(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1230 return sreg<uint8_t>(sn, Sn_KPALVTR);
Soohwan Kim 4:4930f81bbe98 1231 }
Soohwan Kim 4:4930f81bbe98 1232
Soohwan Kim 4:4930f81bbe98 1233 //////////////////////////////////////
Soohwan Kim 4:4930f81bbe98 1234
Soohwan Kim 4:4930f81bbe98 1235 /////////////////////////////////////
Soohwan Kim 4:4930f81bbe98 1236 // Sn_TXBUF & Sn_RXBUF IO function //
Soohwan Kim 4:4930f81bbe98 1237 /////////////////////////////////////
Soohwan Kim 4:4930f81bbe98 1238 /**
Soohwan Kim 4:4930f81bbe98 1239 * @brief Gets the max buffer size of socket sn passed as parameter.
Soohwan Kim 4:4930f81bbe98 1240 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1241 * @return uint16_t. Value of Socket n RX max buffer size.
Soohwan Kim 4:4930f81bbe98 1242 */
Soohwan Kim 4:4930f81bbe98 1243 uint16_t getSn_RxMAX(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1244 return (getSn_RXBUF_SIZE(sn) << 10);
Soohwan Kim 4:4930f81bbe98 1245 }
Soohwan Kim 4:4930f81bbe98 1246
Soohwan Kim 4:4930f81bbe98 1247 /**
Soohwan Kim 4:4930f81bbe98 1248 * @brief Gets the max buffer size of socket sn passed as parameters.
Soohwan Kim 4:4930f81bbe98 1249 * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
Soohwan Kim 4:4930f81bbe98 1250 * @return uint16_t. Value of Socket n TX max buffer size.
Soohwan Kim 4:4930f81bbe98 1251 */
Soohwan Kim 4:4930f81bbe98 1252 //uint16_t getSn_TxMAX(uint8_t sn);
Soohwan Kim 4:4930f81bbe98 1253 uint16_t getSn_TxMAX(uint8_t sn) {
Soohwan Kim 4:4930f81bbe98 1254 return (getSn_TXBUF_SIZE(sn) << 10);
Soohwan Kim 4:4930f81bbe98 1255 }
Soohwan Kim 4:4930f81bbe98 1256
Soohwan Kim 0:6f28332c466f 1257
Soohwan Kim 0:6f28332c466f 1258 protected:
Soohwan Kim 0:6f28332c466f 1259 uint8_t mac[6];
Soohwan Kim 0:6f28332c466f 1260 uint32_t ip;
Soohwan Kim 0:6f28332c466f 1261 uint32_t netmask;
Soohwan Kim 0:6f28332c466f 1262 uint32_t gateway;
Soohwan Kim 0:6f28332c466f 1263 uint32_t dnsaddr;
Soohwan Kim 0:6f28332c466f 1264 bool dhcp;
Soohwan Kim 4:4930f81bbe98 1265
Soohwan Kim 4:4930f81bbe98 1266
Soohwan Kim 0:6f28332c466f 1267
Soohwan Kim 0:6f28332c466f 1268 static WIZnet_Chip* inst;
Soohwan Kim 0:6f28332c466f 1269
Soohwan Kim 0:6f28332c466f 1270 void reg_wr_mac(uint16_t addr, uint8_t* data) {
Soohwan Kim 0:6f28332c466f 1271 spi_write(addr, 0x04, data, 6);
Soohwan Kim 0:6f28332c466f 1272 }
Soohwan Kim 0:6f28332c466f 1273
Soohwan Kim 0:6f28332c466f 1274 void spi_write(uint16_t addr, uint8_t cb, const uint8_t *buf, uint16_t len);
Soohwan Kim 0:6f28332c466f 1275 void spi_read(uint16_t addr, uint8_t cb, uint8_t *buf, uint16_t len);
Soohwan Kim 0:6f28332c466f 1276 SPI* spi;
Soohwan Kim 0:6f28332c466f 1277 DigitalOut cs;
Soohwan Kim 0:6f28332c466f 1278 DigitalOut reset_pin;
Soohwan Kim 0:6f28332c466f 1279 };
Soohwan Kim 0:6f28332c466f 1280
Soohwan Kim 0:6f28332c466f 1281 extern uint32_t str_to_ip(const char* str);
Soohwan Kim 0:6f28332c466f 1282 extern void printfBytes(char* str, uint8_t* buf, int len);
Soohwan Kim 0:6f28332c466f 1283 extern void printHex(uint8_t* buf, int len);
Soohwan Kim 0:6f28332c466f 1284 extern void debug_hex(uint8_t* buf, int len);