Skip to content

Commit 68e8168

Browse files
committed
Merge branch '💥-traitize' into 🦆
2 parents 2418e12 + 192fbd7 commit 68e8168

File tree

228 files changed

+10561
-6540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+10561
-6540
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
run: |
128128
features='${{ matrix.features }}'
129129
if [ "$features" ]; then
130-
features="--features r3_test_suite/$features"
130+
features="--features r3_test_suite/$features --features r3_kernel/$features"
131131
fi
132132
echo "features_param=$features" >> $GITHUB_ENV
133133

Cargo.lock

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"examples/smp_rp_pico",
1010
"src/arm_semihosting",
1111
"src/r3",
12+
"src/r3_kernel",
1213
"src/r3_port_arm",
1314
"src/r3_port_arm_m",
1415
"src/r3_port_arm_m_test_driver",

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,36 @@
1010
<a href="https://repl.it/@yvt/R3-Kernel-Hosted-Port#main.rs"><b>Try it on Repl.it</b></a>
1111
</p>
1212

13-
R3 is a proof-of-concept of a static RTOS that utilizes Rust's compile-time function evaluation mechanism for static configuration (creation of kernel objects and memory allocation).
13+
R3 is a proof-of-concept of a static RTOS that utilizes Rust's compile-time function evaluation mechanism for static configuration (creation of kernel objects and memory allocation) and const traits to decouple kernel interfaces from implementation.
1414

1515
- **All kernel objects are defined statically** for faster boot times, compile-time checking, predictable execution, reduced RAM consumption, no runtime allocation failures, and extra security.
16-
- The kernel and its configurator **don't require an external build tool or a specialized procedural macro**, maintaining transparency.
17-
- The kernel is split into a target-independent portion and a target-specific portion. The target-specific portion (called *a port*) is provided as a separate crate. An application **combines them using the trait system**.
16+
- A kernel and its configurator **don't require an external build tool or a specialized procedural macro**, maintaining transparency and inter-crate composability.
17+
- The kernel API is **not tied to a specific kernel implementation**. Kernels are provided as separate crates, one of which an application chooses and instantiates using the trait system.
1818
- Leverages Rust's type safety for access control of kernel objects. Safe code can't access an object that it doesn't own.
1919

20-
## Features
21-
22-
- Traditional uniprocessor tickless real-time kernel with preemptive scheduling
20+
## R3 API
2321

2422
- **Tasks** are kernel objects associated with application threads and encapsulate their execution states. Tasks can be activated by application code or automatically at boot time. Tasks are assigned priorities (up to 2¹⁵ levels on a 32-bit target, though the implementation is heavily optimized for a smaller number of priorities), which can be changed at runtime. A task can enable **Priority Boost** to temporarily raise its priority to higher than any other tasks. The number of tasks is only limited by memory available.
2523

26-
- This kernel provides a unified interface to control **interrupt lines** and register **interrupt handlers**. In addition, the Arm M-Profile port supports **unmanaged interrupt lines**, which aren't masked when the kernel is handling a system call.
24+
- R3 provides a unified interface to control **interrupt lines** and register **interrupt handlers**. In addition, the Arm M-Profile port supports **unmanaged interrupt lines**, which aren't masked when the kernel is handling a system call.
2725

28-
- This kernel supports common synchronization primitives such as **mutexes**, **semaphores**, and **event groups**. The mutexes can use [the priority ceiling protocol] to avoid unbounded priority inversion and mutual deadlock. Tasks can **park** themselves.
26+
- R3 supports common synchronization primitives such as **mutexes**, **semaphores**, and **event groups**. The mutexes can use [the priority ceiling protocol] to avoid unbounded priority inversion and mutual deadlock. Tasks can **park** themselves.
2927

3028
- The kernel timing mechanism drives **software timers** and a **system-global clock** with microsecond precision. The system clock can be rewound or fast-forwarded for drift compensation. The timing algorithm has a logarithmic time complexity and is therefore scalable. The implementation is robust against a large interrupt processing delay.
3129

3230
- The utility library includes safe container types such as **`Mutex`** and **`RecursiveMutex`**, which are built upon low-level synchronization primitives.
3331

32+
[the priority ceiling protocol]: https://en.wikipedia.org/wiki/Priority_ceiling_protocol
33+
34+
## The Kernel
35+
36+
The R3 original kernel is provided as a separate package [`r3_kernel`][].
37+
38+
- Traditional uniprocessor tickless real-time kernel with preemptive scheduling
39+
3440
- Supports **Arm M-Profile** (all versions shipped so far), **Armv7-A** (no FPU), **RISC-V** as well as **the simulator port** that runs on a host system.
3541

36-
[the priority ceiling protocol]: https://en.wikipedia.org/wiki/Priority_ceiling_protocol
42+
[`r3_kernel`]: https://crates.io/crates/r3_kernel
3743

3844
## Example
3945

@@ -42,6 +48,7 @@ R3 is a proof-of-concept of a static RTOS that utilizes Rust's compile-time func
4248
#![feature(const_fn_trait_bound)]
4349
#![feature(const_mut_refs)]
4450
#![feature(const_fn_fn_ptr_basics)]
51+
#![feature(const_trait_impl)]
4552
#![no_std]
4653
#![no_main]
4754

@@ -50,30 +57,31 @@ R3 is a proof-of-concept of a static RTOS that utilizes Rust's compile-time func
5057
// Instantiate the Armv7-M port
5158
use r3_port_arm_m as port;
5259

53-
port::use_port!(unsafe struct System);
54-
port::use_rt!(unsafe System);
55-
port::use_systick_tickful!(unsafe impl PortTimer for System);
60+
type System = r3_kernel::System<SystemTraits>;
61+
port::use_port!(unsafe struct SystemTraits);
62+
port::use_rt!(unsafe SystemTraits);
63+
port::use_systick_tickful!(unsafe impl PortTimer for SystemTraits);
5664

57-
impl port::ThreadingOptions for System {}
65+
impl port::ThreadingOptions for SystemTraits {}
5866

59-
impl port::SysTickOptions for System {
67+
impl port::SysTickOptions for SystemTraits {
6068
// STMF401 default clock configuration
6169
// SysTick = AHB/8, AHB = HSI (internal 16-MHz RC oscillator)
6270
const FREQUENCY: u64 = 2_000_000;
6371
}
6472

6573
// ----------------------------------------------------------------
6674

67-
use r3::kernel::{Task, cfg::CfgBuilder};
75+
use r3::kernel::Task;
6876

6977
struct Objects {
7078
task: Task<System>,
7179
}
7280

7381
// Instantiate the kernel, allocate object IDs
74-
const COTTAGE: Objects = r3::build!(System, configure_app => Objects);
82+
const COTTAGE: Objects = r3_kernel::build!(SystemTraits, configure_app => Objects);
7583

76-
const fn configure_app(b: &mut CfgBuilder<System>) -> Objects {
84+
const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
7785
System::configure_systick(b);
7886

7987
Objects {

doc/guidelines.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@ Exceptions:
6161

6262
### Optional features should be documented properly (CC-DOC-OPT-FEATURES)
6363

64-
All optional features of `r3` must be listed and explained in the crate-level documentation.
64+
All optional features of `r3` and `r3_kernel` must be listed and explained in the crate-level documentation.
6565

6666
In addition, every public item gated by such features must have [`#[doc(cfg(feature = ...))]` attribute](https://github.com/rust-lang/rust/issues/43781), which displays the required feature on the generated documentation.
6767

6868
```rust
69-
/// Get the current [system time].
70-
///
71-
/// [system time]: crate#kernel-timing
69+
/// Get the current system time.
7270
#[cfg(feature = "system_time")]
7371
#[doc(cfg(feature = "system_time"))]
74-
fn time() -> Result<Time, TimeError>;
72+
pub fn time() -> Result<Time, TimeError>;
7573
```
7674

7775
## Testing
@@ -107,18 +105,18 @@ The runtime overhead caused by unused features should be minimized or eliminated
107105

108106
Example: If no startup hooks are defined, the compiler will simply remove the startup hook initialization loop because it can figure out that `STARTUP_HOOKS` has no elements.
109107

110-
- If the usage of such features can be detected statically in a configuration macro (e.g., `r3::build!`), the macro should control the type choices based on that.
108+
- If the usage of such features can be detected statically in a configuration macro (e.g., `r3_kernel::build!`), the macro should control the type choices based on that.
111109

112110
Examples:
113111

114112
- `r3_portkit::tickful::TickfulState` (used by timer drivers) chooses the optimal algorithm based on parameters.
115113

116114
- Kernel objects are defined statically and their control blocks are stored in static arrays.
117115

118-
- If the above options are infeasible, expose either a `CfgBuilder` method or a Cargo feature to let downstream crates and application developers specify whether a feature should be compiled in.
116+
- If the above options are infeasible, expose either a method in `Cfg` or a Cargo feature to let downstream crates and application developers specify whether a feature should be compiled in.
119117

120118
Examples:
121119

122120
- The system clock is controlled by `system_time` feature. The system time is tracked by an internal variable that is updated on timer interrupts, and there's no hope of the compiler optimizing this out. It's impossible for `build!` to detect the usage of `System::time()`. The system clock is not tied to any particular kernel objects, so the software components dependent on the system clock might not have a configuration function. On the other hand, Cargo features are designed exactly for this use case.
123121

124-
- Application code can change task priorities at runtime. The maximum (lowest) priority affects the size of internal kernel structures, but it's impossible for `build!` to figure that out. Therefore, `CfgBuilder` exposes `num_task_priority_levels` method.
122+
- Application code can change task priorities at runtime. The maximum (lowest) priority affects the size of internal kernel structures, but it's impossible for `build!` to figure that out. Therefore, `Cfg` exposes `num_task_priority_levels` method.

examples/basic/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77

88
[dependencies]
99
r3_port_std = { path = "../../src/r3_port_std" }
10-
r3 = { path = "../../src/r3", features = ["system_time"] }
10+
r3_kernel = { path = "../../src/r3_kernel", features = ["system_time"] }
11+
r3 = { path = "../../src/r3" }
1112

1213
log = { version = "0.4.8" }

examples/basic/src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#![feature(const_fn_trait_bound)]
22
#![feature(const_fn_fn_ptr_basics)]
33
#![feature(const_mut_refs)]
4+
#![feature(const_trait_impl)]
45
#![deny(unsafe_op_in_unsafe_fn)]
56
#![deny(unsupported_naked_functions)]
67
use r3::{
7-
kernel::{cfg::CfgBuilder, Task},
8+
kernel::{prelude::*, traits, Task},
89
prelude::*,
910
sync::Mutex,
1011
};
1112

12-
r3_port_std::use_port!(unsafe struct System);
13+
type System = r3_kernel::System<SystemTraits>;
14+
r3_port_std::use_port!(unsafe struct SystemTraits);
1315

1416
#[derive(Debug)]
1517
struct Objects {
@@ -18,9 +20,9 @@ struct Objects {
1820
mutex1: Mutex<System, u32>,
1921
}
2022

21-
const COTTAGE: Objects = r3::build!(System, configure_app => Objects);
23+
const COTTAGE: Objects = r3_kernel::build!(SystemTraits, configure_app => Objects);
2224

23-
const fn configure_app(b: &mut CfgBuilder<System>) -> Objects {
25+
const fn configure_app(b: &mut r3_kernel::Cfg<'_, SystemTraits>) -> Objects {
2426
b.num_task_priority_levels(4);
2527

2628
let task1 = Task::build()

examples/basic_gr_peach/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ publish = false
88
[dependencies]
99
r3_support_rza1 = { path = "../../src/r3_support_rza1", features = ["semver-exempt"] }
1010
r3_port_arm = { path = "../../src/r3_port_arm" }
11-
r3 = { path = "../../src/r3", features = ["system_time"] }
11+
r3_kernel = { path = "../../src/r3_kernel", features = ["system_time"] }
12+
r3 = { path = "../../src/r3" }
1213

1314
rtt-target = { version = "0.2.0" }
1415
rza1 = { version = "0.2.0", features = ["cpg", "gpio", "scif"] }

0 commit comments

Comments
 (0)