pgm_read_int(): New macro.
[bertos.git] / mware / pgm.h
index 87b46b2822c49ba598766fb9163cef380d5e9b65..673b143dca7fca89db86ac27833b7cd4c448897d 100755 (executable)
@@ -23,6 +23,8 @@
 #define MWARE_PGM_H
 
 #include <cfg/cpu_detect.h>
+#include <cfg/compiler.h> /* For intXX_t */
+#include <cfg/cpu.h> /* For CPU_HARVARD */
 
 #if CPU_AVR
 
@@ -74,7 +76,8 @@
                })
 
 
-       #else
+       #else /* !__AVR_ENHANCED__ */
+
                #define pgm_read_char(addr) \
                ({ \
                        uint16_t __addr16 = (uint16_t)(addr); \
                        __result; \
                })
 
+       #endif /* !__AVR_ENHANCED__ */
+
+       #if SIZEOF_INT == 2
+               #define pgm_read_int(addr) ((int)pgm_read_uint16_t(addr))
+       #else
+               #error Missing support for CPU word size != 16bit
        #endif
 
+       #ifndef PROGMEM
        #define PROGMEM  __attribute__((__progmem__))
+       #endif
+       #ifndef PSTR
        #define PSTR(s) ({ static const char __c[] PROGMEM = (s); &__c[0]; })
+       #endif
 
 #elif CPU_HARVARD
        #error Missing CPU support
 #endif
 
 #ifndef PROGMEM
-#define PROGMEM                /* nothing */
+#define PROGMEM         /* nothing */
 #endif
 
 /*!
@@ -197,10 +210,12 @@ typedef PROGMEM uint32_t pgm_uint32_t;
 #ifdef _PROGMEM
        #define PGM_READ_CHAR(s) pgm_read_char(s)
        #define PGM_FUNC(x)      x ## _P
+       #define PGM_STR(x)       PSTR(x)
        #define PGM_ATTR         PROGMEM
 #else
        #define PGM_READ_CHAR(s) (*(s))
        #define PGM_FUNC(x)      x
+       #define PGM_STR(x)       x
        #define PGM_ATTR         /* nothing */
 #endif
 /* \} */