-
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.
Merge pull request #75 from ArtemKhel/main
Preemptive task manager
- Loading branch information
Showing
34 changed files
with
587 additions
and
106 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
15 changes: 15 additions & 0 deletions
15
examples/rust-examples/xtensa-esp32/scheduler/.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,15 @@ | ||
[build] | ||
rustflags = [ | ||
"-C", "link-arg=-Tlinkall.x", | ||
|
||
"-C", "link-arg=-nostartfiles", | ||
] | ||
|
||
target = "xtensa-esp32-none-elf" | ||
|
||
[unstable] | ||
build-std = ["core", "alloc"] | ||
|
||
[target.'cfg(any(target_arch = "riscv32", target_arch = "xtensa"))'] | ||
runner = "espflash flash --monitor" | ||
|
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_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 = ["preemptive"]} | ||
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"] |
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,36 @@ | ||
# Rust example for xtensa esp32 architecture | ||
|
||
Presented here is a straightforward Rust example utilizing Martos with preemptive scheduler. | ||
|
||
Two tasks are created. They take turns increasing the counter value and printing it out until it reaches 20. Periodically, one preempts the other | ||
|
||
## 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 | ||
``` |
2 changes: 2 additions & 0 deletions
2
examples/rust-examples/xtensa-esp32/scheduler/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 = "esp" |
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,50 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::sync::atomic::{AtomicU32, Ordering}; | ||
use esp_backtrace as _; | ||
use esp_hal::entry; | ||
use esp_hal::xtensa_lx_rt::xtensa_lx::timer::delay; | ||
use esp_println::println; | ||
use martos::{ | ||
init_system, | ||
task_manager::{TaskManager, TaskManagerTrait}, | ||
}; | ||
|
||
/// Counter to work with in loop. | ||
static COUNTER: AtomicU32 = AtomicU32::new(1); | ||
|
||
/// Loop function for task to execute. | ||
fn loop_fn_1() { | ||
let old = COUNTER.fetch_add(1, Ordering::Relaxed); | ||
println!("Loop 0; Counter = {}", old); | ||
delay(10_000_000); | ||
} | ||
|
||
fn loop_fn_2() { | ||
let old = COUNTER.fetch_add(1, Ordering::Relaxed); | ||
println!("Loop 1; Counter = {}", old); | ||
delay(10_000_000); | ||
} | ||
|
||
fn setup() { | ||
println!("Setup") | ||
} | ||
fn stop() -> bool { | ||
if COUNTER.fetch_add(0, Ordering::Relaxed) > 20 { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
// Initialize Martos. | ||
init_system(); | ||
// Add task to execute. | ||
TaskManager::add_task(setup, loop_fn_1, stop); | ||
TaskManager::add_task(setup, loop_fn_2, stop); | ||
// Start task manager. | ||
TaskManager::start_task_manager(); | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#![no_std] | ||
extern crate alloc; | ||
|
||
mod ports; | ||
use ports::PortTrait; | ||
|
Oops, something went wrong.