From 4b3e6d742a1a153d76e3f3d6ba8ad0dafd378e51 Mon Sep 17 00:00:00 2001 From: rubenasplund <ruben.asplund@hotmail.com> Date: Fri, 4 Dec 2020 11:23:37 +0100 Subject: [PATCH] Exercise A --- examples/rtt_timing.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/rtt_timing.rs b/examples/rtt_timing.rs index 4ee6775..1dc033c 100644 --- a/examples/rtt_timing.rs +++ b/examples/rtt_timing.rs @@ -45,7 +45,7 @@ const APP: () = { #[no_mangle] fn timed_loop() -> (u32, u32) { let start = DWT::get_cycle_count(); - for _ in 0..10000 { + for _ in 0..1000 { asm::nop(); } let end = DWT::get_cycle_count(); @@ -63,15 +63,15 @@ fn timed_loop() -> (u32, u32) { // A.1) What is the cycle count for the loop? // > cargo run --example rtt_timing // -// [Your answer here] +// [The loop in timed_loop is looping 335424926-330634772 = 4790154 times] // // A.2) How many cycles per iteration? // -// [Your answer here] +// [4790154/1000 = 4790] // // A.3) Why do we need a wrapping subtraction? // -// [Your answer here] +// [Becasue the variable is a unsigned 32 bit int, which will overflow when taking substraction bit wise. Therefore a wrapper is there to make sure the substraction is correctly calculated even if it overflow.] // // ------------------------------------------------------------------------ // Now try a release (optimized build, see `Cargo.toml` for build options). -- GitLab