Skip to content

Commit

Permalink
Update e310x-hal to new e310x
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed Oct 22, 2024
1 parent fce40cd commit a665980
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 634 deletions.
4 changes: 3 additions & 1 deletion e310x-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Changed

- Remove `virq` feature. Now interrupts are handled by `e310x`
- Apply clippy changes
- Use `portable-atomic` with `zaamo` feature to use native `amo*` operations.
- Official target is now `riscv32imc-unknown-none-elf`, as it does not fully support the A extension.
- Update `e310x` dependency and adapt code
- Bump MSRV to 1.72.0 to ensure a correct behavior of portable-atomic
- Bump MSRV to 1.76.0 to ensure a correct behavior of portable-atomic

## [v0.10.0] - 2023-03-28

Expand Down
12 changes: 6 additions & 6 deletions e310x-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
name = "e310x-hal"
version = "0.11.0"
version = "0.12.0"
authors = ["David Craven <[email protected]>"]
repository = "https://github.com/riscv-rust/e310x"
categories = ["embedded", "hardware-support", "no-std"]
description = "HAL for the E310x family of microcontrollers."
keywords = ["riscv", "e310", "hal"]
license = "ISC"
edition = "2021"
rust-version = "1.72"
rust-version = "1.76"

[dependencies]
embedded-hal = { version = "0.2.6", features = ["unproven"] }
nb = "1.0.0"
riscv = { version = "0.10.1", features = ["critical-section-single-hart"] }
e310x = { path = "../e310x", version = "0.11.0", features = ["rt", "critical-section"] }
riscv = { version = "0.12.1", features = ["critical-section-single-hart"] }
e310x = { path = "../e310x", version = "0.12.0", features = ["rt", "critical-section"] }
portable-atomic = { version = "1.9", default-features = false}

[features]
g002 = ["e310x/g002"]
virq = []
v-trap = ["e310x/v-trap"]

[package.metadata.docs.rs]
features = ["g002", "virq"]
features = ["g002"]
35 changes: 17 additions & 18 deletions e310x-hal/src/clock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Clock configuration
use crate::core::clint::MTIME;
use crate::time::Hertz;
use e310x::{Aonclk as AONCLK, Prci as PRCI};
use e310x::{Aonclk as AONCLK, Prci as PRCI, CLINT};
use riscv::interrupt;
use riscv::register::mcycle;

Expand Down Expand Up @@ -175,10 +174,10 @@ impl CoreClk {
/// The resulting frequency may differ by 0-2% from the requested
fn configure_pll(&self, pllref_freq: Hertz, divout_freq: Hertz) -> Hertz {
let pllref_freq = pllref_freq.0;
assert!((PLLREF_MIN..=PLLREF_MAX).contains(&pllref_freq));
assert!(PLLREF_MIN <= pllref_freq && pllref_freq <= PLLREF_MAX);

let divout_freq = divout_freq.0;
assert!((DIVOUT_MIN..=DIVOUT_MAX).contains(&divout_freq));
assert!(DIVOUT_MIN <= divout_freq && divout_freq <= DIVOUT_MAX);

// Calculate PLL Output Divider settings
let divider_div;
Expand All @@ -205,7 +204,7 @@ impl CoreClk {
2 * (divider_div + 1)
};
let pllout_freq = divout_freq * d;
assert!((PLLOUT_MIN..=PLLOUT_MAX).contains(&pllout_freq));
assert!(PLLOUT_MIN <= pllout_freq && pllout_freq <= PLLOUT_MAX);

// Calculate PLL R ratio
let r = match pllref_freq {
Expand All @@ -218,7 +217,7 @@ impl CoreClk {

// Calculate refr frequency
let refr_freq = pllref_freq / r;
assert!((REFR_MIN..=REFR_MAX).contains(&refr_freq));
assert!(REFR_MIN <= refr_freq && refr_freq <= REFR_MAX);

// Calculate PLL Q ratio
let q = match pllout_freq {
Expand All @@ -230,7 +229,7 @@ impl CoreClk {

// Calculate the desired vco frequency
let target_vco_freq = pllout_freq * q;
assert!((VCO_MIN..=VCO_MAX).contains(&target_vco_freq));
assert!(VCO_MIN <= target_vco_freq && target_vco_freq <= VCO_MAX);

// Calculate PLL F ratio
let f = target_vco_freq / refr_freq;
Expand All @@ -249,15 +248,15 @@ impl CoreClk {
} else {
(f_lo, vco_lo)
};
assert!((VCO_MIN..=VCO_MAX).contains(&vco_freq));
assert!(VCO_MIN <= vco_freq && vco_freq <= VCO_MAX);

// Calculate actual pllout frequency
let pllout_freq = vco_freq / q;
assert!((PLLOUT_MIN..=PLLOUT_MAX).contains(&pllout_freq));
assert!(PLLOUT_MIN <= pllout_freq && pllout_freq <= PLLOUT_MAX);

// Calculate actual divout frequency
let divout_freq = pllout_freq / d;
assert!((DIVOUT_MIN..=DIVOUT_MAX).contains(&divout_freq));
assert!(DIVOUT_MIN <= divout_freq && divout_freq <= DIVOUT_MAX);

// Calculate bit-values
let r: u8 = (r - 1) as u8;
Expand Down Expand Up @@ -291,9 +290,9 @@ impl CoreClk {
// Need to wait 100 us
// RTC is running at 32kHz.
// So wait 4 ticks of RTC.
let mtime = MTIME;
let time = mtime.mtime() + 4;
while mtime.mtime() < time {}
let mtime = CLINT::mtimer().mtime;
let time = mtime.read() + 4;
while mtime.read() < time {}
// Now it is safe to check for PLL Lock
while !prci.pllcfg().read().lock().bit_is_set() {}

Expand Down Expand Up @@ -385,19 +384,19 @@ impl Clocks {

/// Measure the coreclk frequency by counting the number of aonclk ticks.
fn _measure_coreclk(&self, min_ticks: u64) -> Hertz {
let mtime = MTIME;
let mtime = CLINT::mtimer().mtime;
interrupt::free(|| {
// Don't start measuring until we see an mtime tick
while mtime.mtime() == mtime.mtime() {}
while mtime.read() == mtime.read() {}

let start_cycle = mcycle::read64();
let start_time = mtime.mtime();
let start_time = mtime.read();

// Wait for min_ticks to pass
while start_time + min_ticks > mtime.mtime() {}
while start_time + min_ticks > mtime.read() {}

let end_cycle = mcycle::read64();
let end_time = mtime.mtime();
let end_time = mtime.read();

let delta_cycle: u64 = end_cycle - start_cycle;
let delta_time: u64 = end_time - start_time;
Expand Down
117 changes: 0 additions & 117 deletions e310x-hal/src/core/clint.rs

This file was deleted.

17 changes: 4 additions & 13 deletions e310x-hal/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
//! E31 core peripherals

pub mod clint;
pub mod counters;
pub mod plic;

pub use e310x::{CLINT, PLIC};

/// Core peripherals
pub struct CorePeripherals {
/// Core-Local Interruptor
pub clint: clint::Clint,

/// Platform-Level Interrupt Controller
pub plic: plic::Plic,

/// Performance counters
pub counters: counters::PerformanceCounters,
}

impl CorePeripherals {
pub(crate) fn new(clint: e310x::Clint, plic: e310x::Plic) -> Self {
pub(crate) fn new() -> Self {
Self {
clint: clint.into(),
plic: plic.into(),
counters: counters::PerformanceCounters::new(),
}
}
Expand All @@ -31,7 +23,6 @@ impl CorePeripherals {
///
/// Using this function may break the guarantees of the singleton pattern.
pub unsafe fn steal() -> Self {
let p = e310x::Peripherals::steal();
Self::new(p.clint, p.plic)
Self::new()
}
}
Loading

0 comments on commit a665980

Please sign in to comment.