I am going through this discovery book and I have successfully completed it till chapter 8 Leds Again. Now in chapter 9 Clock and timers i was going through these for loop delays using function delay but I am not getting what actually we want to achieve and what this loop is doing in function delay. Can someone please help me with this? I know we are not using delay as we were using it in the previous chapter we have to work with it differently. This is what I want to understand.
#![no_main]
#![no_std]
use aux9::{entry, switch_hal::OutputSwitch, tim6};
#[inline(never)]
fn delay(_tim6: &tim6::RegisterBlock, ms: u16) {
const K: u16 = 3; // this value needs to be tweaked
for _ in 0..(K * ms) {
aux9::nop()
}
}
#[entry]
fn main() -> ! {
let (leds, rcc, tim6) = aux9::init();
let mut leds = leds.into_array();
// TODO initialize TIM6
let ms = 50;
loop {
for curr in 0..8 {
let next = (curr + 1) % 8;
leds[next].on().unwrap();
delay(tim6, ms);
leds[curr].off().unwrap();
delay(tim6, ms);
}
}
}
Okay so I know why we are using nop here I just want to understand the working of constant k & for loop