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