00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _INA90_H_
00025 #define _INA90_H_ 1
00026
00027 #define _CLI() __asm__ __volatile__ ("cli")
00028 #define _SEI() __asm__ __volatile__ ("sei")
00029 #define _NOP() __asm__ __volatile__ ("nop")
00030 #define _WDR() __asm__ __volatile__ ("wdr")
00031 #define _SLEEP() __asm__ __volatile__ ("sleep")
00032 #define _OPC(op) __asm__ __volatile__ (".word %0" : : "n" (op))
00033
00034 #define __LPM_enhanced__(addr) ({ \
00035 unsigned short __addr16 = (unsigned short)(addr); \
00036 unsigned char __result; \
00037 __asm__ ( \
00038 "lpm %0, Z" \
00039 : "=r" (__result) \
00040 : "z" (__addr16) \
00041 ); \
00042 __result; \
00043 })
00044
00045 #define __LPM_classic__(addr) ({ \
00046 unsigned short __addr16 = (unsigned short)(addr); \
00047 unsigned char __result; \
00048 __asm__ ( \
00049 "lpm" "\n\t" \
00050 "mov %0, r0" \
00051 : "=r" (__result) \
00052 : "z" (__addr16) \
00053 : "r0" \
00054 ); \
00055 __result; \
00056 })
00057
00058
00059
00060
00061 #define __ELPM_enhanced__(addr) ({ \
00062 unsigned long __addr32 = (unsigned long)(addr); \
00063 unsigned char __result; \
00064 __asm__ ( \
00065 "out %2, %C1" "\n\t" \
00066 "movw r30, %1" "\n\t" \
00067 "elpm %0, Z" \
00068 : "=r" (__result) \
00069 : "v" (__addr32), "I" (RAMPZ) \
00070 : "r30", "r31" \
00071 ); \
00072 __result; \
00073 })
00074
00075 #define __ELPM_classic__(addr) ({ \
00076 unsigned long __addr32 = (unsigned long)(addr); \
00077 unsigned char __result; \
00078 __asm__ ( \
00079 "out %2, %C1" "\n\t" \
00080 "mov r31, %B1" "\n\t" \
00081 "mov r30, %A1" "\n\t" \
00082 "elpm" "\n\t" \
00083 "mov %0, r0" \
00084 : "=r" (__result) \
00085 : "r" (__addr32), "I" (RAMPZ) \
00086 : "r0", "r30", "r31" \
00087 ); \
00088 __result; \
00089 })
00090
00091 #if defined (__AVR_ENHANCED__)
00092 #define _LPM(addr) __LPM_enhanced__(addr)
00093 #define _ELPM(addr) __ELPM_enhanced__(addr)
00094 #else
00095 #define _LPM(addr) __LPM_classic__(addr)
00096 #define _ELPM(addr) __ELPM_classic__(addr)
00097 #endif
00098
00099
00100 #include <eeprom.h>
00101
00102 #define input(port) inp(port)
00103 #define output(port, val) outp(val, port)
00104
00105 #define __inp_blk__(port, addr, cnt, op) { \
00106 unsigned char __i = (cnt); \
00107 unsigned char *__addr = (addr); \
00108 while (__i) { \
00109 *(__addr op) = input(port); \
00110 __i--; \
00111 } \
00112 }
00113
00114 #define input_block_inc(port, addr, cnt) __inp_blk__(port, addr, cnt, ++)
00115 #define input_block_dec(port, addr, cnt) __inp_blk__(port, addr, cnt, --)
00116
00117 #define __out_blk__(port, addr, cnt, op) { \
00118 unsigned char __i = (cnt); \
00119 const unsigned char *__addr = (addr); \
00120 while (__i) { \
00121 output(port, *(__addr op)); \
00122 __i--; \
00123 } \
00124 }
00125
00126 #define output_block_inc(port, addr, cnt, op) __out_blk__(port, addr, cnt, ++)
00127 #define output_block_dec(port, addr, cnt, op) __out_blk__(port, addr, cnt, --)
00128
00129 #endif
00130