4 * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2004 Giovanni Bajo
6 * This file is part of DevLib - See README.devlib for information.
9 * \brief Support for reading program memory on Harvard architectures.
11 * Support is currently provided for AVR microcontrollers only.
13 * These macros allow building code twice, with and without
14 * pgm support (e.g.: strcpy() and strcpy_P()).
16 * Set the _PROGMEM predefine to compile in conditional
17 * program-memory support.
20 * \note This module contains code ripped out from avr-libc,
21 * which is distributed under a 3-clause BSD license.
26 #include <cpu_detect.h>
30 #ifdef __AVR_ENHANCED__
31 #define pgm_read_char(addr) \
33 uint16_t __addr16 = (uint16_t)(addr); \
44 #define pgm_read_char(addr) \
46 uint16_t __addr16 = (uint16_t)(addr); \
60 #define PROGMEM __attribute__((__progmem__))
61 #define PSTR(s) ({static const char __c[] PROGMEM = (s); __c;})
64 #error Missing CPU support
68 #define PSTR /* nothing */
72 #define PROGMEM /* nothing */
76 * \name Types for variables stored in program memory (harvard processors).
79 typedef PROGMEM char pgm_char;
80 typedef PROGMEM int8_t pgm_int8_t;
81 typedef PROGMEM uint8_t pgm_uint8_t;
82 typedef PROGMEM int16_t pgm_int16_t;
83 typedef PROGMEM uint16_t pgm_uint16_t;
84 typedef PROGMEM int32_t pgm_int32_t;
85 typedef PROGMEM uint32_t pgm_uint32_t;
93 * These macros enable dual compilation of code for both program
96 * Such a function may be defined like this:
99 * void PGM_FUNC(lcd_puts)(PGM_ATTR const char *str)
102 * while ((c = PGM_READ_CHAR(str++))
107 * The above code can be compiled twice: once with the _PROGMEM preprocessor
108 * symbol defined, and once without. The two object modules can then be
109 * linked in the same application for use by client code:
112 * lcd_puts("Hello, world!");
113 * lcd_puts_P(PSTR("Hello, world!"));
115 * // To be used when invoking inside other PGM_FUNC functions:
116 * PGM_FUNC(lcd_puts)(some_string);
120 #define PGM_READ_CHAR(s) pgm_read_char(s)
121 #define PGM_FUNC(x) x ## _P
122 #define PGM_ATTR PROGMEM
124 #define PGM_READ_CHAR(s) (*(s))
125 #define PGM_FUNC(x) x
126 #define PGM_ATTR /* nothing */
130 #endif /* MWARE_PGM_H */