From 579876774e4a145d164e3590275a9e7a035cfdba Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 5 Apr 2026 16:26:56 +0900 Subject: [PATCH] Rename internal symbols: snake_case accessors, REG_ prefix for registers, no reserved identifiers --- w6300/w6300.cpp | 1166 +++++++++++++++++++++++------------------------ 1 file changed, 583 insertions(+), 583 deletions(-) diff --git a/w6300/w6300.cpp b/w6300/w6300.cpp index 19cbc5c..0be652c 100644 --- a/w6300/w6300.cpp +++ b/w6300/w6300.cpp @@ -228,13 +228,13 @@ void pio_write(uint8_t opcode, uint16_t addr, uint8_t* buf, uint16_t len) { using iodata_t = uint8_t; using datasize_t = int16_t; -constexpr int _WIZCHIP_ = 6300; -constexpr uint8_t _WIZCHIP_QSPI_MODE_ = 0x02 << 6; -constexpr int _SOCK_COUNT_ = SOCK_COUNT; -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_; +constexpr uint8_t QSPI_MODE = 0x02 << 6; + + +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; constexpr uint8_t SYS_CHIP_LOCK = (1 << 2); constexpr uint8_t SYS_NET_LOCK = (1 << 1); @@ -276,113 +276,113 @@ constexpr uint32_t RXBUF_BLOCK(uint8_t n) { return 3 + 4 * n; } constexpr uint32_t offset_inc(uint32_t addr, uint32_t n) { return addr + (n << 8); } -constexpr uint32_t _CIDR_ = (0x0000 << 8) + CREG_BLOCK; -constexpr uint32_t _RTL_ = (0x0004 << 8) + CREG_BLOCK; -constexpr uint32_t _VER_ = (0x0002 << 8) + CREG_BLOCK; -constexpr uint32_t _SYSR_ = (0x2000 << 8) + CREG_BLOCK; -constexpr uint32_t _SYCR0_ = (0x2004 << 8) + CREG_BLOCK; -constexpr uint32_t _SYCR1_ = offset_inc(_SYCR0_, 1); -constexpr uint32_t _TCNTR_ = (0x2016 << 8) + CREG_BLOCK; -constexpr uint32_t _TCNTRCLR_ = (0x2020 << 8) + CREG_BLOCK; -constexpr uint32_t _IR_ = (0x2100 << 8) + CREG_BLOCK; -constexpr uint32_t _SIR_ = (0x2101 << 8) + CREG_BLOCK; -constexpr uint32_t _SLIR_ = (0x2102 << 8) + CREG_BLOCK; -constexpr uint32_t _IMR_ = (0x2104 << 8) + CREG_BLOCK; -constexpr uint32_t _IRCLR_ = (0x2108 << 8) + CREG_BLOCK; -constexpr uint32_t _SIMR_ = (0x2114 << 8) + CREG_BLOCK; -constexpr uint32_t _SLIMR_ = (0x2124 << 8) + CREG_BLOCK; -constexpr uint32_t _SLIRCLR_ = (0x2128 << 8) + CREG_BLOCK; -constexpr uint32_t _SLPSR_ = (0x212C << 8) + CREG_BLOCK; -constexpr uint32_t _SLCR_ = (0x2130 << 8) + CREG_BLOCK; -constexpr uint32_t _PHYSR_ = (0x3000 << 8) + CREG_BLOCK; -constexpr uint32_t _PHYRAR_ = (0x3008 << 8) + CREG_BLOCK; -constexpr uint32_t _PHYDIR_ = (0x300C << 8) + CREG_BLOCK; -constexpr uint32_t _PHYDOR_ = (0x3010 << 8) + CREG_BLOCK; -constexpr uint32_t _PHYACR_ = (0x3014 << 8) + CREG_BLOCK; -constexpr uint32_t _PHYDIVR_ = (0x3018 << 8) + CREG_BLOCK; -constexpr uint32_t _PHYCR0_ = (0x301C << 8) + CREG_BLOCK; -constexpr uint32_t _PHYCR1_ = offset_inc(_PHYCR0_, 1); -constexpr uint32_t _NET4MR_ = (0x4000 << 8) + CREG_BLOCK; -constexpr uint32_t _NET6MR_ = (0x4004 << 8) + CREG_BLOCK; -constexpr uint32_t _NETMR_ = (0x4008 << 8) + CREG_BLOCK; -constexpr uint32_t _NETMR2_ = (0x4009 << 8) + CREG_BLOCK; -constexpr uint32_t _PTMR_ = (0x4100 << 8) + CREG_BLOCK; -constexpr uint32_t _PMNR_ = (0x4104 << 8) + CREG_BLOCK; -constexpr uint32_t _PHAR_ = (0x4108 << 8) + CREG_BLOCK; -constexpr uint32_t _PSIDR_ = (0x4110 << 8) + CREG_BLOCK; -constexpr uint32_t _PMRUR_ = (0x4114 << 8) + CREG_BLOCK; -constexpr uint32_t _SHAR_ = (0x4120 << 8) + CREG_BLOCK; -constexpr uint32_t _GAR_ = (0x4130 << 8) + CREG_BLOCK; -constexpr uint32_t _GA4R_ = _GAR_; -constexpr uint32_t _SUBR_ = (0x4134 << 8) + CREG_BLOCK; -constexpr uint32_t _SUB4R_ = _SUBR_; -constexpr uint32_t _SIPR_ = (0x4138 << 8) + CREG_BLOCK; -constexpr uint32_t _SIP4R_ = _SIPR_; -constexpr uint32_t _LLAR_ = (0x4140 << 8) + CREG_BLOCK; -constexpr uint32_t _GUAR_ = (0x4150 << 8) + CREG_BLOCK; -constexpr uint32_t _SUB6R_ = (0x4160 << 8) + CREG_BLOCK; -constexpr uint32_t _GA6R_ = (0x4170 << 8) + CREG_BLOCK; -constexpr uint32_t _SLDIP6R_ = (0x4180 << 8) + CREG_BLOCK; -constexpr uint32_t _SLDIPR_ = (0x418C << 8) + CREG_BLOCK; -constexpr uint32_t _SLDIP4R_ = _SLDIPR_; -constexpr uint32_t _SLDHAR_ = (0x4190 << 8) + CREG_BLOCK; -constexpr uint32_t _PINGIDR_ = (0x4198 << 8) + CREG_BLOCK; -constexpr uint32_t _PINGSEQR_ = (0x419C << 8) + CREG_BLOCK; -constexpr uint32_t _UIPR_ = (0x41A0 << 8) + CREG_BLOCK; -constexpr uint32_t _UIP4R_ = _UIPR_; -constexpr uint32_t _UPORTR_ = (0x41A4 << 8) + CREG_BLOCK; -constexpr uint32_t _UPORT4R_ = _UPORTR_; -constexpr uint32_t _UIP6R_ = (0x41B0 << 8) + CREG_BLOCK; -constexpr uint32_t _UPORT6R_ = (0x41C0 << 8) + CREG_BLOCK; -constexpr uint32_t _INTPTMR_ = (0x41C5 << 8) + CREG_BLOCK; -constexpr uint32_t _PLR_ = (0x41D0 << 8) + CREG_BLOCK; -constexpr uint32_t _PFR_ = (0x41D4 << 8) + CREG_BLOCK; -constexpr uint32_t _VLTR_ = (0x41D8 << 8) + CREG_BLOCK; -constexpr uint32_t _PLTR_ = (0x41DC << 8) + CREG_BLOCK; -constexpr uint32_t _PAR_ = (0x41E0 << 8) + CREG_BLOCK; -constexpr uint32_t _ICMP6BLKR_ = (0x41F0 << 8) + CREG_BLOCK; -constexpr uint32_t _CHPLCKR_ = (0x41F4 << 8) + CREG_BLOCK; -constexpr uint32_t _NETLCKR_ = (0x41F5 << 8) + CREG_BLOCK; -constexpr uint32_t _PHYLCKR_ = (0x41F6 << 8) + CREG_BLOCK; -constexpr uint32_t _RTR_ = (0x4200 << 8) + CREG_BLOCK; -constexpr uint32_t _RCR_ = (0x4204 << 8) + CREG_BLOCK; -constexpr uint32_t _SLRTR_ = (0x4208 << 8) + CREG_BLOCK; -constexpr uint32_t _SLRCR_ = (0x420C << 8) + CREG_BLOCK; -constexpr uint32_t _SLHOPR_ = (0x420F << 8) + CREG_BLOCK; +constexpr uint32_t REG_CIDR = (0x0000 << 8) + CREG_BLOCK; +constexpr uint32_t REG_RTL = (0x0004 << 8) + CREG_BLOCK; +constexpr uint32_t REG_VER = (0x0002 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SYSR = (0x2000 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SYCR0 = (0x2004 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SYCR1 = offset_inc(REG_SYCR0, 1); +constexpr uint32_t REG_TCNTR = (0x2016 << 8) + CREG_BLOCK; +constexpr uint32_t REG_TCNTRCLR = (0x2020 << 8) + CREG_BLOCK; +constexpr uint32_t REG_IR = (0x2100 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SIR = (0x2101 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLIR = (0x2102 << 8) + CREG_BLOCK; +constexpr uint32_t REG_IMR = (0x2104 << 8) + CREG_BLOCK; +constexpr uint32_t REG_IRCLR = (0x2108 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SIMR = (0x2114 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLIMR = (0x2124 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLIRCLR = (0x2128 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLPSR = (0x212C << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLCR = (0x2130 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYSR = (0x3000 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYRAR = (0x3008 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYDIR = (0x300C << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYDOR = (0x3010 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYACR = (0x3014 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYDIVR = (0x3018 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYCR0 = (0x301C << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYCR1 = offset_inc(REG_PHYCR0, 1); +constexpr uint32_t REG_NET4MR = (0x4000 << 8) + CREG_BLOCK; +constexpr uint32_t REG_NET6MR = (0x4004 << 8) + CREG_BLOCK; +constexpr uint32_t REG_NETMR = (0x4008 << 8) + CREG_BLOCK; +constexpr uint32_t REG_NETMR2 = (0x4009 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PTMR = (0x4100 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PMNR = (0x4104 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHAR = (0x4108 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PSIDR = (0x4110 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PMRUR = (0x4114 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SHAR = (0x4120 << 8) + CREG_BLOCK; +constexpr uint32_t REG_GAR = (0x4130 << 8) + CREG_BLOCK; +constexpr uint32_t REG_GA4R = REG_GAR; +constexpr uint32_t REG_SUBR = (0x4134 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SUB4R = REG_SUBR; +constexpr uint32_t REG_SIPR = (0x4138 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SIP4R = REG_SIPR; +constexpr uint32_t REG_LLAR = (0x4140 << 8) + CREG_BLOCK; +constexpr uint32_t REG_GUAR = (0x4150 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SUB6R = (0x4160 << 8) + CREG_BLOCK; +constexpr uint32_t REG_GA6R = (0x4170 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLDIP6R = (0x4180 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLDIPR = (0x418C << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLDIP4R = REG_SLDIPR; +constexpr uint32_t REG_SLDHAR = (0x4190 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PINGIDR = (0x4198 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PINGSEQR = (0x419C << 8) + CREG_BLOCK; +constexpr uint32_t REG_UIPR = (0x41A0 << 8) + CREG_BLOCK; +constexpr uint32_t REG_UIP4R = REG_UIPR; +constexpr uint32_t REG_UPORTR = (0x41A4 << 8) + CREG_BLOCK; +constexpr uint32_t REG_UPORT4R = REG_UPORTR; +constexpr uint32_t REG_UIP6R = (0x41B0 << 8) + CREG_BLOCK; +constexpr uint32_t REG_UPORT6R = (0x41C0 << 8) + CREG_BLOCK; +constexpr uint32_t REG_INTPTMR = (0x41C5 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PLR = (0x41D0 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PFR = (0x41D4 << 8) + CREG_BLOCK; +constexpr uint32_t REG_VLTR = (0x41D8 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PLTR = (0x41DC << 8) + CREG_BLOCK; +constexpr uint32_t REG_PAR = (0x41E0 << 8) + CREG_BLOCK; +constexpr uint32_t REG_ICMP6BLKR = (0x41F0 << 8) + CREG_BLOCK; +constexpr uint32_t REG_CHPLCKR = (0x41F4 << 8) + CREG_BLOCK; +constexpr uint32_t REG_NETLCKR = (0x41F5 << 8) + CREG_BLOCK; +constexpr uint32_t REG_PHYLCKR = (0x41F6 << 8) + CREG_BLOCK; +constexpr uint32_t REG_RTR = (0x4200 << 8) + CREG_BLOCK; +constexpr uint32_t REG_RCR = (0x4204 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLRTR = (0x4208 << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLRCR = (0x420C << 8) + CREG_BLOCK; +constexpr uint32_t REG_SLHOPR = (0x420F << 8) + CREG_BLOCK; -constexpr uint32_t _Sn_MR_(uint8_t n) { return (0x0000 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_PSR_(uint8_t n) { return (0x0004 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_CR_(uint8_t n) { return (0x0010 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_IR_(uint8_t n) { return (0x0020 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_IMR_(uint8_t n) { return (0x0024 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_IRCLR_(uint8_t n) { return (0x0028 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_SR_(uint8_t n) { return (0x0030 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_ESR_(uint8_t n) { return (0x0031 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_PNR_(uint8_t n) { return (0x0100 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_NHR_(uint8_t n) { return _Sn_PNR_(n); } -constexpr uint32_t _Sn_TOSR_(uint8_t n) { return (0x0104 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_TTLR_(uint8_t n) { return (0x0108 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_HOPR_(uint8_t n) { return _Sn_TTLR_(n); } -constexpr uint32_t _Sn_FRGR_(uint8_t n) { return (0x010C << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_MSSR_(uint8_t n) { return (0x0110 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_PORTR_(uint8_t n) { return (0x0114 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_DHAR_(uint8_t n) { return (0x0118 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_DIPR_(uint8_t n) { return (0x0120 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_DIP4R_(uint8_t n) { return _Sn_DIPR_(n); } -constexpr uint32_t _Sn_DIP6R_(uint8_t n) { return (0x0130 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_DPORTR_(uint8_t n) { return (0x0140 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_MR2_(uint8_t n) { return (0x0144 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_RTR_(uint8_t n) { return (0x0180 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_RCR_(uint8_t n) { return (0x0184 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_KPALVTR_(uint8_t n) { return (0x0188 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_TX_BSR_(uint8_t n) { return (0x0200 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_TX_FSR_(uint8_t n) { return (0x0204 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_TX_RD_(uint8_t n) { return (0x0208 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_TX_WR_(uint8_t n) { return (0x020C << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_RX_BSR_(uint8_t n) { return (0x0220 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_RX_RSR_(uint8_t n) { return (0x0224 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_RX_RD_(uint8_t n) { return (0x0228 << 8) + SREG_BLOCK(n); } -constexpr uint32_t _Sn_RX_WR_(uint8_t n) { return (0x022C << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_MR(uint8_t n) { return (0x0000 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_PSR(uint8_t n) { return (0x0004 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_CR(uint8_t n) { return (0x0010 << 8) + SREG_BLOCK(n); } +constexpr uint32_t _SnREG_IR(uint8_t n) { return (0x0020 << 8) + SREG_BLOCK(n); } +constexpr uint32_t _SnREG_IMR(uint8_t n) { return (0x0024 << 8) + SREG_BLOCK(n); } +constexpr uint32_t _SnREG_IRCLR(uint8_t n) { return (0x0028 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_SR(uint8_t n) { return (0x0030 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_ESR(uint8_t n) { return (0x0031 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_PNR(uint8_t n) { return (0x0100 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_NHR(uint8_t n) { return REG_SN_PNR(n); } +constexpr uint32_t REG_SN_TOSR(uint8_t n) { return (0x0104 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_TTLR(uint8_t n) { return (0x0108 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_HOPR(uint8_t n) { return REG_SN_TTLR(n); } +constexpr uint32_t REG_SN_FRGR(uint8_t n) { return (0x010C << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_MSSR(uint8_t n) { return (0x0110 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_PORTR(uint8_t n) { return (0x0114 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_DHAR(uint8_t n) { return (0x0118 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_DIPR(uint8_t n) { return (0x0120 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_DIP4R(uint8_t n) { return REG_SN_DIPR(n); } +constexpr uint32_t REG_SN_DIP6R(uint8_t n) { return (0x0130 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_DPORTR(uint8_t n) { return (0x0140 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_MR2(uint8_t n) { return (0x0144 << 8) + SREG_BLOCK(n); } +constexpr uint32_t _SnREG_RTR(uint8_t n) { return (0x0180 << 8) + SREG_BLOCK(n); } +constexpr uint32_t _SnREG_RCR(uint8_t n) { return (0x0184 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_KPALVTR(uint8_t n) { return (0x0188 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_TX_BSR(uint8_t n) { return (0x0200 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_TX_FSR(uint8_t n) { return (0x0204 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_TX_RD(uint8_t n) { return (0x0208 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_TX_WR(uint8_t n) { return (0x020C << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_RX_BSR(uint8_t n) { return (0x0220 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_RX_RSR(uint8_t n) { return (0x0224 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_RX_RD(uint8_t n) { return (0x0228 << 8) + SREG_BLOCK(n); } +constexpr uint32_t REG_SN_RX_WR(uint8_t n) { return (0x022C << 8) + SREG_BLOCK(n); } constexpr uint8_t SYSR_CHPL = 1 << 7; constexpr uint8_t SYSR_NETL = 1 << 6; @@ -501,11 +501,11 @@ constexpr uint8_t Sn_CR_SEND = 0x20; constexpr uint8_t Sn_CR_SEND6 = 0xA0; constexpr uint8_t Sn_CR_SEND_KEEP = 0x22; constexpr uint8_t Sn_CR_RECV = 0x40; -constexpr uint8_t Sn_IR_SENDOK = 0x10; -constexpr uint8_t Sn_IR_TIMEOUT = 0x08; -constexpr uint8_t Sn_IR_RECV = 0x04; -constexpr uint8_t Sn_IR_DISCON = 0x02; -constexpr uint8_t Sn_IR_CON = 0x01; +constexpr uint8_t SnREG_IRSENDOK = 0x10; +constexpr uint8_t SnREG_IRTIMEOUT = 0x08; +constexpr uint8_t SnREG_IRRECV = 0x04; +constexpr uint8_t SnREG_IRDISCON = 0x02; +constexpr uint8_t SnREG_IRCON = 0x01; constexpr uint8_t SOCK_CLOSED = 0x00; constexpr uint8_t SOCK_INIT = 0x13; constexpr uint8_t SOCK_LISTEN = 0x14; @@ -565,261 +565,261 @@ uint8_t reg_read(uint32_t AddrSel); void reg_write(uint32_t AddrSel, uint8_t wb); void reg_read_buf(uint32_t AddrSel, uint8_t* pBuf, datasize_t len); void reg_write_buf(uint32_t AddrSel, uint8_t* pBuf, datasize_t len); -uint16_t getSn_TX_FSR(uint8_t sn); -uint16_t getSn_RX_RSR(uint8_t sn); +uint16_t get_sn_tx_fsr(uint8_t sn); +uint16_t get_sn_rx_rsr(uint8_t sn); -inline uint8_t getRTL() { return reg_read(_RTL_); } -inline uint16_t getCIDR() { return (((uint16_t)reg_read(_CIDR_) | (((reg_read(_RTL_)) & 0x0F) << 1)) << 8) + reg_read(offset_inc(_CIDR_, 1)); } -inline uint16_t getVER() { return (((uint16_t)reg_read(_VER_)) << 8) + reg_read(offset_inc(_VER_, 1)); } -inline uint8_t getSYSR() { return reg_read(_SYSR_); } -inline uint8_t getSYCR0() { return reg_read(_SYCR0_); } -inline void setSYCR0(uint8_t v) { reg_write(_SYCR0_, v); } -inline uint8_t getSYCR1() { return reg_read(_SYCR1_); } -inline void setSYCR1(uint8_t v) { reg_write(_SYCR1_, v); } -inline uint16_t getTCNTR() { return (((uint16_t)reg_read(_TCNTR_)) << 8) + reg_read(offset_inc(_TCNTR_, 1)); } -inline void setTCNTRCLR(uint8_t v) { reg_write(_TCNTRCLR_, v); } -inline uint8_t getIR() { return reg_read(_IR_); } -inline uint8_t getSIR() { return reg_read(_SIR_); } -inline uint8_t getSLIR() { return reg_read(_SLIR_); } -inline void setIMR(uint8_t v) { reg_write(_IMR_, v); } -inline uint8_t getIMR() { return reg_read(_IMR_); } -inline void setIRCLR(uint8_t v) { reg_write(_IRCLR_, v); } -inline void setIR(uint8_t v) { setIRCLR(v); } -inline void setSIMR(uint8_t v) { reg_write(_SIMR_, v); } -inline uint8_t getSIMR() { return reg_read(_SIMR_); } -inline void setSLIMR(uint8_t v) { reg_write(_SLIMR_, v); } -inline uint8_t getSLIMR() { return reg_read(_SLIMR_); } -inline void setSLIRCLR(uint8_t v) { reg_write(_SLIRCLR_, v); } -inline void setSLIR(uint8_t v) { setSLIRCLR(v); } -inline void setSLPSR(uint8_t v) { reg_write(_SLPSR_, v); } -inline uint8_t getSLPSR() { return reg_read(_SLPSR_); } -inline void setSLCR(uint8_t v) { reg_write(_SLCR_, v); } -inline uint8_t getSLCR() { return reg_read(_SLCR_); } -inline uint8_t getPHYSR() { return reg_read(_PHYSR_); } -inline void setPHYRAR(uint8_t v) { reg_write(_PHYRAR_, v); } -inline uint8_t getPHYRAR() { return reg_read(_PHYRAR_); } -inline void setPHYDIR(uint16_t v) { - reg_write(offset_inc(_PHYDIR_, 1), (uint8_t)(v >> 8)); - reg_write(_PHYDIR_, (uint8_t)v); +inline uint8_t get_rtl() { return reg_read(REG_RTL); } +inline uint16_t get_cidr() { return (((uint16_t)reg_read(REG_CIDR) | (((reg_read(REG_RTL)) & 0x0F) << 1)) << 8) + reg_read(offset_inc(REG_CIDR, 1)); } +inline uint16_t get_ver() { return (((uint16_t)reg_read(REG_VER)) << 8) + reg_read(offset_inc(REG_VER, 1)); } +inline uint8_t get_sysr() { return reg_read(REG_SYSR); } +inline uint8_t get_sycr0() { return reg_read(REG_SYCR0); } +inline void set_sycr0(uint8_t v) { reg_write(REG_SYCR0, v); } +inline uint8_t get_sycr1() { return reg_read(REG_SYCR1); } +inline void set_sycr1(uint8_t v) { reg_write(REG_SYCR1, v); } +inline uint16_t get_tcntr() { return (((uint16_t)reg_read(REG_TCNTR)) << 8) + reg_read(offset_inc(REG_TCNTR, 1)); } +inline void set_tcntrclr(uint8_t v) { reg_write(REG_TCNTRCLR, v); } +inline uint8_t get_ir() { return reg_read(REG_IR); } +inline uint8_t get_sir() { return reg_read(REG_SIR); } +inline uint8_t get_slir() { return reg_read(REG_SLIR); } +inline void set_imr(uint8_t v) { reg_write(REG_IMR, v); } +inline uint8_t get_imr() { return reg_read(REG_IMR); } +inline void set_irclr(uint8_t v) { reg_write(REG_IRCLR, v); } +inline void set_ir(uint8_t v) { set_irclr(v); } +inline void set_simr(uint8_t v) { reg_write(REG_SIMR, v); } +inline uint8_t get_simr() { return reg_read(REG_SIMR); } +inline void set_slimr(uint8_t v) { reg_write(REG_SLIMR, v); } +inline uint8_t get_slimr() { return reg_read(REG_SLIMR); } +inline void set_slirclr(uint8_t v) { reg_write(REG_SLIRCLR, v); } +inline void set_slir(uint8_t v) { set_slirclr(v); } +inline void set_slpsr(uint8_t v) { reg_write(REG_SLPSR, v); } +inline uint8_t get_slpsr() { return reg_read(REG_SLPSR); } +inline void set_slcr(uint8_t v) { reg_write(REG_SLCR, v); } +inline uint8_t get_slcr() { return reg_read(REG_SLCR); } +inline uint8_t get_physr() { return reg_read(REG_PHYSR); } +inline void set_phyrar(uint8_t v) { reg_write(REG_PHYRAR, v); } +inline uint8_t get_phyrar() { return reg_read(REG_PHYRAR); } +inline void set_phydir(uint16_t v) { + reg_write(offset_inc(REG_PHYDIR, 1), (uint8_t)(v >> 8)); + reg_write(REG_PHYDIR, (uint8_t)v); } -inline uint16_t getPHYDOR() { return (((uint16_t)reg_read(offset_inc(_PHYDOR_, 1))) << 8) + reg_read(_PHYDOR_); } -inline void setPHYACR(uint8_t v) { reg_write(_PHYACR_, v); } -inline uint8_t getPHYACR() { return reg_read(_PHYACR_); } -inline void setPHYDIVR(uint8_t v) { reg_write(_PHYDIVR_, v); } -inline uint8_t getPHYDIVR() { return reg_read(_PHYDIVR_); } -inline void setPHYCR0(uint8_t v) { reg_write(_PHYCR0_, v); } -inline void setPHYCR1(uint8_t v) { reg_write(_PHYCR1_, v); } -inline uint8_t getPHYCR1() { return reg_read(_PHYCR1_); } -inline void setNET4MR(uint8_t v) { reg_write(_NET4MR_, v); } -inline void setNET6MR(uint8_t v) { reg_write(_NET6MR_, v); } -inline void setNETMR(uint8_t v) { reg_write(_NETMR_, v); } -inline void setNETMR2(uint8_t v) { reg_write(_NETMR2_, v); } -inline uint8_t getNET4MR() { return reg_read(_NET4MR_); } -inline uint8_t getNET6MR() { return reg_read(_NET6MR_); } -inline uint8_t getNETMR() { return reg_read(_NETMR_); } -inline uint8_t getNETMR2() { return reg_read(_NETMR2_); } -inline void setPTMR(uint8_t v) { reg_write(_PTMR_, v); } -inline uint8_t getPTMR() { return reg_read(_PTMR_); } -inline void setPMNR(uint8_t v) { reg_write(_PMNR_, v); } -inline uint8_t getPMNR() { return reg_read(_PMNR_); } -inline void setPHAR(uint8_t* v) { reg_write_buf(_PHAR_, v, 6); } -inline void getPHAR(uint8_t* v) { reg_read_buf(_PHAR_, v, 6); } -inline void setPSIDR(uint16_t v) { - reg_write(_PSIDR_, (uint8_t)(v >> 8)); - reg_write(offset_inc(_PSIDR_, 1), (uint8_t)v); +inline uint16_t get_phydor() { return (((uint16_t)reg_read(offset_inc(REG_PHYDOR, 1))) << 8) + reg_read(REG_PHYDOR); } +inline void set_phyacr(uint8_t v) { reg_write(REG_PHYACR, v); } +inline uint8_t get_phyacr() { return reg_read(REG_PHYACR); } +inline void set_phydivr(uint8_t v) { reg_write(REG_PHYDIVR, v); } +inline uint8_t get_phydivr() { return reg_read(REG_PHYDIVR); } +inline void set_phycr0(uint8_t v) { reg_write(REG_PHYCR0, v); } +inline void set_phycr1(uint8_t v) { reg_write(REG_PHYCR1, v); } +inline uint8_t get_phycr1() { return reg_read(REG_PHYCR1); } +inline void set_net4mr(uint8_t v) { reg_write(REG_NET4MR, v); } +inline void set_net6mr(uint8_t v) { reg_write(REG_NET6MR, v); } +inline void set_netmr(uint8_t v) { reg_write(REG_NETMR, v); } +inline void set_netmr2(uint8_t v) { reg_write(REG_NETMR2, v); } +inline uint8_t get_net4mr() { return reg_read(REG_NET4MR); } +inline uint8_t get_net6mr() { return reg_read(REG_NET6MR); } +inline uint8_t get_netmr() { return reg_read(REG_NETMR); } +inline uint8_t get_netmr2() { return reg_read(REG_NETMR2); } +inline void set_ptmr(uint8_t v) { reg_write(REG_PTMR, v); } +inline uint8_t get_ptmr() { return reg_read(REG_PTMR); } +inline void set_pmnr(uint8_t v) { reg_write(REG_PMNR, v); } +inline uint8_t get_pmnr() { return reg_read(REG_PMNR); } +inline void set_phar(uint8_t* v) { reg_write_buf(REG_PHAR, v, 6); } +inline void get_phar(uint8_t* v) { reg_read_buf(REG_PHAR, v, 6); } +inline void set_psidr(uint16_t v) { + reg_write(REG_PSIDR, (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_PSIDR, 1), (uint8_t)v); } -inline uint16_t getPSIDR() { return (((uint16_t)reg_read(_PSIDR_)) << 8) + reg_read(offset_inc(_PSIDR_, 1)); } -inline void setPMRUR(uint16_t v) { - reg_write(_PMRUR_, (uint8_t)(v >> 8)); - reg_write(offset_inc(_PMRUR_, 1), (uint8_t)v); +inline uint16_t get_psidr() { return (((uint16_t)reg_read(REG_PSIDR)) << 8) + reg_read(offset_inc(REG_PSIDR, 1)); } +inline void set_pmrur(uint16_t v) { + reg_write(REG_PMRUR, (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_PMRUR, 1), (uint8_t)v); } -inline uint16_t getPMRUR() { return (((uint16_t)reg_read(_PMRUR_)) << 8) + reg_read(offset_inc(_PMRUR_, 1)); } -inline void setSHAR(uint8_t* v) { reg_write_buf(_SHAR_, v, 6); } -inline void getSHAR(uint8_t* v) { reg_read_buf(_SHAR_, v, 6); } -inline void setGAR(uint8_t* v) { reg_write_buf(_GAR_, v, 4); } -inline void getGAR(uint8_t* v) { reg_read_buf(_GAR_, v, 4); } -inline void setGA4R(uint8_t* v) { setGAR(v); } -inline void getGA4R(uint8_t* v) { getGAR(v); } -inline void setSUBR(uint8_t* v) { reg_write_buf(_SUBR_, v, 4); } -inline void getSUBR(uint8_t* v) { reg_read_buf(_SUBR_, v, 4); } -inline void setSUB4R(uint8_t* v) { setSUBR(v); } -inline void getSUB4R(uint8_t* v) { getSUBR(v); } -inline void setSIPR(uint8_t* v) { reg_write_buf(_SIPR_, v, 4); } -inline void getSIPR(uint8_t* v) { reg_read_buf(_SIPR_, v, 4); } -inline void setLLAR(uint8_t* v) { reg_write_buf(_LLAR_, v, 16); } -inline void getLLAR(uint8_t* v) { reg_read_buf(_LLAR_, v, 16); } -inline void setGUAR(uint8_t* v) { reg_write_buf(_GUAR_, v, 16); } -inline void getGUAR(uint8_t* v) { reg_read_buf(_GUAR_, v, 16); } -inline void setSUB6R(uint8_t* v) { reg_write_buf(_SUB6R_, v, 16); } -inline void getSUB6R(uint8_t* v) { reg_read_buf(_SUB6R_, v, 16); } -inline void setGA6R(uint8_t* v) { reg_write_buf(_GA6R_, v, 16); } -inline void getGA6R(uint8_t* v) { reg_read_buf(_GA6R_, v, 16); } -inline void setSLDIPR(uint8_t* v) { reg_write_buf(_SLDIPR_, v, 4); } -inline void setSLDIP4R(uint8_t* v) { setSLDIPR(v); } -inline void getSLDIPR(uint8_t* v) { reg_read_buf(_SLDIPR_, v, 4); } -inline void getSLDIP4R(uint8_t* v) { getSLDIPR(v); } -inline void setSLDIP6R(uint8_t* v) { reg_write_buf(_SLDIP6R_, v, 16); } -inline void getSLDIP6R(uint8_t* v) { reg_read_buf(_SLDIP6R_, v, 16); } -inline void getSLDHAR(uint8_t* v) { reg_read_buf(_SLDHAR_, v, 6); } -inline void setPINGIDR(uint16_t v) { - reg_write(_PINGIDR_, (uint8_t)(v >> 8)); - reg_write(offset_inc(_PINGIDR_, 1), (uint8_t)v); +inline uint16_t get_pmrur() { return (((uint16_t)reg_read(REG_PMRUR)) << 8) + reg_read(offset_inc(REG_PMRUR, 1)); } +inline void set_shar(uint8_t* v) { reg_write_buf(REG_SHAR, v, 6); } +inline void get_shar(uint8_t* v) { reg_read_buf(REG_SHAR, v, 6); } +inline void set_gar(uint8_t* v) { reg_write_buf(REG_GAR, v, 4); } +inline void get_gar(uint8_t* v) { reg_read_buf(REG_GAR, v, 4); } +inline void set_ga4r(uint8_t* v) { set_gar(v); } +inline void get_ga4r(uint8_t* v) { get_gar(v); } +inline void set_subr(uint8_t* v) { reg_write_buf(REG_SUBR, v, 4); } +inline void get_subr(uint8_t* v) { reg_read_buf(REG_SUBR, v, 4); } +inline void set_sub4r(uint8_t* v) { set_subr(v); } +inline void get_sub4r(uint8_t* v) { get_subr(v); } +inline void set_sipr(uint8_t* v) { reg_write_buf(REG_SIPR, v, 4); } +inline void get_sipr(uint8_t* v) { reg_read_buf(REG_SIPR, v, 4); } +inline void set_llar(uint8_t* v) { reg_write_buf(REG_LLAR, v, 16); } +inline void get_llar(uint8_t* v) { reg_read_buf(REG_LLAR, v, 16); } +inline void set_guar(uint8_t* v) { reg_write_buf(REG_GUAR, v, 16); } +inline void get_guar(uint8_t* v) { reg_read_buf(REG_GUAR, v, 16); } +inline void set_sub6r(uint8_t* v) { reg_write_buf(REG_SUB6R, v, 16); } +inline void get_sub6r(uint8_t* v) { reg_read_buf(REG_SUB6R, v, 16); } +inline void set_ga6r(uint8_t* v) { reg_write_buf(REG_GA6R, v, 16); } +inline void get_ga6r(uint8_t* v) { reg_read_buf(REG_GA6R, v, 16); } +inline void set_sldipr(uint8_t* v) { reg_write_buf(REG_SLDIPR, v, 4); } +inline void set_sldip4r(uint8_t* v) { set_sldipr(v); } +inline void get_sldipr(uint8_t* v) { reg_read_buf(REG_SLDIPR, v, 4); } +inline void get_sldip4r(uint8_t* v) { get_sldipr(v); } +inline void set_sldip6r(uint8_t* v) { reg_write_buf(REG_SLDIP6R, v, 16); } +inline void get_sldip6r(uint8_t* v) { reg_read_buf(REG_SLDIP6R, v, 16); } +inline void get_sldhar(uint8_t* v) { reg_read_buf(REG_SLDHAR, v, 6); } +inline void set_pingidr(uint16_t v) { + reg_write(REG_PINGIDR, (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_PINGIDR, 1), (uint8_t)v); } -inline uint16_t getPINGIDR() { return ((uint16_t)(reg_read(_PINGIDR_) << 8)) + reg_read(offset_inc(_PINGIDR_, 1)); } -inline void setPINGSEQR(uint16_t v) { - reg_write(_PINGSEQR_, (uint8_t)(v >> 8)); - reg_write(offset_inc(_PINGSEQR_, 1), (uint8_t)v); +inline uint16_t get_pingidr() { return ((uint16_t)(reg_read(REG_PINGIDR) << 8)) + reg_read(offset_inc(REG_PINGIDR, 1)); } +inline void set_pingseqr(uint16_t v) { + reg_write(REG_PINGSEQR, (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_PINGSEQR, 1), (uint8_t)v); } -inline uint16_t getPINGSEQR() { return ((uint16_t)(reg_read(_PINGSEQR_) << 8)) + reg_read(offset_inc(_PINGSEQR_, 1)); } -inline void getUIPR(uint8_t* v) { reg_read_buf(_UIPR_, v, 4); } -inline void getUIP4R(uint8_t* v) { getUIPR(v); } -inline uint16_t getUPORTR() { return (((uint16_t)reg_read(_UPORTR_)) << 8) + reg_read(offset_inc(_UPORTR_, 1)); } -inline uint16_t getUPORT4R() { return getUPORTR(); } -inline void getUIP6R(uint8_t* v) { reg_read_buf(_UIP6R_, v, 16); } -inline uint16_t getUPORT6R() { return (((uint16_t)reg_read(_UPORT6R_)) << 8) + reg_read(offset_inc(_UPORT6R_, 1)); } -inline void setINTPTMR(uint16_t v) { - reg_write(_INTPTMR_, (uint8_t)(v >> 8)); - reg_write(offset_inc(_INTPTMR_, 1), (uint8_t)v); +inline uint16_t get_pingseqr() { return ((uint16_t)(reg_read(REG_PINGSEQR) << 8)) + reg_read(offset_inc(REG_PINGSEQR, 1)); } +inline void get_uipr(uint8_t* v) { reg_read_buf(REG_UIPR, v, 4); } +inline void get_uip4r(uint8_t* v) { get_uipr(v); } +inline uint16_t get_uportr() { return (((uint16_t)reg_read(REG_UPORTR)) << 8) + reg_read(offset_inc(REG_UPORTR, 1)); } +inline uint16_t get_uport4r() { return get_uportr(); } +inline void get_uip6r(uint8_t* v) { reg_read_buf(REG_UIP6R, v, 16); } +inline uint16_t get_uport6r() { return (((uint16_t)reg_read(REG_UPORT6R)) << 8) + reg_read(offset_inc(REG_UPORT6R, 1)); } +inline void set_intptmr(uint16_t v) { + reg_write(REG_INTPTMR, (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_INTPTMR, 1), (uint8_t)v); } -inline uint16_t getINTPTMR() { return (((uint16_t)reg_read(_INTPTMR_)) << 8) + reg_read(offset_inc(_INTPTMR_, 1)); } -inline uint8_t getPLR() { return reg_read(_PLR_); } -inline uint8_t getPFR() { return reg_read(_PFR_); } -inline uint32_t getVLTR() { - return (((uint32_t)reg_read(_VLTR_)) << 24) + - (((uint32_t)reg_read(offset_inc(_VLTR_, 1))) << 16) + - (((uint32_t)reg_read(offset_inc(_VLTR_, 2))) << 8) + - ((uint32_t)reg_read(offset_inc(_VLTR_, 3))); +inline uint16_t get_intptmr() { return (((uint16_t)reg_read(REG_INTPTMR)) << 8) + reg_read(offset_inc(REG_INTPTMR, 1)); } +inline uint8_t get_plr() { return reg_read(REG_PLR); } +inline uint8_t get_pfr() { return reg_read(REG_PFR); } +inline uint32_t get_vltr() { + return (((uint32_t)reg_read(REG_VLTR)) << 24) + + (((uint32_t)reg_read(offset_inc(REG_VLTR, 1))) << 16) + + (((uint32_t)reg_read(offset_inc(REG_VLTR, 2))) << 8) + + ((uint32_t)reg_read(offset_inc(REG_VLTR, 3))); } -inline uint32_t getPLTR() { - return (((uint32_t)reg_read(_PLTR_)) << 24) + - (((uint32_t)reg_read(offset_inc(_PLTR_, 1))) << 16) + - (((uint32_t)reg_read(offset_inc(_PLTR_, 2))) << 8) + - ((uint32_t)reg_read(offset_inc(_PLTR_, 3))); +inline uint32_t get_pltr() { + return (((uint32_t)reg_read(REG_PLTR)) << 24) + + (((uint32_t)reg_read(offset_inc(REG_PLTR, 1))) << 16) + + (((uint32_t)reg_read(offset_inc(REG_PLTR, 2))) << 8) + + ((uint32_t)reg_read(offset_inc(REG_PLTR, 3))); } -inline void getPAR(uint8_t* v) { reg_read_buf(_PAR_, v, 16); } -inline void setICMP6BLKR(uint8_t v) { reg_write(_ICMP6BLKR_, v); } -inline uint8_t getICMP6BLKR() { return reg_read(_ICMP6BLKR_); } -inline void setCHPLCKR(uint8_t v) { reg_write(_CHPLCKR_, v); } -inline uint8_t getCHPLCKR() { return (getSYSR() & SYSR_CHPL) >> 7; } -inline void CHIPLOCK() { setCHPLCKR(0xFF); } -inline void CHIPUNLOCK() { setCHPLCKR(0xCE); } -inline void setNETLCKR(uint8_t v) { reg_write(_NETLCKR_, v); } -inline uint8_t getNETLCKR() { return (getSYSR() & SYSR_NETL) >> 6; } -inline void NETLOCK() { setNETLCKR(0xC5); } -inline void NETUNLOCK() { setNETLCKR(0x3A); } -inline void setPHYLCKR(uint8_t v) { reg_write(_PHYLCKR_, v); } -inline uint8_t getPHYLCKR() { return (getSYSR() & SYSR_PHYL) >> 5; } -inline void PHYLOCK() { setPHYLCKR(0xFF); } -inline void PHYUNLOCK() { setPHYLCKR(0x53); } -inline void setRTR(uint16_t v) { - reg_write(_RTR_, (uint8_t)(v >> 8)); - reg_write(offset_inc(_RTR_, 1), (uint8_t)v); +inline void get_par(uint8_t* v) { reg_read_buf(REG_PAR, v, 16); } +inline void set_icmp6blkr(uint8_t v) { reg_write(REG_ICMP6BLKR, v); } +inline uint8_t get_icmp6blkr() { return reg_read(REG_ICMP6BLKR); } +inline void set_chplckr(uint8_t v) { reg_write(REG_CHPLCKR, v); } +inline uint8_t get_chplckr() { return (get_sysr() & SYSR_CHPL) >> 7; } +inline void chip_lock() { set_chplckr(0xFF); } +inline void chip_unlock() { set_chplckr(0xCE); } +inline void set_netlckr(uint8_t v) { reg_write(REG_NETLCKR, v); } +inline uint8_t get_netlckr() { return (get_sysr() & SYSR_NETL) >> 6; } +inline void net_lock() { set_netlckr(0xC5); } +inline void net_unlock() { set_netlckr(0x3A); } +inline void set_phylckr(uint8_t v) { reg_write(REG_PHYLCKR, v); } +inline uint8_t get_phylckr() { return (get_sysr() & SYSR_PHYL) >> 5; } +inline void phy_lock() { set_phylckr(0xFF); } +inline void phy_unlock() { set_phylckr(0x53); } +inline void set_rtr(uint16_t v) { + reg_write(REG_RTR, (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_RTR, 1), (uint8_t)v); } -inline uint16_t getRTR() { return (((uint16_t)reg_read(_RTR_)) << 8) + reg_read(offset_inc(_RTR_, 1)); } -inline void setRCR(uint8_t v) { reg_write(_RCR_, v); } -inline uint8_t getRCR() { return reg_read(_RCR_); } -inline void setSLRTR(uint16_t v) { - reg_write(_SLRTR_, (uint8_t)(v >> 8)); - reg_write(offset_inc(_SLRTR_, 1), (uint8_t)v); +inline uint16_t get_rtr() { return (((uint16_t)reg_read(REG_RTR)) << 8) + reg_read(offset_inc(REG_RTR, 1)); } +inline void set_rcr(uint8_t v) { reg_write(REG_RCR, v); } +inline uint8_t get_rcr() { return reg_read(REG_RCR); } +inline void set_slrtr(uint16_t v) { + reg_write(REG_SLRTR, (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_SLRTR, 1), (uint8_t)v); } -inline uint16_t getSLRTR() { return (((uint16_t)reg_read(_SLRTR_)) << 8) + reg_read(offset_inc(_SLRTR_, 1)); } -inline void setSLRCR(uint8_t v) { reg_write(_SLRCR_, v); } -inline uint8_t getSLRCR() { return reg_read(_SLRCR_); } -inline void setSLHOPR(uint8_t v) { reg_write(_SLHOPR_, v); } -inline uint8_t getSLHOPR() { return reg_read(_SLHOPR_); } +inline uint16_t get_slrtr() { return (((uint16_t)reg_read(REG_SLRTR)) << 8) + reg_read(offset_inc(REG_SLRTR, 1)); } +inline void set_slrcr(uint8_t v) { reg_write(REG_SLRCR, v); } +inline uint8_t get_slrcr() { return reg_read(REG_SLRCR); } +inline void set_slhopr(uint8_t v) { reg_write(REG_SLHOPR, v); } +inline uint8_t get_slhopr() { return reg_read(REG_SLHOPR); } -inline void setSn_MR(uint8_t sn, uint8_t v) { reg_write(_Sn_MR_(sn), v); } -inline uint8_t getSn_MR(uint8_t sn) { return reg_read(_Sn_MR_(sn)); } -inline void setSn_PSR(uint8_t sn, uint8_t v) { reg_write(_Sn_PSR_(sn), v); } -inline uint8_t getSn_PSR(uint8_t sn) { return reg_read(_Sn_PSR_(sn)); } -inline void setSn_CR(uint8_t sn, uint8_t v) { reg_write(_Sn_CR_(sn), v); } -inline uint8_t getSn_CR(uint8_t sn) { return reg_read(_Sn_CR_(sn)); } -inline uint8_t getSn_IR(uint8_t sn) { return reg_read(_Sn_IR_(sn)); } -inline void setSn_IMR(uint8_t sn, uint8_t v) { reg_write(_Sn_IMR_(sn), v); } -inline uint8_t getSn_IMR(uint8_t sn) { return reg_read(_Sn_IMR_(sn)); } -inline void setSn_IRCLR(uint8_t sn, uint8_t v) { reg_write(_Sn_IRCLR_(sn), v); } -inline void setSn_IR(uint8_t sn, uint8_t v) { setSn_IRCLR(sn, v); } -inline uint8_t getSn_SR(uint8_t sn) { return reg_read(_Sn_SR_(sn)); } -inline uint8_t getSn_ESR(uint8_t sn) { return reg_read(_Sn_ESR_(sn)); } -inline void setSn_PNR(uint8_t sn, uint8_t v) { reg_write(_Sn_PNR_(sn), v); } -inline void setSn_NHR(uint8_t sn, uint8_t v) { setSn_PNR(sn, v); } -inline uint8_t getSn_PNR(uint8_t sn) { return reg_read(_Sn_PNR_(sn)); } -inline uint8_t getSn_NHR(uint8_t sn) { return getSn_PNR(sn); } -inline void setSn_TOSR(uint8_t sn, uint8_t v) { reg_write(_Sn_TOSR_(sn), v); } -inline uint8_t getSn_TOSR(uint8_t sn) { return reg_read(_Sn_TOSR_(sn)); } -inline uint8_t getSn_TOS(uint8_t sn) { return getSn_TOSR(sn); } -inline void setSn_TOS(uint8_t sn, uint8_t v) { setSn_TOSR(sn, v); } -inline void setSn_TTLR(uint8_t sn, uint8_t v) { reg_write(_Sn_TTLR_(sn), v); } -inline uint8_t getSn_TTLR(uint8_t sn) { return reg_read(_Sn_TTLR_(sn)); } -inline void setSn_TTL(uint8_t sn, uint8_t v) { setSn_TTLR(sn, v); } -inline uint8_t getSn_TTL(uint8_t sn) { return getSn_TTLR(sn); } -inline void setSn_HOPR(uint8_t sn, uint8_t v) { setSn_TTLR(sn, v); } -inline uint8_t getSn_HOPR(uint8_t sn) { return getSn_TTLR(sn); } -inline void setSn_FRGR(uint8_t sn, uint16_t v) { - reg_write(_Sn_FRGR_(sn), (uint8_t)(v >> 8)); - reg_write(offset_inc(_Sn_FRGR_(sn), 1), (uint8_t)v); +inline void set_sn_mr(uint8_t sn, uint8_t v) { reg_write(REG_SN_MR(sn), v); } +inline uint8_t get_sn_mr(uint8_t sn) { return reg_read(REG_SN_MR(sn)); } +inline void set_sn_psr(uint8_t sn, uint8_t v) { reg_write(REG_SN_PSR(sn), v); } +inline uint8_t get_sn_psr(uint8_t sn) { return reg_read(REG_SN_PSR(sn)); } +inline void set_sn_cr(uint8_t sn, uint8_t v) { reg_write(REG_SN_CR(sn), v); } +inline uint8_t get_sn_cr(uint8_t sn) { return reg_read(REG_SN_CR(sn)); } +inline uint8_t get_sn_ir(uint8_t sn) { return reg_read(_SnREG_IR(sn)); } +inline void set_sn_imr(uint8_t sn, uint8_t v) { reg_write(_SnREG_IMR(sn), v); } +inline uint8_t get_sn_imr(uint8_t sn) { return reg_read(_SnREG_IMR(sn)); } +inline void set_sn_irclr(uint8_t sn, uint8_t v) { reg_write(_SnREG_IRCLR(sn), v); } +inline void set_sn_ir(uint8_t sn, uint8_t v) { set_sn_irclr(sn, v); } +inline uint8_t get_sn_sr(uint8_t sn) { return reg_read(REG_SN_SR(sn)); } +inline uint8_t get_sn_esr(uint8_t sn) { return reg_read(REG_SN_ESR(sn)); } +inline void set_sn_pnr(uint8_t sn, uint8_t v) { reg_write(REG_SN_PNR(sn), v); } +inline void set_sn_nhr(uint8_t sn, uint8_t v) { set_sn_pnr(sn, v); } +inline uint8_t get_sn_pnr(uint8_t sn) { return reg_read(REG_SN_PNR(sn)); } +inline uint8_t get_sn_nhr(uint8_t sn) { return get_sn_pnr(sn); } +inline void set_sn_tosr(uint8_t sn, uint8_t v) { reg_write(REG_SN_TOSR(sn), v); } +inline uint8_t get_sn_tosr(uint8_t sn) { return reg_read(REG_SN_TOSR(sn)); } +inline uint8_t get_sn_tos(uint8_t sn) { return get_sn_tosr(sn); } +inline void set_sn_tos(uint8_t sn, uint8_t v) { set_sn_tosr(sn, v); } +inline void set_sn_ttlr(uint8_t sn, uint8_t v) { reg_write(REG_SN_TTLR(sn), v); } +inline uint8_t get_sn_ttlr(uint8_t sn) { return reg_read(REG_SN_TTLR(sn)); } +inline void set_sn_ttl(uint8_t sn, uint8_t v) { set_sn_ttlr(sn, v); } +inline uint8_t get_sn_ttl(uint8_t sn) { return get_sn_ttlr(sn); } +inline void set_sn_hopr(uint8_t sn, uint8_t v) { set_sn_ttlr(sn, v); } +inline uint8_t get_sn_hopr(uint8_t sn) { return get_sn_ttlr(sn); } +inline void set_sn_frgr(uint8_t sn, uint16_t v) { + reg_write(REG_SN_FRGR(sn), (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_SN_FRGR(sn), 1), (uint8_t)v); } -inline uint16_t getSn_FRGR(uint8_t sn) { return (((uint16_t)reg_read(_Sn_FRGR_(sn))) << 8) + reg_read(offset_inc(_Sn_FRGR_(sn), 1)); } -inline void setSn_MSSR(uint8_t sn, uint16_t v) { - reg_write(_Sn_MSSR_(sn), (uint8_t)(v >> 8)); - reg_write(offset_inc(_Sn_MSSR_(sn), 1), (uint8_t)v); +inline uint16_t get_sn_frgr(uint8_t sn) { return (((uint16_t)reg_read(REG_SN_FRGR(sn))) << 8) + reg_read(offset_inc(REG_SN_FRGR(sn), 1)); } +inline void set_sn_mssr(uint8_t sn, uint16_t v) { + reg_write(REG_SN_MSSR(sn), (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_SN_MSSR(sn), 1), (uint8_t)v); } -inline uint16_t getSn_MSSR(uint8_t sn) { return (((uint16_t)reg_read(_Sn_MSSR_(sn))) << 8) + reg_read(offset_inc(_Sn_MSSR_(sn), 1)); } -inline void setSn_PORTR(uint8_t sn, uint16_t v) { - reg_write(_Sn_PORTR_(sn), (uint8_t)(v >> 8)); - reg_write(offset_inc(_Sn_PORTR_(sn), 1), (uint8_t)v); +inline uint16_t get_sn_mssr(uint8_t sn) { return (((uint16_t)reg_read(REG_SN_MSSR(sn))) << 8) + reg_read(offset_inc(REG_SN_MSSR(sn), 1)); } +inline void set_sn_portr(uint8_t sn, uint16_t v) { + reg_write(REG_SN_PORTR(sn), (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_SN_PORTR(sn), 1), (uint8_t)v); } -inline uint16_t getSn_PORTR(uint8_t sn) { return (((uint16_t)reg_read(_Sn_PORTR_(sn))) << 8) + reg_read(offset_inc(_Sn_PORTR_(sn), 1)); } -inline void setSn_DHAR(uint8_t sn, uint8_t* v) { reg_write_buf(_Sn_DHAR_(sn), v, 6); } -inline void getSn_DHAR(uint8_t sn, uint8_t* v) { reg_read_buf(_Sn_DHAR_(sn), v, 6); } -inline void setSn_DIPR(uint8_t sn, uint8_t* v) { reg_write_buf(_Sn_DIPR_(sn), v, 4); } -inline void getSn_DIPR(uint8_t sn, uint8_t* v) { reg_read_buf(_Sn_DIPR_(sn), v, 4); } -inline void setSn_DIP4R(uint8_t sn, uint8_t* v) { setSn_DIPR(sn, v); } -inline void getSn_DIP4R(uint8_t sn, uint8_t* v) { getSn_DIPR(sn, v); } -inline void setSn_DIP6R(uint8_t sn, uint8_t* v) { reg_write_buf(_Sn_DIP6R_(sn), v, 16); } -inline void getSn_DIP6R(uint8_t sn, uint8_t* v) { reg_read_buf(_Sn_DIP6R_(sn), v, 16); } -inline void setSn_DPORTR(uint8_t sn, uint16_t v) { - reg_write(_Sn_DPORTR_(sn), (uint8_t)(v >> 8)); - reg_write(offset_inc(_Sn_DPORTR_(sn), 1), (uint8_t)v); +inline uint16_t get_sn_portr(uint8_t sn) { return (((uint16_t)reg_read(REG_SN_PORTR(sn))) << 8) + reg_read(offset_inc(REG_SN_PORTR(sn), 1)); } +inline void set_sn_dhar(uint8_t sn, uint8_t* v) { reg_write_buf(REG_SN_DHAR(sn), v, 6); } +inline void get_sn_dhar(uint8_t sn, uint8_t* v) { reg_read_buf(REG_SN_DHAR(sn), v, 6); } +inline void set_sn_dipr(uint8_t sn, uint8_t* v) { reg_write_buf(REG_SN_DIPR(sn), v, 4); } +inline void get_sn_dipr(uint8_t sn, uint8_t* v) { reg_read_buf(REG_SN_DIPR(sn), v, 4); } +inline void set_sn_dip4r(uint8_t sn, uint8_t* v) { set_sn_dipr(sn, v); } +inline void get_sn_dip4r(uint8_t sn, uint8_t* v) { get_sn_dipr(sn, v); } +inline void set_sn_dip6r(uint8_t sn, uint8_t* v) { reg_write_buf(REG_SN_DIP6R(sn), v, 16); } +inline void get_sn_dip6r(uint8_t sn, uint8_t* v) { reg_read_buf(REG_SN_DIP6R(sn), v, 16); } +inline void set_sn_dportr(uint8_t sn, uint16_t v) { + reg_write(REG_SN_DPORTR(sn), (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_SN_DPORTR(sn), 1), (uint8_t)v); } -inline uint16_t getSn_DPORTR(uint8_t sn) { return (((uint16_t)reg_read(_Sn_DPORTR_(sn))) << 8) + reg_read(offset_inc(_Sn_DPORTR_(sn), 1)); } -inline uint16_t getSn_DPORT(uint8_t sn) { return getSn_DPORTR(sn); } -inline void setSn_DPORT(uint8_t sn, uint16_t v) { setSn_DPORTR(sn, v); } -inline void setSn_MR2(uint8_t sn, uint8_t v) { reg_write(_Sn_MR2_(sn), v); } -inline uint8_t getSn_MR2(uint8_t sn) { return reg_read(_Sn_MR2_(sn)); } -inline void setSn_RTR(uint8_t sn, uint16_t v) { - reg_write(_Sn_RTR_(sn), (uint8_t)(v >> 8)); - reg_write(offset_inc(_Sn_RTR_(sn), 1), (uint8_t)v); +inline uint16_t get_sn_dportr(uint8_t sn) { return (((uint16_t)reg_read(REG_SN_DPORTR(sn))) << 8) + reg_read(offset_inc(REG_SN_DPORTR(sn), 1)); } +inline uint16_t get_sn_dport(uint8_t sn) { return get_sn_dportr(sn); } +inline void set_sn_dport(uint8_t sn, uint16_t v) { set_sn_dportr(sn, v); } +inline void set_sn_mr2(uint8_t sn, uint8_t v) { reg_write(REG_SN_MR2(sn), v); } +inline uint8_t get_sn_mr2(uint8_t sn) { return reg_read(REG_SN_MR2(sn)); } +inline void set_sn_rtr(uint8_t sn, uint16_t v) { + reg_write(_SnREG_RTR(sn), (uint8_t)(v >> 8)); + reg_write(offset_inc(_SnREG_RTR(sn), 1), (uint8_t)v); } -inline uint16_t getSn_RTR(uint8_t sn) { return (((uint16_t)reg_read(_Sn_RTR_(sn))) << 8) + reg_read(offset_inc(_Sn_RTR_(sn), 1)); } -inline void setSn_RCR(uint8_t sn, uint8_t v) { reg_write(_Sn_RCR_(sn), v); } -inline uint8_t getSn_RCR(uint8_t sn) { return reg_read(_Sn_RCR_(sn)); } -inline void setSn_KPALVTR(uint8_t sn, uint8_t v) { reg_write(_Sn_KPALVTR_(sn), v); } -inline uint8_t getSn_KPALVTR(uint8_t sn) { return reg_read(_Sn_KPALVTR_(sn)); } -inline void setSn_TX_BSR(uint8_t sn, uint8_t v) { reg_write(_Sn_TX_BSR_(sn), v); } -inline void setSn_TXBUF_SIZE(uint8_t sn, uint8_t v) { setSn_TX_BSR(sn, v); } -inline uint8_t getSn_TX_BSR(uint8_t sn) { return reg_read(_Sn_TX_BSR_(sn)); } -inline uint8_t getSn_TXBUF_SIZE(uint8_t sn) { return getSn_TX_BSR(sn); } -inline uint16_t getSn_TxMAX(uint8_t sn) { return getSn_TX_BSR(sn) << 10; } +inline uint16_t get_sn_rtr(uint8_t sn) { return (((uint16_t)reg_read(_SnREG_RTR(sn))) << 8) + reg_read(offset_inc(_SnREG_RTR(sn), 1)); } +inline void set_sn_rcr(uint8_t sn, uint8_t v) { reg_write(_SnREG_RCR(sn), v); } +inline uint8_t get_sn_rcr(uint8_t sn) { return reg_read(_SnREG_RCR(sn)); } +inline void set_sn_kpalvtr(uint8_t sn, uint8_t v) { reg_write(REG_SN_KPALVTR(sn), v); } +inline uint8_t get_sn_kpalvtr(uint8_t sn) { return reg_read(REG_SN_KPALVTR(sn)); } +inline void set_sn_tx_bsr(uint8_t sn, uint8_t v) { reg_write(REG_SN_TX_BSR(sn), v); } +inline void set_sn_txbuf_size(uint8_t sn, uint8_t v) { set_sn_tx_bsr(sn, v); } +inline uint8_t get_sn_tx_bsr(uint8_t sn) { return reg_read(REG_SN_TX_BSR(sn)); } +inline uint8_t get_sn_txbuf_size(uint8_t sn) { return get_sn_tx_bsr(sn); } +inline uint16_t get_sn_tx_max(uint8_t sn) { return get_sn_tx_bsr(sn) << 10; } -inline uint16_t getSn_TX_RD(uint8_t sn) { return (((uint16_t)reg_read(_Sn_TX_RD_(sn))) << 8) + reg_read(offset_inc(_Sn_TX_RD_(sn), 1)); } -inline void setSn_TX_WR(uint8_t sn, uint16_t v) { - reg_write(_Sn_TX_WR_(sn), (uint8_t)(v >> 8)); - reg_write(offset_inc(_Sn_TX_WR_(sn), 1), (uint8_t)v); +inline uint16_t get_sn_tx_rd(uint8_t sn) { return (((uint16_t)reg_read(REG_SN_TX_RD(sn))) << 8) + reg_read(offset_inc(REG_SN_TX_RD(sn), 1)); } +inline void set_sn_tx_wr(uint8_t sn, uint16_t v) { + reg_write(REG_SN_TX_WR(sn), (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_SN_TX_WR(sn), 1), (uint8_t)v); } -inline uint16_t getSn_TX_WR(uint8_t sn) { return ((uint16_t)reg_read(_Sn_TX_WR_(sn)) << 8) + reg_read(offset_inc(_Sn_TX_WR_(sn), 1)); } -inline void setSn_RX_BSR(uint8_t sn, uint8_t v) { reg_write(_Sn_RX_BSR_(sn), v); } -inline void setSn_RXBUF_SIZE(uint8_t sn, uint8_t v) { setSn_RX_BSR(sn, v); } -inline uint8_t getSn_RX_BSR(uint8_t sn) { return reg_read(_Sn_RX_BSR_(sn)); } -inline uint8_t getSn_RXBUF_SIZE(uint8_t sn) { return getSn_RX_BSR(sn); } -inline uint16_t getSn_RxMAX(uint8_t sn) { return getSn_RX_BSR(sn) << 10; } +inline uint16_t get_sn_tx_wr(uint8_t sn) { return ((uint16_t)reg_read(REG_SN_TX_WR(sn)) << 8) + reg_read(offset_inc(REG_SN_TX_WR(sn), 1)); } +inline void set_sn_rx_bsr(uint8_t sn, uint8_t v) { reg_write(REG_SN_RX_BSR(sn), v); } +inline void set_sn_rxbuf_size(uint8_t sn, uint8_t v) { set_sn_rx_bsr(sn, v); } +inline uint8_t get_sn_rx_bsr(uint8_t sn) { return reg_read(REG_SN_RX_BSR(sn)); } +inline uint8_t get_sn_rxbuf_size(uint8_t sn) { return get_sn_rx_bsr(sn); } +inline uint16_t get_sn_rx_max(uint8_t sn) { return get_sn_rx_bsr(sn) << 10; } -inline void setSn_RX_RD(uint8_t sn, uint16_t v) { - reg_write(_Sn_RX_RD_(sn), (uint8_t)(v >> 8)); - reg_write(offset_inc(_Sn_RX_RD_(sn), 1), (uint8_t)v); +inline void set_sn_rx_rd(uint8_t sn, uint16_t v) { + reg_write(REG_SN_RX_RD(sn), (uint8_t)(v >> 8)); + reg_write(offset_inc(REG_SN_RX_RD(sn), 1), (uint8_t)v); } -inline uint16_t getSn_RX_RD(uint8_t sn) { return ((uint16_t)reg_read(_Sn_RX_RD_(sn)) << 8) + reg_read(offset_inc(_Sn_RX_RD_(sn), 1)); } -inline uint16_t getSn_RX_WR(uint8_t sn) { return ((uint16_t)reg_read(_Sn_RX_WR_(sn)) << 8) + reg_read(offset_inc(_Sn_RX_WR_(sn), 1)); } +inline uint16_t get_sn_rx_rd(uint8_t sn) { return ((uint16_t)reg_read(REG_SN_RX_RD(sn)) << 8) + reg_read(offset_inc(REG_SN_RX_RD(sn), 1)); } +inline uint16_t get_sn_rx_wr(uint8_t sn) { return ((uint16_t)reg_read(REG_SN_RX_WR(sn)) << 8) + reg_read(offset_inc(REG_SN_RX_WR(sn), 1)); } static critical_section_t g_cris_sec; void cris_enter() { @@ -831,7 +831,7 @@ void cris_exit() { } static uint8_t make_opcode(uint32_t addr, uint8_t rw) { - return static_cast((addr & 0xFF) | rw | _WIZCHIP_QSPI_MODE_); + return static_cast((addr & 0xFF) | rw | QSPI_MODE); } static uint16_t make_addr(uint32_t addr) { @@ -872,60 +872,60 @@ void reg_read_buf(uint32_t AddrSel, uint8_t* pBuf, datasize_t len) { cris_exit(); } -uint16_t getSn_TX_FSR(uint8_t sn) { +uint16_t get_sn_tx_fsr(uint8_t sn) { uint16_t prev_val = -1, val = 0; do { prev_val = val; - val = reg_read(_Sn_TX_FSR_(sn)); - val = (val << 8) + reg_read(offset_inc(_Sn_TX_FSR_(sn), 1)); + val = reg_read(REG_SN_TX_FSR(sn)); + val = (val << 8) + reg_read(offset_inc(REG_SN_TX_FSR(sn), 1)); } while (val != prev_val); return val; } -uint16_t getSn_RX_RSR(uint8_t sn) { +uint16_t get_sn_rx_rsr(uint8_t sn) { uint16_t prev_val = -1, val = 0; do { prev_val = val; - val = reg_read(_Sn_RX_RSR_(sn)); - val = (val << 8) + reg_read(offset_inc(_Sn_RX_RSR_(sn), 1)); + val = reg_read(REG_SN_RX_RSR(sn)); + val = (val << 8) + reg_read(offset_inc(REG_SN_RX_RSR(sn), 1)); } while (val != prev_val); return val; } void send_data(uint8_t sn, uint8_t *data, uint16_t len) { - uint16_t ptr = getSn_TX_WR(sn); + uint16_t ptr = get_sn_tx_wr(sn); uint32_t addrsel = ((uint32_t)ptr << 8) + TXBUF_BLOCK(sn); reg_write_buf(addrsel, data, len); ptr += len; - setSn_TX_WR(sn, ptr); + set_sn_tx_wr(sn, ptr); } void recv_data(uint8_t sn, uint8_t *data, uint16_t len) { if (len == 0) return; - uint16_t ptr = getSn_RX_RD(sn); + uint16_t ptr = get_sn_rx_rd(sn); uint32_t addrsel = ((uint32_t)ptr << 8) + RXBUF_BLOCK(sn); reg_read_buf(addrsel, data, len); ptr += len; - setSn_RX_RD(sn, ptr); + set_sn_rx_rd(sn, ptr); } void recv_ignore(uint8_t sn, uint16_t len) { - setSn_RX_RD(sn, getSn_RX_RD(sn) + len); + set_sn_rx_rd(sn, get_sn_rx_rd(sn) + len); } void mdio_write(uint8_t phyregaddr, uint16_t var) { - setPHYRAR(phyregaddr); - setPHYDIR(var); - setPHYACR(PHYACR_WRITE); - while (getPHYACR()); + set_phyrar(phyregaddr); + set_phydir(var); + set_phyacr(PHYACR_WRITE); + while (get_phyacr()); } uint16_t mdio_read(uint8_t phyregaddr) { - setPHYRAR(phyregaddr); - setPHYACR(PHYACR_READ); - while (getPHYACR()); - return getPHYDOR(); + set_phyrar(phyregaddr); + set_phyacr(PHYACR_READ); + while (get_phyacr()); + return get_phydor(); } } // namespace @@ -940,20 +940,20 @@ static constexpr char CHIP_ID[] = "W6300"; void soft_reset() { uint8_t gw[4], sn[4], sip[4], mac[6]; uint8_t gw6[16], sn6[16], lla[16], gua[16]; - uint8_t islock = getSYSR(); + uint8_t islock = get_sysr(); - CHIPUNLOCK(); - getSHAR(mac); getGAR(gw); getSUBR(sn); getSIPR(sip); - getGA6R(gw6); getSUB6R(sn6); getLLAR(lla); getGUAR(gua); - setSYCR0(SYCR0_RST); - getSYCR0(); + chip_unlock(); + get_shar(mac); get_gar(gw); get_subr(sn); get_sipr(sip); + get_ga6r(gw6); get_sub6r(sn6); get_llar(lla); get_guar(gua); + set_sycr0(SYCR0_RST); + get_sycr0(); - NETUNLOCK(); - setSHAR(mac); setGAR(gw); setSUBR(sn); setSIPR(sip); - setGA6R(gw6); setSUB6R(sn6); setLLAR(lla); setGUAR(gua); + net_unlock(); + set_shar(mac); set_gar(gw); set_subr(sn); set_sipr(sip); + set_ga6r(gw6); set_sub6r(sn6); set_llar(lla); set_guar(gua); - if (islock & SYSR_CHPL) CHIPLOCK(); - if (islock & SYSR_NETL) NETLOCK(); + if (islock & SYSR_CHPL) chip_lock(); + if (islock & SYSR_NETL) net_lock(); } int8_t init_buffers(std::span txsize, std::span rxsize) { @@ -964,7 +964,7 @@ int8_t init_buffers(std::span txsize, std::span rx tmp += txsize[i]; if (tmp > 32) return -1; } - for (int i = 0; i < SOCK_COUNT; i++) setSn_TXBUF_SIZE(i, txsize[i]); + for (int i = 0; i < SOCK_COUNT; i++) set_sn_txbuf_size(i, txsize[i]); } if (!rxsize.empty()) { int8_t tmp = 0; @@ -972,36 +972,36 @@ int8_t init_buffers(std::span txsize, std::span rx tmp += rxsize[i]; if (tmp > 32) return -1; } - for (int i = 0; i < SOCK_COUNT; i++) setSn_RXBUF_SIZE(i, rxsize[i]); + for (int i = 0; i < SOCK_COUNT; i++) set_sn_rxbuf_size(i, rxsize[i]); } return 0; } void clear_interrupt(intr_kind intr) { - setIRCLR((uint8_t)intr); + set_irclr((uint8_t)intr); uint8_t sir = (uint8_t)((uint16_t)intr >> 8); for (int i = 0; i < SOCK_COUNT; i++) - if (sir & (1 << i)) setSn_IRCLR(i, 0xFF); - setSLIRCLR((uint8_t)((uint32_t)intr >> 16)); + if (sir & (1 << i)) set_sn_irclr(i, 0xFF); + set_slirclr((uint8_t)((uint32_t)intr >> 16)); } intr_kind get_interrupt() { - uint32_t ret = getSIR(); - ret = (ret << 8) + getIR(); - ret = (((uint32_t)getSLIR()) << 16) | ret; + uint32_t ret = get_sir(); + ret = (ret << 8) + get_ir(); + ret = (((uint32_t)get_slir()) << 16) | ret; return (intr_kind)ret; } void set_interrupt_mask(intr_kind intr) { - setIMR((uint8_t)intr); - setSIMR((uint8_t)((uint16_t)intr >> 8)); - setSLIMR((uint8_t)((uint32_t)intr >> 16)); + set_imr((uint8_t)intr); + set_simr((uint8_t)((uint16_t)intr >> 8)); + set_slimr((uint8_t)((uint32_t)intr >> 16)); } intr_kind get_interrupt_mask() { - uint32_t ret = getSIMR(); - ret = (ret << 8) + getIMR(); - ret = (((uint32_t)getSLIMR()) << 16) | ret; + uint32_t ret = get_simr(); + ret = (ret << 8) + get_imr(); + ret = (((uint32_t)get_slimr()) << 16) | ret; return (intr_kind)ret; } @@ -1023,10 +1023,10 @@ void reset_phy() { void set_phy_conf(const phy_conf& phyconf) { uint16_t tmp = mdio_read(PHYRAR_BMCR); if (phyconf.mode == PHY_MODE_TE) { - setPHYCR1(getPHYCR1() | PHYCR1_TE); - setPHYCR0(PHYCR0_AUTO); + set_phycr1(get_phycr1() | PHYCR1_TE); + set_phycr0(PHYCR0_AUTO); } else { - setPHYCR1(getPHYCR1() & ~PHYCR1_TE); + set_phycr1(get_phycr1() & ~PHYCR1_TE); if (phyconf.mode == PHY_MODE_AUTONEGO) { tmp |= BMCR_ANE; } else { @@ -1041,7 +1041,7 @@ void set_phy_conf(const phy_conf& phyconf) { phy_conf get_phy_conf() { phy_conf result; uint16_t tmp = mdio_read(PHYRAR_BMCR); - result.mode = (getPHYCR1() & PHYCR1_TE) ? PHY_MODE_TE : ((tmp & BMCR_ANE) ? PHY_MODE_AUTONEGO : PHY_MODE_MANUAL); + result.mode = (get_phycr1() & PHYCR1_TE) ? PHY_MODE_TE : ((tmp & BMCR_ANE) ? PHY_MODE_AUTONEGO : PHY_MODE_MANUAL); result.duplex = (tmp & BMCR_DPX) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF; result.speed = (tmp & BMCR_SPD) ? PHY_SPEED_100 : PHY_SPEED_10; return result; @@ -1049,8 +1049,8 @@ phy_conf get_phy_conf() { phy_conf get_phy_status() { phy_conf result; - uint8_t tmp = getPHYSR(); - result.mode = (getPHYCR1() & PHYCR1_TE) ? PHY_MODE_TE : ((tmp & (1 << 5)) ? PHY_MODE_MANUAL : PHY_MODE_AUTONEGO); + uint8_t tmp = get_physr(); + result.mode = (get_phycr1() & PHYCR1_TE) ? PHY_MODE_TE : ((tmp & (1 << 5)) ? PHY_MODE_MANUAL : PHY_MODE_AUTONEGO); result.speed = (tmp & PHYSR_SPD) ? PHY_SPEED_10 : PHY_SPEED_100; result.duplex = (tmp & PHYSR_DPX) ? PHY_DUPLEX_HALF : PHY_DUPLEX_FULL; return result; @@ -1064,10 +1064,10 @@ void set_phy_power_mode(uint8_t pmode) { } void set_net_info(const net_info& p) { - setSHAR(const_cast(p.mac.data())); setGAR(const_cast(p.gw.data())); - setSUBR(const_cast(p.sn.data())); setSIPR(const_cast(p.ip.data())); - setGA6R(const_cast(p.gw6.data())); setSUB6R(const_cast(p.sn6.data())); - setLLAR(const_cast(p.lla.data())); setGUAR(const_cast(p.gua.data())); + set_shar(const_cast(p.mac.data())); set_gar(const_cast(p.gw.data())); + set_subr(const_cast(p.sn.data())); set_sipr(const_cast(p.ip.data())); + set_ga6r(const_cast(p.gw6.data())); set_sub6r(const_cast(p.sn6.data())); + set_llar(const_cast(p.lla.data())); set_guar(const_cast(p.gua.data())); memcpy(dns_, p.dns.data(), 4); memcpy(dns6_, p.dns6.data(), 16); ipmode_ = p.ipmode; @@ -1075,8 +1075,8 @@ void set_net_info(const net_info& p) { net_info get_net_info() { net_info p = {}; - getSHAR(p.mac.data()); getGAR(p.gw.data()); getSUBR(p.sn.data()); getSIPR(p.ip.data()); - getGA6R(p.gw6.data()); getSUB6R(p.sn6.data()); getLLAR(p.lla.data()); getGUAR(p.gua.data()); + get_shar(p.mac.data()); get_gar(p.gw.data()); get_subr(p.sn.data()); get_sipr(p.ip.data()); + get_ga6r(p.gw6.data()); get_sub6r(p.sn6.data()); get_llar(p.lla.data()); get_guar(p.gua.data()); memcpy(p.dns.data(), dns_, 4); memcpy(p.dns6.data(), dns6_, 16); p.ipmode = ipmode_; @@ -1085,72 +1085,72 @@ net_info get_net_info() { void set_net_mode(netmode_type netmode) { uint32_t tmp = (uint32_t)netmode; - setNETMR((uint8_t)tmp); - setNETMR2((uint8_t)(tmp >> 8)); - setNET4MR((uint8_t)(tmp >> 16)); - setNET6MR((uint8_t)(tmp >> 24)); + set_netmr((uint8_t)tmp); + set_netmr2((uint8_t)(tmp >> 8)); + set_net4mr((uint8_t)(tmp >> 16)); + set_net6mr((uint8_t)(tmp >> 24)); } netmode_type get_net_mode() { - uint32_t ret = getNETMR(); - ret = (ret << 8) + getNETMR2(); - ret = (ret << 16) + getNET4MR(); - ret = (ret << 24) + getNET6MR(); + uint32_t ret = get_netmr(); + ret = (ret << 8) + get_netmr2(); + ret = (ret << 16) + get_net4mr(); + ret = (ret << 24) + get_net6mr(); return (netmode_type)ret; } void set_timeout(const net_timeout& t) { - setRCR(t.s_retry_cnt); setRTR(t.s_time_100us); - setSLRCR(t.sl_retry_cnt); setSLRTR(t.sl_time_100us); + set_rcr(t.s_retry_cnt); set_rtr(t.s_time_100us); + set_slrcr(t.sl_retry_cnt); set_slrtr(t.sl_time_100us); } net_timeout get_timeout() { - return {getRCR(), getRTR(), getSLRCR(), getSLRTR()}; + return {get_rcr(), get_rtr(), get_slrcr(), get_slrtr()}; } int8_t send_arp(arp_request& arp) { uint8_t tmp; - if (arp.destinfo.len == 16) { setSLDIP6R(const_cast(arp.destinfo.ip.data())); setSLCR(SLCR_ARP6); } - else { setSLDIP4R(const_cast(arp.destinfo.ip.data())); setSLCR(SLCR_ARP4); } - while (getSLCR()); - while ((tmp = getSLIR()) == 0x00); - setSLIRCLR(~SLIR_RA); - if (tmp & (SLIR_ARP4 | SLIR_ARP6)) { getSLDHAR(arp.dha.data()); return 0; } + if (arp.destinfo.len == 16) { set_sldip6r(const_cast(arp.destinfo.ip.data())); set_slcr(SLCR_ARP6); } + else { set_sldip4r(const_cast(arp.destinfo.ip.data())); set_slcr(SLCR_ARP4); } + while (get_slcr()); + while ((tmp = get_slir()) == 0x00); + set_slirclr(~SLIR_RA); + if (tmp & (SLIR_ARP4 | SLIR_ARP6)) { get_sldhar(arp.dha.data()); return 0; } return -1; } int8_t send_ping(const ping_request& ping) { uint8_t tmp; - setPINGIDR(ping.id); setPINGSEQR(ping.seq); - if (ping.destinfo.len == 16) { setSLDIP6R(const_cast(ping.destinfo.ip.data())); setSLCR(SLCR_PING6); } - else { setSLDIP4R(const_cast(ping.destinfo.ip.data())); setSLCR(SLCR_PING4); } - while (getSLCR()); - while ((tmp = getSLIR()) == 0x00); - setSLIRCLR(~SLIR_RA); + set_pingidr(ping.id); set_pingseqr(ping.seq); + if (ping.destinfo.len == 16) { set_sldip6r(const_cast(ping.destinfo.ip.data())); set_slcr(SLCR_PING6); } + else { set_sldip4r(const_cast(ping.destinfo.ip.data())); set_slcr(SLCR_PING4); } + while (get_slcr()); + while ((tmp = get_slir()) == 0x00); + set_slirclr(~SLIR_RA); if (tmp & (SLIR_PING4 | SLIR_PING6)) return 0; return -1; } int8_t send_dad(std::span ipv6) { uint8_t tmp; - setSLDIP6R(const_cast(ipv6.data())); setSLCR(SLCR_NS); - while (getSLCR()); - while ((tmp = getSLIR()) == 0x00); - setSLIRCLR(~SLIR_RA); + set_sldip6r(const_cast(ipv6.data())); set_slcr(SLCR_NS); + while (get_slcr()); + while ((tmp = get_slir()) == 0x00); + set_slirclr(~SLIR_RA); if (tmp & SLIR_TOUT) return 0; return -1; } int8_t send_slaac(prefix& pfx) { uint8_t tmp; - setSLCR(SLCR_RS); - while (getSLCR()); - while ((tmp = getSLIR()) == 0x00); - setSLIRCLR(~SLIR_RA); + set_slcr(SLCR_RS); + while (get_slcr()); + while ((tmp = get_slir()) == 0x00); + set_slirclr(~SLIR_RA); if (tmp & SLIR_RS) { - pfx.len = getPLR(); pfx.flag = getPFR(); - pfx.valid_lifetime = getVLTR(); pfx.preferred_lifetime = getPLTR(); - getPAR(pfx.prefix.data()); + pfx.len = get_plr(); pfx.flag = get_pfr(); + pfx.valid_lifetime = get_vltr(); pfx.preferred_lifetime = get_pltr(); + get_par(pfx.prefix.data()); return 0; } return -1; @@ -1158,20 +1158,20 @@ int8_t send_slaac(prefix& pfx) { int8_t send_unsolicited() { uint8_t tmp; - setSLCR(SLCR_UNA); - while (getSLCR()); - while ((tmp = getSLIR()) == 0x00); - setSLIRCLR(~SLIR_RA); + set_slcr(SLCR_UNA); + while (get_slcr()); + while ((tmp = get_slir()) == 0x00); + set_slirclr(~SLIR_RA); if (tmp & SLIR_TOUT) return 0; return -1; } int8_t get_prefix(prefix& pfx) { - if (getSLIR() & SLIR_RA) { - pfx.len = getPLR(); pfx.flag = getPFR(); - pfx.valid_lifetime = getVLTR(); pfx.preferred_lifetime = getPLTR(); - getPAR(pfx.prefix.data()); - setSLIRCLR(SLIR_RA); + if (get_slir() & SLIR_RA) { + pfx.len = get_plr(); pfx.flag = get_pfr(); + pfx.valid_lifetime = get_vltr(); pfx.preferred_lifetime = get_pltr(); + get_par(pfx.prefix.data()); + set_slirclr(SLIR_RA); } return -1; } @@ -1180,17 +1180,17 @@ constexpr uint16_t SOCK_ANY_PORT_NUM = 0xC000; static uint16_t sock_any_port = SOCK_ANY_PORT_NUM; static uint16_t sock_io_mode_bits = 0; static uint16_t sock_is_sending = 0; -static uint16_t sock_remained_size[_SOCK_COUNT_] = {0,}; -uint8_t sock_pack_info[_SOCK_COUNT_] = {0,}; +static uint16_t sock_remained_size[SOCK_COUNT] = {0,}; +uint8_t sock_pack_info[SOCK_COUNT] = {0,}; #define FAIL(e) return std::unexpected(sock_error::e) -#define CHECK_SOCKNUM() do { if(sn >= _SOCK_COUNT_) FAIL(sock_num); } while(0) -#define CHECK_SOCKMODE(mode) do { if((getSn_MR(sn) & 0x0F) != mode) FAIL(sock_mode); } while(0) -#define CHECK_TCPMODE() do { if((getSn_MR(sn) & 0x03) != 0x01) FAIL(sock_mode); } while(0) -#define CHECK_UDPMODE() do { if((getSn_MR(sn) & 0x03) != 0x02) FAIL(sock_mode); } while(0) -#define CHECK_IPMODE() do { if((getSn_MR(sn) & 0x07) != 0x03) FAIL(sock_mode); } while(0) -#define CHECK_DGRAMMODE() do { if(getSn_MR(sn) == Sn_MR_CLOSED) FAIL(sock_mode); if((getSn_MR(sn) & 0x03) == 0x01) FAIL(sock_mode); } while(0) -#define CHECK_SOCKINIT() do { if((getSn_SR(sn) != SOCK_INIT)) FAIL(sock_init); } while(0) +#define CHECK_SOCKNUM() do { if(sn >= SOCK_COUNT) FAIL(sock_num); } while(0) +#define CHECK_SOCKMODE(mode) do { if((get_sn_mr(sn) & 0x0F) != mode) FAIL(sock_mode); } while(0) +#define CHECK_TCPMODE() do { if((get_sn_mr(sn) & 0x03) != 0x01) FAIL(sock_mode); } while(0) +#define CHECK_UDPMODE() do { if((get_sn_mr(sn) & 0x03) != 0x02) FAIL(sock_mode); } while(0) +#define CHECK_IPMODE() do { if((get_sn_mr(sn) & 0x07) != 0x03) FAIL(sock_mode); } while(0) +#define CHECK_DGRAMMODE() do { if(get_sn_mr(sn) == Sn_MR_CLOSED) FAIL(sock_mode); if((get_sn_mr(sn) & 0x03) == 0x01) FAIL(sock_mode); } while(0) +#define CHECK_SOCKINIT() do { if((get_sn_sr(sn) != SOCK_INIT)) FAIL(sock_init); } while(0) #define CHECK_SOCKDATA() do { if(len == 0) FAIL(data_len); } while(0) #define CHECK_IPZERO(addr, addrlen) do { uint16_t ipzero=0; for(uint8_t i=0; i open_socket(socket_id sid, protocol proto, CHECK_SOCKNUM(); switch (pr & 0x0F) { case Sn_MR_TCP4: - getSIPR(taddr); + get_sipr(taddr); CHECK_IPZERO(taddr, 4); break; case Sn_MR_TCP6: - getLLAR(taddr); + get_llar(taddr); CHECK_IPZERO(taddr, 16); break; case Sn_MR_TCPD: - getSIPR(taddr); + get_sipr(taddr); CHECK_IPZERO(taddr, 4); - getLLAR(taddr); + get_llar(taddr); CHECK_IPZERO(taddr, 16); break; case Sn_MR_UDP: @@ -1247,35 +1247,35 @@ std::expected open_socket(socket_id sid, protocol proto, } } close(sid); - setSn_MR(sn, (pr | (fl & 0xF0))); - setSn_MR2(sn, fl & 0x03); + set_sn_mr(sn, (pr | (fl & 0xF0))); + set_sn_mr2(sn, fl & 0x03); if (!p) { p = sock_any_port++; if (sock_any_port == 0xFFF0) sock_any_port = SOCK_ANY_PORT_NUM; } - setSn_PORTR(sn, p); - setSn_CR(sn, Sn_CR_OPEN); - while (getSn_CR(sn)); + set_sn_portr(sn, p); + set_sn_cr(sn, Sn_CR_OPEN); + while (get_sn_cr(sn)); sock_io_mode_bits &= ~(1 << sn); sock_io_mode_bits |= ((fl & (static_cast(sock_flag::io_nonblock) >> 3)) << sn); sock_is_sending &= ~(1 << sn); sock_remained_size[sn] = 0; sock_pack_info[sn] = static_cast(pack_info::completed); - while (getSn_SR(sn) == SOCK_CLOSED); + while (get_sn_sr(sn) == SOCK_CLOSED); return sid; } std::expected close(socket_id sid) { uint8_t sn = static_cast(sid); CHECK_SOCKNUM(); - setSn_CR(sn, Sn_CR_CLOSE); - while (getSn_CR(sn)); - setSn_IR(sn, 0xFF); + set_sn_cr(sn, Sn_CR_CLOSE); + while (get_sn_cr(sn)); + set_sn_ir(sn, 0xFF); sock_io_mode_bits &= ~(1 << sn); sock_is_sending &= ~(1 << sn); sock_remained_size[sn] = 0; sock_pack_info[sn] = PACK_NONE; - while (getSn_SR(sn) != SOCK_CLOSED); + while (get_sn_sr(sn) != SOCK_CLOSED); return {}; } @@ -1284,9 +1284,9 @@ std::expected listen(socket_id sid) { CHECK_SOCKNUM(); CHECK_TCPMODE(); CHECK_SOCKINIT(); - setSn_CR(sn, Sn_CR_LISTEN); - while (getSn_CR(sn)); - while (getSn_SR(sn) != SOCK_LISTEN) { + set_sn_cr(sn, Sn_CR_LISTEN); + while (get_sn_cr(sn)); + while (get_sn_sr(sn) != SOCK_LISTEN) { close(sid); FAIL(sock_closed); } @@ -1303,27 +1303,27 @@ std::expected connect(socket_id sid, const ip_address& addr, p CHECK_IPZERO(addr.ip.data(), addrlen); if (p == 0) FAIL(port_zero); - setSn_DPORTR(sn, p); + set_sn_dportr(sn, p); if (addrlen == 16) { - if (getSn_MR(sn) & 0x08) { - setSn_DIP6R(sn, const_cast(addr.ip.data())); - setSn_CR(sn, Sn_CR_CONNECT6); + if (get_sn_mr(sn) & 0x08) { + set_sn_dip6r(sn, const_cast(addr.ip.data())); + set_sn_cr(sn, Sn_CR_CONNECT6); } else { FAIL(sock_mode); } } else { - if (getSn_MR(sn) == Sn_MR_TCP6) FAIL(sock_mode); - setSn_DIPR(sn, const_cast(addr.ip.data())); - setSn_CR(sn, Sn_CR_CONNECT); + if (get_sn_mr(sn) == Sn_MR_TCP6) FAIL(sock_mode); + set_sn_dipr(sn, const_cast(addr.ip.data())); + set_sn_cr(sn, Sn_CR_CONNECT); } - while (getSn_CR(sn)); + while (get_sn_cr(sn)); if (sock_io_mode_bits & (1 << sn)) FAIL(busy); - while (getSn_SR(sn) != SOCK_ESTABLISHED) { - if (getSn_IR(sn) & Sn_IR_TIMEOUT) { - setSn_IR(sn, Sn_IR_TIMEOUT); + while (get_sn_sr(sn) != SOCK_ESTABLISHED) { + if (get_sn_ir(sn) & SnREG_IRTIMEOUT) { + set_sn_ir(sn, SnREG_IRTIMEOUT); FAIL(timeout); } - if (getSn_SR(sn) == SOCK_CLOSED) FAIL(sock_closed); + if (get_sn_sr(sn) == SOCK_CLOSED) FAIL(sock_closed); } return {}; } @@ -1332,13 +1332,13 @@ std::expected disconnect(socket_id sid) { uint8_t sn = static_cast(sid); CHECK_SOCKNUM(); CHECK_TCPMODE(); - if (getSn_SR(sn) != SOCK_CLOSED) { - setSn_CR(sn, Sn_CR_DISCON); - while (getSn_CR(sn)); + if (get_sn_sr(sn) != SOCK_CLOSED) { + set_sn_cr(sn, Sn_CR_DISCON); + while (get_sn_cr(sn)); sock_is_sending &= ~(1 << sn); if (sock_io_mode_bits & (1 << sn)) FAIL(busy); - while (getSn_SR(sn) != SOCK_CLOSED) { - if (getSn_IR(sn) & Sn_IR_TIMEOUT) { + while (get_sn_sr(sn) != SOCK_CLOSED) { + if (get_sn_ir(sn) & SnREG_IRTIMEOUT) { close(sid); FAIL(timeout); } @@ -1353,11 +1353,11 @@ std::expected send(socket_id sid, std::span uint16_t freesize = 0; uint16_t len = buf.size(); - freesize = getSn_TxMAX(sn); + freesize = get_sn_tx_max(sn); if (len > freesize) len = freesize; while (1) { - freesize = (uint16_t)getSn_TX_FSR(sn); - tmp = getSn_SR(sn); + freesize = (uint16_t)get_sn_tx_fsr(sn); + tmp = get_sn_sr(sn); if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT)) { if (tmp == SOCK_CLOSED) close(sid); FAIL(sock_status); @@ -1367,18 +1367,18 @@ std::expected send(socket_id sid, std::span } send_data(sn, const_cast(buf.data()), len); if (sock_is_sending & (1 << sn)) { - while (!(getSn_IR(sn) & Sn_IR_SENDOK)) { - tmp = getSn_SR(sn); + while (!(get_sn_ir(sn) & SnREG_IRSENDOK)) { + tmp = get_sn_sr(sn); if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT)) { - if ((tmp == SOCK_CLOSED) || (getSn_IR(sn) & Sn_IR_TIMEOUT)) close(sid); + if ((tmp == SOCK_CLOSED) || (get_sn_ir(sn) & SnREG_IRTIMEOUT)) close(sid); FAIL(sock_status); } if (sock_io_mode_bits & (1 << sn)) FAIL(busy); } - setSn_IR(sn, Sn_IR_SENDOK); + set_sn_ir(sn, SnREG_IRSENDOK); } - setSn_CR(sn, Sn_CR_SEND); - while (getSn_CR(sn)); + set_sn_cr(sn, Sn_CR_SEND); + while (get_sn_cr(sn)); sock_is_sending |= (1 << sn); return len; } @@ -1393,16 +1393,16 @@ std::expected recv(socket_id sid, std::span buf) CHECK_SOCKMODE(Sn_MR_TCP); CHECK_SOCKDATA(); - recvsize = getSn_RxMAX(sn); + recvsize = get_sn_rx_max(sn); if (recvsize < len) len = recvsize; while (1) { - recvsize = (uint16_t)getSn_RX_RSR(sn); - tmp = getSn_SR(sn); + recvsize = (uint16_t)get_sn_rx_rsr(sn); + tmp = get_sn_sr(sn); if (tmp != SOCK_ESTABLISHED) { if (tmp == SOCK_CLOSE_WAIT) { if (recvsize != 0) break; - else if (getSn_TX_FSR(sn) == getSn_TxMAX(sn)) { + else if (get_sn_tx_fsr(sn) == get_sn_tx_max(sn)) { close(sid); FAIL(sock_status); } @@ -1417,8 +1417,8 @@ std::expected recv(socket_id sid, std::span buf) if (recvsize < len) len = recvsize; recv_data(sn, buf.data(), len); - setSn_CR(sn, Sn_CR_RECV); - while (getSn_CR(sn)); + set_sn_cr(sn, Sn_CR_RECV); + while (get_sn_cr(sn)); return len; } @@ -1432,7 +1432,7 @@ std::expected sendto(socket_id sid, std::span sendto(socket_id sid, std::span(addr.ip.data())); + set_sn_dip6r(sn, const_cast(addr.ip.data())); tcmd = Sn_CR_SEND6; } else { FAIL(sock_mode); } } else if (addrlen == 4) { if (tmp == Sn_MR_UDP6 || tmp == Sn_MR_IPRAW6) FAIL(sock_mode); - setSn_DIPR(sn, const_cast(addr.ip.data())); + set_sn_dipr(sn, const_cast(addr.ip.data())); tcmd = Sn_CR_SEND; } else { FAIL(ip_invalid); @@ -1460,30 +1460,30 @@ std::expected sendto(socket_id sid, std::span freesize) len = freesize; while (1) { - freesize = getSn_TX_FSR(sn); - if (getSn_SR(sn) == SOCK_CLOSED) FAIL(sock_closed); + freesize = get_sn_tx_fsr(sn); + if (get_sn_sr(sn) == SOCK_CLOSED) FAIL(sock_closed); if ((sock_io_mode_bits & (1 << sn)) && (len > freesize)) FAIL(busy); if (len <= freesize) break; }; send_data(sn, const_cast(buf.data()), len); - setSn_CR(sn, tcmd); - while (getSn_CR(sn)); + set_sn_cr(sn, tcmd); + while (get_sn_cr(sn)); while (1) { - tmp = getSn_IR(sn); - if (tmp & Sn_IR_SENDOK) { - setSn_IR(sn, Sn_IR_SENDOK); + tmp = get_sn_ir(sn); + if (tmp & SnREG_IRSENDOK) { + set_sn_ir(sn, SnREG_IRSENDOK); break; - } else if (tmp & Sn_IR_TIMEOUT) { - setSn_IR(sn, Sn_IR_TIMEOUT); + } else if (tmp & SnREG_IRTIMEOUT) { + set_sn_ir(sn, SnREG_IRTIMEOUT); FAIL(timeout); } } @@ -1500,7 +1500,7 @@ std::expected recvfrom(socket_id sid, std::span b CHECK_SOCKNUM(); CHECK_SOCKDATA(); - switch ((mr = getSn_MR(sn)) & 0x0F) { + switch ((mr = get_sn_mr(sn)) & 0x0F) { case Sn_MR_UDP: case Sn_MR_IPRAW: case Sn_MR_IPRAW6: @@ -1512,8 +1512,8 @@ std::expected recvfrom(socket_id sid, std::span b if (sock_remained_size[sn] == 0) { while (1) { - pack_len = getSn_RX_RSR(sn); - if (getSn_SR(sn) == SOCK_CLOSED) FAIL(sock_closed); + pack_len = get_sn_rx_rsr(sn); + if (get_sn_sr(sn) == SOCK_CLOSED) FAIL(sock_closed); if (pack_len != 0) { sock_pack_info[sn] = PACK_NONE; break; @@ -1523,8 +1523,8 @@ std::expected recvfrom(socket_id sid, std::span b } recv_data(sn, head, 2); - setSn_CR(sn, Sn_CR_RECV); - while (getSn_CR(sn)); + set_sn_cr(sn, Sn_CR_RECV); + while (get_sn_cr(sn)); pack_len = head[0] & 0x07; pack_len = (pack_len << 8) + head[1]; @@ -1536,8 +1536,8 @@ std::expected recvfrom(socket_id sid, std::span b if (sock_pack_info[sn] & PACK_IPv6) addr.len = 16; else addr.len = 4; recv_data(sn, addr.ip.data(), addr.len); - setSn_CR(sn, Sn_CR_RECV); - while (getSn_CR(sn)); + set_sn_cr(sn, Sn_CR_RECV); + while (get_sn_cr(sn)); break; case Sn_MR_MACRAW: if (sock_remained_size[sn] == 0) { @@ -1560,8 +1560,8 @@ std::expected recvfrom(socket_id sid, std::span b if (sock_pack_info[sn] & PACK_IPv6) addr.len = 16; else addr.len = 4; recv_data(sn, addr.ip.data(), addr.len); - setSn_CR(sn, Sn_CR_RECV); - while (getSn_CR(sn)); + set_sn_cr(sn, Sn_CR_RECV); + while (get_sn_cr(sn)); } break; default: @@ -1572,18 +1572,18 @@ std::expected recvfrom(socket_id sid, std::span b sock_remained_size[sn] = pack_len; sock_pack_info[sn] |= PACK_FIRST; - if ((getSn_MR(sn) & 0x03) == 0x02) { + if ((get_sn_mr(sn) & 0x03) == 0x02) { recv_data(sn, head, 2); port = static_cast((((uint16_t)head[0]) << 8) + head[1]); - setSn_CR(sn, Sn_CR_RECV); - while (getSn_CR(sn)); + set_sn_cr(sn, Sn_CR_RECV); + while (get_sn_cr(sn)); } if (len < sock_remained_size[sn]) pack_len = len; else pack_len = sock_remained_size[sn]; recv_data(sn, buf.data(), pack_len); - setSn_CR(sn, Sn_CR_RECV); - while (getSn_CR(sn)); + set_sn_cr(sn, Sn_CR_RECV); + while (get_sn_cr(sn)); sock_remained_size[sn] -= pack_len; if (sock_remained_size[sn] != 0) sock_pack_info[sn] |= PACK_REMAINED; @@ -1598,10 +1598,10 @@ std::optional peek_socket_msg(socket_id sid, std::span uint8_t sn = static_cast(sid); uint32_t rx_ptr = 0; uint16_t i = 0, sub_idx = 0; - if ((getSn_RX_RSR(sn) > 0) && (subsize > 0)) { - rx_ptr = ((uint32_t)getSn_RX_RD(sn) << 8) + RXBUF_BLOCK(sn); + if ((get_sn_rx_rsr(sn) > 0) && (subsize > 0)) { + rx_ptr = ((uint32_t)get_sn_rx_rd(sn) << 8) + RXBUF_BLOCK(sn); sub_idx = 0; - for (i = 0; i < getSn_RX_RSR(sn); i++) { + for (i = 0; i < get_sn_rx_rsr(sn); i++) { if (reg_read(rx_ptr) == submsg[sub_idx]) { sub_idx++; if (sub_idx == subsize) return static_cast(i + 1 - sub_idx); @@ -1639,18 +1639,18 @@ void init() { } bool check() { - return getCIDR() == 0x6300; + return get_cidr() == 0x6300; } void init_net(const net_info& info) { - CHIPUNLOCK(); - NETUNLOCK(); + chip_unlock(); + net_unlock(); set_net_info(info); } std::expected set_socket_io_mode(socket_id sid, sock_io_mode mode) { uint8_t sn = static_cast(sid); - if (sn >= _SOCK_COUNT_) FAIL(sock_num); + if (sn >= SOCK_COUNT) FAIL(sock_num); if (mode == sock_io_mode::nonblock) sock_io_mode_bits |= (1 << sn); else if (mode == sock_io_mode::block) sock_io_mode_bits &= ~(1 << sn); else FAIL(arg); @@ -1663,109 +1663,109 @@ sock_io_mode get_socket_io_mode(socket_id sid) { } uint16_t get_socket_max_tx(socket_id sid) { - return getSn_TxMAX(static_cast(sid)); + return get_sn_tx_max(static_cast(sid)); } uint16_t get_socket_max_rx(socket_id sid) { - return getSn_RxMAX(static_cast(sid)); + return get_sn_rx_max(static_cast(sid)); } std::expected clear_socket_interrupt(socket_id sid, uint8_t flags) { uint8_t sn = static_cast(sid); - if (sn >= _SOCK_COUNT_) FAIL(sock_num); + if (sn >= SOCK_COUNT) FAIL(sock_num); if (flags > SIK_ALL) FAIL(arg); - setSn_IR(sn, flags); + set_sn_ir(sn, flags); return {}; } uint8_t get_socket_interrupt(socket_id sid) { - return getSn_IR(static_cast(sid)); + return get_sn_ir(static_cast(sid)); } std::expected set_socket_interrupt_mask(socket_id sid, uint8_t mask) { uint8_t sn = static_cast(sid); - if (sn >= _SOCK_COUNT_) FAIL(sock_num); + if (sn >= SOCK_COUNT) FAIL(sock_num); if (mask > SIK_ALL) FAIL(arg); - setSn_IMR(sn, mask); + set_sn_imr(sn, mask); return {}; } uint8_t get_socket_interrupt_mask(socket_id sid) { - return getSn_IMR(static_cast(sid)); + return get_sn_imr(static_cast(sid)); } std::expected set_socket_prefer(socket_id sid, srcv6_prefer pref) { uint8_t sn = static_cast(sid); - if (sn >= _SOCK_COUNT_) FAIL(sock_num); + if (sn >= SOCK_COUNT) FAIL(sock_num); uint8_t v = static_cast(pref); if ((v & 0x03) == 0x01) FAIL(arg); - setSn_PSR(sn, v); + set_sn_psr(sn, v); return {}; } srcv6_prefer get_socket_prefer(socket_id sid) { - return static_cast(getSn_PSR(static_cast(sid))); + return static_cast(get_sn_psr(static_cast(sid))); } void set_socket_ttl(socket_id sid, uint8_t ttl) { - setSn_TTL(static_cast(sid), ttl); + set_sn_ttl(static_cast(sid), ttl); } uint8_t get_socket_ttl(socket_id sid) { - return getSn_TTL(static_cast(sid)); + return get_sn_ttl(static_cast(sid)); } void set_socket_tos(socket_id sid, uint8_t tos) { - setSn_TOS(static_cast(sid), tos); + set_sn_tos(static_cast(sid), tos); } uint8_t get_socket_tos(socket_id sid) { - return getSn_TOS(static_cast(sid)); + return get_sn_tos(static_cast(sid)); } void set_socket_mss(socket_id sid, uint16_t mss) { - setSn_MSSR(static_cast(sid), mss); + set_sn_mssr(static_cast(sid), mss); } uint16_t get_socket_mss(socket_id sid) { - return getSn_MSSR(static_cast(sid)); + return get_sn_mssr(static_cast(sid)); } void set_socket_dest_ip(socket_id sid, const ip_address& addr) { uint8_t sn = static_cast(sid); - if (addr.len == 16) setSn_DIP6R(sn, const_cast(addr.ip.data())); - else setSn_DIPR(sn, const_cast(addr.ip.data())); + if (addr.len == 16) set_sn_dip6r(sn, const_cast(addr.ip.data())); + else set_sn_dipr(sn, const_cast(addr.ip.data())); } ip_address get_socket_dest_ip(socket_id sid) { uint8_t sn = static_cast(sid); ip_address addr = {}; - if (getSn_ESR(sn) & TCPSOCK_MODE) { - getSn_DIP6R(sn, addr.ip.data()); + if (get_sn_esr(sn) & TCPSOCK_MODE) { + get_sn_dip6r(sn, addr.ip.data()); addr.len = 16; } else { - getSn_DIPR(sn, addr.ip.data()); + get_sn_dipr(sn, addr.ip.data()); addr.len = 4; } return addr; } void set_socket_dest_port(socket_id sid, port_num port) { - setSn_DPORTR(static_cast(sid), static_cast(port)); + set_sn_dportr(static_cast(sid), static_cast(port)); } port_num get_socket_dest_port(socket_id sid) { - return static_cast(getSn_DPORTR(static_cast(sid))); + return static_cast(get_sn_dportr(static_cast(sid))); } std::expected send_keepalive(socket_id sid) { uint8_t sn = static_cast(sid); - if ((getSn_MR(sn) & 0x03) != 0x01) FAIL(sock_mode); - if (getSn_KPALVTR(sn) != 0) FAIL(sock_opt); - setSn_CR(sn, Sn_CR_SEND_KEEP); - while (getSn_CR(sn) != 0) { - if (getSn_IR(sn) & Sn_IR_TIMEOUT) { - setSn_IR(sn, Sn_IR_TIMEOUT); + if ((get_sn_mr(sn) & 0x03) != 0x01) FAIL(sock_mode); + if (get_sn_kpalvtr(sn) != 0) FAIL(sock_opt); + set_sn_cr(sn, Sn_CR_SEND_KEEP); + while (get_sn_cr(sn) != 0) { + if (get_sn_ir(sn) & SnREG_IRTIMEOUT) { + set_sn_ir(sn, SnREG_IRTIMEOUT); FAIL(timeout); } } @@ -1773,36 +1773,36 @@ std::expected send_keepalive(socket_id sid) { } void set_socket_keepalive_auto(socket_id sid, uint8_t interval) { - setSn_KPALVTR(static_cast(sid), interval); + set_sn_kpalvtr(static_cast(sid), interval); } uint8_t get_socket_keepalive_auto(socket_id sid) { - return getSn_KPALVTR(static_cast(sid)); + return get_sn_kpalvtr(static_cast(sid)); } uint16_t get_socket_send_buf(socket_id sid) { - return getSn_TX_FSR(static_cast(sid)); + return get_sn_tx_fsr(static_cast(sid)); } uint16_t get_socket_recv_buf(socket_id sid) { - return getSn_RX_RSR(static_cast(sid)); + return get_sn_rx_rsr(static_cast(sid)); } uint8_t get_socket_status(socket_id sid) { - return getSn_SR(static_cast(sid)); + return get_sn_sr(static_cast(sid)); } uint8_t get_socket_ext_status(socket_id sid) { - return getSn_ESR(static_cast(sid)) & 0x07; + return get_sn_esr(static_cast(sid)) & 0x07; } uint8_t get_socket_mode(socket_id sid) { - return getSn_MR(static_cast(sid)) & 0x0F; + return get_sn_mr(static_cast(sid)) & 0x0F; } uint16_t get_socket_remain_size(socket_id sid) { uint8_t sn = static_cast(sid); - if (getSn_MR(sn) & 0x01) return getSn_RX_RSR(sn); + if (get_sn_mr(sn) & 0x01) return get_sn_rx_rsr(sn); return sock_remained_size[sn]; }