00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _CPL_DEF_H
00013 #define _CPL_DEF_H
00014
00015 #include <time.h>
00016 #ifdef LINUX
00017 #include <pthread.h>
00018 #endif
00019
00020 #include "common_defs.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifdef LINUX
00030 typedef int HANDLE;
00031 #define INVALID_HANDLE_VALUE -1
00032 typedef int SOCKET;
00033 #define INVALID_SOCKET -1
00034 #endif
00035
00036 #define CPL_DIM_RX_BUFF 260
00037 #define CPL_DIM_TX_BUFF 260
00038
00039
00040
00041 #define CPL_LOW_BYTE( w) ( *( UINT8*)( (UINT16*)&w))
00042 #define CPL_HIGH_BYTE( w) ( *((( UINT8*) ((UINT16*) &w))+ 1 ))
00043 #define CPL_MAKE_WORD( a, b) (((UINT16)((UINT8)(a)))| (((UINT16)((UINT8)(b)))<< 8))
00044
00045 #define MSK_BYTE( bCh) ( 1<< (( UINT8)bCh))
00046 #define MSK_WORD( wCh) ( 1<< (( UINT16)wCh))
00047
00048 #define CPL_SWAP_WORD( value) CPL_MAKE_WORD( CPL_HIGH_BYTE( value), CPL_LOW_BYTE( value))
00049
00050 #define CPL_GET_WORD( pWord) ( CPL_MAKE_WORD( *(UINT8*)(( UINT8*)(pWord)+1), *( UINT8*)(pWord)))
00051 #define CPL_GET_NATIVE_WORD( pWord) ( CPL_MAKE_WORD( *(UINT8*)(( UINT8*)(pWord)), *( UINT8*)(pWord)+1))
00052
00053 #define CPL_SET_NATIVE_WORD( pWord, wValue) *( UINT8*)(pWord)= CPL_LOW_BYTE(wValue);*(UINT8*)(( UINT8*)(pWord)+1)= CPL_HIGH_BYTE(wValue);
00054 #define CPL_SET_WORD( pWord, wValue) *( UINT8*)(pWord)= CPL_HIGH_BYTE(wValue);*(UINT8*)(( UINT8*)(pWord)+1)= CPL_LOW_BYTE(wValue);
00055
00056 typedef enum
00057 {
00058 RX_BUFFER,
00059 TX_BUFFER,
00060 BOTH_BUFFER,
00061 } CPLBufferType;
00062
00063 typedef enum
00064 {
00065 CPL_COM,
00066 CPL_ETH,
00067 } CPLDevice;
00068
00069 typedef enum
00070 {
00071 SERBAUD_9600,
00072 SERBAUD_19200,
00073 SERBAUD_38400,
00074 SERBAUD_57600,
00075 SERBAUD_115200,
00076 } CPLComBaudrate;
00077 typedef enum
00078 {
00079 SERPARITY_NONE,
00080 SERPARITY_EVEN,
00081 SERPARITY_ODD,
00082 } CPLComParity;
00083
00084 typedef enum
00085 {
00086 STOP_ONE,
00087 STOP_5ONE,
00088 STOP_TWO,
00089 } CPLComStopBit;
00090
00091 typedef enum
00092 {
00093 DATA_SEVEN,
00094 DATA_EIGHT,
00095 } CPLComDataBit;
00096
00097 typedef enum
00098 {
00099 RTS_DISABLE,
00100
00101 RTS_HANDSHAKE,
00102 } CPLComRtsFlow;
00103
00104 typedef enum
00105 {
00106 DTR_DISABLE,
00107 DTR_HANDSHAKE,
00108 } CPLComDtrFlow;
00109
00110 typedef struct
00111 {
00112 char m_com_str[ 256];
00113 CPLComBaudrate m_baudrate;
00114 CPLComParity m_parity;
00115 CPLComDataBit m_dataBit;
00116 CPLComStopBit m_stopBit;
00117 CPLComRtsFlow m_RTSFlow;
00118 CPLComDtrFlow m_DTRFlow;
00119 } CPLComDevice;
00120
00121 typedef struct
00122 {
00123 char m_address[ 64];
00124 int m_port;
00125 } CPLEthDevice;
00126
00127 typedef struct
00128 {
00129 CPLDevice m_device;
00130 union
00131 {
00132 CPLComDevice m_com_device;
00133 CPLEthDevice m_eth_device;
00134 } m_device_config;
00135 } CPLConfig;
00136
00137 typedef struct
00138 {
00139 UINT8 m_bBuffTX[ CPL_DIM_TX_BUFF];
00140 UINT8 m_bBuffRX[ CPL_DIM_RX_BUFF];
00141 UINT16 m_wBuffTXIni;
00142 UINT16 m_wBuffRXLen;
00143 UINT16 m_wBuffTXLen;
00144 union
00145 {
00146 HANDLE m_serial;
00147 SOCKET m_socket;
00148 #if defined (LINUX)
00149 UINT32 m_tag;
00150 #elif defined (WIN32)
00151 UINT32 *m_tag;
00152 #else
00153 ???
00154 #endif
00155 } m_comm;
00156 clock_t m_rx_tout;
00157 CPLConfig m_config;
00158 #ifdef LINUX
00159 pthread_mutex_t m_mutex;
00160 #endif
00161 #ifdef WIN32
00162 HANDLE m_mutex;
00163 #endif
00164 } CPL_OBJ;
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 void CPL_BiosInit( CPL_OBJ* pCPLObj );
00179 BOOL CPL_Open( CPL_OBJ* pCPLObj, const CPLConfig* pConfig);
00180 BOOL CPL_Close( CPL_OBJ* pCPLObj);
00181 void CPL_Flush( CPL_OBJ* pCPLObj, CPLBufferType type );
00182
00183 UINT8* CPL_GetBuffTX( CPL_OBJ* pCPLObj, UINT16 *wSize);
00184 BOOL CPL_TX( CPL_OBJ* pCPLObj, UINT16 wCount);
00185 const UINT8* CPL_GetBuffRX( CPL_OBJ* pCPLObj, UINT16 *wSize);
00186 BOOL CPL_RX( CPL_OBJ* pCPLObj, UINT16 wCount);
00187 UINT16 CPL_GetCount( CPL_OBJ* pCPLObj, CPLBufferType type );
00188 UINT16 CPL_GetFree( CPL_OBJ* pCPLObj, CPLBufferType type );
00189 BOOL CPL_IsDataReady( CPL_OBJ* pCPLObj);
00190 BOOL CPL_Reconnect( CPL_OBJ* pCPLObj);
00191 BOOL CPL_direct_TX( CPL_OBJ* pCPLObj, const UINT8* bBuff, UINT16 wCount);
00192 BOOL CPL_direct_RX( CPL_OBJ* pCPLObj, UINT8* bBuff, UINT16 *wCount);
00193
00194 #endif