Skip to content
Snippets Groups Projects
Commit 7c0265b9 authored by Ruben Asplund's avatar Ruben Asplund
Browse files

cyccnt.rs DONE

parent 3c984479
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,8 @@ extern crate panic_klee; ...@@ -9,8 +9,8 @@ extern crate panic_klee;
#[no_mangle] #[no_mangle]
fn main() { fn main() {
let mut core = cortex_m::Peripherals::take().unwrap(); let mut core = cortex_m::Peripherals::take().unwrap();
// core.DCB.enable_trace(); core.DCB.enable_trace();
// core.DWT.enable_cycle_counter(); core.DWT.enable_cycle_counter();
let start: u32 = core.DWT.cyccnt.read(); let start: u32 = core.DWT.cyccnt.read();
...@@ -208,9 +208,10 @@ fn main() { ...@@ -208,9 +208,10 @@ fn main() {
// Why does these values cause an error debug/dev build but not in a release build? // Why does these values cause an error debug/dev build but not in a release build?
// //
// [This line is causing the problem: let _time = end - start; // [This line is causing the problem: let _time = end - start;
// When taking substraction of values two values there is a high risk that it will overflow, // When taking substraction between two values with unsigned variable,
// therefore the error occurs in debug/dev build. // there is a possibility that the value becomes negative. The u32 cant represent negative
// In release build the substractions occurs and no overflow is found then errors will not occurs. // values therefore error occurs in debug/dev build.
// In release build the substractions occurs and no negative value is found then errors will not occur.
// It seems like the release build is not detecting potential problems, only problems that occurs.] // It seems like the release build is not detecting potential problems, only problems that occurs.]
// //
// C) Fix the problem! // C) Fix the problem!
...@@ -223,8 +224,8 @@ fn main() { ...@@ -223,8 +224,8 @@ fn main() {
// There are numerous ways to solve the problem. // There are numerous ways to solve the problem.
// Argue for your solution in your own words. // Argue for your solution in your own words.
// //
// [The substraction can overflow, to remove the error and make sure the substraction is almost always correct, // [I added wrapper_sub to the caculation. It will remove the error and make sure the substraction wrap around instead
// we need to use wrapper_sub.] // of giving an error when the differance is negative. ]
// //
// D) Learning outcomes and major takeaways. // D) Learning outcomes and major takeaways.
// //
...@@ -243,7 +244,13 @@ fn main() { ...@@ -243,7 +244,13 @@ fn main() {
// //
// How long time would lines 16/17 take to run to trigger the error? // How long time would lines 16/17 take to run to trigger the error?
// //
// [your answer here] // [
// They are hard do find becasue the error appears when the timer has wrapped around.
// The error is triggered when end is smaller than start.
// The CYCCNT is a 32 bit unsigned integer, it will wrap around when the value has reached 2^32.
// 2^32/8MHz = 537 s
// It would take at least 537s.
// ]
// //
// Of course this is a contrived example, and may not occur in practice. // Of course this is a contrived example, and may not occur in practice.
// But, it represents a class of problems/errors/bugs that is // But, it represents a class of problems/errors/bugs that is
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment