Skip to content

Commit

Permalink
Mutex: Moved from HAL to Aerugo
Browse files Browse the repository at this point in the history
  • Loading branch information
SteelPh0enix committed Sep 4, 2023
1 parent 750037c commit ae0bca0
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ assert_cmd = "2.0"
[features]
default = ["log"]
use-aerugo-cortex-m = ["aerugo-cortex-m", "aerugo-samv71-hal"]
use-aerugo-x86 = ["aerugo-x86", "aerugo-x86-hal"]
use-aerugo-x86 = ["aerugo-x86", "aerugo-x86-hal", "critical-section/std"]
test-aerugo-cortex-m = ["use-aerugo-x86"]
rt = ["aerugo-samv71-hal?/rt"]
log = ["aerugo-cortex-m?/log", "aerugo-x86?/log"]
Expand Down
1 change: 0 additions & 1 deletion arch/cortex-m/aerugo-cortex-m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license.workspace = true
description = "Cortex-M specific implementation for Aerugo"

[dependencies]
cortex-m = "0.7.7"
rtt-target = "0.4.0"

[features]
Expand Down
2 changes: 0 additions & 2 deletions arch/cortex-m/aerugo-cortex-m/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Cortex-M specific implementation for Aerugo.

#[cfg(feature = "log")]
mod logger;
mod mutex;

#[cfg(feature = "log")]
pub use self::logger::{init_log, log, logln};
pub use self::mutex::Mutex;
2 changes: 0 additions & 2 deletions arch/x86/aerugo-x86/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ x86 specific implementation for Aerugo.

#[cfg(feature = "log")]
mod logger;
mod mutex;

#[cfg(feature = "log")]
pub use self::logger::{init_log, log, logln};
pub use self::mutex::Mutex;
57 changes: 0 additions & 57 deletions arch/x86/aerugo-x86/src/mutex.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/boolean_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub use self::boolean_condition_storage::BooleanConditionStorage;

use crate::aerugo::{Aerugo, AERUGO};
use crate::api::{InitError, SystemApi};
use crate::arch::Mutex;
use crate::data_provider::DataProvider;
use crate::internal_list::InternalList;
use crate::tasklet::TaskletPtr;
use crate::Mutex;

/// List of tasklets registered to a condition
type TaskletList = InternalList<TaskletPtr, { Aerugo::TASKLET_COUNT }>;
Expand Down
2 changes: 1 addition & 1 deletion src/event/event_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use heapless::spsc::Queue;

use crate::aerugo::AERUGO;
use crate::api::{RuntimeError, SystemApi};
use crate::arch::Mutex;
use crate::data_provider::DataProvider;
use crate::event::EventId;
use crate::event_manager::EventManager;
use crate::tasklet::TaskletPtr;
use crate::utils::max;
use crate::Mutex;

/// Type for event queue.
type EventQueue = Queue<EventId, { max(EventManager::EVENT_COUNT, 2) }>;
Expand Down
2 changes: 1 addition & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use heapless::binary_heap::{BinaryHeap, Max};

use crate::aerugo::{Aerugo, AERUGO};
use crate::api::{RuntimeApi, RuntimeError, SystemApi};
use crate::arch::Mutex;
use crate::tasklet::{TaskletPtr, TaskletStatus};
use crate::Mutex;

/// Type for the tasklet execution queue
type TaskletQueue<const N: usize> = BinaryHeap<TaskletPtr, Max, N>;
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod execution_monitoring;
mod executor;
mod internal_list;
mod message_queue;
mod mutex;
mod stubs;
mod tasklet;
mod time_manager;
Expand All @@ -33,13 +34,16 @@ pub use self::event::{EventEnabler, EventId};
pub use self::message_queue::{MessageQueueHandle, MessageQueueStorage};
pub use self::tasklet::{TaskletConfig, TaskletStorage};
pub use aerugo_hal::{time, Duration, Instant, SystemHardwareConfig};
pub use mutex::Mutex;

#[cfg(feature = "use-aerugo-cortex-m")]
#[cfg(feature = "log")]
pub(crate) use aerugo_cortex_m as arch;
#[cfg(feature = "use-aerugo-cortex-m")]
pub use aerugo_samv71_hal as hal;

#[cfg(feature = "use-aerugo-x86")]
#[cfg(feature = "log")]
pub(crate) use aerugo_x86 as arch;
#[cfg(feature = "use-aerugo-x86")]
pub use aerugo_x86_hal as hal;
Expand Down
2 changes: 1 addition & 1 deletion src/message_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub(crate) use self::message_queue_storage::QueueData;

use crate::aerugo::{Aerugo, AERUGO};
use crate::api::{InitError, RuntimeError, SystemApi};
use crate::arch::Mutex;
use crate::data_provider::DataProvider;
use crate::internal_list::InternalList;
use crate::tasklet::TaskletPtr;
use crate::Mutex;

/// List of tasklets registered to a queue
type TaskletList = InternalList<TaskletPtr, { Aerugo::TASKLET_COUNT }>;
Expand Down
2 changes: 1 addition & 1 deletion src/message_queue/message_queue_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use core::cell::OnceCell;
use heapless::Vec;

use crate::api::InitError;
use crate::arch::Mutex;
use crate::message_queue::MessageQueueHandle;
use crate::Mutex;

/// Type of the queue buffer storage.
pub(crate) type QueueBuffer = Vec<u8, { core::mem::size_of::<MessageQueue<(), 0>>() }>;
Expand Down
4 changes: 1 addition & 3 deletions arch/cortex-m/aerugo-cortex-m/src/mutex.rs → src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use core::cell::UnsafeCell;

use cortex_m::interrupt;

/// Mutex based on the critical section.
///
/// # Generic Parameters
Expand Down Expand Up @@ -46,7 +44,7 @@ impl<T: ?Sized> Mutex<T> {
#[inline(always)]
#[allow(dead_code)]
pub fn lock<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
unsafe { interrupt::free(|_| f(self.as_mut_ref())) }
unsafe { critical_section::with(|_| f(self.as_mut_ref())) }
}

/// Returns a mutable reference to the stored value.
Expand Down
2 changes: 1 addition & 1 deletion src/tasklet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ use core::cell::{OnceCell, UnsafeCell};

use crate::aerugo::AERUGO;
use crate::api::{InitError, RuntimeApi};
use crate::arch::Mutex;
use crate::boolean_condition::BooleanConditionSet;
use crate::data_provider::DataProvider;
use crate::Instant;
use crate::Mutex;

/// Type of function that is executed by the tasklet in its step.
pub(crate) type StepFn<T, C> = fn(T, &mut C, &'static dyn RuntimeApi);
Expand Down

0 comments on commit ae0bca0

Please sign in to comment.