pub trait PortTimer {
const MAX_TICK_COUNT: UTicks;
const MAX_TIMEOUT: UTicks;
// Required method
unsafe fn tick_count() -> UTicks;
// Provided methods
unsafe fn pend_tick_after(tick_count_delta: UTicks) { ... }
unsafe fn pend_tick() { ... }
}Expand description
Implemented by a port. This trait contains items related to controlling a system timer.
Safety
These methods are only meant to be called by the kernel.
Required Associated Constants§
sourceconst MAX_TICK_COUNT: UTicks
const MAX_TICK_COUNT: UTicks
The maximum value that tick_count can return. Must be greater
than zero.
sourceconst MAX_TIMEOUT: UTicks
const MAX_TIMEOUT: UTicks
The maximum value that can be passed to pend_tick_after. Must be
greater than zero.
This value should be somewhat smaller than MAX_TICK_COUNT. The
difference determines the kernel’s resilience against overdue
timer interrupts.
This is ignored and can take any value if pend_tick_after is
implemented as no-op.
Required Methods§
sourceunsafe fn tick_count() -> UTicks
unsafe fn tick_count() -> UTicks
Read the current tick count (timer value).
This value steadily increases over time. When it goes past
MAX_TICK_COUNT, it “wraps around” to 0.
The returned value must be in range 0..=MAX_TICK_COUNT.
Precondition: CPU Lock active
Provided Methods§
sourceunsafe fn pend_tick_after(tick_count_delta: UTicks)
unsafe fn pend_tick_after(tick_count_delta: UTicks)
Indicate that tick_count_delta ticks may elapse before the kernel
should receive a call to PortToKernel::timer_tick.
“tick_count_delta ticks” include the current (ongoing) tick. For
example, tick_count_delta == 1 means timer_tick should be
preferably called right after the next tick boundary.
The driver might track time in a coarser granularity than microseconds.
In this case, the driver should wait until the earliest moment when
tick_count() >= current_tick_count + tick_count_delta (where
current_tick_count is the current value of tick_count(); not taking
the wrap-around behavior into account) is fulfilled and call
timer_tick.
It’s legal to ignore the calls to this method entirely and call
timer_tick at a steady rate, resulting in something similar to a
“tickful” kernel. The default implementation does nothing assuming that
the port driver is implemented in this way.
tick_count_delta must be in range 1..=MAX_TIMEOUT.
Precondition: CPU Lock active
sourceunsafe fn pend_tick()
unsafe fn pend_tick()
Pend a call to PortToKernel::timer_tick as soon as possible.
The default implementation calls pend_tick_after(1).
Precondition: CPU Lock active