altos: Document how delay_done is used in ao_pyro.c
authorKeith Packard <keithp@keithp.com>
Mon, 21 Feb 2022 17:43:54 +0000 (09:43 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 21 Feb 2022 17:46:08 +0000 (09:46 -0800)
delay_done is the time at which the delay finishes, but non-zero
values also indicate that some delay is pending. Add a comment about
why the value is set to 1 when it is zero, and switch the tests of
this value to comparisons against zero.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_pyro.c

index ee94eca35c5c22c461cc576b3bf04cd7a4fadd8b..d4091205d2114afff64d11c1bea194a6f70f2936 100644 (file)
@@ -303,7 +303,18 @@ ao_pyro_check(void)
                                if (delay < 0)
                                        delay = 0;
                                delay_done = ao_time() + (AO_TICK_TYPE) delay;
-                               if (!delay_done)
+
+                               /*
+                                * delay_done is the time at which the
+                                * delay ends, but it is also used as
+                                * an indication that a delay is
+                                * active -- non-zero values indicate
+                                * an active delay. This code ensures
+                                * the value is non-zero, which might
+                                * introduce an additional tick
+                                * of delay.
+                                */
+                               if (delay_done == 0)
                                        delay_done = 1;
                                pyro_delay_done[p] = delay_done;
                        }
@@ -312,7 +323,7 @@ ao_pyro_check(void)
                /* Check to see if we're just waiting for
                 * the delay to expire
                 */
-               if (pyro_delay_done[p]) {
+               if (pyro_delay_done[p] != 0) {
 
                        /* Check to make sure the required conditions
                         * remain valid. If not, inhibit the channel