-
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 #1 from IvanArkhipov1999/task-manager
Task manager
- Loading branch information
Showing
23 changed files
with
665 additions
and
273 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
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 +1,23 @@ | ||
# MA-RTOS | ||
# Martos | ||
|
||
Martos is a simple RTOS for developing multi-agent real-time systems. | ||
Software for Martos can be written on both Rust (recommended) and C languages. | ||
|
||
In current version it has only primitive task manager and timer counter. | ||
|
||
## Programming on Rust | ||
For writing software on Rust you can use Martos as dependency: | ||
``` | ||
[dependencies] | ||
ma_rtos = ... | ||
``` | ||
|
||
Rust examples for different architecures you can see in examples/rust-examples. | ||
|
||
## Programming on C | ||
For writing software on C you can link your project with Martos static library. | ||
You can get Martos static library from release artifacts. | ||
If you want to build Martos static library yourself, see c-library directory. | ||
It contains static library targets for different architectures. | ||
|
||
C examples for different architecures you can see in examples/c-examples. |
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 @@ | ||
[target.xtensa-esp32-none-elf] | ||
runner = "espflash flash --monitor" | ||
|
||
|
||
[build] | ||
rustflags = [ | ||
"-C", "link-arg=-Tlinkall.x", | ||
|
||
"-C", "link-arg=-nostartfiles", | ||
] | ||
|
||
target = "xtensa-esp32-none-elf" | ||
|
||
[unstable] | ||
build-std = ["core"] | ||
|
||
[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,21 @@ | ||
[package] | ||
name = "xtensa_esp32_static_lib" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "xtensa_esp32_static_lib" | ||
crate-type = ["staticlib"] | ||
|
||
[profile.release] | ||
debug = true | ||
|
||
[dependencies] | ||
# TODO: path should be from git, then from crates.io | ||
ma_rtos = { path = "../../", features = ["c-library"] } | ||
esp32-hal = "0.18.0" | ||
esp-backtrace = { version = "0.11.0", features = ["esp32", "panic-handler", "exception-handler", "println"] } | ||
esp-println = { version = "0.9.0", features = ["esp32"] } | ||
|
||
[features] | ||
default = ["esp32-hal/xtal-40mhz"] |
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,36 @@ | ||
// TODO: maybe all this should be in martos, not in c-library folder | ||
|
||
#![no_std] | ||
|
||
use ma_rtos::task_manager::TaskExecutor; | ||
use ma_rtos::timer::{TickType, Timer}; | ||
|
||
#[panic_handler] | ||
fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn setup_timer() { | ||
Timer::setup_timer() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn loop_timer() { | ||
Timer::loop_timer() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn stop_condition_timer() -> bool { | ||
Timer::stop_condition_timer() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn get_tick_counter() -> TickType { | ||
Timer::get_tick_counter() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn new_task_executor() -> TaskExecutor { | ||
TaskExecutor::new() | ||
} |
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,6 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(hello_world) |
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 @@ | ||
|
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,7 @@ | ||
idf_component_register(SRCS "hello_world_main.c" | ||
INCLUDE_DIRS "") | ||
|
||
# Linking with martos static library. Set here path to it in your project. | ||
# Here path is so for ci. | ||
# TODO: should be more beautiful linking | ||
target_link_libraries(${COMPONENT_LIB} ${CMAKE_CURRENT_LIST_DIR}/../../../../c-library/xtensa-esp32/target/xtensa-esp32-none-elf/debug/libxtensa_esp32_static_lib.a -Wl,--allow-multiple-definition) |
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,11 @@ | ||
#include <stdio.h> | ||
|
||
extern long get_tick_counter(); | ||
|
||
void app_main(void) | ||
{ | ||
long tick = get_tick_counter(); | ||
printf("tick in c = %ld\n", tick); | ||
|
||
for (;;) {} | ||
} |
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 @@ | ||
[target.xtensa-esp32-none-elf] | ||
runner = "espflash flash --monitor" | ||
|
||
|
||
[build] | ||
rustflags = [ | ||
"-C", "link-arg=-Tlinkall.x", | ||
|
||
"-C", "link-arg=-nostartfiles", | ||
] | ||
|
||
target = "xtensa-esp32-none-elf" | ||
|
||
[unstable] | ||
build-std = ["core"] | ||
|
||
[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,17 @@ | ||
[package] | ||
name = "example_xtensa_esp32" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[profile.release] | ||
debug = true | ||
|
||
[dependencies] | ||
# TODO: path should be from git, then from crates.io | ||
ma_rtos = { path = "../../../" } | ||
esp32-hal = "0.18.0" | ||
esp-backtrace = { version = "0.11.0", features = ["esp32", "panic-handler", "exception-handler", "println"] } | ||
esp-println = { version = "0.9.0", features = ["esp32"] } | ||
|
||
[features] | ||
default = ["esp32-hal/xtal-40mhz"] |
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,42 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::sync::atomic::{AtomicU32, Ordering}; | ||
use esp32_hal::entry; | ||
use esp_backtrace as _; | ||
use esp_println::println; | ||
use ma_rtos::task_manager; | ||
|
||
/// Counter to work with in loop. | ||
static COUNTER: AtomicU32 = AtomicU32::new(1); | ||
|
||
/// Setup function for task to execute. | ||
fn setup_fn() { | ||
println!("Setup hello world!") | ||
} | ||
|
||
/// Loop function for task to execute. | ||
fn loop_fn() { | ||
COUNTER.fetch_add(1, Ordering::Relaxed); | ||
println!("Loop hello world!"); | ||
println!("Counter = {}", unsafe { COUNTER.as_ptr().read() }); | ||
} | ||
|
||
/// Stop condition function for task to execute. | ||
fn stop_condition_fn() -> bool { | ||
let value = unsafe { COUNTER.as_ptr().read() }; | ||
if value % 50 == 0 { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
// Creating task executer. | ||
let mut task_executor = task_manager::TaskExecutor::new(); | ||
// Add task to execute. | ||
task_executor.add_task(setup_fn, loop_fn, stop_condition_fn); | ||
// Start task manager. | ||
task_executor.start_task_manager(); | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -1,28 +1,4 @@ | ||
use crate::timer::{TickType, Timer}; | ||
use lazy_static::lazy_static; | ||
use std::thread; | ||
use std::time::Duration; | ||
#![no_std] | ||
|
||
pub mod connection; | ||
pub mod task_manager; | ||
pub mod timer; | ||
|
||
lazy_static! { | ||
static ref TIMER: Timer = Timer::new(0, 5, 0.1); | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn init_timer() { | ||
TIMER.start(); | ||
thread::sleep(Duration::from_millis(5)); | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn stop_timer() { | ||
thread::sleep(Duration::from_millis(5)); | ||
TIMER.stop(); | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn get_tick_counter() -> TickType { | ||
TIMER.get_tick_counter() | ||
} |
Oops, something went wrong.