@@ -13,18 +13,21 @@ pub const XAPIC_TIMER_DIV_CONF_OFFSET: u32 = 0x3E0;
1313/// * `timer_vector` - The interrupt vector to use for the timer.
1414///
1515/// # Returns
16- /// The number of ticks per 10ms .
16+ /// The number of ticks per the configured period .
1717pub unsafe fn calibrate_timer < F1 , F2 > ( read_reg : F1 , write_reg : F2 , timer_vector : u8 ) -> u64
1818where
1919 F1 : Fn ( u32 ) -> u32 ,
2020 F2 : Fn ( u32 , u32 ) ,
2121{
22+ let period_ms = crate :: config:: TIMER_PERIOD_MS ;
23+ let period_us = period_ms * 1000 ;
24+
2225 // Stop timer
2326 write_reg ( XAPIC_TIMER_INIT_COUNT_OFFSET , 0 ) ;
2427 // Set divider to 16
2528 write_reg ( XAPIC_TIMER_DIV_CONF_OFFSET , 0x3 ) ;
2629
27- let ( ticks_per_10ms , _) = super :: calibrate_with_pit ( 10000 , || {
30+ let ( ticks_per_period , _) = super :: calibrate_with_pit ( period_us , || {
2831 // Set APIC timer to max
2932 write_reg ( XAPIC_TIMER_INIT_COUNT_OFFSET , 0xFFFFFFFF ) ;
3033 move || {
@@ -33,11 +36,14 @@ where
3336 }
3437 } ) ;
3538
36- info ! ( "APIC Timer calibrated: {} ticks per 10ms" , ticks_per_10ms) ;
39+ info ! (
40+ "APIC Timer calibrated: {} ticks per {}ms" ,
41+ ticks_per_period, period_ms
42+ ) ;
3743
38- // Set timer for periodic interrupt at 100Hz (10ms)
44+ // Set timer for periodic interrupt at the configured frequency
3945 write_reg ( XAPIC_LVT_TIMER_OFFSET , 0x20000 | timer_vector as u32 ) ; // Periodic mode
40- write_reg ( XAPIC_TIMER_INIT_COUNT_OFFSET , ticks_per_10ms as u32 ) ;
46+ write_reg ( XAPIC_TIMER_INIT_COUNT_OFFSET , ticks_per_period as u32 ) ;
4147
42- ticks_per_10ms
48+ ticks_per_period
4349}
0 commit comments