pub fn write(&mut self, offset: u16, data: &[u8; 4]) {
        let val = u32::from_le_bytes(*data);

        match offset {
            RTCMR => {
                // Set the match register.
                // TODO: Implement the match register functionality.
                self.mr = val;
            }
            RTCLR => {
                // The guest can make adjustments to its time by writing to
                // this register. When these adjustments happen, we calculate the
                // offset as the difference between the LR value and the host time.
                // This offset is later used to calculate the RTC value (see
                // `get_rtc_value`).
                self.lr = val;
                // Both lr & offset are u32, hence the following
                // conversions are safe, and the result fits in an i64.
                self.offset = self.lr as i64 - get_current_time() as i64;
            }
            RTCCR => {
                // Writing 1 to the control register resets the RTC value,
                // which means both the load register and the offset are reset.
                if val == 1 {
                    self.lr = 0;
                    self.offset = 0;
                }
            }
            RTCIMSC => {
                // Set or clear the interrupt mask.
                self.imsc = val & 1;
            }
            RTCICR => {
                // Writing 1 clears the interrupt; however, since the match
                // register is unimplemented, this should never be necessary.
                self.ris &= !val;
            }
            _ => {
                // RTCDR, RTCRIS, and RTCMIS are read-only, so writes to these
                // registers or to an invalid offset are ignored; however,
                // We increment the invalid_write() method of the events struct.
                self.events.invalid_write();
            }
        };
    }
/// 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`](struct.Rtc.html#example).
Handles a write request from the driver at `offset` offset from the
base register address.
Handles a write request from the driver at ` offset ` offset from the base register address .
pub fn write(&mut self, offset: u16, data: &[u8; 4]) {
        let val = u32::from_le_bytes(*data);
        match offset {
            RTCMR => {
                // Set the match register.
                // TODO: Implement the match register functionality.
                self.mr = val;
            }
            RTCLR => {
                // The guest can make adjustments to its time by writing to
                // this register. When these adjustments happen, we calculate the
                // offset as the difference between the LR value and the host time.
                // This offset is later used to calculate the RTC value (see
                // `get_rtc_value`).
                self.lr = val;
                // Both lr & offset are u32, hence the following
                // conversions are safe, and the result fits in an i64.
                self.offset = self.lr as i64 - get_current_time() as i64;
            }
            RTCCR => {
                // Writing 1 to the control register resets the RTC value,
                // which means both the load register and the offset are reset.
                if val == 1 {
                    self.lr = 0;
                    self.offset = 0;
                }
            }
            RTCIMSC => {
                // Set or clear the interrupt mask.
                self.imsc = val & 1;
            }
            RTCICR => {
                // Writing 1 clears the interrupt; however, since the match
                // register is unimplemented, this should never be necessary.
                self.ris &= !val;
            }
            _ => {
                // RTCDR, RTCRIS, and RTCMIS are read-only, so writes to these
                // registers or to an invalid offset are ignored; however,
                // We increment the invalid_write() method of the events struct.
                self.events.invalid_write();
            }
        };
    }
pub fn write ( & mut self , offset : u16 , data : & [ u8 ; 4 ] ) { let val = u32 :: from_le_bytes ( * data ) ; match offset { RTCMR => { // Set the match register. // TODO: Implement the match register functionality. self . mr = val ; } RTCLR => { // The guest can make adjustments to its time by writing to // this register. When these adjustments happen, we calculate the // offset as the difference between the LR value and the host time. // This offset is later used to calculate the RTC value (see // `get_rtc_value`). self . lr = val ; // Both lr & offset are u32, hence the following // conversions are safe, and the result fits in an i64. self . offset = self . lr as i64 - get_current_time ( ) as i64 ; } RTCCR => { // Writing 1 to the control register resets the RTC value, // which means both the load register and the offset are reset. if val == 1 { self . lr = 0 ; self . offset = 0 ; } } RTCIMSC => { // Set or clear the interrupt mask. self . imsc = val & 1 ; } RTCICR => { // Writing 1 clears the interrupt; however, since the match // register is unimplemented, this should never be necessary. self . ris &= ! val ; } _ => { // RTCDR, RTCRIS, and RTCMIS are read-only, so writes to these // registers or to an invalid offset are ignored; however, // We increment the invalid_write() method of the events struct. self . events . invalid_write ( ) ; } } ; }
Handles a write request from the driver at `offset` offset from the
base register address.
Handles a write request from the driver at ` offset ` offset from the base register address .
&mut self
offset
u16
data
&[u8; 4]
example
You can see an example of how to use this function in the
[`Example` section from `Rtc`](struct.Rtc.html#example).
You can see an example of how to use this function in the [ ` Example ` section from ` Rtc ` ] ( struct . Rtc . html#example ) .