Struct hal_x86_64::time::Pit

source ·
pub struct Pit { /* private fields */ }
Expand description

Intel 8253/8254 Programmable Interval Timer (PIT).

The PIT is a simple timer, with three channels. The most interesting is channel 0, which is capable of firing an interrupt to the 8259 PIC or I/O APIC on ISA interrupt vector 0. Channel 1 was used to time the DRAM refresh rate on ancient IBM PCs and is now generally unused (and may not be implemented in hardware), and channel 2 was connected to the IBM PC speaker and could be used to play sounds.

The PIT has a non-configurable base frequency of 1.193182 MHz, for extremely cool reasons, but a 16-bit divisor can be used to determine what multiple of this base frequency each channel fires at.

Implementations§

source§

impl Pit

source

pub const BASE_FREQUENCY_HZ: usize = 1_193_180usize

The PIT’s base frequency runs at roughly 1.193182 MHz, for extremely cool reasons.

source

pub fn sleep_blocking(&mut self, duration: Duration) -> Result<(), PitError>

Sleep (by spinning) for duration.

This function sets a flag indicating that a sleep is in progress, and configures the PIT to fire an interrupt on channel 0 in duration. It then spins until the flag is cleared by an interrupt handler.

Usage Notes

This is a low-level way of sleeping, and is not recommended for use as a system’s primary method of sleeping for a duration. Instead, a timer wheel or other way of tracking multiple sleepers should be constructed and advanced based on a periodic timer. This function is provided primarily to allow using the PIT to calibrate other timers as part of initialization code, rather than for general purpose use in an operating system.

In particular, using this function is subject to the following considerations:

  • An interrupt handler for the PIT interrupt which clears the sleeping flag must be installed. This is done automatically by the Controller::init function in the interrupt module. If that interrupt handler is not present, this function will spin forever!
  • If the PIT is currently in periodic mode, it will be put in oneshot mode when this function is called. This will temporarily disable the existing periodic timer.
  • This function returns an error if another CPU core is already sleeping. It should generally be used only prior to the initialization of application processors.
Returns
  • Ok(()) after duration if a sleep was successfully completed.
  • Err(InvalidDuration) if the provided duration was too long.
source

pub fn start_periodic_timer( &mut self, interval: Duration ) -> Result<(), PitError>

Configures PIT channel 0 in periodic mode, to fire an interrupt every time the provided interval elapses.

Returns
source

pub fn interrupt_in( &mut self, duration: Duration ) -> Result<(), InvalidDuration>

Configure the PIT to send an IRQ 0 interrupt in duration.

This configures the PIT in mode 0 (oneshot mode). Once the interrupt has fired, in order to use the periodic timer, the pit must be put back into periodic mode by calling Pit::start_periodic_timer.

Trait Implementations§

source§

impl Debug for Pit

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Pit

§

impl Send for Pit

§

impl Sync for Pit

§

impl Unpin for Pit

§

impl UnwindSafe for Pit

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.