X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Fpgm.h;h=0369186a4014bcf8d274ba51224e09f446a93c4e;hb=ce0a95c32a39e3eed1d3f2aa5ff4395bebdb99ed;hp=eebe87fe1107a8a716f5ce63632a5303759d82e5;hpb=4b681f454badd9055c35b60d9a3ecd8da11c4b80;p=bertos.git diff --git a/bertos/cpu/pgm.h b/bertos/cpu/pgm.h index eebe87fe..0369186a 100644 --- a/bertos/cpu/pgm.h +++ b/bertos/cpu/pgm.h @@ -26,8 +26,7 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2005 ,2006, 2007 Develer S.r.l. (http://www.develer.com/) - * + * Copyright 2005, 2006, 2007, 2008 Develer S.r.l. (http://www.develer.com/) * --> * * \brief Support for reading program memory on Harvard architectures. @@ -43,6 +42,8 @@ * * \note This module contains code ripped out from avr-libc, * which is distributed under a 3-clause BSD license. + * + * \author Bernie Innocenti */ #ifndef MWARE_PGM_H #define MWARE_PGM_H @@ -55,7 +56,7 @@ #if CPU_AVR #ifdef __AVR_ENHANCED__ - #define pgm_read_char(addr) \ + #define pgm_read8(addr) \ ({ \ uint16_t __addr16 = (uint16_t)(addr); \ uint8_t __result; \ @@ -67,7 +68,7 @@ ); \ __result; \ }) - #define pgm_read_uint16_t(addr) \ + #define pgm_read16(addr) \ ({ \ uint16_t __addr16 = (uint16_t)(addr); \ uint16_t __result; \ @@ -84,7 +85,7 @@ #else /* !__AVR_ENHANCED__ */ - #define pgm_read_char(addr) \ + #define pgm_read8(addr) \ ({ \ uint16_t __addr16 = (uint16_t)(addr); \ uint8_t __result; \ @@ -98,7 +99,7 @@ ); \ __result; \ }) - #define pgm_read_uint16_t(addr) \ + #define pgm_read16(addr) \ ({ \ uint16_t __addr16 = (uint16_t)(addr); \ uint16_t __result; \ @@ -118,12 +119,7 @@ #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 - + #define pgm_read32(addr) ((uint32_t)(pgm_read16(addr) | (((uint32_t)pgm_read16(((const uint8_t *)(addr)) + 2)) << 16))) #ifndef PROGMEM #define PROGMEM __attribute__((__progmem__)) #endif @@ -138,6 +134,25 @@ #error Missing CPU support #endif + +#if !CPU_HARVARD + #define pgm_read8(a) (*(const uint8_t *)(a)) + #define pgm_read16(a) (*(const uint16_t *)(a)) + #define pgm_read32(a) (*(const uint32_t *)(a)) +#endif + +#define pgm_read_char(a) pgm_read8(a) +#define pgm_read_uint16_t(addr) pgm_read16(addr) + + +#if SIZEOF_INT == 2 + #define pgm_read_int(addr) ((int)pgm_read16(addr)) +#elif SIZEOF_INT == 4 + #define pgm_read_int(addr) ((int)pgm_read32(addr)) +#else + #error Missing support for CPU word size! +#endif + #ifndef PSTR #define PSTR /* nothing */ #endif @@ -195,16 +210,23 @@ typedef PROGMEM uint32_t pgm_uint32_t; * \{ */ #ifdef _PROGMEM - #define PGM_READ_CHAR(s) pgm_read_char(s) + #define PGM_READ8(a) pgm_read8(a) + #define PGM_READ16(a) pgm_read16(a) + #define PGM_READ32(a) pgm_read32(a) #define PGM_FUNC(x) PFUNC(x) #define PGM_STR(x) PSTR(x) #define PGM_ATTR PROGMEM #else - #define PGM_READ_CHAR(s) (*(s)) + #define PGM_READ8(a) (*(const uint8_t *)(a)) + #define PGM_READ16(a) (*(const uint16_t *)(a)) + #define PGM_READ32(a) (*(const uint32_t *)(a)) #define PGM_FUNC(x) x #define PGM_STR(x) x #define PGM_ATTR /* nothing */ #endif + +#define PGM_READ_CHAR(addr) PGM_READ8(addr) + /* \} */