Skip to content

Commit

Permalink
Improve test tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgian committed Jun 15, 2023
1 parent 188d627 commit 5c41782
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Available commands:
- **help** shows available commands
- **ls** lists root directory entries
- **cat <filename>** displays content of a file
- **test** tests CPU scheduler with dummy tasks
- **test <a,b,c>** runs a dummy task
- **run <file>** loads file as task and adds it to the task list
- **ps** lists running tasks
- **rt <id>** removes specified task
Expand Down
79 changes: 66 additions & 13 deletions kernel/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const APP_SIGNATURE: u32 = 0xB16B00B5;
const HELP: &'static str = "Available commands:
ls - lists root directory entries
cat <file> - displays content of a file
test - tests CPU scheduler with dummy tasks
test <a,b,c> - runs a dummy task
run <file> - loads file as task and adds it to the task list
ps - lists running tasks
rt <id> - removes specified task";
Expand Down Expand Up @@ -114,15 +114,27 @@ impl Shell {
self.run(&b);
},

//add three test tasks to scheduler
_b if self.is_command("test") => unsafe {
let mut task1 = Task::new(task_a as u32);
let mut task2 = Task::new(task_b as u32);
let mut task3 = Task::new(task_c as u32);

TASK_MANAGER.add_task(&mut task1 as *mut Task);
TASK_MANAGER.add_task(&mut task2 as *mut Task);
TASK_MANAGER.add_task(&mut task3 as *mut Task);
//run test task
b if self.is_command("test") => unsafe {
let a = b[5];

match a {
'a' => {
let mut task1 = Task::new(task_a as u32);
TASK_MANAGER.add_task(&mut task1 as *mut Task);
}
'b' => {
let mut task1 = Task::new(task_b as u32);
TASK_MANAGER.add_task(&mut task1 as *mut Task);
}
'c' => {
let mut task1 = Task::new(task_c as u32);
TASK_MANAGER.add_task(&mut task1 as *mut Task);
}
_ => {
libfelix::println!("Specify test a, b, or c!");
}
}
},

//help command
Expand Down Expand Up @@ -197,20 +209,61 @@ impl Shell {
}
}


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

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 {
libfelix::print!("B");
if a == 300_000_000 {
libfelix::println!("Process B running. {}% complete.", b);
a = 0;
b += 5;

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 {
libfelix::print!("C");
if a == 300_000_000 {
libfelix::println!("Process C running. {}% complete.", b);
a = 0;
b += 5;

if b == 100 {
libfelix::println!("Process C complete.");
break;
}
}
a += 1;
}
loop{}
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
channel = "nightly-2023-05-04"
components = ["rustfmt", "rust-src"]

0 comments on commit 5c41782

Please sign in to comment.