From: batt Date: Wed, 29 Sep 2010 15:48:36 +0000 (+0000) Subject: Progmem macros: add support for non-havard CPU as well; general refactoring. X-Git-Tag: 2.6.0~45 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8ca90529774ad36e903a8750795ff637f6ce2a72;p=bertos.git Progmem macros: add support for non-havard CPU as well; general refactoring. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4356 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/pgm.h b/bertos/cpu/pgm.h index 2db6cdc3..0369186a 100644 --- a/bertos/cpu/pgm.h +++ b/bertos/cpu/pgm.h @@ -56,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; \ @@ -68,7 +68,7 @@ ); \ __result; \ }) - #define pgm_read_uint16_t(addr) \ + #define pgm_read16(addr) \ ({ \ uint16_t __addr16 = (uint16_t)(addr); \ uint16_t __result; \ @@ -85,7 +85,7 @@ #else /* !__AVR_ENHANCED__ */ - #define pgm_read_char(addr) \ + #define pgm_read8(addr) \ ({ \ uint16_t __addr16 = (uint16_t)(addr); \ uint8_t __result; \ @@ -99,7 +99,7 @@ ); \ __result; \ }) - #define pgm_read_uint16_t(addr) \ + #define pgm_read16(addr) \ ({ \ uint16_t __addr16 = (uint16_t)(addr); \ uint16_t __result; \ @@ -119,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 @@ -139,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 @@ -196,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) + /* \} */