@@ -80,6 +80,7 @@ use core::marker::PhantomData;
80
80
pub struct HrTimer < T > {
81
81
#[ pin]
82
82
timer : Opaque < bindings:: hrtimer > ,
83
+ mode : HrTimerMode ,
83
84
_t : PhantomData < T > ,
84
85
}
85
86
@@ -93,7 +94,7 @@ unsafe impl<T> Sync for HrTimer<T> {}
93
94
94
95
impl < T > HrTimer < T > {
95
96
/// Return an initializer for a new timer instance.
96
- pub fn new ( ) -> impl PinInit < Self >
97
+ pub fn new ( mode : HrTimerMode ) -> impl PinInit < Self >
97
98
where
98
99
T : HrTimerCallback ,
99
100
{
@@ -108,10 +109,11 @@ impl<T> HrTimer<T> {
108
109
place,
109
110
Some ( T :: Pointer :: run) ,
110
111
bindings:: CLOCK_MONOTONIC as i32 ,
111
- bindings :: hrtimer_mode_HRTIMER_MODE_REL ,
112
+ mode . into_c ( ) ,
112
113
) ;
113
114
}
114
115
} ) ,
116
+ mode: mode,
115
117
_t: PhantomData ,
116
118
} )
117
119
}
@@ -369,7 +371,7 @@ pub unsafe trait HasHrTimer<T> {
369
371
Self :: c_timer_ptr ( this) . cast_mut ( ) ,
370
372
expires. to_ns ( ) ,
371
373
0 ,
372
- bindings :: hrtimer_mode_HRTIMER_MODE_REL ,
374
+ ( * Self :: raw_get_timer ( this ) ) . mode . into_c ( ) ,
373
375
) ;
374
376
}
375
377
}
@@ -393,6 +395,80 @@ impl HrTimerRestart {
393
395
}
394
396
}
395
397
398
+ /// Operational mode of [`HrTimer`].
399
+ // NOTE: Some of these have the same encoding on the C side, so we keep
400
+ // `repr(Rust)` and convert elsewhere.
401
+ #[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
402
+ pub enum HrTimerMode {
403
+ /// Timer expires at the given expiration time.
404
+ Absolute ,
405
+ /// Timer expires after the given expiration time interpreted as a duration from now.
406
+ Relative ,
407
+ /// Timer does not move between CPU cores.
408
+ Pinned ,
409
+ /// Timer handler is executed in soft irq context.
410
+ Soft ,
411
+ /// Timer handler is executed in hard irq context.
412
+ Hard ,
413
+ /// Timer expires at the given expiration time.
414
+ /// Timer does not move between CPU cores.
415
+ AbsolutePinned ,
416
+ /// Timer expires after the given expiration time interpreted as a duration from now.
417
+ /// Timer does not move between CPU cores.
418
+ RelativePinned ,
419
+ /// Timer expires at the given expiration time.
420
+ /// Timer handler is executed in soft irq context.
421
+ AbsoluteSoft ,
422
+ /// Timer expires after the given expiration time interpreted as a duration from now.
423
+ /// Timer handler is executed in soft irq context.
424
+ RelativeSoft ,
425
+ /// Timer expires at the given expiration time.
426
+ /// Timer does not move between CPU cores.
427
+ /// Timer handler is executed in soft irq context.
428
+ AbsolutePinnedSoft ,
429
+ /// Timer expires after the given expiration time interpreted as a duration from now.
430
+ /// Timer does not move between CPU cores.
431
+ /// Timer handler is executed in soft irq context.
432
+ RelativePinnedSoft ,
433
+ /// Timer expires at the given expiration time.
434
+ /// Timer handler is executed in hard irq context.
435
+ AbsoluteHard ,
436
+ /// Timer expires after the given expiration time interpreted as a duration from now.
437
+ /// Timer handler is executed in hard irq context.
438
+ RelativeHard ,
439
+ /// Timer expires at the given expiration time.
440
+ /// Timer does not move between CPU cores.
441
+ /// Timer handler is executed in hard irq context.
442
+ AbsolutePinnedHard ,
443
+ /// Timer expires after the given expiration time interpreted as a duration from now.
444
+ /// Timer does not move between CPU cores.
445
+ /// Timer handler is executed in hard irq context.
446
+ RelativePinnedHard ,
447
+ }
448
+
449
+ impl HrTimerMode {
450
+ fn into_c ( self ) -> bindings:: hrtimer_mode {
451
+ use bindings:: * ;
452
+ match self {
453
+ HrTimerMode :: Absolute => hrtimer_mode_HRTIMER_MODE_ABS,
454
+ HrTimerMode :: Relative => hrtimer_mode_HRTIMER_MODE_REL,
455
+ HrTimerMode :: Pinned => hrtimer_mode_HRTIMER_MODE_PINNED,
456
+ HrTimerMode :: Soft => hrtimer_mode_HRTIMER_MODE_SOFT,
457
+ HrTimerMode :: Hard => hrtimer_mode_HRTIMER_MODE_HARD,
458
+ HrTimerMode :: AbsolutePinned => hrtimer_mode_HRTIMER_MODE_ABS_PINNED,
459
+ HrTimerMode :: RelativePinned => hrtimer_mode_HRTIMER_MODE_REL_PINNED,
460
+ HrTimerMode :: AbsoluteSoft => hrtimer_mode_HRTIMER_MODE_ABS_SOFT,
461
+ HrTimerMode :: RelativeSoft => hrtimer_mode_HRTIMER_MODE_REL_SOFT,
462
+ HrTimerMode :: AbsolutePinnedSoft => hrtimer_mode_HRTIMER_MODE_ABS_PINNED_SOFT,
463
+ HrTimerMode :: RelativePinnedSoft => hrtimer_mode_HRTIMER_MODE_REL_PINNED_SOFT,
464
+ HrTimerMode :: AbsoluteHard => hrtimer_mode_HRTIMER_MODE_ABS_HARD,
465
+ HrTimerMode :: RelativeHard => hrtimer_mode_HRTIMER_MODE_REL_HARD,
466
+ HrTimerMode :: AbsolutePinnedHard => hrtimer_mode_HRTIMER_MODE_ABS_PINNED_HARD,
467
+ HrTimerMode :: RelativePinnedHard => hrtimer_mode_HRTIMER_MODE_REL_PINNED_HARD,
468
+ }
469
+ }
470
+ }
471
+
396
472
/// Use to implement the [`HasHrTimer<T>`] trait.
397
473
///
398
474
/// See [`module`] documentation for an example.
0 commit comments