Skip to content

Commit a665980

Browse files
committed
Update e310x-hal to new e310x
1 parent fce40cd commit a665980

File tree

12 files changed

+48
-634
lines changed

12 files changed

+48
-634
lines changed

e310x-hal/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

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

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

e310x-hal/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
[package]
22
name = "e310x-hal"
3-
version = "0.11.0"
3+
version = "0.12.0"
44
authors = ["David Craven <david@craven.ch>"]
55
repository = "https://github.com/riscv-rust/e310x"
66
categories = ["embedded", "hardware-support", "no-std"]
77
description = "HAL for the E310x family of microcontrollers."
88
keywords = ["riscv", "e310", "hal"]
99
license = "ISC"
1010
edition = "2021"
11-
rust-version = "1.72"
11+
rust-version = "1.76"
1212

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

2020
[features]
2121
g002 = ["e310x/g002"]
22-
virq = []
22+
v-trap = ["e310x/v-trap"]
2323

2424
[package.metadata.docs.rs]
25-
features = ["g002", "virq"]
25+
features = ["g002"]

e310x-hal/src/clock.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Clock configuration
2-
use crate::core::clint::MTIME;
32
use crate::time::Hertz;
4-
use e310x::{Aonclk as AONCLK, Prci as PRCI};
3+
use e310x::{Aonclk as AONCLK, Prci as PRCI, CLINT};
54
use riscv::interrupt;
65
use riscv::register::mcycle;
76

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

180179
let divout_freq = divout_freq.0;
181-
assert!((DIVOUT_MIN..=DIVOUT_MAX).contains(&divout_freq));
180+
assert!(DIVOUT_MIN <= divout_freq && divout_freq <= DIVOUT_MAX);
182181

183182
// Calculate PLL Output Divider settings
184183
let divider_div;
@@ -205,7 +204,7 @@ impl CoreClk {
205204
2 * (divider_div + 1)
206205
};
207206
let pllout_freq = divout_freq * d;
208-
assert!((PLLOUT_MIN..=PLLOUT_MAX).contains(&pllout_freq));
207+
assert!(PLLOUT_MIN <= pllout_freq && pllout_freq <= PLLOUT_MAX);
209208

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

219218
// Calculate refr frequency
220219
let refr_freq = pllref_freq / r;
221-
assert!((REFR_MIN..=REFR_MAX).contains(&refr_freq));
220+
assert!(REFR_MIN <= refr_freq && refr_freq <= REFR_MAX);
222221

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

231230
// Calculate the desired vco frequency
232231
let target_vco_freq = pllout_freq * q;
233-
assert!((VCO_MIN..=VCO_MAX).contains(&target_vco_freq));
232+
assert!(VCO_MIN <= target_vco_freq && target_vco_freq <= VCO_MAX);
234233

235234
// Calculate PLL F ratio
236235
let f = target_vco_freq / refr_freq;
@@ -249,15 +248,15 @@ impl CoreClk {
249248
} else {
250249
(f_lo, vco_lo)
251250
};
252-
assert!((VCO_MIN..=VCO_MAX).contains(&vco_freq));
251+
assert!(VCO_MIN <= vco_freq && vco_freq <= VCO_MAX);
253252

254253
// Calculate actual pllout frequency
255254
let pllout_freq = vco_freq / q;
256-
assert!((PLLOUT_MIN..=PLLOUT_MAX).contains(&pllout_freq));
255+
assert!(PLLOUT_MIN <= pllout_freq && pllout_freq <= PLLOUT_MAX);
257256

258257
// Calculate actual divout frequency
259258
let divout_freq = pllout_freq / d;
260-
assert!((DIVOUT_MIN..=DIVOUT_MAX).contains(&divout_freq));
259+
assert!(DIVOUT_MIN <= divout_freq && divout_freq <= DIVOUT_MAX);
261260

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

@@ -385,19 +384,19 @@ impl Clocks {
385384

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

393392
let start_cycle = mcycle::read64();
394-
let start_time = mtime.mtime();
393+
let start_time = mtime.read();
395394

396395
// Wait for min_ticks to pass
397-
while start_time + min_ticks > mtime.mtime() {}
396+
while start_time + min_ticks > mtime.read() {}
398397

399398
let end_cycle = mcycle::read64();
400-
let end_time = mtime.mtime();
399+
let end_time = mtime.read();
401400

402401
let delta_cycle: u64 = end_cycle - start_cycle;
403402
let delta_time: u64 = end_time - start_time;

e310x-hal/src/core/clint.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

e310x-hal/src/core/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
//! E31 core peripherals
22
3-
pub mod clint;
43
pub mod counters;
5-
pub mod plic;
4+
5+
pub use e310x::{CLINT, PLIC};
66

77
/// Core peripherals
88
pub struct CorePeripherals {
9-
/// Core-Local Interruptor
10-
pub clint: clint::Clint,
11-
12-
/// Platform-Level Interrupt Controller
13-
pub plic: plic::Plic,
14-
159
/// Performance counters
1610
pub counters: counters::PerformanceCounters,
1711
}
1812

1913
impl CorePeripherals {
20-
pub(crate) fn new(clint: e310x::Clint, plic: e310x::Plic) -> Self {
14+
pub(crate) fn new() -> Self {
2115
Self {
22-
clint: clint.into(),
23-
plic: plic.into(),
2416
counters: counters::PerformanceCounters::new(),
2517
}
2618
}
@@ -31,7 +23,6 @@ impl CorePeripherals {
3123
///
3224
/// Using this function may break the guarantees of the singleton pattern.
3325
pub unsafe fn steal() -> Self {
34-
let p = e310x::Peripherals::steal();
35-
Self::new(p.clint, p.plic)
26+
Self::new()
3627
}
3728
}

0 commit comments

Comments
 (0)