24#include "wizchip_conf.h"
25#include "wizchip_qspi_pio.h"
48 if (polarities == NULL)
56#define ADD(name, flag) \
61 LOG_PLAIN("%s%s", first ? "" : ",", name); \
87 return "NET_IP_REMOTE";
91 return "NET_IP_LOCAL";
95 return "NET_PORT_LOCAL";
97 return "NET_PORT_REMOTE";
175 bool changed =
false;
188 wiz_NetInfo net_info;
189 wizchip_getnetinfo(&net_info);
190 if (memcmp(net_info.ip, payload->
value.
ip, 4) != 0)
193 memcpy(net_info.ip, payload->
value.
ip, 4);
194 wizchip_setnetinfo(&net_info);
201 wiz_NetInfo net_info;
202 wizchip_getnetinfo(&net_info);
203 if (memcmp(net_info.sn, payload->
value.
ip, 4) != 0)
205 memcpy(net_info.sn, payload->
value.
ip, 4);
206 wizchip_setnetinfo(&net_info);
213 wiz_NetInfo net_info;
214 wizchip_getnetinfo(&net_info);
215 if (memcmp(net_info.gw, payload->
value.
ip, 4) != 0)
217 memcpy(net_info.gw, payload->
value.
ip, 4);
218 wizchip_setnetinfo(&net_info);
265 wiz_NetInfo net_info;
266 wizchip_getnetinfo(&net_info);
267 LOG_PLAIN(
"ip=%u.%u.%u.%u sn=%u.%u.%u.%u gw=%u.%u.%u.%u\r\n", net_info.ip[0],
268 net_info.ip[1], net_info.ip[2], net_info.ip[3], net_info.sn[0], net_info.sn[1],
269 net_info.sn[2], net_info.sn[3], net_info.gw[0], net_info.gw[1], net_info.gw[2],
318 LOG_ERROR(
"Cannot change clock mode during ongoing transmission!\r\n");
321 LOG_PLAIN(
"Switching to %s mode.\r\n", external_clock ?
"external" :
"internal");
328 LOG_INFO(
"Already in %s mode.\r\n", external_clock ?
"external" :
"internal");
354 :
"internal (TCK Pin 17)");
386 static uint64_t prev_udp_rx_frames = 0U;
387 static uint64_t prev_hdlc_frame_ready = 0U;
388 static uint64_t prev_udp_tx_frames = 0U;
389 static uint64_t prev_hdlc_decode_fail = 0U;
390 static uint64_t prev_serial_rx_bytes = 0U;
391 uint32_t report_now_ms = to_ms_since_boot(get_absolute_time());
392 uint32_t elapsed_ms = 0U;
397 if (elapsed_ms == 0U)
408 status_stats->
udp_rx_rate_fps = (d_udp_rx_frames * 1000U) / elapsed_ms;
410 status_stats->
udp_tx_rate_fps = (d_udp_tx_frames * 1000U) / elapsed_ms;
436 " udp_tx=%" PRIu64 "\r\n",
461 " hardcap_bytes=%" PRIu64 "\r\n",
468 " Accum : pos=%zu proc=%zu state=%d off=%u cand_valid=%d cand_end=%zu\r\n",
473 " rx_drop_acc_full=%" PRIu64 " hunt_idle_drop=%" PRIu64 "\r\n",
496 " PIO TX : stalled=%" PRIu32 "\r\n",
528 const char* cli_line = NULL;
537 LOG_DEBUG(
"tx_queue_enqueue_udp_frame: %d\r\n",
574 LOG_PLAIN(
"Storing persistent config in flash.\r\n");
582 LOG_PLAIN(
"Config stored. Dumping for checking:\r\n");
587 LOG_PLAIN(
"Wiping persistent config in flash.\r\n");
589 LOG_PLAIN(
"Config wiped. Dumping for checking:\r\n");
float baudrate_estimator_get_current_estimation(V24_PIN_T pin)
Get latest baudrate estimate.
void handle_cli_line(const char *line)
Parse and execute one CLI input line.
log_level_t get_loglevel(void)
Get current global log level.
#define PRINT_FRAME_HEX(label, payload_ptr, length)
void fatal_panic(e2s_error_t reason)
Print error message and panic.
e2s_error_t
Common error codes returned by ether2ser modules.
static apply_result_t ev_set_v24_settings(const event_queue_data_t *payload, app_ctx_t *app)
static const char * hdlc_sync_state_name(HDLC_SYNC_STATE_T state)
static void print_net_settings_event(const event_t *event)
static const char * net_setting_id_name(event_queue_data_types_t event_id)
static void print_status_event(app_ctx_t *app, ev_status_stats_t *status_stats)
static void ev_get_v24_settings(const event_queue_data_t *payload, app_ctx_t *app)
static void ev_status(app_ctx_t *app, ev_status_stats_t *status_stats)
void event_dispatch(const event_t *event, app_ctx_t *app)
Dispatch one event to the corresponding handler.
static bool ev_set_net_settings(const event_queue_data_t *payload, app_ctx_t *app)
static void print_v24_polarities(const V24_POLARITIES_T *polarities)
static void ev_get_net_settings(const event_queue_data_t *payload, const app_ctx_t *app)
static void request_save_config(void)
bool event_queue_push(const event_t *event_entry)
Enqueue an event.
bool event_get_payload_ptr(const event_t *event, size_t required_size, const void **out)
Resolve payload pointer and validate minimum payload size.
event_queue_data_types_t
Typed payload selector for configuration-oriented events.
bool hdlc_decode(const HDLC_FRAME_T *frame, uint8_t *payload, const size_t out_capacity, size_t *payload_length, bool lsb_first)
Decode an HDLC bit-stuffed frame.
void hdlc_sync_acc_init(HDLC_SYNC_ACCUMULATOR_T *accumulator, uint8_t sync_byte)
Initialize HDLC sync accumulator state.
HDLC_SYNC_STATE_T
HDLC synchronizer state machine states.
@ HDLC_SYNC_STATE_HUNTING
@ HDLC_SYNC_STATE_SYNCING
void print_flash_usage(void)
Print flash usage statistics.
void dump_config(void)
Print current configuration to console/log output.
void config_write(const config_t *cfg)
Write configuration to flash.
void print_memory_usage(void)
Print RAM usage statistics.
void config_wipe(void)
Erase persistent configuration sector.
void reinit_v24_config(V24_CONFIG_T *config, V24_BAUDRATE_T baudrate)
Reinitialize V.24 runtime configuration and derived timing values.
const v24_runtime_t * get_v24_runtime(void)
Returns a pointer to the v24 runtime.
v24_runtime_t v24_runtime
void rx_clock_update_settings(V24_RX_POLARITIES_T *polarities)
Apply RX runtime settings to an already configured RX PIO SM. Take note that this function relies on ...
void tx_clock_update_settings(V24_CONFIG_T *config)
Apply TX runtime settings to an already configured TX PIO SM. Take note that this function relies on ...
Generic HDLC frame buffer descriptor.
TX_QUEUE_ENTRY_T current_entry
V24_POLARITIES_T polarities
Combined TX and RX polarity configuration.
V24_RX_POLARITIES_T rx_polarities
V24_TX_POLARITIES_T tx_polarities
Global application context shared across modules.
UDP_FRAME_T tx_frame_buffer
UDP_FRAME_T rx_frame_buffer
HDLC_SYNC_ACCUMULATOR_T accumulator
payload_statistics_t stats
NETWORK_CONFIG_T net_config
UDP_CONFIG_T local_config
config_t persistent_config
UDP_CONFIG_T destination_config
HDLC_FRAME_T reconstructed_frame
UDP_CONFIG_T local_config
NETWORK_CONFIG_T net_config
UDP_CONFIG_T remote_config
uint64_t hdlc_rx_rate_fps
uint64_t decode_fail_rate
uint64_t serial_rx_rate_bps
Generic event payload wrapper for network/V.24 config operations.
V24_POLARITIES_T polarities
event_queue_data_types_t id
union event_queue_data_t::@0 value
uint64_t rx_fifo_stall_events
uint64_t sync_candidate_consume
uint64_t hdlc_decode_fail
uint64_t tx_queue_used_max
uint64_t resync_no_progress_count
uint64_t decode_fail_crc_mismatch
uint64_t sync_hardcap_drop_events
uint64_t udp_rx_throttle_enter
uint64_t tx_queue_drop_frames
uint64_t accumulator_pos_max
uint64_t hunt_idle_drop_bytes
uint64_t event_queue_drop_events
uint64_t decode_fail_unstuff_error
uint64_t udp_rx_throttle_skips
uint64_t log_queue_used_max
uint64_t hdlc_frame_ready
uint64_t serial_rx_drop_acc_full
uint64_t decode_fail_invalid_frame
uint64_t event_queue_used_max
uint64_t decode_fail_too_short
uint64_t sync_hardcap_drop_bytes
uint64_t resync_idle_timeout_count
uint64_t sync_lookahead_wait_syncing
uint64_t resync_hard_fail_count
uint64_t udp_tx_buffer_full_counts
uint64_t decode_fail_payload_too_long
uint64_t sync_lookahead_wait_synced
uint64_t udp_rx_buffer_full_counts
bool tx_queue_is_empty(TX_QUEUE_T *queue)
Check whether queue and active entry are fully drained.
e2s_error_t tx_queue_enqueue_udp_frame(TX_QUEUE_T *queue, const UDP_FRAME_T *frame)
Encode UDP frame to HDLC and append it to TX queue.
void w5500_udp_tx(UDP_CONFIG_T *send_config, const UDP_FRAME_T *frame)
Send one UDP frame through W5500.
e2s_error_t w5500_reconfigure_udp_socket(UDP_CONFIG_T *config)
Reconfigure UDP socket with new endpoint settings.
void reboot(void)
Reboots by resetting the watchdog.