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

Exercise A

parent 6d483d4d
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ const APP: () = { ...@@ -45,7 +45,7 @@ const APP: () = {
#[no_mangle] #[no_mangle]
fn timed_loop() -> (u32, u32) { fn timed_loop() -> (u32, u32) {
let start = DWT::get_cycle_count(); let start = DWT::get_cycle_count();
for _ in 0..10000 { for _ in 0..1000 {
asm::nop(); asm::nop();
} }
let end = DWT::get_cycle_count(); let end = DWT::get_cycle_count();
...@@ -63,15 +63,15 @@ fn timed_loop() -> (u32, u32) { ...@@ -63,15 +63,15 @@ fn timed_loop() -> (u32, u32) {
// A.1) What is the cycle count for the loop? // A.1) What is the cycle count for the loop?
// > cargo run --example rtt_timing // > 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? // A.2) How many cycles per iteration?
// //
// [Your answer here] // [4790154/1000 = 4790]
// //
// A.3) Why do we need a wrapping subtraction? // 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). // Now try a release (optimized build, see `Cargo.toml` for build options).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment