diff --git a/.gitignore b/.gitignore
index f5d7bb8..74ad10a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,3 +37,4 @@ config.status
*.bbl
auto
autom4te.cache
+!/lib/c/*.h
diff --git a/compiler/obc/c/async_avr.ml b/compiler/obc/c/async_avr.ml
index ff7baab..0f37fa9 100644
--- a/compiler/obc/c/async_avr.ml
+++ b/compiler/obc/c/async_avr.ml
@@ -31,4 +31,22 @@ struct
let gen_copy_func_out cd = gen_copy_func cd "_out"
+ let includes = ["avr"]
+
+ let decls_and_defs classes =
+ (* run_timers is declared in avr.h (because of the ISR macro which
+ * I don't know how to generate here) *)
+ let defs = [
+ Cfundef {
+ C.f_name = "run_timers";
+ f_retty = Cty_void;
+ f_args = [];
+ f_body = {
+ var_decls = [];
+ block_body = []
+ }
+ }
+ ] in
+ [], defs
+
end
diff --git a/compiler/obc/c/async_backend.mli b/compiler/obc/c/async_backend.mli
index 90ce29b..8639efc 100644
--- a/compiler/obc/c/async_backend.mli
+++ b/compiler/obc/c/async_backend.mli
@@ -5,4 +5,6 @@ module type AsyncBackend =
sig
val gen_copy_func_in : class_def -> cdef
val gen_copy_func_out : class_def -> cdef
+ val includes : string list
+ val decls_and_defs : class_def list -> cdecl list * cdef list
end
diff --git a/compiler/obc/c/cgen.ml b/compiler/obc/c/cgen.ml
index 8c19269..43086e2 100644
--- a/compiler/obc/c/cgen.ml
+++ b/compiler/obc/c/cgen.ml
@@ -1080,9 +1080,14 @@ let global_file_header name prog =
| s -> s ^ "_types")
dependencies in
+ let dependencies_types = AvrBackend.includes @ dependencies_types in
+
let classes = program_classes prog in
- let (decls, defs) =
- List.split (List.map cdefs_and_cdecls_of_class_def classes) in
+ let decls_and_defs = List.map cdefs_and_cdecls_of_class_def classes in
+ let decls_and_defs =
+ (AvrBackend.decls_and_defs classes) :: decls_and_defs
+ in
+ let (decls, defs) = List.split decls_and_defs in
let decls = List.concat decls
and defs = List.concat defs in
diff --git a/lib/c/avr.h b/lib/c/avr.h
new file mode 100644
index 0000000..acd5931
--- /dev/null
+++ b/lib/c/avr.h
@@ -0,0 +1,52 @@
+/***********************************************************************/
+/* */
+/* Heptagon */
+/* */
+/* Gwenael Delaval, LIG/INRIA, UJF */
+/* Leonard Gerard, Parkas, ENS */
+/* Adrien Guatto, Parkas, ENS */
+/* Cedric Pasteur, Parkas, ENS */
+/* Marc Pouzet, Parkas, ENS */
+/* */
+/* Copyright 2012 ENS, INRIA, UJF */
+/* */
+/* This file is part of the Heptagon compiler. */
+/* */
+/* Heptagon is free software: you can redistribute it and/or modify it */
+/* under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation, either version 3 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* Heptagon is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with Heptagon. If not, see */
+/* */
+/***********************************************************************/
+
+/* Pervasives module for the Heptagon compiler */
+
+#ifndef DECADES_AVR_H
+#define DECADES_AVR_H
+#ifdef __AVR__
+#include
+#include
+
+void run_timers();
+
+ISR(TIMER0_OVF_vect) {
+ run_timers();
+}
+
+static inline void atomic_memcpy(void *dest, const void *src, size_t size) {
+ ATOMIC_BLOCK(ATOMIC_FORCEON) {
+ memcpy(dest, src, size);
+ }
+}
+
+#endif
+#endif
+
diff --git a/lib/c/pervasives.h b/lib/c/pervasives.h
index 0b4db76..720f3f1 100644
--- a/lib/c/pervasives.h
+++ b/lib/c/pervasives.h
@@ -32,9 +32,6 @@
#ifndef DECADES_PERVASIVES_H
#define DECADES_PERVASIVES_H
#include
-#ifdef __AVR__
-#include
-#endif
typedef float real;
@@ -45,13 +42,5 @@ static inline int between(int idx, int n)
return o;
}
-#ifdef __AVR__
-static inline void atomic_memcpy(void *dest, const void *src, size_t size) {
- ATOMIC_BLOCK(ATOMIC_FORCEON) {
- memcpy(dest, src, size);
- }
-}
-#endif
-
#endif