Skip to content
Snippets Groups Projects
Commit 3595a0c9 authored by Henrik Tjäder's avatar Henrik Tjäder
Browse files

Fixed the critical section so can use DWT

parent 01f90c9a
No related branches found
No related tags found
No related merge requests found
......@@ -51,3 +51,8 @@ PLAIN however is mutable and will be changed on the "return" of decode()
Currently there is only one function so it should be safe, however, with
two tasks this would not be the case. In a typical microcontroller setting
with interrupt handlers it would be similar "safe" like C.
## Debug vs Release analysis
Time taken to decode ABC is `Decoded in 4457 cycles`,
while in release mode this is reduced to `Decoded in 338 cycles`.
......@@ -3,14 +3,16 @@
extern crate cortex_m_semihosting;
extern crate stm32f40x;
extern crate cortex_m;
use core::fmt::Write;
use cortex_m_semihosting::hio;
//use std::str::from_utf8;
use core::str::from_utf8;
use stm32f40x::{DWT};
static ABC: [u32; 4] = [0x9fdd9158,
0x85715808,
0xac73323a,
......@@ -252,14 +254,31 @@ fn main() {
// get a handle to the *host* standard output
let mut stdout = hio::hstdout().unwrap();
// Critical section
cortex_m::interrupt::free(
|cs| {
// Enable the DWT CYCCNT
let dwt = DWT.borrow(cs);
dwt.enable_cycle_counter();
writeln!(stdout, "Time to decode!").unwrap();
let mut seed = 0x0e0657c1;
decode(&CODED, unsafe { &mut PLAIN }, &mut seed);
//writeln!(stdout, "current counter:\n {:?}", dwt.cyccnt.read()).unwrap();
let before = dwt.cyccnt.read();
decode(&ABC, unsafe { &mut PLAIN }, &mut seed);
//decode(&CODED, unsafe { &mut PLAIN }, &mut seed);
let after = dwt.cyccnt.read();
writeln!(stdout, "Decoded in {} cycles", after-before).unwrap();
writeln!(stdout, "Decoded:\n {:#?}", from_utf8(unsafe { &PLAIN }).unwrap()).unwrap();
}
);
/*
let mut locseed;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment