Struct vm_superio::rtc_pl031::Rtc

source ·
pub struct Rtc<EV: RtcEvents> { /* private fields */ }
Expand description

A PL031 Real Time Clock (RTC) that emulates a long time base counter.

This structure emulates the registers for the RTC.

Example


let mut data = [0; 4];
let mut rtc = Rtc::new();
const RTCDR: u16 = 0x0; // Data Register.
const RTCLR: u16 = 0x8; // Load Register.

// Write system time since UNIX_EPOCH in seconds to the load register.
let v = SystemTime::now()
    .duration_since(UNIX_EPOCH)
    .unwrap()
    .as_secs() as u32;
data = v.to_le_bytes();
rtc.write(RTCLR, &data);

// Read the value back out of the load register.
rtc.read(RTCLR, &mut data);
assert_eq!(v, u32::from_le_bytes(data));

// Sleep for 1.5 seconds to let the counter tick.
let delay = Duration::from_millis(1500);
thread::sleep(delay);

// Read the current RTC value from the Data Register.
rtc.read(RTCDR, &mut data);
assert!(u32::from_le_bytes(data) > v);

Implementations

Creates a new AMBA PL031 RTC instance without any metric capabilities. The instance is created from the default state.

Creates a new AMBA PL031 RTC instance from a given state and that is able to track events during operation using the passed rtc_events object. For creating the instance from a fresh state, with_events or new methods can be used.

Arguments
  • state - A reference to the state from which the Rtc is constructed.
  • rtc_events - The RtcEvents implementation used to track the occurrence of failure or missed events in the RTC operation.

Creates a new AMBA PL031 RTC instance that is able to track events during operation using the passed rtc_events object. The instance is created from the default state.

Arguments
  • rtc_events - The RtcEvents implementation used to track the occurrence of failure or missed events in the RTC operation.

Returns the state of the RTC.

Provides a reference to the RTC events object.

Handles a write request from the driver at offset offset from the base register address.

Arguments
  • offset - The offset from the base register specifying the register to be written.
  • data - The little endian, 4 byte array to write to the register
Example

You can see an example of how to use this function in the Example section from Rtc.

Handles a read request from the driver at offset offset from the base register address.

Arguments
  • offset - The offset from the base register specifying the register to be read.
  • data - The little-endian, 4 byte array storing the read value.
Example

You can see an example of how to use this function in the Example section from Rtc.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.