Convert W6300 #defines to constexpr/inline across all headers
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "socket.h"
|
||||
|
||||
#define SOCK_ANY_PORT_NUM 0xC000
|
||||
constexpr uint16_t SOCK_ANY_PORT_NUM = 0xC000;
|
||||
|
||||
static uint16_t sock_any_port = SOCK_ANY_PORT_NUM;
|
||||
static uint16_t sock_io_mode = 0;
|
||||
@@ -18,15 +18,6 @@ uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
|
||||
#define CHECK_SOCKDATA() do { if(len == 0) return SOCKERR_DATALEN; } while(0)
|
||||
#define CHECK_IPZERO(addr, addrlen) do { uint16_t ipzero=0; for(uint8_t i=0; i<addrlen; i++) ipzero += (uint16_t)addr[i]; if(ipzero == 0) return SOCKERR_IPINVALID; } while(0)
|
||||
|
||||
#define Sn_MR_TCP4 (Sn_MR_TCP)
|
||||
#define Sn_MR_UDP4 (Sn_MR_UDP)
|
||||
#define Sn_MR_IPRAW4 (Sn_MR_IPRAW)
|
||||
#define Sn_MR_TCP6 (0x09)
|
||||
#define Sn_MR_UDP6 (0x0A)
|
||||
#define Sn_MR_IPRAW6 (0x0B)
|
||||
#define Sn_MR_TCPD (0x0D)
|
||||
#define Sn_MR_UDPD (0x0E)
|
||||
|
||||
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) {
|
||||
uint8_t taddr[16];
|
||||
CHECK_SOCKNUM();
|
||||
|
||||
104
w6300/socket.h
104
w6300/socket.h
@@ -1,62 +1,60 @@
|
||||
#pragma once
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
#define SOCKET uint8_t
|
||||
using SOCKET = uint8_t;
|
||||
|
||||
#define SOCK_OK 1
|
||||
#define SOCK_BUSY 0
|
||||
#define SOCK_FATAL -1000
|
||||
constexpr int16_t SOCK_OK = 1;
|
||||
constexpr int16_t SOCK_BUSY = 0;
|
||||
constexpr int16_t SOCK_FATAL = -1000;
|
||||
constexpr int16_t SOCK_ERROR = 0;
|
||||
constexpr int16_t SOCKERR_SOCKNUM = SOCK_ERROR - 1;
|
||||
constexpr int16_t SOCKERR_SOCKOPT = SOCK_ERROR - 2;
|
||||
constexpr int16_t SOCKERR_SOCKINIT = SOCK_ERROR - 3;
|
||||
constexpr int16_t SOCKERR_SOCKCLOSED = SOCK_ERROR - 4;
|
||||
constexpr int16_t SOCKERR_SOCKMODE = SOCK_ERROR - 5;
|
||||
constexpr int16_t SOCKERR_SOCKFLAG = SOCK_ERROR - 6;
|
||||
constexpr int16_t SOCKERR_SOCKSTATUS = SOCK_ERROR - 7;
|
||||
constexpr int16_t SOCKERR_ARG = SOCK_ERROR - 10;
|
||||
constexpr int16_t SOCKERR_PORTZERO = SOCK_ERROR - 11;
|
||||
constexpr int16_t SOCKERR_IPINVALID = SOCK_ERROR - 12;
|
||||
constexpr int16_t SOCKERR_TIMEOUT = SOCK_ERROR - 13;
|
||||
constexpr int16_t SOCKERR_DATALEN = SOCK_ERROR - 14;
|
||||
constexpr int16_t SOCKERR_BUFFER = SOCK_ERROR - 15;
|
||||
constexpr int16_t SOCKFATAL_PACKLEN = SOCK_FATAL - 1;
|
||||
|
||||
#define SOCK_ERROR 0
|
||||
#define SOCKERR_SOCKNUM (SOCK_ERROR - 1)
|
||||
#define SOCKERR_SOCKOPT (SOCK_ERROR - 2)
|
||||
#define SOCKERR_SOCKINIT (SOCK_ERROR - 3)
|
||||
#define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4)
|
||||
#define SOCKERR_SOCKMODE (SOCK_ERROR - 5)
|
||||
#define SOCKERR_SOCKFLAG (SOCK_ERROR - 6)
|
||||
#define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7)
|
||||
#define SOCKERR_ARG (SOCK_ERROR - 10)
|
||||
#define SOCKERR_PORTZERO (SOCK_ERROR - 11)
|
||||
#define SOCKERR_IPINVALID (SOCK_ERROR - 12)
|
||||
#define SOCKERR_TIMEOUT (SOCK_ERROR - 13)
|
||||
#define SOCKERR_DATALEN (SOCK_ERROR - 14)
|
||||
#define SOCKERR_BUFFER (SOCK_ERROR - 15)
|
||||
constexpr uint8_t SF_MULTI_ENABLE = Sn_MR_MULTI;
|
||||
constexpr uint8_t SF_ETHER_OWN = Sn_MR_MF;
|
||||
constexpr uint8_t SF_BROAD_BLOCK = Sn_MR_BRDB;
|
||||
constexpr uint8_t SF_TCP_FPSH = Sn_MR_FPSH;
|
||||
constexpr uint8_t SF_TCP_NODELAY = Sn_MR_ND;
|
||||
constexpr uint8_t SF_IGMP_VER2 = Sn_MR_MC;
|
||||
constexpr uint8_t SF_SOLICIT_BLOCK = Sn_MR_SMB;
|
||||
constexpr uint8_t SF_ETHER_MULTI4B = Sn_MR_MMB4;
|
||||
constexpr uint8_t SF_UNI_BLOCK = Sn_MR_UNIB;
|
||||
constexpr uint8_t SF_ETHER_MULIT6B = Sn_MR_MMB6;
|
||||
constexpr uint8_t SF_FORCE_ARP = Sn_MR2_FARP;
|
||||
constexpr uint8_t SF_DHA_MANUAL = Sn_MR2_DHAM;
|
||||
constexpr uint8_t SF_IO_NONBLOCK = 0x01 << 3;
|
||||
|
||||
#define SOCKFATAL_PACKLEN (SOCK_FATAL - 1)
|
||||
constexpr uint8_t PACK_IPv6 = 1 << 7;
|
||||
constexpr uint8_t PACK_IPV6_ALLNODE = PACK_IPv6 | (1 << 6);
|
||||
constexpr uint8_t PACK_IPV6_MULTI = PACK_IPv6 | (1 << 5);
|
||||
constexpr uint8_t PACK_IPV6_LLA = PACK_IPv6 | (1 << 4);
|
||||
constexpr uint8_t PACK_COMPLETED = 1 << 3;
|
||||
constexpr uint8_t PACK_REMAINED = 1 << 2;
|
||||
constexpr uint8_t PACK_FIRST = 1 << 1;
|
||||
constexpr uint8_t PACK_NONE = 0x00;
|
||||
|
||||
#define SF_MULTI_ENABLE (Sn_MR_MULTI)
|
||||
#define SF_ETHER_OWN (Sn_MR_MF)
|
||||
#define SF_BROAD_BLOCK (Sn_MR_BRDB)
|
||||
#define SF_TCP_FPSH (Sn_MR_FPSH)
|
||||
#define SF_TCP_NODELAY (Sn_MR_ND)
|
||||
#define SF_IGMP_VER2 (Sn_MR_MC)
|
||||
#define SF_SOLICIT_BLOCK (Sn_MR_SMB)
|
||||
#define SF_ETHER_MULTI4B (Sn_MR_MMB4)
|
||||
#define SF_UNI_BLOCK (Sn_MR_UNIB)
|
||||
#define SF_ETHER_MULIT6B (Sn_MR_MMB6)
|
||||
#define SF_FORCE_ARP (Sn_MR2_FARP)
|
||||
#define SF_DHA_MANUAL (Sn_MR2_DHAM)
|
||||
#define SF_IO_NONBLOCK (0x01 << 3)
|
||||
constexpr uint8_t SRCV6_PREFER_AUTO = PSR_AUTO;
|
||||
constexpr uint8_t SRCV6_PREFER_LLA = PSR_LLA;
|
||||
constexpr uint8_t SRCV6_PREFER_GUA = PSR_GUA;
|
||||
|
||||
#define PACK_IPv6 (1<<7)
|
||||
#define PACK_IPV6_ALLNODE (PACK_IPv6 | (1<<6))
|
||||
#define PACK_IPV6_MULTI (PACK_IPv6 | (1<<5))
|
||||
#define PACK_IPV6_LLA (PACK_IPv6 | (1<<4))
|
||||
#define PACK_COMPLETED (1<<3)
|
||||
#define PACK_REMAINED (1<<2)
|
||||
#define PACK_FIRST (1<<1)
|
||||
#define PACK_NONE (0x00)
|
||||
constexpr uint8_t TCPSOCK_MODE = Sn_ESR_TCPM;
|
||||
constexpr uint8_t TCPSOCK_OP = Sn_ESR_TCPOP;
|
||||
constexpr uint8_t TCPSOCK_SIP = Sn_ESR_IP6T;
|
||||
|
||||
#define SRCV6_PREFER_AUTO (PSR_AUTO)
|
||||
#define SRCV6_PREFER_LLA (PSR_LLA)
|
||||
#define SRCV6_PREFER_GUA (PSR_GUA)
|
||||
|
||||
#define TCPSOCK_MODE (Sn_ESR_TCPM)
|
||||
#define TCPSOCK_OP (Sn_ESR_TCPOP)
|
||||
#define TCPSOCK_SIP (Sn_ESR_IP6T)
|
||||
|
||||
#define SOCK_IO_BLOCK 0
|
||||
#define SOCK_IO_NONBLOCK 1
|
||||
constexpr uint8_t SOCK_IO_BLOCK = 0;
|
||||
constexpr uint8_t SOCK_IO_NONBLOCK = 1;
|
||||
|
||||
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
|
||||
int8_t close(uint8_t sn);
|
||||
@@ -114,7 +112,7 @@ int8_t connect_W6x00(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen
|
||||
int32_t sendto_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port, uint8_t addrlen);
|
||||
int32_t recvfrom_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen);
|
||||
|
||||
#define connect(sn, addr, port, addrlen) connect_W6x00(sn, addr, port, addrlen)
|
||||
#define sendto(sn, buf, len, addr, port, addrlen) sendto_W6x00(sn, buf, len, addr, port, addrlen)
|
||||
#define recvfrom(sn, buf, len, addr, port, addrlen) recvfrom_W6x00(sn, buf, len, addr, port, addrlen)
|
||||
inline int8_t connect(uint8_t sn, uint8_t* addr, uint16_t port, uint8_t addrlen) { return connect_W6x00(sn, addr, port, addrlen); }
|
||||
inline int32_t sendto(uint8_t sn, uint8_t* buf, uint16_t len, uint8_t* addr, uint16_t port, uint8_t addrlen) { return sendto_W6x00(sn, buf, len, addr, port, addrlen); }
|
||||
inline int32_t recvfrom(uint8_t sn, uint8_t* buf, uint16_t len, uint8_t* addr, uint16_t* port, uint8_t* addrlen) { return recvfrom_W6x00(sn, buf, len, addr, port, addrlen); }
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ void wiz_delay_ms(uint32_t milliseconds) {
|
||||
}
|
||||
}
|
||||
|
||||
#if (_PHY_IO_MODE_ == _PHY_IO_MODE_MII_)
|
||||
void wiz_mdio_write(uint8_t phyregaddr, uint16_t var) {
|
||||
setPHYRAR(phyregaddr);
|
||||
setPHYDIR(var);
|
||||
@@ -105,4 +104,3 @@ uint16_t wiz_mdio_read(uint8_t phyregaddr) {
|
||||
while (getPHYACR());
|
||||
return getPHYDOR();
|
||||
}
|
||||
#endif
|
||||
|
||||
1396
w6300/w6300.h
1396
w6300/w6300.h
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,13 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
#define W6300 6300
|
||||
#define _WIZCHIP_ W6300
|
||||
constexpr int _WIZCHIP_ = 6300;
|
||||
|
||||
#define _PHY_IO_MODE_PHYCR_ 0x0000
|
||||
#define _PHY_IO_MODE_MII_ 0x0010
|
||||
#define _PHY_IO_MODE_ _PHY_IO_MODE_MII_
|
||||
constexpr uint16_t _PHY_IO_MODE_PHYCR_ = 0x0000;
|
||||
constexpr uint16_t _PHY_IO_MODE_MII_ = 0x0010;
|
||||
constexpr uint16_t _PHY_IO_MODE_ = _PHY_IO_MODE_MII_;
|
||||
|
||||
#define _WIZCHIP_QSPI_MODE_ (0x02 << 6)
|
||||
constexpr uint8_t _WIZCHIP_QSPI_MODE_ = 0x02 << 6;
|
||||
|
||||
using iodata_t = uint8_t;
|
||||
using datasize_t = int16_t;
|
||||
@@ -16,7 +15,7 @@ using datasize_t = int16_t;
|
||||
#include "w6300.h"
|
||||
|
||||
constexpr int WIZCHIP_SOCK_NUM = 8;
|
||||
#define _WIZCHIP_SOCK_NUM_ WIZCHIP_SOCK_NUM
|
||||
constexpr int _WIZCHIP_SOCK_NUM_ = WIZCHIP_SOCK_NUM;
|
||||
|
||||
enum ctlwizchip_type {
|
||||
CW_SYS_LOCK, CW_SYS_UNLOCK, CW_GET_SYSLOCK,
|
||||
|
||||
Reference in New Issue
Block a user