Skip to content

Commit 90d9eb2

Browse files
aescolarcarlescufi
authored andcommitted
native_posix: timer: Improve arch_busy_wait() doc
Expand a bit the native_posix arch_busy_wait() documentation so it is clearer Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 9b024eb commit 90d9eb2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

drivers/timer/native_posix_timer.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,27 @@ u32_t z_clock_elapsed(void)
122122
*
123123
* Note that interrupts may be received in the meanwhile and that therefore this
124124
* thread may loose context
125+
*
126+
* This special arch_busy_wait() is necessary due to how the POSIX arch/SOC INF
127+
* models a CPU. Conceptually it could be thought as if the MCU was running
128+
* at an infinitely high clock, and therefore no simulated time passes while
129+
* executing instructions(*1).
130+
* Therefore to be able to busy wait this function does the equivalent of
131+
* programming a dedicated timer which will raise a non-maskable interrupt,
132+
* and halting the CPU.
133+
*
134+
* (*1) In reality simulated time is simply not advanced just due to the "MCU"
135+
* running. Meaning, the SW running on the MCU is assumed to take 0 time.
125136
*/
126137
void arch_busy_wait(u32_t usec_to_wait)
127138
{
128139
u64_t time_end = hwm_get_time() + usec_to_wait;
129140

130141
while (hwm_get_time() < time_end) {
131-
/*There may be wakes due to other interrupts*/
142+
/*
143+
* There may be wakes due to other interrupts including
144+
* other threads calling arch_busy_wait
145+
*/
132146
hwtimer_wake_in_time(time_end);
133147
posix_halt_cpu();
134148
}

0 commit comments

Comments
 (0)