2026-04-05 21:04:56 +09:00
|
|
|
#pragma once
|
2026-04-19 00:32:13 -07:00
|
|
|
#include <cstdint>
|
2026-04-07 21:36:50 +09:00
|
|
|
#include <span>
|
2026-04-11 08:15:41 +09:00
|
|
|
#include "eth.h"
|
|
|
|
|
#include "ipv4.h"
|
2026-04-10 22:18:44 +09:00
|
|
|
#include "span_writer.h"
|
2026-04-11 14:26:53 +09:00
|
|
|
#include "callback_list.h"
|
2026-04-07 07:34:24 +09:00
|
|
|
|
|
|
|
|
struct net_state {
|
2026-04-11 08:15:41 +09:00
|
|
|
eth::mac_addr mac;
|
|
|
|
|
ipv4::ip4_addr ip;
|
2026-04-07 07:34:24 +09:00
|
|
|
};
|
2026-04-05 21:04:56 +09:00
|
|
|
|
2026-04-19 00:32:13 -07:00
|
|
|
using net_frame_callback = bool (*)(std::span<const uint8_t> frame);
|
2026-04-11 14:26:53 +09:00
|
|
|
|
2026-04-11 15:01:37 +09:00
|
|
|
using frame_cb_list = callback_list<net_frame_callback, 16>;
|
2026-04-11 14:26:53 +09:00
|
|
|
using frame_cb_handle = frame_cb_list::node*;
|
2026-04-07 21:36:50 +09:00
|
|
|
|
2026-04-19 00:32:13 -07:00
|
|
|
inline constexpr uint16_t PICOMAP_PORT_BE = __builtin_bswap16(28781);
|
|
|
|
|
|
2026-04-05 21:04:56 +09:00
|
|
|
bool net_init();
|
2026-04-07 07:34:24 +09:00
|
|
|
const net_state& net_get_state();
|
2026-04-11 14:26:53 +09:00
|
|
|
frame_cb_handle net_add_frame_callback(net_frame_callback cb);
|
|
|
|
|
void net_remove_frame_callback(frame_cb_handle h);
|
2026-04-10 22:48:28 +09:00
|
|
|
void net_poll(std::span<uint8_t> tx);
|
2026-04-11 08:15:41 +09:00
|
|
|
void net_send_raw(std::span<const uint8_t> data);
|