AP_HAL: added workaround for AVR delegates in PROGMEM

This commit is contained in:
Andrew Tridgell 2015-05-13 10:26:52 +10:00
parent be587beedc
commit d57fcf7e46

View File

@ -2,9 +2,31 @@
#ifndef __AP_HAL_NAMESPACE_H__
#define __AP_HAL_NAMESPACE_H__
#include "string.h"
#include "utility/FastDelegate.h"
#if defined(__AVR__)
/*
gcc on AVR doesn't allow for delegates in progmem. It gives a
warning that the progmem area is uninitialised, and fills the area
with zeros. This is a workaround.
*/
#define DELEGATE_FUNCTION_VOID_TYPEDEF(type) typedef void (*type)(const void *)
#define AP_HAL_CLASSPROC_VOID(classptr, func) (void (*)(const void*))func
#else
#define DELEGATE_FUNCTION_VOID_TYPEDEF(type) typedef fastdelegate::FastDelegate0<void> type
#define AP_HAL_CLASSPROC_VOID(classptr, func) fastdelegate::MakeDelegate(classptr, func)
#endif
// macros to hide the details of delegate functions using FastDelegate
#define AP_HAL_CLASSPROC(classptr, func) fastdelegate::MakeDelegate(classptr, func)
#define AP_HAL_MEMBERPROC(func) AP_HAL_CLASSPROC(this, func)
#define DELEGATE_FUNCTION0(rettype) fastdelegate::FastDelegate0<rettype>
#define DELEGATE_FUNCTION1(rettype, args...) fastdelegate::FastDelegate1<args, rettype>
#define DELEGATE_FUNCTION2(rettype, args...) fastdelegate::FastDelegate2<args, rettype>
namespace AP_HAL {
/* Toplevel pure virtual class Hal.*/
@ -40,7 +62,7 @@ namespace AP_HAL {
which allows us to encapculate a member function as a type
*/
typedef void(*Proc)(void);
typedef fastdelegate::FastDelegate0<> MemberProc;
typedef DELEGATE_FUNCTION0(void) MemberProc;
/**
* Global names for all of the existing SPI devices on all platforms.
@ -63,7 +85,4 @@ namespace AP_HAL {
}
// macro to hide the details of AP_HAL::MemberProc
#define AP_HAL_MEMBERPROC(func) fastdelegate::MakeDelegate(this, func)
#endif // __AP_HAL_NAMESPACE_H__