-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add dynamic thread priority example
- Loading branch information
Showing
6 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ subdirs: | |
- random | ||
- threading | ||
- threading-channel | ||
- threading-dynamic-prios | ||
- usb-serial |
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 = "threading-dynamic-prios" | ||
version = "0.1.0" | ||
authors = ["Elena Frank <[email protected]>"] | ||
edition.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
riot-rs = { path = "../../src/riot-rs", features = ["threading"] } | ||
riot-rs-boards = { path = "../../src/riot-rs-boards" } |
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,13 @@ | ||
# threading-dynamic-prios | ||
|
||
## About | ||
|
||
This application demonstrates threading with dynamic priorities. | ||
|
||
## How to run | ||
|
||
In this folder, run | ||
|
||
laze build -b nrf52840dk run | ||
|
||
The application will start two threads that change their priorities during runtime. |
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,5 @@ | ||
apps: | ||
- name: threading-dynamic-prios | ||
selects: | ||
- ?release | ||
- sw/threading |
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,42 @@ | ||
#![no_main] | ||
#![no_std] | ||
#![feature(type_alias_impl_trait)] | ||
#![feature(used_with_arg)] | ||
|
||
use riot_rs::{debug::log::*, thread::ThreadId}; | ||
|
||
#[riot_rs::thread(autostart, priority = 3)] | ||
fn thread0() { | ||
let pid = riot_rs::thread::current_pid().unwrap(); | ||
info!( | ||
"{}: Running at prio {}.", | ||
pid, | ||
riot_rs::thread::get_priority(pid).unwrap() | ||
); | ||
let new_thread1_prio = 5; | ||
info!("{}: Changing Thread 1's prio to {}.", pid, new_thread1_prio); | ||
riot_rs::thread::set_priority(ThreadId::new(1), new_thread1_prio); | ||
info!( | ||
"{}: Running again at prio {}.", | ||
pid, | ||
riot_rs::thread::get_priority(pid).unwrap() | ||
); | ||
} | ||
|
||
#[riot_rs::thread(autostart, priority = 1)] | ||
fn thread1() { | ||
let pid = riot_rs::thread::current_pid().unwrap(); | ||
info!( | ||
"{}: Running at prio {}.", | ||
pid, | ||
riot_rs::thread::get_priority(pid).unwrap() | ||
); | ||
let new_prio = 1; | ||
info!("{}: Changing own prio back to {}.", pid, new_prio); | ||
riot_rs::thread::set_priority(pid, new_prio); | ||
info!( | ||
"{}: Running again at prio {}.", | ||
pid, | ||
riot_rs::thread::get_priority(pid).unwrap() | ||
); | ||
} |