Add and use atomic_memcpy for the AVR backend
This commit is contained in:
parent
f72a092af3
commit
fbad83a61d
3 changed files with 19 additions and 5 deletions
|
@ -3,7 +3,7 @@ open C
|
|||
open Obc
|
||||
open Async_backend
|
||||
|
||||
module PosixBackend : AsyncBackend =
|
||||
module AvrBackend : AsyncBackend =
|
||||
struct
|
||||
let qn_append q suffix =
|
||||
{ qual = q.qual; name = q.name ^ suffix }
|
||||
|
@ -15,7 +15,9 @@ struct
|
|||
(* TODO(Arduino): add const qualifier *)
|
||||
let arg_ty = Cty_ptr (Cty_id (qn_append cd.cd_name suffix)) in
|
||||
let sizeof = Cfun_call ("sizeof", [Cderef (Cvar "src")]) in
|
||||
let memcpy = Cfun_call ("memcpy", [Cvar "dest"; Cvar "src"; sizeof]) in
|
||||
let memcpy =
|
||||
Cfun_call ("atomic_memcpy", [Cvar "dest"; Cvar "src"; sizeof])
|
||||
in
|
||||
Cfundef {
|
||||
C.f_name = func_name;
|
||||
f_retty = Cty_void;
|
|
@ -34,7 +34,7 @@ open Idents
|
|||
open Obc
|
||||
open Obc_utils
|
||||
open Types
|
||||
open Async_posix
|
||||
open Async_avr
|
||||
|
||||
open Modules
|
||||
open Signature
|
||||
|
@ -891,8 +891,8 @@ let cdefs_and_cdecls_of_class_def cd =
|
|||
let step_fun_def = fun_def_of_step_fun cd.cd_name
|
||||
cd.cd_objs cd.cd_mems cd.cd_objs step_m in
|
||||
(* TODO(Arduino): let the user choose the backend they want *)
|
||||
let copy_in_def = PosixBackend.gen_copy_func_in cd in
|
||||
let copy_out_def = PosixBackend.gen_copy_func_out cd in
|
||||
let copy_in_def = AvrBackend.gen_copy_func_in cd in
|
||||
let copy_out_def = AvrBackend.gen_copy_func_out cd in
|
||||
let async_step_fun_def = async_fun_def_of_step_fun cd.cd_name
|
||||
cd.cd_objs cd.cd_mems cd.cd_objs step_m (cdef_name copy_in_def)
|
||||
(cdef_name copy_out_def) in
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
|
||||
#ifndef DECADES_PERVASIVES_H
|
||||
#define DECADES_PERVASIVES_H
|
||||
#include <string.h>
|
||||
#ifdef __AVR__
|
||||
#include <util/atomic.h>
|
||||
#endif
|
||||
|
||||
typedef float real;
|
||||
|
||||
|
@ -41,5 +45,13 @@ 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue