-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(melpo+config): Initial "platform configuration" support, startin…
…g with Melpo (#202) This PR is the initial work towards implementing #199. This introduces a `config` crate, which provides tools for platforms to have compile time defined configuration as a toml file. This PR only implements these changes for `melpomene`, as adding support to hardware platforms may require more invasive crate re-orgs.
- Loading branch information
1 parent
7d5c8cb
commit e1cce16
Showing
24 changed files
with
1,074 additions
and
229 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
mnemos_config::buildtime::render_project::<melpo_config::PlatformConfig>("melpo.toml").unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "melpo-config" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
serde = { version = "1.0.178", features = ["derive"] } | ||
mnemos-kernel = { package = "mnemos", path = "../../../source/kernel"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
//! Configuration types for Melpomene | ||
//! | ||
//! Separate crate so it can be used from the build.rs script | ||
use std::{net::SocketAddr, time::Duration}; | ||
|
||
use mnemos_kernel::forth::Params; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct PlatformConfig { | ||
/// TCP simulated uart driver settings | ||
/// | ||
/// If this field is None, then the tcp uart service will not | ||
/// be spawned. | ||
pub tcp_uart: TcpUartConfig, | ||
|
||
/// Embedded Graphics Simulator display settings | ||
/// | ||
/// If this field is None, then the display service will not | ||
/// be spawned. | ||
pub display: DisplayConfig, | ||
|
||
/// Forth GUI shell settings | ||
/// | ||
/// If this field is None, then the shell service will not | ||
/// be spawned. | ||
pub forth_shell: ForthShell, | ||
|
||
/// The maximum amount of time to sleep before repolling the | ||
/// executor (even if no simulated IRQs are received) | ||
pub sleep_cap: Option<Duration>, | ||
} | ||
|
||
impl PlatformConfig { | ||
pub const fn default_sleep_cap() -> Duration { | ||
Duration::from_millis(100) | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct TcpUartConfig { | ||
/// Should the TCP UART be enabled? | ||
#[serde(default)] | ||
pub enabled: bool, | ||
/// The maximum kchannel depth for processing messages | ||
#[serde(default = "TcpUartConfig::default_kchannel_depth")] | ||
pub kchannel_depth: usize, | ||
/// Incoming TCP buffer size in bytes | ||
#[serde(default = "TcpUartConfig::default_incoming_size")] | ||
pub incoming_size: usize, | ||
/// Outgoing TCP buffer size in bytes | ||
#[serde(default = "TcpUartConfig::default_outgoing_size")] | ||
pub outgoing_size: usize, | ||
/// Socket addr opened as a simulated serial port | ||
/// | ||
/// For example: "127.0.0.1:9999" | ||
#[serde(default = "TcpUartConfig::default_socket_addr")] | ||
pub socket_addr: SocketAddr, | ||
} | ||
|
||
impl TcpUartConfig { | ||
pub const DEFAULT_KCHANNEL_DEPTH: usize = 2; | ||
pub const DEFAULT_INCOMING_SIZE: usize = 4096; | ||
pub const DEFAULT_OUTGOING_SIZE: usize = 4096; | ||
pub const DEFAULT_SOCKET_ADDR_STR: &str = "127.0.0.1:9999"; | ||
|
||
const fn default_kchannel_depth() -> usize { | ||
Self::DEFAULT_KCHANNEL_DEPTH | ||
} | ||
const fn default_incoming_size() -> usize { | ||
Self::DEFAULT_INCOMING_SIZE | ||
} | ||
const fn default_outgoing_size() -> usize { | ||
Self::DEFAULT_OUTGOING_SIZE | ||
} | ||
fn default_socket_addr() -> SocketAddr { | ||
Self::DEFAULT_SOCKET_ADDR_STR.parse().unwrap() | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct DisplayConfig { | ||
/// Should the display be enabled | ||
#[serde(default)] | ||
pub enabled: bool, | ||
/// The maximum kchannel depth for processing messages | ||
#[serde(default = "DisplayConfig::default_kchannel_depth")] | ||
pub kchannel_depth: usize, | ||
/// The maximum number of frames per second. Must be >= 1 | ||
#[serde(default = "DisplayConfig::default_frames_per_second")] | ||
pub frames_per_second: usize, | ||
} | ||
|
||
impl DisplayConfig { | ||
pub const DEFAULT_KCHANNEL_DEPTH: usize = 2; | ||
pub const DEFAULT_FRAMES_PER_SECOND: usize = 20; | ||
|
||
const fn default_kchannel_depth() -> usize { | ||
Self::DEFAULT_KCHANNEL_DEPTH | ||
} | ||
const fn default_frames_per_second() -> usize { | ||
Self::DEFAULT_FRAMES_PER_SECOND | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct ForthShell { | ||
/// Should the forth shell be enabled | ||
#[serde(default)] | ||
pub enabled: bool, | ||
/// IO buffer capacity in bytes | ||
#[serde(default = "ForthShell::default_capacity")] | ||
pub capacity: usize, | ||
/// Forth shell parameters | ||
#[serde(default = "ForthShell::default_params")] | ||
pub params: Params, | ||
} | ||
|
||
impl ForthShell { | ||
pub const DEFAULT_CAPACITY: usize = 1024; | ||
pub const DEFAULT_PARAMS: Params = Params::new(); | ||
|
||
const fn default_capacity() -> usize { | ||
Self::DEFAULT_CAPACITY | ||
} | ||
const fn default_params() -> Params { | ||
Self::DEFAULT_PARAMS | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Melpomene configuration | ||
# | ||
# Required fields are defined below. Commented out items are the default | ||
# values, uncomment to override the defaults. | ||
|
||
[kernel] | ||
max_drivers = 16 | ||
timer_granularity = { secs = 0, nanos = 1000 } # 1us | ||
|
||
[services.keyboard_mux] | ||
enabled = true | ||
# max_keyboards = 8 | ||
# buffer_capacity = 32 | ||
sermux_port_enabled = true | ||
# sermux_port = 2 | ||
|
||
[services.serial_mux] | ||
enabled = true | ||
# max_ports = 16 | ||
# max_frame = 512 | ||
|
||
[services.spawnulator] | ||
enabled = true | ||
# capacity = 16 | ||
|
||
[services.sermux_loopback] | ||
enabled = true | ||
# port = 0 | ||
# buffer_size = 128 | ||
|
||
[services.sermux_hello] | ||
enabled = true | ||
# port = 1 | ||
# buffer_size = 32 | ||
# message = "hello\r\n" | ||
# interval = { secs = 1, nanos = 0 } | ||
|
||
[platform] | ||
# sleep_cap = { secs = 0, nanos = 100_000_000 } # 100ms | ||
|
||
[platform.display] | ||
enabled = true | ||
# kchannel_depth = 2 | ||
# frames_per_second = 20 | ||
|
||
[platform.tcp_uart] | ||
enabled = true | ||
# socket_addr = "127.0.0.1:9999" | ||
# incoming_size = 4096 | ||
# outgoing_size = 4096 | ||
# kchannel_depth = 2 | ||
|
||
[platform.forth_shell] | ||
enabled = true | ||
# capacity = 1024 | ||
|
||
# [platform.forth_shell.params] | ||
# stack_size = 256 | ||
# input_buf_size = 256 | ||
# output_buf_size = 256 | ||
# dictionary_size = 4096 | ||
# stdin_capacity = 1024 | ||
# stdout_capacity = 1024 | ||
# bag_of_holding_capacity = 16 | ||
# spawnulator_timeout = { secs = 5, nanos = 0 } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,9 @@ | ||
use crate::{sim_drivers::tcp_serial, sim_tracing}; | ||
use crate::sim_tracing; | ||
use clap::Parser; | ||
use std::net::SocketAddr; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(author, version, about)] | ||
pub struct Args { | ||
#[clap(flatten)] | ||
pub melpomene: MelpomeneOptions, | ||
|
||
#[clap(flatten)] | ||
pub tracing: sim_tracing::TracingOpts, | ||
} | ||
|
||
#[derive(Debug, clap::Args)] | ||
pub struct MelpomeneOptions { | ||
/// Address to bind the TCP listener for the simulated serial port. | ||
#[clap(long, default_value_t = tcp_serial::default_addr())] | ||
pub serial_addr: SocketAddr, | ||
} |
Oops, something went wrong.