aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs168
1 files changed, 23 insertions, 145 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 43079c17..ba967623 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -50,7 +50,6 @@
//!
//! In increasing grade of complexity, see the [examples](./examples/index.html)
//! module.
-
#![deny(missing_docs)]
#![deny(warnings)]
#![feature(asm)]
@@ -61,76 +60,32 @@
extern crate cortex_m;
extern crate cortex_m_rtfm_macros;
+extern crate rtfm_core;
extern crate static_ref;
+use core::u8;
+
+pub use rtfm_core::{Resource, Static, Threshold};
pub use cortex_m::asm::{bkpt, wfi};
-pub use cortex_m::interrupt::CriticalSection;
-pub use cortex_m::interrupt::free as atomic;
pub use cortex_m_rtfm_macros::app;
-pub use static_ref::Static;
-use cortex_m::interrupt::Nr;
+use cortex_m::interrupt::{self, Nr};
#[cfg(not(armv6m))]
-use cortex_m::register::{basepri, basepri_max};
+use cortex_m::register::basepri;
pub mod examples;
-/// A resource, a means to share data between tasks
-pub trait Resource {
- /// The data protected by the resource
- type Data;
-
- /// Borrows the resource data for the duration of a *global* critical
- /// section
- fn borrow<'cs>(
- &'cs self,
- cs: &'cs CriticalSection,
- ) -> &'cs Static<Self::Data>;
-
- /// Mutable variant of `borrow`
- fn borrow_mut<'cs>(
- &'cs mut self,
- cs: &'cs CriticalSection,
- ) -> &'cs mut Static<Self::Data>;
-
- /// Claims the resource data for the span of the closure `f`. For the
- /// duration of the closure other tasks that may access the resource data
- /// are prevented from preempting the current task.
- fn claim<R, F>(&self, t: &mut Threshold, f: F) -> R
- where
- F: FnOnce(&Static<Self::Data>, &mut Threshold) -> R;
-
- /// Mutable variant of `claim`
- fn claim_mut<R, F>(&mut self, t: &mut Threshold, f: F) -> R
- where
- F: FnOnce(&mut Static<Self::Data>, &mut Threshold) -> R;
-}
-
-impl<T> Resource for Static<T> {
- type Data = T;
-
- fn borrow<'cs>(&'cs self, _cs: &'cs CriticalSection) -> &'cs Static<T> {
- self
- }
-
- fn borrow_mut<'cs>(
- &'cs mut self,
- _cs: &'cs CriticalSection,
- ) -> &'cs mut Static<T> {
- self
- }
-
- fn claim<R, F>(&self, t: &mut Threshold, f: F) -> R
- where
- F: FnOnce(&Static<Self::Data>, &mut Threshold) -> R,
- {
- f(self, t)
- }
-
- fn claim_mut<R, F>(&mut self, t: &mut Threshold, f: F) -> R
- where
- F: FnOnce(&mut Static<Self::Data>, &mut Threshold) -> R,
- {
- f(self, t)
+/// Executes the closure `f` in an interrupt free context
+pub fn atomic<R, F>(t: &mut Threshold, f: F) -> R
+where
+ F: FnOnce(&mut Threshold) -> R,
+{
+ if t.value() == u8::MAX {
+ f(t)
+ } else {
+ interrupt::disable();
+ let r = f(&mut unsafe { Threshold::max() });
+ unsafe { interrupt::enable() };
+ r
}
}
@@ -147,20 +102,19 @@ where
F: FnOnce(T, &mut Threshold) -> R,
{
let max_priority = 1 << nvic_prio_bits;
- if ceiling > t.value {
+ if ceiling > t.value() {
match () {
#[cfg(armv6m)]
- () => {
- atomic(|_| f(data, &mut Threshold::new(max_priority)))
- }
+ () => atomic(t, |t| f(data, t)),
+
#[cfg(not(armv6m))]
() => {
if ceiling == max_priority {
- atomic(|_| f(data, &mut Threshold::new(max_priority)))
+ atomic(t, |t| f(data, t))
} else {
let old = basepri::read();
let hw = (max_priority - ceiling) << (8 - nvic_prio_bits);
- basepri_max::write(hw);
+ basepri::write(hw);
let ret = f(data, &mut Threshold::new(ceiling));
basepri::write(old);
ret
@@ -172,25 +126,6 @@ where
}
}
-/// Preemption threshold token
-///
-/// The preemption threshold indicates the priority a task must have to preempt
-/// the current context. For example a threshold of 2 indicates that only
-/// interrupts / exceptions with a priority of 3 or greater can preempt the
-/// current context
-pub struct Threshold {
- value: u8,
-}
-
-impl Threshold {
- #[doc(hidden)]
- pub unsafe fn new(value: u8) -> Self {
- Threshold { value }
- }
-}
-
-impl !Send for Threshold {}
-
/// Sets an interrupt as pending
///
/// If the interrupt priority is high enough the interrupt will be serviced
@@ -205,63 +140,6 @@ where
nvic.set_pending(interrupt);
}
-/// Binds a task `$handler` to the interrupt / exception `$NAME`
-///
-/// This macro takes two arguments: the name of an exception / interrupt and the
-/// path to the function that will be used as the task handler. That function
-/// must have signature `fn(&mut Threshold, $NAME::Resources)`.
-///
-/// Optionally, a third argument may be used to declare task local data.
-/// The handler will have exclusive access to these *local* variables on each
-/// invocation. If the third argument is used then the signature of the handler
-/// function must be `fn(&mut Threshold, &mut $locals, $NAME::Resources)`.
-#[macro_export]
-macro_rules! task {
- ($NAME:ident, $handler:path) => {
- #[allow(non_snake_case)]
- #[allow(unsafe_code)]
- #[no_mangle]
- pub unsafe extern "C" fn $NAME() {
- let f: fn(&mut $crate::Threshold, ::$NAME::Resources) = $handler;
-
- f(
- &mut $crate::Threshold::new(::$NAME::$NAME),
- ::$NAME::Resources::new(),
- );
- }
- };
-
- ($NAME:ident, $handler:path, $locals:ident {
- $(static $var:ident: $ty:ty = $expr:expr;)+
- }) => {
- #[allow(non_snake_case)]
- struct $locals {
- $($var: $crate::Static<$ty>,)+
- }
-
- #[allow(non_snake_case)]
- #[allow(unsafe_code)]
- #[no_mangle]
- pub unsafe extern "C" fn $NAME() {
- let f: fn(
- &mut $crate::Threshold,
- &mut $locals,
- ::$NAME::Resources,
- ) = $handler;
-
- static mut LOCALS: $locals = $locals {
- $($var: unsafe { $crate::Static::new($expr) },)+
- };
-
- f(
- &mut $crate::Threshold::new(::$NAME::$NAME),
- &mut LOCALS,
- ::$NAME::Resources::new(),
- );
- }
- };
-}
-
#[allow(non_camel_case_types)]
#[doc(hidden)]
pub enum Exception {
rade-deps'>upgrade-deps Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/examples/env-vars (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-02-28[ci] update lockfile (#2676)Gravatar Fred K. Schott 1-6/+6
2022-02-28fix(runtime): do not render empty Fragment (#2667)Gravatar Mateus Esdras 1-0/+3
2022-02-28fix(hmr): HMR regression related to .astro updates (#2681)Gravatar Nate Moore 6-7/+24
2022-02-28Fix HTMLElement expression warning (#2675)Gravatar Jonathan Neal 1-1/+1
2022-02-28[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-27[ci] update lockfile (#2668)Gravatar Fred K. Schott 1-80/+80
2022-02-27[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-26[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-25[ci] yarn formatGravatar natemoo-re 1-20/+20
2022-02-25[ci] release (#2666)astro@0.23.2Gravatar github-actions[bot] 32-59/+57
2022-02-25[ci] yarn formatGravatar natemoo-re 2-12/+6
2022-02-25fix astro scoping of "@import" inside of style tags (#2656)Gravatar Fred K. Schott 3-6/+35
2022-02-25[ci] update lockfile (#2659)Gravatar Fred K. Schott 1-20/+20
2022-02-25feat: improve third-party Astro package compatability (#2665)Gravatar Nate Moore 3-6/+100
2022-02-25get new example working during buildGravatar Fred K. Schott 4-16/+21
2022-02-25[ci] yarn formatGravatar FredKSchott 1-7/+6
2022-02-25Add Non-HTML Pages example (#2637)Gravatar Joel Kuzmarski 11-0/+136
2022-02-25[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-24[ci] yarn formatGravatar natemoo-re 2-24/+24
2022-02-24[ci] release (#2641)astro@0.23.1@astrojs/markdown-remark@0.6.2Gravatar github-actions[bot] 38-90/+81
2022-02-24ensure utf8 encoding when serving html (#2654)Gravatar Fred K. Schott 3-4/+9
2022-02-24fix(core): Issue #2625. error with process.env.LANG larger than 5 (#2645)Gravatar Javier Cortés 2-1/+6
2022-02-24[ci] update lockfile (#2646)Gravatar Fred K. Schott 1-130/+124
2022-02-24chore: upgrade compiler (#2653)Gravatar Nate Moore 3-11/+11
2022-02-24[ci] yarn formatGravatar natemoo-re 2-5/+5
2022-02-24Add fine-grained HMR support (#2649)Gravatar Nate Moore 7-36/+37
2022-02-24[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-23Fixed incorrect types and imports (#2630)Gravatar Juan Martín Seery 27-35/+37
2022-02-23Add sass dev dep to blog-multiple-authors example (#2643)Gravatar Joel Kuzmarski 1-1/+2
2022-02-23Fix(component): align starting position in Markdown slot (#2631)Gravatar Shinobu Hayashi 4-6/+61
2022-02-23[ci] yarn formatGravatar matthewp 1-1/+1
2022-02-23Run all smoke tests with the static build (#2609)Gravatar Matthew Phillips 2-26/+32
2022-02-23[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-22[ci] update lockfile (#2624)Gravatar Fred K. Schott 1-171/+201
2022-02-22Fixed shiki import to work with "type": "module" (#2628)Gravatar Juan Martín Seery 3-5/+13