From: zer0 Date: Sat, 9 Jan 2010 16:37:39 +0000 (+0100) Subject: better compilation on host X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=4a33e94c3809e67674577509044653bac4a4d87a;p=aversive.git better compilation on host --- diff --git a/include/aversive/parts.h b/include/aversive/parts.h index 329342f..7e82f5f 100644 --- a/include/aversive/parts.h +++ b/include/aversive/parts.h @@ -269,7 +269,9 @@ #elif defined (__AVR_ATxmega64A3__) #include #else +#ifndef HOST_VERSION #error "This arch is not implemented yet" #endif +#endif #endif /* _AVERSIVE_PARTS_H_ */ diff --git a/include/aversive/pgmspace.h b/include/aversive/pgmspace.h index d6dadb8..ff37bdf 100644 --- a/include/aversive/pgmspace.h +++ b/include/aversive/pgmspace.h @@ -30,28 +30,15 @@ #ifndef HOST_VERSION #include +#define PGMS_FMT "%S" #else #include - -#define printf_P printf -#define memcmp_P memcmp -#define strcat_P strcat -#define strcmp_P strcmp -#define strncmp_P strncmp -#define strlen_P strlen -#define vfprintf_P vfprintf -#define vsprintf_P vsprintf -#define PGM_P const char * -#define PSTR(x) x -#define PROGMEM - -/* XXX don't define it, it's dangerous because it can be used to read - * an address that have not the same size */ -/* #define pgm_read_word(x) (*(x)) */ -/* #define pgm_read_byte(x) (*(x)) */ +#include +#include +#include typedef void prog_void; typedef char prog_char; @@ -64,6 +51,87 @@ typedef int32_t prog_int32_t; typedef uint32_t prog_uint32_t; typedef int64_t prog_int64_t; + +static inline int memcmp_P(const void *s1, + const prog_void *s2, unsigned n) +{ + return memcmp(s1, s2, n); +} + +static inline void *memcpy_P(void *s1, + const prog_void *s2, unsigned n) +{ + return memcpy(s1, s2, n); +} + +static inline char *strcat_P(char *s1, const prog_char *s2) +{ + return strcat(s1, s2); +} + +static inline char *strcpy_P(char *s1, const prog_char *s2) +{ + return strcpy(s1, s2); +} + +static inline char *strncpy_P(char *s1, const prog_char *s2, + unsigned n) +{ + return strncpy(s1, s2, n); +} + +static inline int strcmp_P(const char *s1, const prog_char *s2) +{ + return strcmp(s1, s2); +} + +static inline int strncmp_P(const char *s1, const prog_char *s2, + unsigned n) +{ + return strncmp(s1, s2, n); +} + +static inline unsigned strlen_P(const prog_char *s) +{ + return strlen(s); +} + +static inline int vfprintf_P(FILE *stream, + const prog_char *s, va_list ap) +{ + return vfprintf(stream, s, ap); +} + +static inline int vsprintf_P(char *buf, const prog_char *s, + va_list ap) +{ + return vsprintf(buf, s, ap); +} + +#define PGM_P const char * +#define PSTR(x) x +#define PROGMEM +#define printf_P(arg...) printf(args) +#define sprintf_P(buf, args...) sprintf(buf, args) +#define snprintf_P(buf, n, args...) snprintf(buf, n, args) + +static inline uint32_t pgm_read_dword(const prog_void *x) +{ + return *(uint32_t *)x; +} + +static inline uint16_t pgm_read_word(const prog_void *x) +{ + return *(uint16_t *)x; +} + +static inline uint8_t pgm_read_byte(const prog_void *x) +{ + return *(uint8_t *)x; +} + +#define PGMS_FMT "%s" + #endif /* HOST_VERSION */ #endif /* _AVERSIVE_PGMSPACE_H_ */