Convert W6300 #defines to constexpr/inline across all headers

This commit is contained in:
Ian Gulliver
2026-04-04 17:21:57 +09:00
parent 92e00476da
commit 224fe4f7eb
5 changed files with 590 additions and 936 deletions

View File

@@ -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); }