00001
00040 #ifndef ARCH_HUGEMEM_H_INCLUDED
00041 #define ARCH_HUGEMEM_H_INCLUDED
00042
00060 #if defined(CONFIG_HAVE_HUGEMEM) || defined(__DOXYGEN__)
00061 # if defined(__GNUC__) || defined(__DOXYGEN__)
00062 #include <cpu/regs.h>
00063
00064 typedef uint32_t hugemem_ptr_t;
00065
00066 #define HUGEMEM_NULL 0
00067
00068 static inline uint_fast8_t hugemem_read8(const hugemem_ptr_t from)
00069 {
00070 uint8_t value;
00071
00072 asm volatile(
00073 "movw r30, %A1 \n\t"
00074 "out %2, %C1 \n\t"
00075 "ld %0, Z \n\t"
00076 "out %2, __zero_reg__ \n\t"
00077 : "=r"(value)
00078 : "r"(from), "i"(CPU_REG(RAMPZ))
00079 : "r30", "r31"
00080 );
00081
00082 return value;
00083 }
00084
00085 uint_fast16_t hugemem_read16(const hugemem_ptr_t from);
00086 uint_fast32_t hugemem_read32(const hugemem_ptr_t from);
00087
00088 static inline void hugemem_write8(hugemem_ptr_t to, uint_fast8_t val)
00089 {
00090 asm volatile(
00091 "movw r30, %A0 \n\t"
00092 "out %2, %C0 \n\t"
00093 "st Z, %1 \n\t"
00094 "out %2, __zero_reg__ \n\t"
00095 :
00096 : "r"(to), "r"(val), "i"(CPU_REG(RAMPZ))
00097 : "r30", "r31"
00098 );
00099 }
00100
00101 void hugemem_write16(hugemem_ptr_t to, uint_fast16_t val);
00102 void hugemem_write32(hugemem_ptr_t to, uint_fast32_t val);
00103
00104 # elif defined(__ICCAVR__)
00105 typedef void __huge *hugemem_ptr_t;
00106
00107 #define HUGEMEM_NULL NULL
00108
00109 static inline uint_fast8_t hugemem_read8(const hugemem_ptr_t from)
00110 {
00111 return *(volatile __huge uint8_t *)from;
00112 }
00113
00114 static inline uint_fast16_t hugemem_read16(const hugemem_ptr_t from)
00115 {
00116 return *(volatile __huge uint16_t *)from;
00117 }
00118
00119 static inline uint_fast32_t hugemem_read32(const hugemem_ptr_t from)
00120 {
00121 return *(volatile __huge uint32_t *)from;
00122 }
00123
00124 static inline void hugemem_write8(hugemem_ptr_t to, uint_fast8_t val)
00125 {
00126 *(__huge uint8_t *)to = val;
00127 }
00128
00129 static inline void hugemem_write16(hugemem_ptr_t to, uint_fast16_t val)
00130 {
00131 *(__huge uint16_t *)to = val;
00132 }
00133
00134 static inline void hugemem_write32(hugemem_ptr_t to, uint_fast32_t val)
00135 {
00136 *(__huge uint32_t *)to = val;
00137 }
00138 # endif
00139
00140 void hugemem_read_block(void *to, const hugemem_ptr_t from, size_t size);
00141 void hugemem_write_block(hugemem_ptr_t to, const void *from, size_t size);
00142
00143 #else
00144 # include <generic/hugemem.h>
00145 #endif
00146
00147
00148 #endif