Skip to content

Cortex M0(+) DWT fixes #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/peripheral/dwt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Data Watchpoint and Trace unit

use volatile_register::{RO, RW, WO};
#[cfg(not(armv6m))]
use volatile_register::WO;
use volatile_register::{RO, RW};

use peripheral::DWT;

Expand All @@ -10,25 +12,41 @@ pub struct RegisterBlock {
/// Control
pub ctrl: RW<u32>,
/// Cycle Count
#[cfg(not(armv6m))]
pub cyccnt: RW<u32>,
/// CPI Count
#[cfg(not(armv6m))]
pub cpicnt: RW<u32>,
/// Exception Overhead Count
#[cfg(not(armv6m))]
pub exccnt: RW<u32>,
/// Sleep Count
#[cfg(not(armv6m))]
pub sleepcnt: RW<u32>,
/// LSU Count
#[cfg(not(armv6m))]
pub lsucnt: RW<u32>,
/// Folded-instruction Count
#[cfg(not(armv6m))]
pub foldcnt: RW<u32>,
/// Cortex-M0(+) does not have these parts
#[cfg(armv6m)]
reserved: [u32; 6],
/// Program Counter Sample
pub pcsr: RO<u32>,
/// Comparators
#[cfg(armv6m)]
pub c: [Comparator; 2],
#[cfg(not(armv6m))]
/// Comparators
pub c: [Comparator; 16],
#[cfg(not(armv6m))]
reserved: [u32; 932],
/// Lock Access
#[cfg(not(armv6m))]
pub lar: WO<u32>,
/// Lock Status
#[cfg(not(armv6m))]
pub lsr: RO<u32>,
}

Expand All @@ -46,11 +64,13 @@ pub struct Comparator {

impl DWT {
/// Enables the cycle counter
#[cfg(not(armv6m))]
pub fn enable_cycle_counter(&mut self) {
unsafe { self.ctrl.modify(|r| r | 1) }
}

/// Returns the current clock cycle count
#[cfg(not(armv6m))]
pub fn get_cycle_count() -> u32 {
// NOTE(unsafe) atomic read with no side effects
unsafe { (*Self::ptr()).cyccnt.read() }
Expand Down
8 changes: 8 additions & 0 deletions src/peripheral/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ fn dwt() {
let dwt = unsafe { &*::peripheral::DWT::ptr() };

assert_eq!(address(&dwt.ctrl), 0xE000_1000);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.cyccnt), 0xE000_1004);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.cpicnt), 0xE000_1008);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.exccnt), 0xE000_100C);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.sleepcnt), 0xE000_1010);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.lsucnt), 0xE000_1014);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.foldcnt), 0xE000_1018);
assert_eq!(address(&dwt.pcsr), 0xE000_101C);
assert_eq!(address(&dwt.c[0].comp), 0xE000_1020);
Expand All @@ -42,7 +48,9 @@ fn dwt() {
assert_eq!(address(&dwt.c[1].comp), 0xE000_1030);
assert_eq!(address(&dwt.c[1].mask), 0xE000_1034);
assert_eq!(address(&dwt.c[1].function), 0xE000_1038);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.lar), 0xE000_1FB0);
#[cfg(not(armv6m))]
assert_eq!(address(&dwt.lsr), 0xE000_1FB4);
}

Expand Down