00001
00038 #ifndef ARCH_PROGMEM_H_INCLUDED
00039 #define ARCH_PROGMEM_H_INCLUDED
00040
00041 #include <stdint.h>
00042
00060 #if defined(__GNUC__)
00061 # define __progmem __attribute__((__progmem__))
00062 # define __progmem_arg
00063 # define DECLARE_PROGMEM(type, name) const type name __progmem
00064 # define DEFINE_PROGMEM(type, name) const type name __progmem
00065
00066 static inline uint8_t progmem_read8(const uint8_t *p)
00067 {
00068 uint8_t value;
00069
00070 asm("lpm %0, Z" : "=r"(value) : "z"(p));
00071
00072 return value;
00073 }
00074
00075 static inline uint16_t progmem_read16(const uint16_t *p)
00076 {
00077 uint16_t value;
00078
00079 asm("lpm %A0, Z+\n\t"
00080 "lpm %B0, Z"
00081 : "=&r"(value), "+z"(p));
00082
00083 return value;
00084 }
00085
00086 static inline uint32_t progmem_read32(const uint32_t *p)
00087 {
00088 uint32_t value;
00089
00090 asm("lpm %A0, Z+\n\t"
00091 "lpm %B0, Z+\n\t"
00092 "lpm %C0, Z+\n\t"
00093 "lpm %D0, Z"
00094 : "=&r"(value), "+z"(p));
00095
00096 return value;
00097 }
00098
00099 #elif defined(__ICCAVR__)
00100
00101 # if defined(CONFIG_MEMORY_MODEL_TINY) || defined(CONFIG_MEMORY_MODEL_SMALL)
00102 # define __progmem __flash
00103 # define __progmem_arg __flash
00104 # elif defined(CONFIG_MEMORY_MODEL_LARGE)
00105 # define __progmem __farflash
00106 # define __progmem_arg __farflash
00107 # endif
00108
00109 # define DECLARE_PROGMEM(type, name) const __progmem type name
00110 # define DEFINE_PROGMEM(type, name) const __progmem type name
00111
00112 static inline uint8_t progmem_read8(const uint8_t __progmem *p)
00113 {
00114 return *p;
00115 }
00116
00117 static inline uint16_t progmem_read16(const uint16_t __progmem *p)
00118 {
00119 return *p;
00120 }
00121
00122 static inline uint32_t progmem_read32(const uint32_t __progmem *p)
00123 {
00124 return *p;
00125 }
00126
00127 #elif defined(__DOXYGEN__)
00128
00129
00130
00131
00132
00133
00134 # define __progmem __attribute__((__progmem__))
00135 # define __progmem_arg
00136 # define DECLARE_PROGMEM(type, name) const type name __progmem
00137 # define DEFINE_PROGMEM(type, name) const type name __progmem
00138
00139 static inline uint8_t progmem_read8(const uint8_t __progmem *p)
00140 {
00141 }
00142
00143 static inline uint16_t progmem_read16(const uint16_t __progmem *p)
00144 {
00145 }
00146
00147 static inline uint32_t progmem_read32(const uint32_t __progmem *p)
00148 {
00149 }
00150
00151 #endif
00152
00154
00155 #endif