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