1
- //! The public interface for the RISC-V timer.
1
+ //! The public interface for the `mtime`-based timer driver .
2
2
use r3_core:: kernel:: InterruptNum ;
3
3
4
- /// Attach the implementation of [`PortTimer`] that is based on the RISC-V timer
5
- /// (`mtime`/`mtimecfg`) to a given kernel trait type. This macro also
4
+ /// Attach the implementation of [`PortTimer`] based on the RISC-V machine-mode
5
+ /// timer (`mtime`/`mtimecfg`) to a given kernel trait type. This macro also
6
6
/// implements [`Timer`] on the system type.
7
- /// **Requires [`TimerOptions `].**
7
+ /// **Requires [`MtimeOptions `].**
8
8
///
9
9
/// [`PortTimer`]: r3_kernel::PortTimer
10
10
/// [`Timer`]: crate::Timer
11
11
///
12
12
/// You should do the following:
13
13
///
14
- /// - Implement [`TimerOptions `] on the system type `$Traits`.
14
+ /// - Implement [`MtimeOptions `] on the system type `$Traits`.
15
15
/// - Call `$Traits::configure_timer()` in your configuration function.
16
16
/// See the following example.
17
17
///
18
18
/// ```rust,ignore
19
- /// r3_port_riscv::use_timer !(unsafe impl PortTimer for System);
19
+ /// r3_port_riscv::use_mtime !(unsafe impl PortTimer for System);
20
20
///
21
- /// impl r3_port_riscv::TimerOptions for System {
21
+ /// impl r3_port_riscv::MtimeOptions for System {
22
22
/// const MTIME_PTR: usize = 0x1001_1000;
23
23
/// const MTIMECMP_PTR: usize = 0x1001_1000;
24
24
/// const FREQUENCY: u64 = 1_000_000;
@@ -32,10 +32,10 @@ use r3_core::kernel::InterruptNum;
32
32
///
33
33
/// # Safety
34
34
///
35
- /// - `TimerOptions ` must be configured correctly.
35
+ /// - `MtimeOptions ` must be configured correctly.
36
36
///
37
37
#[ macro_export]
38
- macro_rules! use_timer {
38
+ macro_rules! use_mtime {
39
39
( unsafe impl PortTimer for $Traits: ty) => {
40
40
const _: ( ) = {
41
41
use $crate:: r3_core:: {
@@ -44,55 +44,55 @@ macro_rules! use_timer {
44
44
} ;
45
45
use $crate:: r3_kernel:: { PortTimer , System , UTicks } ;
46
46
use $crate:: r3_portkit:: tickless;
47
- use $crate:: { timer , Timer , TimerOptions } ;
47
+ use $crate:: { mtime , MtimeOptions , Timer } ;
48
48
49
49
impl PortTimer for $Traits {
50
50
const MAX_TICK_COUNT : UTicks = u32 :: MAX ;
51
51
const MAX_TIMEOUT : UTicks = u32 :: MAX ;
52
52
53
53
unsafe fn tick_count( ) -> UTicks {
54
54
// Safety: We are just forwarding the call
55
- unsafe { timer :: imp:: tick_count:: <Self >( ) }
55
+ unsafe { mtime :: imp:: tick_count:: <Self >( ) }
56
56
}
57
57
58
58
unsafe fn pend_tick( ) {
59
59
// Safety: We are just forwarding the call
60
- unsafe { timer :: imp:: pend_tick:: <Self >( ) }
60
+ unsafe { mtime :: imp:: pend_tick:: <Self >( ) }
61
61
}
62
62
63
63
unsafe fn pend_tick_after( tick_count_delta: UTicks ) {
64
64
// Safety: We are just forwarding the call
65
- unsafe { timer :: imp:: pend_tick_after:: <Self >( tick_count_delta) }
65
+ unsafe { mtime :: imp:: pend_tick_after:: <Self >( tick_count_delta) }
66
66
}
67
67
}
68
68
69
69
impl Timer for $Traits {
70
70
unsafe fn init( ) {
71
- unsafe { timer :: imp:: init:: <Self >( ) }
71
+ unsafe { mtime :: imp:: init:: <Self >( ) }
72
72
}
73
73
}
74
74
75
75
const TICKLESS_CFG : tickless:: TicklessCfg =
76
76
match tickless:: TicklessCfg :: new( tickless:: TicklessOptions {
77
- hw_freq_num: <$Traits as TimerOptions >:: FREQUENCY ,
78
- hw_freq_denom: <$Traits as TimerOptions >:: FREQUENCY_DENOMINATOR ,
79
- hw_headroom_ticks: <$Traits as TimerOptions >:: HEADROOM ,
77
+ hw_freq_num: <$Traits as MtimeOptions >:: FREQUENCY ,
78
+ hw_freq_denom: <$Traits as MtimeOptions >:: FREQUENCY_DENOMINATOR ,
79
+ hw_headroom_ticks: <$Traits as MtimeOptions >:: HEADROOM ,
80
80
// `mtime` is a 64-bit free-running counter and it is
81
81
// expensive to create a 32-bit timer with an arbitrary
82
82
// period out of it.
83
83
force_full_hw_period: true ,
84
84
// If clearing `mtime` is not allowed, we must record the
85
85
// starting value of `mtime` by calling `reset`.
86
- resettable: !<$Traits as TimerOptions >:: RESET_MTIME ,
86
+ resettable: !<$Traits as MtimeOptions >:: RESET_MTIME ,
87
87
} ) {
88
88
Ok ( x) => x,
89
89
Err ( e) => e. panic( ) ,
90
90
} ;
91
91
92
92
static mut TIMER_STATE : tickless:: TicklessState <TICKLESS_CFG > = Init :: INIT ;
93
93
94
- // Safety: Only `use_timer !` is allowed to `impl` this
95
- unsafe impl timer :: imp:: TimerInstance for $Traits {
94
+ // Safety: Only `use_mtime !` is allowed to `impl` this
95
+ unsafe impl mtime :: imp:: TimerInstance for $Traits {
96
96
const TICKLESS_CFG : tickless:: TicklessCfg = TICKLESS_CFG ;
97
97
98
98
type TicklessState = tickless:: TicklessState <TICKLESS_CFG >;
@@ -107,15 +107,15 @@ macro_rules! use_timer {
107
107
where
108
108
C : ~const traits:: CfgInterruptLine <System = System <Self >>,
109
109
{
110
- timer :: imp:: configure( b) ;
110
+ mtime :: imp:: configure( b) ;
111
111
}
112
112
}
113
113
} ;
114
114
} ;
115
115
}
116
116
117
- /// The options for [`use_timer !`].
118
- pub trait TimerOptions {
117
+ /// The options for [`use_mtime !`].
118
+ pub trait MtimeOptions {
119
119
/// The memory address of the `mtime` register.
120
120
const MTIME_PTR : usize ;
121
121
0 commit comments