fn update_regs(&mut self) -> MemResult<()> {
        // calculate the time delta
        let now = Instant::now();
        let dt = now.duration_since(self.last_time).as_nanos() as u64;
        self.last_time = now;

        if !self.enabled {
            return Ok(());
        }

        let khz = self.clksel.khz();

        // calculate number of ticks the timer should decrement by
        let microticks = dt * khz + self.microticks as u64;
        let ticks = (microticks / 1_000_000) as u32;
        self.microticks = (microticks % 1_000_000) as u32;

        match self.mode {
            Mode::FreeRunning => {
                self.val = self.val.wrapping_sub(ticks) & self.wrapmask;
            }
            Mode::Periodic => {
                let loadval = match self.loadval {
                    Some(v) => v,
                    None => {
                        return Err(ContractViolation {
                            msg: "Periodic mode enabled before setting a Load value".to_string(),
                            severity: log::Level::Error,
                            stub_val: None,
                        })
                    }
                };
                self.val = if loadval == 0 {
                    0
                } else if self.val < ticks {
                    let remaining_ticks = ticks - self.val;
                    loadval - (remaining_ticks % loadval)
                } else {
                    self.val - ticks
                }
            }
        }

        Ok(())
    }
/// Lazily update the registers on read / write.
Lazily update the registers on read / write.
Lazily update the registers on read / write .
fn update_regs(&mut self) -> MemResult<()> {
        // calculate the time delta
        let now = Instant::now();
        let dt = now.duration_since(self.last_time).as_nanos() as u64;
        self.last_time = now;
        if !self.enabled {
            return Ok(());
        }
        let khz = self.clksel.khz();
        // calculate number of ticks the timer should decrement by
        let microticks = dt * khz + self.microticks as u64;
        let ticks = (microticks / 1_000_000) as u32;
        self.microticks = (microticks % 1_000_000) as u32;
        match self.mode {
            Mode::FreeRunning => {
                self.val = self.val.wrapping_sub(ticks) & self.wrapmask;
            }
            Mode::Periodic => {
                let loadval = match self.loadval {
                    Some(v) => v,
                    None => {
                        return Err(ContractViolation {
                            msg: "Periodic mode enabled before setting a Load value".to_string(),
                            severity: log::Level::Error,
                            stub_val: None,
                        })
                    }
                };
                self.val = if loadval == 0 {
                    0
                } else if self.val < ticks {
                    let remaining_ticks = ticks - self.val;
                    loadval - (remaining_ticks % loadval)
                } else {
                    self.val - ticks
                }
            }
        }
        Ok(())
    }
fn update_regs ( & mut self ) -> MemResult < ( ) > { // calculate the time delta let now = Instant :: now ( ) ; let dt = now . duration_since ( self . last_time ) . as_nanos ( ) as u64 ; self . last_time = now ; if ! self . enabled { return Ok ( ( ) ) ; } let khz = self . clksel . khz ( ) ; // calculate number of ticks the timer should decrement by let microticks = dt * khz + self . microticks as u64 ; let ticks = ( microticks / 1_000_000 ) as u32 ; self . microticks = ( microticks % 1_000_000 ) as u32 ; match self . mode { Mode :: FreeRunning => { self . val = self . val . wrapping_sub ( ticks ) & self . wrapmask ; } Mode :: Periodic => { let loadval = match self . loadval { Some ( v ) => v , None => { return Err ( ContractViolation { msg : " " . to_string ( ) , severity : log :: Level :: Error , stub_val : None , } ) } } ; self . val = if loadval == 0 { 0 } else if self . val < ticks { let remaining_ticks = ticks - self . val ; loadval - ( remaining_ticks % loadval ) } else { self . val - ticks } } } Ok ( ( ) ) }
Lazily update the registers on read / write.
Lazily update the registers on read / write .
&mut self
&mut self