/******************************************************************************************************************* *File Name : drvbase.h *Description : the file is driver config for cpu *Date : 2008/06/16 *Author : yuanguiyou --History: ------------------------------------------------------------------------------------------------------------------ *change info: *******************************************************************************************************************/ #ifndef DRVBASE_H #define DRVBASE_H #ifndef outb #define outb(addr, data) addr = (data) #endif #ifndef inb #define inb(addr) (addr) #endif #ifndef outw #define outw(addr, data) addr = (data) #endif #ifndef inw #define inw(addr) (addr) #endif #ifndef BV #define BV(bit) (1<<(bit)) #endif #ifndef cbi #define cbi(reg,bit) reg &= ~(BV(bit)) #endif #ifndef sbi #define sbi(reg,bit) reg |= (BV(bit)) #endif #ifndef cli #define cli() __asm__ __volatile__ ("cli" ::) #endif #ifndef sei #define sei() __asm__ __volatile__ ("sei" ::) #endif // support for individual port pin naming in the mega128 // see port128.h for details #ifdef __AVR_ATmega128__ // not currently necessary due to inclusion // of these defines in newest AVR-GCC // do a quick test to see if include is needed #ifndef PD0 #include "port128.h" #endif #endif // use this for packed structures // (this is seldom necessary on an 8-bit architecture like AVR, // but can assist in code portability to AVR) #define GNUC_PACKED __attribute__((packed)) // port address helpers #define DDR(x) ((x)-1) // address of data direction register of port x #define PIN(x) ((x)-2) // address of input register of port x // MIN/MAX/ABS macros #define MIN(a,b) ((ab)?(a):(b)) #define ABS(x) ((x>0)?(x):(-x)) // constants #define PI 3.14159265359 #ifndef WIN32 #ifndef FALSE // true/false defines #define FALSE 0 #define TRUE 1 #endif #endif // datatype definitions macros typedef unsigned char u08; typedef signed char s08; typedef unsigned short u16; typedef signed short s16; typedef unsigned long u32; typedef signed long s32; typedef unsigned long long u64; typedef signed long long s64; /* use inttypes.h instead // C99 standard integer type definitions typedef unsigned char uint8_t; typedef signed char int8_t; typedef unsigned short uint16_t; typedef signed short int16_t; typedef unsigned long uint32_t; typedef signed long int32_t; typedef unsigned long uint64_t; typedef signed long int64_t; */ // maximum value that can be held // by unsigned data types (8,16,32bits) #define MAX_U08 255 #define MAX_U16 65535 #define MAX_U32 4294967295 // maximum values that can be held // by signed data types (8,16,32bits) #define MIN_S08 -128 #define MAX_S08 127 #define MIN_S16 -32768 #define MAX_S16 32767 #define MIN_S32 -2147483648 #define MAX_S32 2147483647 #ifndef WIN32 // more type redefinitions typedef unsigned char BOOL; typedef unsigned char BYTE; typedef unsigned int WORD; typedef unsigned long DWORD; typedef unsigned char UCHAR; typedef unsigned int UINT; typedef unsigned short USHORT; typedef unsigned long ULONG; typedef char CHAR; typedef int INT; typedef long LONG; #endif #define F_CPU 8000000 // 8MHz processor #define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond #endif