Skip to content

Commit

Permalink
Move dummy tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgian committed Jun 30, 2023
1 parent 89c8e63 commit 8e33cd3
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 82 deletions.
97 changes: 97 additions & 0 deletions kernel/src/multitasking/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ pub struct Task {
pub running: bool,
}

static mut TASK_A: Task = Task {
stack: [0; 4096],
cpu_state: 0 as *mut CPUState,
running: false,
};

static mut TASK_B: Task = Task {
stack: [0; 4096],
cpu_state: 0 as *mut CPUState,
running: false,
};

static mut TASK_C: Task = Task {
stack: [0; 4096],
cpu_state: 0 as *mut CPUState,
running: false,
};

#[repr(C, packed)]
pub struct CPUState {
//manually pushed
Expand Down Expand Up @@ -176,8 +194,87 @@ impl TaskManager {
}
}
}

pub fn add_dummy_task_a(&mut self) {
unsafe {
TASK_A.init(task_a as u32);
self.add_task(&mut TASK_A as *mut Task);
}
}

pub fn add_dummy_task_b(&mut self) {
unsafe {
TASK_B.init(task_b as u32);
self.add_task(&mut TASK_B as *mut Task);
}
}

pub fn add_dummy_task_c(&mut self) {
unsafe {
TASK_C.init(task_c as u32);
self.add_task(&mut TASK_C as *mut Task);
}
}
}

fn idle() {
loop{}
}

//EXAMPLE TASKS
fn task_a() {
let mut a: u32 = 0;
let mut b: u8 = 0;
loop {
if a == 300_000_000 {
libfelix::println!("Process A running. {}% complete.", b);
a = 0;
b += 1;

if b == 100 {
libfelix::println!("Process A complete.");
break;
}
}
a += 1;
}
loop{}
}

fn task_b() {
let mut a: u32 = 0;
let mut b: u8 = 0;
loop {
if a == 300_000_000 {
libfelix::println!("Process B running. {}% complete.", b);
a = 0;
b += 1;

if b == 100 {
libfelix::println!("Process B complete.");
break;
}
}
a += 1;
}
loop{}
}

fn task_c() {
let mut a: u32 = 0;
let mut b: u8 = 0;
loop {
if a == 300_000_000 {
libfelix::println!("Process C running. {}% complete.", b);
a = 0;
b += 1;

if b == 100 {
libfelix::println!("Process C complete.");
break;
}
}
a += 1;
}
loop{}
}
85 changes: 3 additions & 82 deletions kernel/src/shell/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@ use crate::multitasking::task::TASK_MANAGER;
const APP_TARGET: u32 = 0x0050_0000;
const APP_SIGNATURE: u32 = 0xB16B00B5;

static mut TASK_A: Task = Task {
stack: [0; 4096],
cpu_state: 0 as *mut CPUState,
running: false,
};

static mut TASK_B: Task = Task {
stack: [0; 4096],
cpu_state: 0 as *mut CPUState,
running: false,
};

static mut TASK_C: Task = Task {
stack: [0; 4096],
cpu_state: 0 as *mut CPUState,
running: false,
};

const HELP: &'static str = "Available commands:
ls - lists root directory entries
cat <file> - displays content of a file
Expand Down Expand Up @@ -144,16 +126,13 @@ impl Shell {

match a {
'a' => {
TASK_A.init(task_a as u32);
TASK_MANAGER.add_task(&mut TASK_A as *mut Task);
TASK_MANAGER.add_dummy_task_a();
}
'b' => {
TASK_B.init(task_b as u32);
TASK_MANAGER.add_task(&mut TASK_B as *mut Task);
TASK_MANAGER.add_dummy_task_b();
}
'c' => {
TASK_C.init(task_c as u32);
TASK_MANAGER.add_task(&mut TASK_C as *mut Task);
TASK_MANAGER.add_dummy_task_c();
}
_ => {
libfelix::println!("Specify test a, b, or c!");
Expand Down Expand Up @@ -235,61 +214,3 @@ impl Shell {
}
}


//EXAMPLE TASKS
fn task_a() {
let mut a: u32 = 0;
let mut b: u8 = 0;
loop {
if a == 300_000_000 {
libfelix::println!("Process A running. {}% complete.", b);
a = 0;
b += 1;

if b == 100 {
libfelix::println!("Process A complete.");
break;
}
}
a += 1;
}
loop{}
}

fn task_b() {
let mut a: u32 = 0;
let mut b: u8 = 0;
loop {
if a == 300_000_000 {
libfelix::println!("Process B running. {}% complete.", b);
a = 0;
b += 1;

if b == 100 {
libfelix::println!("Process B complete.");
break;
}
}
a += 1;
}
loop{}
}

fn task_c() {
let mut a: u32 = 0;
let mut b: u8 = 0;
loop {
if a == 300_000_000 {
libfelix::println!("Process C running. {}% complete.", b);
a = 0;
b += 1;

if b == 100 {
libfelix::println!("Process C complete.");
break;
}
}
a += 1;
}
loop{}
}

0 comments on commit 8e33cd3

Please sign in to comment.