@@ -79,6 +79,7 @@ use core::marker::PhantomData;
7979pub struct HrTimer < T > {
8080 #[ pin]
8181 timer : Opaque < bindings:: hrtimer > ,
82+ mode : HrTimerMode ,
8283 _t : PhantomData < T > ,
8384}
8485
@@ -92,7 +93,7 @@ unsafe impl<T> Sync for HrTimer<T> {}
9293
9394impl < T > HrTimer < T > {
9495 /// Return an initializer for a new timer instance.
95- pub fn new ( ) -> impl PinInit < Self >
96+ pub fn new ( mode : HrTimerMode ) -> impl PinInit < Self >
9697 where
9798 T : HrTimerCallback ,
9899 {
@@ -107,10 +108,11 @@ impl<T> HrTimer<T> {
107108 place,
108109 Some ( T :: Pointer :: run) ,
109110 bindings:: CLOCK_MONOTONIC as i32 ,
110- bindings :: hrtimer_mode_HRTIMER_MODE_REL ,
111+ mode . into_c ( ) ,
111112 ) ;
112113 }
113114 } ) ,
115+ mode: mode,
114116 _t: PhantomData ,
115117 } )
116118 }
@@ -371,7 +373,7 @@ pub unsafe trait HasHrTimer<T> {
371373 Self :: c_timer_ptr ( self_ptr) . cast_mut ( ) ,
372374 expires. to_ns ( ) ,
373375 0 ,
374- bindings :: hrtimer_mode_HRTIMER_MODE_REL ,
376+ ( * Self :: raw_get_timer ( self_ptr ) ) . mode . into_c ( ) ,
375377 ) ;
376378 }
377379 }
@@ -394,6 +396,78 @@ impl HrTimerRestart {
394396 }
395397}
396398
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+
397471/// Use to implement the [`HasHrTimer<T>`] trait.
398472///
399473/// See [`module`] documentation for an example.
0 commit comments