Replace raw uint8_t constants with enum class types, move internal constants to cpp

This commit is contained in:
Ian Gulliver
2026-04-05 08:18:28 +09:00
parent 8a48c58a0b
commit 0b81ca6139
2 changed files with 113 additions and 62 deletions

View File

@@ -39,23 +39,6 @@ enum intr_kind : uint32_t {
IK_INT_ALL = 0x00FFFF97
};
constexpr uint8_t SYS_CHIP_LOCK = (1 << 2);
constexpr uint8_t SYS_NET_LOCK = (1 << 1);
constexpr uint8_t SYS_PHY_LOCK = (1 << 0);
constexpr uint8_t PHY_MODE_MANUAL = 0;
constexpr uint8_t PHY_MODE_AUTONEGO = 1;
constexpr uint8_t PHY_MODE_TE = 2;
constexpr uint8_t PHY_CONFBY_HW = 0;
constexpr uint8_t PHY_CONFBY_SW = 1;
constexpr uint8_t PHY_SPEED_10 = 0;
constexpr uint8_t PHY_SPEED_100 = 1;
constexpr uint8_t PHY_DUPLEX_HALF = 0;
constexpr uint8_t PHY_DUPLEX_FULL = 1;
constexpr uint8_t PHY_LINK_OFF = 0;
constexpr uint8_t PHY_LINK_ON = 1;
constexpr uint8_t PHY_POWER_NORM = 0;
constexpr uint8_t PHY_POWER_DOWN = 1;
struct phy_conf {
uint8_t by;
@@ -169,9 +152,6 @@ void init();
bool check();
void init_net(net_info info);
using iodata_t = uint8_t;
using datasize_t = int16_t;
constexpr int16_t SOCK_OK = 1;
constexpr int16_t SOCK_BUSY = 0;
constexpr int16_t SOCK_FATAL = -1000;
@@ -191,41 +171,76 @@ constexpr int16_t SOCKERR_DATALEN = SOCK_ERROR - 14;
constexpr int16_t SOCKERR_BUFFER = SOCK_ERROR - 15;
constexpr int16_t SOCKFATAL_PACKLEN = SOCK_FATAL - 1;
constexpr uint8_t SF_MULTI_ENABLE = 1 << 7;
constexpr uint8_t SF_ETHER_OWN = 1 << 7;
constexpr uint8_t SF_BROAD_BLOCK = 1 << 6;
constexpr uint8_t SF_TCP_FPSH = 1 << 6;
constexpr uint8_t SF_TCP_NODELAY = 1 << 5;
constexpr uint8_t SF_IGMP_VER2 = 1 << 5;
constexpr uint8_t SF_SOLICIT_BLOCK = 1 << 5;
constexpr uint8_t SF_ETHER_MULTI4B = 1 << 5;
constexpr uint8_t SF_UNI_BLOCK = 1 << 4;
constexpr uint8_t SF_ETHER_MULIT6B = 1 << 4;
constexpr uint8_t SF_FORCE_ARP = 1 << 0;
constexpr uint8_t SF_DHA_MANUAL = 1 << 1;
constexpr uint8_t SF_IO_NONBLOCK = 1 << 3;
enum class protocol : uint8_t {
tcp = 0x01,
udp = 0x02,
ipraw = 0x03,
macraw = 0x07,
tcp6 = 0x09,
udp6 = 0x0A,
ipraw6 = 0x0B,
tcp_dual = 0x0D,
udp_dual = 0x0E,
};
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;
enum class sock_flag : uint8_t {
none = 0,
multi_enable = 1 << 7,
ether_own = 1 << 7,
broad_block = 1 << 6,
tcp_fpsh = 1 << 6,
tcp_nodelay = 1 << 5,
igmp_ver2 = 1 << 5,
solicit_block = 1 << 5,
ether_multi4b = 1 << 5,
uni_block = 1 << 4,
ether_multi6b = 1 << 4,
force_arp = 1 << 0,
dha_manual = 1 << 1,
io_nonblock = 1 << 3,
};
constexpr sock_flag operator|(sock_flag a, sock_flag b) {
return static_cast<sock_flag>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
}
constexpr uint8_t operator&(sock_flag a, sock_flag b) {
return static_cast<uint8_t>(a) & static_cast<uint8_t>(b);
}
constexpr uint8_t SRCV6_PREFER_AUTO = 0x00;
constexpr uint8_t SRCV6_PREFER_LLA = 0x02;
constexpr uint8_t SRCV6_PREFER_GUA = 0x03;
enum class pack_info : uint8_t {
none = 0x00,
first = 1 << 1,
remained = 1 << 2,
completed = 1 << 3,
ipv6_lla = (1 << 7) | (1 << 4),
ipv6_multi = (1 << 7) | (1 << 5),
ipv6_allnode = (1 << 7) | (1 << 6),
ipv6 = 1 << 7,
};
constexpr pack_info operator|(pack_info a, pack_info b) {
return static_cast<pack_info>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
}
constexpr uint8_t operator&(pack_info a, pack_info b) {
return static_cast<uint8_t>(a) & static_cast<uint8_t>(b);
}
constexpr uint8_t TCPSOCK_MODE = 1 << 2;
constexpr uint8_t TCPSOCK_OP = 1 << 1;
constexpr uint8_t TCPSOCK_SIP = 1 << 0;
enum class srcv6_prefer : uint8_t {
auto_select = 0x00,
lla = 0x02,
gua = 0x03,
};
constexpr uint8_t SOCK_IO_BLOCK = 0;
constexpr uint8_t SOCK_IO_NONBLOCK = 1;
enum class tcp_sock_info : uint8_t {
mode = 1 << 2,
op = 1 << 1,
sip = 1 << 0,
};
int8_t open_socket(socket_id sn, uint8_t protocol, port_num port, uint8_t flag);
enum class sock_io_mode : uint8_t {
block = 0,
nonblock = 1,
};
int8_t open_socket(socket_id sn, protocol proto, port_num port, sock_flag flag);
int8_t close(socket_id sn);
int8_t listen(socket_id sn);
int8_t disconnect(socket_id sn);