Skip to content

Compatibility with riscv v0.14.0, riscv-peripheral v0.3.0, and riscv-rt v0.15.0 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions e310x-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- Update `e310x` dependency and adapt code

## [v0.12.0] - 2024-12-10

### Changed
Expand Down
2 changes: 1 addition & 1 deletion e310x-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ embedded-io = "0.6.1"
e310x = { path = "../e310x", version = "0.12.0", features = ["rt", "critical-section"] }
nb = "1.0.0"
portable-atomic = { version = "1.9", default-features = false}
riscv = { version = "0.12.1", features = ["critical-section-single-hart"] }
riscv = { version = "0.14.0", features = ["critical-section-single-hart"] }

[features]
g002 = ["e310x/g002"]
Expand Down
6 changes: 3 additions & 3 deletions e310x-hal/src/clock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Clock configuration
use crate::time::Hertz;
use e310x::{Aonclk as AONCLK, Prci as PRCI, CLINT};
use e310x::{Aonclk as AONCLK, Clint, Prci as PRCI};
use riscv::interrupt;
use riscv::register::mcycle;

Expand Down Expand Up @@ -290,7 +290,7 @@ impl CoreClk {
// Need to wait 100 us
// RTC is running at 32kHz.
// So wait 4 ticks of RTC.
let mtime = CLINT::mtimer().mtime;
let mtime = unsafe { Clint::steal() }.mtimer().mtime();
let time = mtime.read() + 4;
while mtime.read() < time {}
// Now it is safe to check for PLL Lock
Expand Down Expand Up @@ -384,7 +384,7 @@ impl Clocks {

/// Measure the coreclk frequency by counting the number of aonclk ticks.
fn _measure_coreclk(&self, min_ticks: u64) -> Hertz {
let mtime = CLINT::mtimer().mtime;
let mtime = unsafe { Clint::steal() }.mtimer().mtime();
interrupt::free(|| {
// Don't start measuring until we see an mtime tick
while mtime.read() == mtime.read() {}
Expand Down
2 changes: 1 addition & 1 deletion e310x-hal/src/core/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct PerformanceCounters {
}

impl PerformanceCounters {
pub(crate) fn new() -> Self {
pub(crate) const fn new() -> Self {
Self {
mcycle: MCYCLE,
minstret: MINSTRET,
Expand Down
12 changes: 9 additions & 3 deletions e310x-hal/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

pub mod counters;

pub use e310x::{CLINT, PLIC};
use e310x::{Clint, Plic};

/// Core peripherals
pub struct CorePeripherals {
/// Core Local Interruptor (CLINT)
pub clint: Clint,
/// Platform-Level Interrupt Controller (PLIC)
pub plic: Plic,
/// Performance counters
pub counters: counters::PerformanceCounters,
}

impl CorePeripherals {
pub(crate) fn new() -> Self {
pub(crate) const fn new(clint: Clint, plic: Plic) -> Self {
Self {
clint,
plic,
counters: counters::PerformanceCounters::new(),
}
}
Expand All @@ -23,6 +29,6 @@ impl CorePeripherals {
///
/// Using this function may break the guarantees of the singleton pattern.
pub unsafe fn steal() -> Self {
Self::new()
Self::new(Clint::steal(), Plic::steal())
}
}
13 changes: 7 additions & 6 deletions e310x-hal/src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # Delays

use crate::clock::Clocks;
use e310x::CLINT;
use e310x::Clint;
use embedded_hal::delay::DelayNs;
use riscv::register::mip;

Expand All @@ -22,7 +22,7 @@ impl DelayNs for Delay {
fn delay_ns(&mut self, ns: u32) {
let ticks = (ns as u64) * TICKS_PER_SECOND / 1_000_000_000;

let mtime = CLINT::mtimer().mtime;
let mtime = unsafe { Clint::steal() }.mtimer().mtime();
let t = mtime.read() + ticks;
while mtime.read() < t {}
}
Expand All @@ -45,12 +45,13 @@ impl Sleep {
impl DelayNs for Sleep {
fn delay_ns(&mut self, ns: u32) {
let ticks = (ns as u64) * u64::from(self.clock_freq) / 1_000_000_000;
let t = CLINT::mtimer().mtime.read() + ticks;
let clint = unsafe { e310x::Clint::steal() };
let t = clint.mtimer().mtime().read() + ticks;

CLINT::mtimecmp0().write(t);
clint.mtimecmp0().write(t);

// Enable timer interrupt
unsafe { CLINT::mtimer_enable() };
unsafe { clint.mtimer().enable() };

// Wait For Interrupt will put CPU to sleep until an interrupt hits
// in our case when internal timer mtime value >= mtimecmp value
Expand All @@ -66,6 +67,6 @@ impl DelayNs for Sleep {
}

// Clear timer interrupt
CLINT::mtimer_disable();
clint.mtimer().disable();
}
}
2 changes: 1 addition & 1 deletion e310x-hal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl From<Peripherals> for DeviceResources {
};

DeviceResources {
core_peripherals: CorePeripherals::new(),
core_peripherals: CorePeripherals::new(p.clint, p.plic),
peripherals,
pins: p.gpio0.into(),
}
Expand Down
2 changes: 1 addition & 1 deletion e310x/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- The I2C0 code is now gated under the `g002` feature
- Regenerate code with `svd2rust` 0.36.1
- Use `riscv` v0.13.0 and `riscv-rt` v0.14.0
- Use `riscv` v0.14.0, `riscv-peripheral` v0.3.0, and `riscv-rt` v0.15.0
- In vectored mode, align `mtvec` to 64 bytes

## [v0.12.0] - 2024-12-10
Expand Down
6 changes: 3 additions & 3 deletions e310x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ edition = "2021"

[dependencies]
critical-section = { version = "1.2.0", optional = true }
riscv = "0.13.0"
riscv-peripheral = "0.2.0"
riscv-rt = { version = "0.14.0", features = ["no-interrupts"], optional = true }
riscv = "0.14.0"
riscv-peripheral = "0.3.0"
riscv-rt = { version = "0.15.0", features = ["no-interrupts"], optional = true }
vcell = "0.1.3"

[features]
Expand Down
3 changes: 1 addition & 2 deletions e310x/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ riscv_config:

clint:
name: "CLINT"
freq: 32768
async_delay: false
mtime_freq: 32768

plic:
name: "PLIC"
Expand Down
8 changes: 4 additions & 4 deletions e310x/src/aonclk/lfrosccfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ impl R {
impl W {
#[doc = "Bits 0:5"]
#[inline(always)]
pub fn div(&mut self) -> DivW<LfrosccfgSpec> {
pub fn div(&mut self) -> DivW<'_, LfrosccfgSpec> {
DivW::new(self, 0)
}
#[doc = "Bits 16:20"]
#[inline(always)]
pub fn trim(&mut self) -> TrimW<LfrosccfgSpec> {
pub fn trim(&mut self) -> TrimW<'_, LfrosccfgSpec> {
TrimW::new(self, 16)
}
#[doc = "Bit 30"]
#[inline(always)]
pub fn enable(&mut self) -> EnableW<LfrosccfgSpec> {
pub fn enable(&mut self) -> EnableW<'_, LfrosccfgSpec> {
EnableW::new(self, 30)
}
#[doc = "Bit 31"]
#[inline(always)]
pub fn ready(&mut self) -> ReadyW<LfrosccfgSpec> {
pub fn ready(&mut self) -> ReadyW<'_, LfrosccfgSpec> {
ReadyW::new(self, 31)
}
}
Expand Down
64 changes: 32 additions & 32 deletions e310x/src/gpio0/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,162 +295,162 @@ impl R {
impl W {
#[doc = "Bit 0"]
#[inline(always)]
pub fn pin0(&mut self) -> Pin0W<DriveSpec> {
pub fn pin0(&mut self) -> Pin0W<'_, DriveSpec> {
Pin0W::new(self, 0)
}
#[doc = "Bit 1"]
#[inline(always)]
pub fn pin1(&mut self) -> Pin1W<DriveSpec> {
pub fn pin1(&mut self) -> Pin1W<'_, DriveSpec> {
Pin1W::new(self, 1)
}
#[doc = "Bit 2"]
#[inline(always)]
pub fn pin2(&mut self) -> Pin2W<DriveSpec> {
pub fn pin2(&mut self) -> Pin2W<'_, DriveSpec> {
Pin2W::new(self, 2)
}
#[doc = "Bit 3"]
#[inline(always)]
pub fn pin3(&mut self) -> Pin3W<DriveSpec> {
pub fn pin3(&mut self) -> Pin3W<'_, DriveSpec> {
Pin3W::new(self, 3)
}
#[doc = "Bit 4"]
#[inline(always)]
pub fn pin4(&mut self) -> Pin4W<DriveSpec> {
pub fn pin4(&mut self) -> Pin4W<'_, DriveSpec> {
Pin4W::new(self, 4)
}
#[doc = "Bit 5"]
#[inline(always)]
pub fn pin5(&mut self) -> Pin5W<DriveSpec> {
pub fn pin5(&mut self) -> Pin5W<'_, DriveSpec> {
Pin5W::new(self, 5)
}
#[doc = "Bit 6"]
#[inline(always)]
pub fn pin6(&mut self) -> Pin6W<DriveSpec> {
pub fn pin6(&mut self) -> Pin6W<'_, DriveSpec> {
Pin6W::new(self, 6)
}
#[doc = "Bit 7"]
#[inline(always)]
pub fn pin7(&mut self) -> Pin7W<DriveSpec> {
pub fn pin7(&mut self) -> Pin7W<'_, DriveSpec> {
Pin7W::new(self, 7)
}
#[doc = "Bit 8"]
#[inline(always)]
pub fn pin8(&mut self) -> Pin8W<DriveSpec> {
pub fn pin8(&mut self) -> Pin8W<'_, DriveSpec> {
Pin8W::new(self, 8)
}
#[doc = "Bit 9"]
#[inline(always)]
pub fn pin9(&mut self) -> Pin9W<DriveSpec> {
pub fn pin9(&mut self) -> Pin9W<'_, DriveSpec> {
Pin9W::new(self, 9)
}
#[doc = "Bit 10"]
#[inline(always)]
pub fn pin10(&mut self) -> Pin10W<DriveSpec> {
pub fn pin10(&mut self) -> Pin10W<'_, DriveSpec> {
Pin10W::new(self, 10)
}
#[doc = "Bit 11"]
#[inline(always)]
pub fn pin11(&mut self) -> Pin11W<DriveSpec> {
pub fn pin11(&mut self) -> Pin11W<'_, DriveSpec> {
Pin11W::new(self, 11)
}
#[doc = "Bit 12"]
#[inline(always)]
pub fn pin12(&mut self) -> Pin12W<DriveSpec> {
pub fn pin12(&mut self) -> Pin12W<'_, DriveSpec> {
Pin12W::new(self, 12)
}
#[doc = "Bit 13"]
#[inline(always)]
pub fn pin13(&mut self) -> Pin13W<DriveSpec> {
pub fn pin13(&mut self) -> Pin13W<'_, DriveSpec> {
Pin13W::new(self, 13)
}
#[doc = "Bit 14"]
#[inline(always)]
pub fn pin14(&mut self) -> Pin14W<DriveSpec> {
pub fn pin14(&mut self) -> Pin14W<'_, DriveSpec> {
Pin14W::new(self, 14)
}
#[doc = "Bit 15"]
#[inline(always)]
pub fn pin15(&mut self) -> Pin15W<DriveSpec> {
pub fn pin15(&mut self) -> Pin15W<'_, DriveSpec> {
Pin15W::new(self, 15)
}
#[doc = "Bit 16"]
#[inline(always)]
pub fn pin16(&mut self) -> Pin16W<DriveSpec> {
pub fn pin16(&mut self) -> Pin16W<'_, DriveSpec> {
Pin16W::new(self, 16)
}
#[doc = "Bit 17"]
#[inline(always)]
pub fn pin17(&mut self) -> Pin17W<DriveSpec> {
pub fn pin17(&mut self) -> Pin17W<'_, DriveSpec> {
Pin17W::new(self, 17)
}
#[doc = "Bit 18"]
#[inline(always)]
pub fn pin18(&mut self) -> Pin18W<DriveSpec> {
pub fn pin18(&mut self) -> Pin18W<'_, DriveSpec> {
Pin18W::new(self, 18)
}
#[doc = "Bit 19"]
#[inline(always)]
pub fn pin19(&mut self) -> Pin19W<DriveSpec> {
pub fn pin19(&mut self) -> Pin19W<'_, DriveSpec> {
Pin19W::new(self, 19)
}
#[doc = "Bit 20"]
#[inline(always)]
pub fn pin20(&mut self) -> Pin20W<DriveSpec> {
pub fn pin20(&mut self) -> Pin20W<'_, DriveSpec> {
Pin20W::new(self, 20)
}
#[doc = "Bit 21"]
#[inline(always)]
pub fn pin21(&mut self) -> Pin21W<DriveSpec> {
pub fn pin21(&mut self) -> Pin21W<'_, DriveSpec> {
Pin21W::new(self, 21)
}
#[doc = "Bit 22"]
#[inline(always)]
pub fn pin22(&mut self) -> Pin22W<DriveSpec> {
pub fn pin22(&mut self) -> Pin22W<'_, DriveSpec> {
Pin22W::new(self, 22)
}
#[doc = "Bit 23"]
#[inline(always)]
pub fn pin23(&mut self) -> Pin23W<DriveSpec> {
pub fn pin23(&mut self) -> Pin23W<'_, DriveSpec> {
Pin23W::new(self, 23)
}
#[doc = "Bit 24"]
#[inline(always)]
pub fn pin24(&mut self) -> Pin24W<DriveSpec> {
pub fn pin24(&mut self) -> Pin24W<'_, DriveSpec> {
Pin24W::new(self, 24)
}
#[doc = "Bit 25"]
#[inline(always)]
pub fn pin25(&mut self) -> Pin25W<DriveSpec> {
pub fn pin25(&mut self) -> Pin25W<'_, DriveSpec> {
Pin25W::new(self, 25)
}
#[doc = "Bit 26"]
#[inline(always)]
pub fn pin26(&mut self) -> Pin26W<DriveSpec> {
pub fn pin26(&mut self) -> Pin26W<'_, DriveSpec> {
Pin26W::new(self, 26)
}
#[doc = "Bit 27"]
#[inline(always)]
pub fn pin27(&mut self) -> Pin27W<DriveSpec> {
pub fn pin27(&mut self) -> Pin27W<'_, DriveSpec> {
Pin27W::new(self, 27)
}
#[doc = "Bit 28"]
#[inline(always)]
pub fn pin28(&mut self) -> Pin28W<DriveSpec> {
pub fn pin28(&mut self) -> Pin28W<'_, DriveSpec> {
Pin28W::new(self, 28)
}
#[doc = "Bit 29"]
#[inline(always)]
pub fn pin29(&mut self) -> Pin29W<DriveSpec> {
pub fn pin29(&mut self) -> Pin29W<'_, DriveSpec> {
Pin29W::new(self, 29)
}
#[doc = "Bit 30"]
#[inline(always)]
pub fn pin30(&mut self) -> Pin30W<DriveSpec> {
pub fn pin30(&mut self) -> Pin30W<'_, DriveSpec> {
Pin30W::new(self, 30)
}
#[doc = "Bit 31"]
#[inline(always)]
pub fn pin31(&mut self) -> Pin31W<DriveSpec> {
pub fn pin31(&mut self) -> Pin31W<'_, DriveSpec> {
Pin31W::new(self, 31)
}
}
Expand Down
Loading