//! Data Watchpoint and Trace unit use volatile_register::{RO, RW, WO}; use peripheral::DWT; /// Register block #[repr(C)] pub struct RegisterBlock { /// Control pub ctrl: RW, /// Cycle Count pub cyccnt: RW, /// CPI Count pub cpicnt: RW, /// Exception Overhead Count pub exccnt: RW, /// Sleep Count pub sleepcnt: RW, /// LSU Count pub lsucnt: RW, /// Folded-instruction Count pub foldcnt: RW, /// Program Counter Sample pub pcsr: RO, /// Comparators pub c: [Comparator; 16], reserved: [u32; 932], /// Lock Access pub lar: WO, /// Lock Status pub lsr: RO, } /// Comparator #[repr(C)] pub struct Comparator { /// Comparator pub comp: RW, /// Comparator Mask pub mask: RW, /// Comparator Function pub function: RW, reserved: u32, } impl DWT { /// Enables the cycle counter pub fn enable_cycle_counter(&mut self) { unsafe { self.ctrl.modify(|r| r | 1) } } /// Returns the current clock cycle count pub fn get_cycle_count() -> u32 { // NOTE(unsafe) atomic read with no side effects unsafe { (*Self::ptr()).cyccnt.read() } } }