The ECU runs an RTOS.
Almost every subroutine apart from the initialization runs in a task.
Tasks are scheduled to run in a certain raster. So fixed time (except some tasks that run crank-sync).
Add a counter, increment this counter every iteration, if MSB is set, turn it on, if MSB is not set turn it off.
Now you have blinking light.
If it's too slow/too fast, adjust.
For counter find free RAM.
Think about it like this:
uint8_t ctr = 0;
void 20ms_raster_task() {
if (ctr > 0x80) {
bclr P2.4
} else {
bset P2.4
}
ctr++;
}
With this example the light is on for 2.56 seconds and after that off for 2.56 seconds, because 256 iterations of 20ms raster take 5.12 seconds to execute.
Thats too slow and for adjusting delay ctr reset should be added instead of overflowing byte
You also want to zeros ctr when flashing done or the next time event starts at a random phase
uint_8t count // num of flashes
uint_8t delay // delay between flashes counter
if (count == 0xFF) {count = 0;} // iirc in me7 its 0xFF in non-used ram, so in code init should be done
if (count > 0) // from switching routine >> (if (new_map != old_map) { count = new_map; old_map=new_map;} // new_map represents the value of current mapSet in range of 1-5 for example. fires once after map changed.
{
if (delay < ??) { bset b_mil; }
else { bclr b_mil; }
delay++;
}
if (delay > (??*2)) // 2.54 is a huge delay so zeros instead of overflowing :-\
{
delay=0;
count -=1; // eof blink
}
}
else
{ delay = 0; } // reset timer after all blinks completed
OR
in me7 there is a B_milblk which blinks at 1hz freq and i suppose its a 1000ms / 20ms = 50 ticks on every phase and 100 ticks for complete cycle
so it could be simplified like that. notice about delay is a word now
uint16_t delay_w
if (delay_w >1) // from switching routine >> if (new_map != old_map) { delay_w = new_map * 100; old_map=new_map;}
{
bset B_milblk;
delay_w -=1 ;
}
if ((delay_w == 1) or (delay_w == 0xFFFF)) // do not use 'else' to avoid conflict with a stock B_milblk routine when delay=0
{
bclr B_milblk;
delay_w = 0;
}