sparreal_kernel/task/
mod.rs1use alloc::string::{String, ToString};
2use tcb::set_current;
3
4mod schedule;
5mod tcb;
6
7pub use schedule::suspend;
8pub use tcb::{Pid, TaskControlBlock, TaskControlBlockData, current};
9
10#[derive(Debug, Clone)]
11pub enum TaskError {
12 NoMemory,
13}
14
15#[derive(Debug, Clone)]
16pub struct TaskConfig {
17 pub name: String,
18 pub priority: usize,
19 pub stack_size: usize,
20}
21
22impl TaskConfig {
23 pub fn new(name: impl ToString) -> Self {
24 Self {
25 name: name.to_string(),
26 priority: 0,
27 stack_size: 2 * 1024 * 1024,
28 }
29 }
30}
31
32pub fn spawn_with_config<F>(f: F, config: TaskConfig) -> Result<(), TaskError>
33where
34 F: FnOnce() + Send + 'static,
35{
36 let task = TaskControlBlock::new(f, config)?;
37
38 tcb::current().switch_to(&task);
39
40 Ok(())
41}
42
43pub fn init() {
44 let task = TaskControlBlock::new_main();
45 set_current(&task);
46}
47
48pub fn wake_up_in_irq(_pid: Pid) {}