diff --git a/Cargo.lock b/Cargo.lock index ada0d1883b..be3b3c2b31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5861,6 +5861,7 @@ dependencies = [ "ringbuf", "serde", "ssmarshal", + "static-cell", "task-jefe-api", "userlib", "zerocopy 0.8.27", diff --git a/app/demo-stm32g0-nucleo/app-g031.toml b/app/demo-stm32g0-nucleo/app-g031.toml index bb537f7d37..e4ab820fe1 100644 --- a/app/demo-stm32g0-nucleo/app-g031.toml +++ b/app/demo-stm32g0-nucleo/app-g031.toml @@ -15,7 +15,7 @@ name = "task-jefe" priority = 0 max-sizes = {flash = 4096, ram = 512} start = true -stacksize = 368 +stacksize = 200 notifications = ["fault", "timer"] [tasks.sys] diff --git a/app/demo-stm32g0-nucleo/app-g070-mini.toml b/app/demo-stm32g0-nucleo/app-g070-mini.toml index 12bcb86183..290b4ec9b5 100644 --- a/app/demo-stm32g0-nucleo/app-g070-mini.toml +++ b/app/demo-stm32g0-nucleo/app-g070-mini.toml @@ -21,7 +21,7 @@ name = "task-jefe" priority = 0 max-sizes = {flash = 4096, ram = 512} start = true -stacksize = 400 +stacksize = 200 notifications = ["fault", "timer"] [tasks.idle] diff --git a/app/demo-stm32g0-nucleo/app-g070.toml b/app/demo-stm32g0-nucleo/app-g070.toml index 57eabd710f..8017ba6945 100644 --- a/app/demo-stm32g0-nucleo/app-g070.toml +++ b/app/demo-stm32g0-nucleo/app-g070.toml @@ -16,7 +16,7 @@ name = "task-jefe" priority = 0 max-sizes = {flash = 4096, ram = 512} start = true -stacksize = 400 +stacksize = 200 notifications = ["fault", "timer"] [tasks.sys] diff --git a/app/oxcon2023g0/app.toml b/app/oxcon2023g0/app.toml index 64e050c4f2..c88d020c58 100644 --- a/app/oxcon2023g0/app.toml +++ b/app/oxcon2023g0/app.toml @@ -6,7 +6,7 @@ board = "oxcon2023g0" [kernel] name = "oxcon2023g0" -requires = {flash = 11680, ram = 1296} +requires = {flash = 11744, ram = 1296} stacksize = 640 [tasks.jefe] @@ -15,7 +15,7 @@ priority = 0 max-sizes = {flash = 4096, ram = 512} start = true features = ["nano"] -stacksize = 368 +stacksize = 200 notifications = ["fault", "timer"] [tasks.sys] diff --git a/sys/num-tasks/build.rs b/sys/num-tasks/build.rs index 6b632b9ffe..caf62c2c5d 100644 --- a/sys/num-tasks/build.rs +++ b/sys/num-tasks/build.rs @@ -23,6 +23,7 @@ fn main() -> Result<(), Box> { if build_util::has_feature("task-enum") { writeln!(task_file, "#[allow(non_camel_case_types)]").unwrap(); + writeln!(task_file, "#[derive(Copy, Clone)]").unwrap(); writeln!(task_file, "pub enum Task {{").unwrap(); for line in task_enum { writeln!(task_file, "{line}").unwrap(); diff --git a/task/jefe/Cargo.toml b/task/jefe/Cargo.toml index 72ed229ec6..95919ab3a9 100644 --- a/task/jefe/Cargo.toml +++ b/task/jefe/Cargo.toml @@ -21,6 +21,7 @@ hubris-num-tasks = { path = "../../sys/num-tasks", features = ["task-enum"] } ringbuf = { path = "../../lib/ringbuf" } task-jefe-api = { path = "../jefe-api" } userlib = { path = "../../sys/userlib" } +static-cell = { path = "../../lib/static-cell" } [build-dependencies] anyhow = { workspace = true } diff --git a/task/jefe/src/main.rs b/task/jefe/src/main.rs index f2db0c5f20..4abdd4aa32 100644 --- a/task/jefe/src/main.rs +++ b/task/jefe/src/main.rs @@ -37,12 +37,12 @@ use core::convert::Infallible; use hubris_num_tasks::NUM_TASKS; use humpty::DumpArea; use idol_runtime::RequestError; +use static_cell::ClaimOnceCell; use task_jefe_api::{DumpAgentError, ResetReason}; use userlib::{kipc, Generation, TaskId}; -#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Disposition { - #[default] Restart, Hold, } @@ -64,10 +64,23 @@ const MIN_RUN_TIME: u64 = 50; #[export_name = "main"] fn main() -> ! { - let mut task_states = [TaskStatus::default(); hubris_num_tasks::NUM_TASKS]; - for held_task in generated::HELD_TASKS { - task_states[held_task as usize].disposition = Disposition::Hold; - } + let task_states = { + static STATES: ClaimOnceCell<[TaskStatus; NUM_TASKS]> = { + const INITIAL_STATE: TaskStatus = TaskStatus { + disposition: Disposition::Restart, + state: TaskState::Running { started_at: 0 }, + }; + let mut tasks = [INITIAL_STATE; NUM_TASKS]; + let mut i = 0; + while i < generated::HELD_TASKS.len() { + let held_task = generated::HELD_TASKS[i] as usize; + tasks[held_task].disposition = Disposition::Hold; + i += 1; + } + ClaimOnceCell::new(tasks) + }; + STATES.claim() + }; let deadline = userlib::set_timer_relative(TIMER_INTERVAL, notifications::TIMER_MASK); @@ -77,7 +90,7 @@ fn main() -> ! { let mut server = ServerImpl { state: 0, deadline, - task_states: &mut task_states, + task_states, any_tasks_in_timeout: false, reset_reason: ResetReason::Unknown, @@ -322,7 +335,7 @@ impl idl::InOrderJefeImpl for ServerImpl<'_> { /// Structure we use for tracking the state of the tasks we supervise. There is /// one of these per supervised task. -#[derive(Copy, Clone, Debug, Default)] +#[derive(Copy, Clone, Debug)] struct TaskStatus { disposition: Disposition, state: TaskState, @@ -340,12 +353,6 @@ enum TaskState { }, } -impl Default for TaskState { - fn default() -> Self { - TaskState::Running { started_at: 0 } - } -} - impl idol_runtime::NotificationHandler for ServerImpl<'_> { fn current_notification_mask(&self) -> u32 { notifications::FAULT_MASK | notifications::TIMER_MASK