@@ -4,8 +4,9 @@ use constance::kernel::{
4
4
} ;
5
5
use constance_port_arm:: Gic ;
6
6
use constance_portkit:: tickless:: { TicklessCfg , TicklessStateTrait } ;
7
+ use rza1:: ostm0 as ostm;
7
8
8
- use crate :: os_timer:: { cfg:: OsTimerOptions , os_timer_regs } ;
9
+ use crate :: os_timer:: cfg:: OsTimerOptions ;
9
10
10
11
/// Implemented on a system type by [`use_os_timer!`].
11
12
///
@@ -26,9 +27,9 @@ pub unsafe trait OsTimerInstance: Kernel + OsTimerOptions + Gic {
26
27
}
27
28
28
29
trait OsTimerInstanceExt : OsTimerInstance {
29
- fn ostm_regs ( ) -> & ' static os_timer_regs :: OsTimer {
30
+ fn ostm_regs ( ) -> & ' static ostm :: RegisterBlock {
30
31
// 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 ) }
32
33
}
33
34
}
34
35
impl < T : OsTimerInstance > OsTimerInstanceExt for T { }
@@ -66,11 +67,18 @@ pub fn init<System: OsTimerInstance>() {
66
67
// OS Timer will operate in Free-Running Comparison Mode, where the timer
67
68
// counts up from `0` and generates an interrupt when the counter value
68
69
// 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
74
82
75
83
debug_assert_eq ! ( tcfg. hw_max_tick_count( ) , u32 :: MAX ) ;
76
84
@@ -83,7 +91,7 @@ pub fn init<System: OsTimerInstance>() {
83
91
}
84
92
85
93
fn hw_tick_count < System : OsTimerInstance > ( ) -> u32 {
86
- System :: ostm_regs ( ) . CNT . get ( )
94
+ System :: ostm_regs ( ) . cnt . read ( ) . bits ( )
87
95
}
88
96
89
97
/// Implements [`constance::kernel::PortTimer::tick_count`]
@@ -125,7 +133,8 @@ pub unsafe fn pend_tick_after<System: OsTimerInstance>(tick_count_delta: UTicks)
125
133
let cur_hw_tick_count = hw_tick_count :: < System > ( ) ;
126
134
let measurement = tstate. mark_reference_and_measure ( tcfg, cur_hw_tick_count, tick_count_delta) ;
127
135
128
- ostm. CMP . set ( measurement. end_hw_tick_count ) ;
136
+ ostm. cmp
137
+ . write ( |w| w. cmp ( ) . bits ( measurement. end_hw_tick_count ) ) ;
129
138
130
139
// Did we go past `hw_tick_count` already? In that case, pend an interrupt
131
140
// manually because the timer might not have generated an interrupt.
0 commit comments