Skip to content

Commit 637a3d1

Browse files
committed
refactor(support_rza1): use ::rza1 to access memory-mapped registers
1 parent 2eeda94 commit 637a3d1

File tree

5 files changed

+30
-54
lines changed

5 files changed

+30
-54
lines changed

Cargo.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constance_support_rza1/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ constance_port_arm = { path = "../constance_port_arm" }
1414
constance_portkit = { path = "../constance_portkit" }
1515
constance = { path = "../constance" }
1616

17-
register = "0.5.1"
17+
rza1 = { version = "0.2.0", features = ["ostm"] }

src/constance_support_rza1/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub extern crate constance_port_arm;
2626
pub mod os_timer {
2727
pub mod cfg;
2828
pub mod imp;
29-
mod os_timer_regs;
3029
}
3130

3231
pub use self::os_timer::cfg::*;

src/constance_support_rza1/src/os_timer/imp.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use constance::kernel::{
44
};
55
use constance_port_arm::Gic;
66
use constance_portkit::tickless::{TicklessCfg, TicklessStateTrait};
7+
use rza1::ostm0 as ostm;
78

8-
use crate::os_timer::{cfg::OsTimerOptions, os_timer_regs};
9+
use crate::os_timer::cfg::OsTimerOptions;
910

1011
/// Implemented on a system type by [`use_os_timer!`].
1112
///
@@ -26,9 +27,9 @@ pub unsafe trait OsTimerInstance: Kernel + OsTimerOptions + Gic {
2627
}
2728

2829
trait OsTimerInstanceExt: OsTimerInstance {
29-
fn ostm_regs() -> &'static os_timer_regs::OsTimer {
30+
fn ostm_regs() -> &'static ostm::RegisterBlock {
3031
// Safety: Verified by the user of `use_os_timer!`
31-
unsafe { &*(Self::OSTM_BASE as *const os_timer_regs::OsTimer) }
32+
unsafe { &*(Self::OSTM_BASE as *const ostm::RegisterBlock) }
3233
}
3334
}
3435
impl<T: OsTimerInstance> OsTimerInstanceExt for T {}
@@ -66,11 +67,18 @@ pub fn init<System: OsTimerInstance>() {
6667
// OS Timer will operate in Free-Running Comparison Mode, where the timer
6768
// counts up from `0` and generates an interrupt when the counter value
6869
// matches `OSTMCMP`.
69-
ostm.TT.set(1); // stop
70-
ostm.CTL
71-
.write(os_timer_regs::CTL::MD0::Disable + os_timer_regs::CTL::MD1::FreeRunningComparison);
72-
ostm.CMP.set(u32::MAX); // dummy - a real value will be set soon while booting
73-
ostm.TS.set(1); // start
70+
ostm.tt.write(|w| w.tt().stop()); // stop
71+
ostm.ctl.write(|w| {
72+
w
73+
// Don't generate an interrupt on start
74+
.md0()
75+
.clear_bit()
76+
// Free-Running Comparison Mode
77+
.md1()
78+
.free_running_comparison()
79+
});
80+
ostm.cmp.write(|w| w.cmp().bits(u32::MAX)); // dummy - a real value will be set soon while booting
81+
ostm.ts.write(|w| w.ts().start()); // start
7482

7583
debug_assert_eq!(tcfg.hw_max_tick_count(), u32::MAX);
7684

@@ -83,7 +91,7 @@ pub fn init<System: OsTimerInstance>() {
8391
}
8492

8593
fn hw_tick_count<System: OsTimerInstance>() -> u32 {
86-
System::ostm_regs().CNT.get()
94+
System::ostm_regs().cnt.read().bits()
8795
}
8896

8997
/// Implements [`constance::kernel::PortTimer::tick_count`]
@@ -125,7 +133,8 @@ pub unsafe fn pend_tick_after<System: OsTimerInstance>(tick_count_delta: UTicks)
125133
let cur_hw_tick_count = hw_tick_count::<System>();
126134
let measurement = tstate.mark_reference_and_measure(tcfg, cur_hw_tick_count, tick_count_delta);
127135

128-
ostm.CMP.set(measurement.end_hw_tick_count);
136+
ostm.cmp
137+
.write(|w| w.cmp().bits(measurement.end_hw_tick_count));
129138

130139
// Did we go past `hw_tick_count` already? In that case, pend an interrupt
131140
// manually because the timer might not have generated an interrupt.

src/constance_support_rza1/src/os_timer/os_timer_regs.rs

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

0 commit comments

Comments
 (0)