2026-04-04 16:22:37 +09:00
|
|
|
#pragma once
|
2026-04-05 08:55:51 +09:00
|
|
|
#include <array>
|
2026-04-04 16:22:37 +09:00
|
|
|
#include <cstdint>
|
2026-04-05 08:38:16 +09:00
|
|
|
#include <expected>
|
2026-04-05 08:55:51 +09:00
|
|
|
#include <span>
|
2026-04-03 22:37:43 +09:00
|
|
|
|
2026-04-05 07:01:43 +09:00
|
|
|
namespace w6300 {
|
2026-04-04 20:36:22 +09:00
|
|
|
|
2026-04-07 07:09:11 +09:00
|
|
|
constexpr int sock_count = 8;
|
2026-04-05 07:01:43 +09:00
|
|
|
|
2026-04-05 07:30:50 +09:00
|
|
|
enum class socket_id : uint8_t {};
|
|
|
|
|
enum class port_num : uint16_t {};
|
|
|
|
|
|
2026-04-05 08:55:51 +09:00
|
|
|
enum class sock_error : int16_t {
|
|
|
|
|
busy = 0,
|
|
|
|
|
sock_num = -1,
|
|
|
|
|
sock_opt = -2,
|
|
|
|
|
sock_init = -3,
|
|
|
|
|
sock_closed = -4,
|
|
|
|
|
sock_mode = -5,
|
|
|
|
|
sock_flag = -6,
|
|
|
|
|
sock_status = -7,
|
|
|
|
|
arg = -10,
|
|
|
|
|
port_zero = -11,
|
|
|
|
|
ip_invalid = -12,
|
|
|
|
|
timeout = -13,
|
|
|
|
|
data_len = -14,
|
|
|
|
|
buffer = -15,
|
|
|
|
|
fatal_packlen = -1001,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum class sock_io_mode : uint8_t {
|
|
|
|
|
block = 0,
|
|
|
|
|
nonblock = 1,
|
2026-04-04 20:36:22 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum intr_kind : uint32_t {
|
2026-04-07 07:09:11 +09:00
|
|
|
ik_pppoe_terminated = (1 << 0), ik_dest_unreach = (1 << 1), ik_ip_conflict = (1 << 2),
|
|
|
|
|
ik_dest_unreach6 = (1 << 4), ik_wol = (1 << 7), ik_net_all = 0x97,
|
|
|
|
|
ik_sock_0 = (1 << 8), ik_sock_1 = (1 << 9), ik_sock_2 = (1 << 10), ik_sock_3 = (1 << 11),
|
|
|
|
|
ik_sock_4 = (1 << 12), ik_sock_5 = (1 << 13), ik_sock_6 = (1 << 14), ik_sock_7 = (1 << 15),
|
|
|
|
|
ik_sock_all = (0xFF << 8),
|
|
|
|
|
ik_sockl_tout = (1 << 16), ik_sockl_arp4 = (1 << 17), ik_sockl_ping4 = (1 << 18),
|
|
|
|
|
ik_sockl_arp6 = (1 << 19), ik_sockl_ping6 = (1 << 20), ik_sockl_ns = (1 << 21),
|
|
|
|
|
ik_sockl_rs = (1 << 22), ik_sockl_ra = (1 << 23), ik_sockl_all = (0xFF << 16),
|
|
|
|
|
ik_int_all = 0x00FFFF97
|
2026-04-04 20:36:22 +09:00
|
|
|
};
|
|
|
|
|
|
2026-04-05 07:01:43 +09:00
|
|
|
struct ip_address {
|
2026-04-05 08:55:51 +09:00
|
|
|
std::array<uint8_t, 16> ip;
|
2026-04-04 20:36:22 +09:00
|
|
|
uint8_t len;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-05 08:55:51 +09:00
|
|
|
void init_spi();
|
|
|
|
|
void reset();
|
|
|
|
|
void init();
|
|
|
|
|
bool check();
|
2026-04-05 07:01:43 +09:00
|
|
|
|
2026-04-05 15:32:20 +09:00
|
|
|
void clear_interrupt(intr_kind intr);
|
|
|
|
|
void set_interrupt_mask(intr_kind intr);
|
2026-04-05 07:01:43 +09:00
|
|
|
|
2026-04-05 08:38:16 +09:00
|
|
|
std::expected<socket_id, sock_error> open_socket(socket_id sn, protocol proto, port_num port, sock_flag flag);
|
2026-04-05 15:32:20 +09:00
|
|
|
std::expected<uint16_t, sock_error> sendto(socket_id sn, std::span<const uint8_t> buf, const ip_address& addr, port_num port);
|
|
|
|
|
std::expected<uint16_t, sock_error> recvfrom(socket_id sn, std::span<uint8_t> buf, ip_address& addr, port_num& port);
|
2026-04-05 08:55:51 +09:00
|
|
|
|
|
|
|
|
std::expected<void, sock_error> set_socket_io_mode(socket_id sn, sock_io_mode mode);
|
2026-04-06 20:01:22 +09:00
|
|
|
void set_socket_dest_mac(socket_id sn, const std::array<uint8_t, 6>& mac);
|
2026-04-05 08:55:51 +09:00
|
|
|
uint16_t get_socket_recv_buf(socket_id sn);
|
2026-04-05 07:01:43 +09:00
|
|
|
|
|
|
|
|
} // namespace w6300
|