Files
picomap/firmware/w6300/w6300.h

100 lines
2.9 KiB
C++

#pragma once
#include <array>
#include <cstdint>
#include <expected>
#include <span>
namespace w6300 {
constexpr int sock_count = 8;
enum class socket_id : uint8_t {};
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,
};
enum intr_kind : uint32_t {
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
};
void init_spi();
void reset();
void init();
bool check();
void clear_interrupt(intr_kind intr);
void set_interrupt_mask(intr_kind intr);
std::expected<socket_id, sock_error> open_socket(socket_id sn, protocol proto, sock_flag flag);
std::expected<uint16_t, sock_error> send(socket_id sn, std::span<const uint8_t> buf);
std::expected<uint16_t, sock_error> recv(socket_id sn, std::span<uint8_t> buf);
std::expected<void, sock_error> set_socket_io_mode(socket_id sn, sock_io_mode mode);
void set_socket_dest_mac(socket_id sn, const std::array<uint8_t, 6>& mac);
uint16_t get_socket_recv_buf(socket_id sn);
} // namespace w6300