#ifndef __MY_MACH_H #define __MY_MACH_H /* 包含的头文件---------------------------------------------------------------*/ #include /* 类型定义 ------------------------------------------------------------------*/ /* 常量定义 ------------------------------------------------------------------*/ enum { A_SENDING, //发送中 A_WAITTING, //等待回复 A_RE_SENDING, //重发 A_RES_OK, //结果:成功 A_RES_ERROR, //结果:一次错误 A_RES_OUTTIME, //结果:超时 A_RES_ALLSTEP_OK, //结果:所有步骤都成功 A_RES_DOMSG_OK, //获取DO信息OK A_MAX }; /* 宏定义 --------------------------------------------------------------------*/ #define max(a,b) ( ((a)>(b)) ? (a):(b) ) #define min(a,b) ( ((a)>(b)) ? (b):(a) ) #define ARRAY_SIZE( ARRAY ) (sizeof (ARRAY) / sizeof (ARRAY[0])) #define GetBit(dat,bit) (((dat)&(1<<(bit)))?1:0) #define SetBit(dat,bit,val) ((val)?((dat)|=(1<<(bit))):((dat)&=(~(1<<(bit))))) #define setBitMask(dat, bitMask, setval) ((dat)=(((dat)&(~(bitMask)))|((setval)&(bitMask)))) #define Put16Byte(Low8Byte,Hig8Byte) (((Low8Byte&(0xFF*1UL)))|(((Hig8Byte&(0xFF*1UL)))<<8)) #define GetHig8Byte(dat) (((dat*1UL)>>8)&0xFF) #define GetLow8Byte(dat) (((dat*1UL)>>0)&0xFF) typedef unsigned int uint_32 ; typedef unsigned short uint_16 ; //16位 #define BSWAP_16(x) \ (uint_16)((((uint_16)(x) & 0x00ff) << 8) | \ (((uint_16)(x) & 0xff00) >> 8) \ ) //32位 #define BSWAP_32(x) \ (uint_32)((((uint_32)(x) & 0xff000000) >> 24) | \ (((uint_32)(x) & 0x00ff0000) >> 8) | \ (((uint_32)(x) & 0x0000ff00) << 8) | \ (((uint_32)(x) & 0x000000ff) << 24) \ ) #define BinToHex(n) \ ( \ ((n>>21)&0x80)| \ ((n>>18)&0x40)| \ ((n>>15)&0x20)| \ ((n>>12)&0x10)| \ ((n>>9)&0x08)| \ ((n>>6)&0x04)| \ ((n>>3)&0x02)| \ ((n)&0x01) \ ) #define Bin(n) BinToHex(0x##n##l) #define _STR(s) #s #define STR(s) _STR(s) // 转换宏 #define _CONS(a,b) int(a##e##b) #define CONS(a,b) _CONS(a,b) // 转换宏 /* 函数定义------------------------------------------------------------------ */ #endif