Reset only stateful async nodes

This commit is contained in:
jeltz 2020-12-30 02:03:06 +01:00
parent 4827bdd9fe
commit 2c7466e2de
Signed by: jeltz
GPG key ID: 800882B66C0C3326
4 changed files with 21 additions and 3 deletions

View file

@ -1,7 +1,9 @@
open Obc
open C
open Modules
open Idents
open Names
open Signature
let async_global_var_name od = "g_async__" ^ (name od.o_ident)
@ -31,12 +33,18 @@ let async_global_objs_decls cd =
(fun (name, ty) -> Cdecl_extern (name, ty))
(async_global_objs_vars cd)
let od_is_stateful od =
let sig_info = find_value od.o_class in
sig_info.node_stateful
let async_reset cd =
let async_objs = filter_async_objs cd in
let stateful = List.filter od_is_stateful async_objs in
List.map
(fun od ->
let global = Cvar (async_global_var_name od) in
let field = Cfield (global, local_qn "mem") in
let field = Cfield (global, local_qn "self") in
let reset = cname_of_qn od.o_class ^ "_reset" in
Csexpr (Cfun_call (reset, [Caddrof field])))
(filter_async_objs cd)
stateful

View file

@ -11,7 +11,6 @@ struct
| Timer_ms of int
(* FIXME(Arduino): don't do a shallow copy *)
(* FIXME(Arduino): add a mutex… *)
let gen_copy_func cd suffix =
let func_name = (cname_of_qn cd.cd_name) ^ "_copy" ^ suffix in
(* TODO(Arduino): add const qualifier *)
@ -109,4 +108,6 @@ struct
] in
[], defs
let main_init = [Csexpr (Cfun_call ("init_timer1", []))]
end

View file

@ -7,4 +7,5 @@ sig
val gen_copy_func_out : class_def -> cdef
val includes : string list
val decls_and_defs : obj_dec list -> cdecl list * cdef list
val main_init : cstm list
end

View file

@ -37,6 +37,7 @@ open Signature
open C
open Cgen
open Async
open Async_avr
open Compiler_utils
(** {1 Main C function generation} *)
@ -412,6 +413,13 @@ let mk_main name p =
classes
in
(*
* We add these instructions at the end because otherwise the timer
* could be triggered while the initial reset of the async nodes is
* not yet terminated.
*)
let res_l = res_l @ AvrBackend.main_init in
[("_main.c", Csource (defs @ [main_skel var_l res_l step_l]));
("_main.h", Cheader ([name], []))];
) else