Skip to content

Commit

Permalink
Merge pull request #144 from rust-embedded/clean-peripheral
Browse files Browse the repository at this point in the history
remove peripheral module
  • Loading branch information
MabezDev authored Oct 11, 2023
2 parents 6301ad4 + f08efb9 commit 27f78b5
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 487 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Add `mstatus::uxl` and `mstatus::sxl`
- Add `mstatus::ube`, `mstatus::sbe`, and `mstatus::mbe` endianness bit fields
- Add `mstatush` registers (RISCV-32 only)
- Add generic implementation of a PLIC peripheral
- Add `asm::fence()`, a wrapper for implementing a `fence` instruction
- Add `asm::fence_i()`, a wrapper for implementing a `fence.i` instruction
- Add `TryFrom` implementation for `mcause::{Interrupt, Exception}` and `scause::{Interrupt, Exception}`
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ targets = [

[features]
critical-section-single-hart = ["critical-section/restore-state-bool"]
plic = ["volatile-register"]

[dependencies]
critical-section = "1.1.0"
embedded-hal = "0.2.6"
volatile-register = { version = "0.2.1", optional = true }
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
pub mod asm;
pub mod delay;
pub mod interrupt;
#[cfg(feature = "plic")]
pub mod peripheral;
pub mod register;

#[macro_use]
Expand Down
158 changes: 0 additions & 158 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,161 +55,3 @@ macro_rules! singleton {
})
};
}

/// Macro to create interfaces to PLIC contexts in PACs.
///
/// This macro expects 5 arguments:
///
/// - `PLIC`: name of the PLIC context interface structure to be created.
/// We recommend to leave `PLIC` for context 0 and `PLICx` for the remaining contexts.
///
/// - `BASE`: base address of the PLIC peripheral of the target.
///
/// - `CONTEXT`: context number assigned to the PLIC interface.
///
/// - `INTERRUPT`: enum type of the external interruptions of the target.
/// This type must implement the [`crate::peripheral::plic::InterruptNumber`] trait.
///
/// - `PRIORITY`: enum type of the priority levels supported by the target.
/// This type must implement the [`crate::peripheral::plic::PriorityNumber`] trait.
///
/// # Note
///
/// This macro requires the `plic` feature to be active.
#[cfg(feature = "plic")]
#[macro_export]
macro_rules! plic_context {
($PLIC:ident, $BASE:literal, $CONTEXT:literal, $INTERRUPT:ident, $PRIORITY:ident) => {
/// Platform-Level Interrupt Controller (PLIC) context.
#[repr(transparent)]
pub struct $PLIC {
context: $crate::peripheral::PLIC<$BASE, $CONTEXT>,
}

impl $PLIC {
/// Creates a new PLIC context interface.
pub const fn new() -> Self {
Self {
context: $crate::peripheral::PLIC::new(),
}
}

/// Enables machine external interrupts.
#[inline(always)]
pub fn enable() {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::enable();
}

/// Disables machine external interrupts.
#[inline(always)]
pub fn disable() {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::disable();
}

/// Returns the priority level associated to a given interrupt source.
#[inline(always)]
pub fn priority(source: $INTERRUPT) -> $PRIORITY {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::priority(source)
}

/// Getter method for the priority level associated to a given interrupt source.
#[inline(always)]
pub fn get_priority(&self, source: $INTERRUPT) -> $PRIORITY {
Self::priority(source)
}

/// Sets the priority level of a given interrupt source.
///
/// # Note
///
/// Interrupt source priorities are shared among all the contexts of the PLIC.
/// Thus, changing the priority of sources may affect other PLIC contexts.
///
/// # Safety
///
/// Changing priority levels can break priority-based critical sections and compromise memory safety.
#[inline(always)]
pub unsafe fn set_priority(&mut self, source: $INTERRUPT, priority: $PRIORITY) {
self.context.set_priority(source, priority);
}

/// Checks if an interrupt triggered by a given source is pending.
#[inline(always)]
pub fn is_interrupt_pending(source: $INTERRUPT) -> bool {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::is_interrupt_pending(source)
}

/// Checks if an interrupt source is enabled for the PLIC context.
#[inline(always)]
pub fn is_interrupt_enabled(source: $INTERRUPT) -> bool {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::is_interrupt_enabled(source)
}

/// Enables an interrupt source for the PLIC context.
///
/// # Safety
///
/// It performs non-atomic read-modify-write operations, which may lead to undefined behavior.
/// Additionally, Enabling an interrupt source can break mask-based critical sections.
#[inline(always)]
pub unsafe fn enable_interrupt(&mut self, source: $INTERRUPT) {
self.context.enable_interrupt(source);
}

/// Disables an interrupt source for the PLIC context.
///
/// # Safety
///
/// It performs non-atomic read-modify-write operations, which may lead to undefined behavior.
#[inline(always)]
pub unsafe fn disable_interrupt(&mut self, source: $INTERRUPT) {
self.context.disable_interrupt(source);
}

/// Returns the priority threshold of the PLIC context.
#[inline(always)]
pub fn threshold() -> $PRIORITY {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::threshold()
}

/// Getter method for the priority threshold of the PLIC context.
#[inline(always)]
pub fn get_threshold(&self) -> $PRIORITY {
Self::threshold()
}

/// Sets the priority threshold for for the PLIC context.
///
/// # Safety
///
/// Unmasking an interrupt source can break mask-based critical sections.
#[inline(always)]
pub unsafe fn set_threshold(&mut self, priority: $PRIORITY) {
self.context.set_threshold(priority);
}

/// Claims the number of a pending interrupt for for the PLIC context.
/// If no interrupt is pending for this context, it returns [`None`].
#[inline(always)]
pub fn claim() -> Option<$INTERRUPT> {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::claim()
}

/// Marks a pending interrupt as complete from for the PLIC context.
#[inline(always)]
pub fn complete(source: $INTERRUPT) {
$crate::peripheral::PLIC::<$BASE, $CONTEXT>::complete(source);
}

/// Resets the PLIC peripherals.
///
/// # Safety
///
/// It performs non-atomic read-modify-write operations, which may lead to undefined behavior.
#[inline(always)]
pub unsafe fn reset(&mut self) {
self.context.reset::<$INTERRUPT, $PRIORITY>();
}
}
};
}
44 changes: 0 additions & 44 deletions src/peripheral.rs

This file was deleted.

Loading

0 comments on commit 27f78b5

Please sign in to comment.