diff --git a/compiler/obc/c/async_avr.ml b/compiler/obc/c/async_avr.ml index 310d33f..96b43fa 100644 --- a/compiler/obc/c/async_avr.ml +++ b/compiler/obc/c/async_avr.ml @@ -43,16 +43,14 @@ struct | 0 -> abs a | b -> gcd b (a mod b) - let fold_gcd l = List.fold_left gcd (List.hd l) (List.tl l) - let lcm a b = match a, b with | 0, _ | _, 0 -> 0 | _ -> abs (a * b) / (gcd a b) let fold_lcm l = List.fold_left lcm (List.hd l) (List.tl l) - let count_of_ack base = function - | Timer_ms ms -> ms / base + let ms_of_ack = function + | Timer_ms ms -> ms let incr_mod name modulo = let one_const = Cconst (Ccint 1) in @@ -60,12 +58,12 @@ struct let incr = Cbop ("+", Cvar name, one_const) in Caffect (CLvar name, Cbop ("%", incr, modulo_const)) - let call_step_async base tick_var (od, ack) = + let call_step_async tick_var (od, ack) = let step = (cname_of_qn od.o_class) ^ "_async_step" in let global = async_global_var_name od in let call = Csexpr (Cfun_call (step, [Caddrof (Cvar global)])) in let zero = Cconst (Ccint 0) in - let timer = Cconst (Ccint (count_of_ack base ack)) in + let timer = Cconst (Ccint (ms_of_ack ack)) in let cond = Cbop ("==", Cbop ("%", tick_var, timer), zero) in Cif (cond, [call], []) @@ -83,12 +81,11 @@ struct let body = match timers with | [] -> [] | _ -> - let base_timer = fold_gcd timers in - let max_timer = fold_lcm timers in + let lcm_timer = fold_lcm timers in let steps = - List.map (call_step_async base_timer (Cvar "tick")) trans + List.map (call_step_async (Cvar "tick")) trans in - let incr = incr_mod "tick" (max_timer / base_timer) in + let incr = incr_mod "tick" lcm_timer in steps @ [incr] in (* run_timers is declared in avr.h (because of the ISR macro which