ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
app_init.c
Go to the documentation of this file.
1
2/*
3 * ether2ser - Ethernet <-> synchronous V.24 (RS-232/V.28) bridge
4 *
5 * File: src/system/app_init.c
6 * Purpose: Application context initialization and startup defaults.
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Copyright (c) 2026 Florian <f.leuze@outlook.de>
11 */
12
13// Related headers
14#include "app_context.h"
15
16// Standard library headers
17#include <stdbool.h>
18#include <string.h>
19
20// Library Headers
21
22// Project Headers
24#include "drivers/v24_config.h"
27#include "protocol/hdlc_sync.h"
28#include "system/common.h"
30
31// Generated headers
33
35{
36 return app_ctx;
37}
38
39void init_app(app_ctx_t* app, const config_t* persistent_config)
40{
41 app_ctx = app;
42 memset(&app->stats, 0, sizeof(app->stats));
43 app->need_prompt = true;
45 app->rx_frame_buffer.length = 0;
46
48 app->tx_frame_buffer.length = 0;
49
50 if (app->config_valid)
51 {
52 memcpy(&app->persistent_config, persistent_config, sizeof(config_t));
54
61 }
62 else
63 {
64 // Setup loglevel
66 // Initialize Network Configuration
69 .port = DEFAULT_UDP_PORT,
70 };
73 app->v24_config.external_clock = false;
74
77 };
79 }
80
81 // Initialize HDLC Sync
84 .length = 0,
85 .capacity = sizeof(app->reconstructed_frame_buffer)};
86}
app_ctx_t * app_ctx
Definition app_init.c:32
void init_app(app_ctx_t *app, const config_t *persistent_config)
Initialize application context from persistent/default configuration.
Definition app_init.c:39
app_ctx_t * get_app_ctx(void)
Get access to the app context. This context is owned by main, app_init just takes hold of a pointer t...
Definition app_init.c:34
void set_loglevel(log_level_t level)
Set current global log level.
Definition log.c:66
@ LOG_LEVEL_DEBUG
Definition common.h:91
#define HDLC_FLAG_BYTE
Definition hdlc_common.h:29
void hdlc_sync_acc_init(HDLC_SYNC_ACCUMULATOR_T *accumulator, uint8_t sync_byte)
Initialize HDLC sync accumulator state.
Definition hdlc_sync.c:507
void reinit_v24_config(V24_CONFIG_T *config, V24_BAUDRATE_T baudrate)
Reinitialize V.24 runtime configuration and derived timing values.
void init_v24_config(V24_CONFIG_T *config, V24_BAUDRATE_T baudrate)
Initialize V.24 runtime configuration structure.
Generic HDLC frame buffer descriptor.
Definition hdlc_common.h:38
uint8_t * payload
Definition hdlc_common.h:40
uint8_t broadcast_address[4]
UDP endpoint configuration.
uint8_t ip_address[4]
uint16_t port
size_t length
uint8_t * payload
V24_BAUDRATE_T baudrate
Definition v24_config.h:89
bool external_clock
Definition v24_config.h:97
Global application context shared across modules.
Definition app_context.h:98
uint8_t reconstructed_frame_buffer[RX_HDLC_SYNC_MAX_BUFFER_SIZE]
UDP_FRAME_T tx_frame_buffer
bool need_prompt
UDP_FRAME_T rx_frame_buffer
HDLC_SYNC_ACCUMULATOR_T accumulator
payload_statistics_t stats
uint8_t rx_frame_buffer_data[RX_BUF_SIZE]
NETWORK_CONFIG_T net_config
UDP_CONFIG_T local_config
V24_CONFIG_T v24_config
config_t persistent_config
Definition app_context.h:99
UDP_CONFIG_T destination_config
uint8_t tx_frame_buffer_data[TX_BUF_SIZE]
bool config_valid
HDLC_FRAME_T reconstructed_frame
Persistent configuration blob stored in flash.
UDP_CONFIG_T local_config
NETWORK_CONFIG_T net_config
V24_CONFIG_T v24_config
log_level_t log_level
UDP_CONFIG_T remote_config
@ V24_BAUD_9600
Definition v24_config.h:36
void w5500_set_network_defaults(NETWORK_CONFIG_T *config)
Fill network config with compile-time defaults.
void w5500_set_network(NETWORK_CONFIG_T *config)
Apply network configuration to W5500 hardware.
#define DEFAULT_UDP_PORT
#define DEFAULT_IP_ADDR