-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
442 additions
and
52 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
examples/rust-examples/mips64/scheduler/cooperative/.cargo/config.toml
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 @@ | ||
[build] | ||
rustflags = [ | ||
"-C", "link-arg=-Ttext=0x80010000", | ||
"-C", "link-arg=-emain", | ||
] | ||
|
||
target = "mips64el-unknown-linux-gnuabi64" | ||
|
||
[unstable] | ||
build-std = ["core", "alloc"] | ||
|
||
[target.mips64el-unknown-linux-gnuabi64] | ||
linker = "lld" |
14 changes: 14 additions & 0 deletions
14
examples/rust-examples/mips64/scheduler/cooperative/Cargo.toml
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,14 @@ | ||
[package] | ||
name = "example_mips64_cooperative_scheduler" | ||
version = "0.4.0" | ||
edition = "2021" | ||
|
||
[profile.release] | ||
panic = "abort" | ||
debug = true | ||
|
||
[dependencies] | ||
# Specifying Martos version | ||
#martos = "0.4.0" | ||
# Specifying current Martos version path for ci | ||
martos = { path = "../../../../../", features = ["cooperative"] } |
38 changes: 38 additions & 0 deletions
38
examples/rust-examples/mips64/scheduler/cooperative/README.md
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,38 @@ | ||
# Rust example for mips64 architecture | ||
|
||
Presented here is a straightforward Rust example utilizing Martos with a cooperative scheduler. | ||
|
||
The program begins with a main task that increments a shared counter on each iteration. | ||
Once the counter reaches the value of 25, the main task dynamically adds an inner task to the task manager. | ||
The inner task also increments the shared counter on each iteration and stops execution when the counter becomes | ||
divisible by 10. This setup showcases Martos' flexibility in managing tasks, including adding new tasks dynamically | ||
during execution. | ||
|
||
## How to install dependencies | ||
|
||
Below is an illustrative example demonstrating the installation of building toolchains on a Linux (Ubuntu/Debian): | ||
|
||
``` | ||
apt update && apt install curl build-essential lld | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
rustup toolchain install nightly | ||
rustup default 1.71 | ||
rustup target add mips64el-unknown-linux-gnuabi64 | ||
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu | ||
``` | ||
|
||
## How to build the example | ||
|
||
Below, you will find an illustrative example showcasing the building process on a Linux system (Ubuntu/Debian): | ||
|
||
``` | ||
cargo +nightly build --release | ||
``` | ||
|
||
## How to run the example | ||
|
||
Below, you will find an illustrative example showcasing the running on a Linux system (Ubuntu/Debian): | ||
|
||
``` | ||
cargo +nightly run | ||
``` |
2 changes: 2 additions & 0 deletions
2
examples/rust-examples/mips64/scheduler/cooperative/rust-toolchain.toml
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,2 @@ | ||
[toolchain] | ||
channel = "nightly" |
63 changes: 63 additions & 0 deletions
63
examples/rust-examples/mips64/scheduler/cooperative/src/main.rs
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,63 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::sync::atomic::{AtomicU32, Ordering}; | ||
use martos::{ | ||
init_system, | ||
task_manager::{TaskManager, TaskManagerTrait}, | ||
}; | ||
|
||
#[panic_handler] | ||
fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} | ||
|
||
static COUNTER: AtomicU32 = AtomicU32::new(1); | ||
|
||
/// Setup function for the main task. | ||
fn main_task_setup_fn() {} | ||
|
||
/// Loop function for the main task. | ||
fn main_task_loop_fn() { | ||
let count = COUNTER.fetch_add(1, Ordering::Relaxed); | ||
if count == 25 { | ||
TaskManager::add_task( | ||
inner_task_setup_fn, | ||
inner_task_loop_fn, | ||
inner_task_stop_condition_fn, | ||
); | ||
} | ||
} | ||
|
||
/// Stop condition for the main task. | ||
fn main_task_stop_condition_fn() -> bool { | ||
false | ||
} | ||
|
||
/// Setup function for the inner task. | ||
fn inner_task_setup_fn() {} | ||
|
||
/// Loop function for the inner task. | ||
fn inner_task_loop_fn() { | ||
COUNTER.fetch_add(1, Ordering::Relaxed); | ||
} | ||
|
||
/// Stop condition for the inner task. | ||
fn inner_task_stop_condition_fn() -> bool { | ||
let value = unsafe { COUNTER.as_ptr().read() }; | ||
value % 10 == 0 | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn __start() -> ! { | ||
// Initialize Martos. | ||
init_system(); | ||
// Add task to execute. | ||
TaskManager::add_task( | ||
main_task_setup_fn, | ||
main_task_loop_fn, | ||
main_task_stop_condition_fn, | ||
); | ||
// Start task manager. | ||
TaskManager::start_task_manager(); | ||
} |
File renamed without changes.
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
45 changes: 45 additions & 0 deletions
45
examples/rust-examples/risc-v-esp32-c6/scheduler/cooperative/README.md
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,45 @@ | ||
# Rust example for risc-v esp32c6 architecture | ||
|
||
Presented here is a straightforward Rust example utilizing Martos with a cooperative scheduler. | ||
|
||
The example begins with a main task that handles a counter, incrementing it by 1 and printing the updated value. | ||
An inner task is dynamically added once the counter reaches 25, and it increments the counter by 1. The inner task | ||
periodically terminates itself when the counter is a multiple of 10, showcasing dynamic task creation and cooperative | ||
task switching. | ||
|
||
## How to install dependencies | ||
|
||
For comprehensive guidance on installing the necessary dependencies for developing applications targeting the RISC-V | ||
ESP32-C6 architecture, | ||
please refer to [the official website](https://docs.esp-rs.org/book/installation/riscv-and-xtensa.html). | ||
Below is an illustrative example demonstrating the installation of building toolchains on a Linux (Ubuntu/Debian): | ||
|
||
``` | ||
apt-get -qq update | ||
apt-get install -y -q build-essential curl | ||
curl https://sh.rustup.rs -sSf | sh -s -- -y | ||
cargo install espup | ||
espup install | ||
``` | ||
|
||
## How to build the example | ||
|
||
For a thorough guide on developing projects for the RISC-V ESP32-C6 architecture across various operating systems, | ||
we recommend | ||
consulting [the official website](https://docs.esp-rs.org/book/installation/riscv-and-xtensa.html#3-set-up-the-environment-variables). | ||
Below, you will find an illustrative example showcasing the building process on a Linux system (Ubuntu/Debian): | ||
|
||
``` | ||
. $HOME/export-esp.sh | ||
cargo build | ||
``` | ||
|
||
## How to run the example | ||
|
||
For detailed instructions on running projects for the RISC-V ESP32-C6 architecture across various operating systems, | ||
we recommend consulting [the official website](https://docs.esp-rs.org/book/tooling/espflash.html). | ||
Below, you will find an illustrative example showcasing the running on a Linux system (Ubuntu/Debian): | ||
|
||
``` | ||
cargo run | ||
``` |
File renamed without changes.
71 changes: 71 additions & 0 deletions
71
examples/rust-examples/risc-v-esp32-c6/scheduler/cooperative/src/main.rs
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,71 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::sync::atomic::{AtomicU32, Ordering}; | ||
use esp_hal::entry; | ||
use esp_println::println; | ||
use martos::{ | ||
init_system, | ||
task_manager::{TaskManager, TaskManagerTrait}, | ||
}; | ||
|
||
/// Counter to work with in loop. | ||
static COUNTER: AtomicU32 = AtomicU32::new(1); | ||
|
||
/// Setup function for the main task. | ||
fn main_task_setup_fn() { | ||
println!("Main task setup.\n"); | ||
} | ||
|
||
/// Loop function for the main task. | ||
fn main_task_loop_fn() { | ||
let count = COUNTER.fetch_add(1, Ordering::Relaxed); | ||
println!("Main task loop: Counter = {}.\n", unsafe { | ||
COUNTER.as_ptr().read() | ||
}); | ||
if count == 25 { | ||
TaskManager::add_task( | ||
inner_task_setup_fn, | ||
inner_task_loop_fn, | ||
inner_task_stop_condition_fn, | ||
); | ||
} | ||
} | ||
|
||
/// Stop condition for the main task. | ||
fn main_task_stop_condition_fn() -> bool { | ||
false | ||
} | ||
|
||
/// Setup function for the inner task. | ||
fn inner_task_setup_fn() { | ||
println!("Inner task setup.\n"); | ||
} | ||
|
||
/// Loop function for the inner task. | ||
fn inner_task_loop_fn() { | ||
COUNTER.fetch_add(1, Ordering::Relaxed); | ||
println!("Inner task loop: Counter = {}.\n", unsafe { | ||
COUNTER.as_ptr().read() | ||
}); | ||
} | ||
|
||
/// Stop condition for the inner task. | ||
fn inner_task_stop_condition_fn() -> bool { | ||
let value = unsafe { COUNTER.as_ptr().read() }; | ||
value % 10 == 0 | ||
} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
// Initialize Martos. | ||
init_system(); | ||
// Add task to execute. | ||
TaskManager::add_task( | ||
main_task_setup_fn, | ||
main_task_loop_fn, | ||
main_task_stop_condition_fn, | ||
); | ||
// Start task manager. | ||
TaskManager::start_task_manager(); | ||
} |
49 changes: 0 additions & 49 deletions
49
examples/rust-examples/risc-v-esp32-c6/scheduler/src/main.rs
This file was deleted.
Oops, something went wrong.
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
examples/rust-examples/xtensa-esp32/scheduler/cooperative/Cargo.toml
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,19 @@ | ||
[package] | ||
name = "example_xtensa_esp32_cooperative_scheduler" | ||
version = "0.3.0" | ||
edition = "2021" | ||
|
||
[profile.release] | ||
debug = true | ||
|
||
[dependencies] | ||
# Specifying Martos version | ||
#martos = "0.3.0" | ||
# Specifying current Martos version path for ci | ||
martos = { path = "../../../../../", features = ["cooperative"] } | ||
esp-hal = "0.21.1" | ||
esp-backtrace = { version = "0.14.1", features = ["esp32", "panic-handler", "exception-handler", "println"] } | ||
esp-println = { version = "0.11.0", features = ["esp32"] } | ||
|
||
[features] | ||
default = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-println/esp32"] |
45 changes: 45 additions & 0 deletions
45
examples/rust-examples/xtensa-esp32/scheduler/cooperative/README.md
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,45 @@ | ||
# Rust example for xtensa esp32 architecture | ||
|
||
Presented here is a straightforward Rust example utilizing Martos with a cooperative scheduler. | ||
|
||
The example begins with a main task that handles a counter, incrementing it by 1 and printing the updated value. | ||
An inner task is dynamically added once the counter reaches 25, and it increments the counter by 1. The inner task | ||
periodically terminates itself when the counter is a multiple of 10, showcasing dynamic task creation and cooperative | ||
task switching. | ||
|
||
## How to install dependencies | ||
|
||
For comprehensive guidance on installing the necessary dependencies for developing applications targeting the Xtensa | ||
ESP32 architecture, | ||
please refer to [the official website](https://docs.esp-rs.org/book/installation/riscv-and-xtensa.html). | ||
Below is an illustrative example demonstrating the installation of building toolchains on a Linux (Ubuntu/Debian): | ||
|
||
``` | ||
apt-get -qq update | ||
apt-get install -y -q build-essential curl | ||
curl https://sh.rustup.rs -sSf | sh -s -- -y | ||
cargo install espup | ||
espup install | ||
``` | ||
|
||
## How to build the example | ||
|
||
For a thorough guide on developing projects for the Xtensa ESP32 architecture across various operating systems, | ||
we recommend | ||
consulting [the official website](https://docs.esp-rs.org/book/installation/riscv-and-xtensa.html#3-set-up-the-environment-variables). | ||
Below, you will find an illustrative example showcasing the building process on a Linux system (Ubuntu/Debian): | ||
|
||
``` | ||
. $HOME/export-esp.sh | ||
cargo build --release | ||
``` | ||
|
||
## How to run the example | ||
|
||
For detailed instructions on running projects for the Xtensa ESP32 architecture across various operating systems, | ||
we recommend consulting [the official website](https://docs.esp-rs.org/book/tooling/espflash.html). | ||
Below, you will find an illustrative example showcasing the running on a Linux system (Ubuntu/Debian): | ||
|
||
``` | ||
cargo run | ||
``` |
File renamed without changes.
Oops, something went wrong.