📄 csddriver.h
字号:
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the CSDDRIVER_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// CSDDRIVER_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#define CSDDRIVER_EXPORTS
#ifdef CSDDRIVER_EXPORTS
#define CSDDRIVER_API __declspec(dllexport)
#else
#define CSDDRIVER_API __declspec(dllimport)
#endif
#include "ISRCSD.h"
//enum len {ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT};
//enum pat {S,E};
//enum typ {D,R};
enum fil {SIN,DOU};
enum lis {LON,LOFF};
enum tes {TON,TOFF};
enum sle {SON,SOFF};
enum bau {B1000,B800,B500,B320,B250,B160,B125,B80,B40,B20,B10,B5};
typedef struct _CAN_PORTSTRUCT{
enum fil filter;
enum lis lis_on;
enum tes test;
enum sle sleep;
enum bau baud_rate;
unsigned char code1;
unsigned char code2;
unsigned char code3;
unsigned char code4;
unsigned char mask1;
unsigned char mask2;
unsigned char mask3;
unsigned char mask4;
}CAN_PORTSTRUCT;
typedef struct __CAN_STRUCT{
// PUCHAR dwIOBase; // @field IO Base Address - unmapped
DWORD Index; // @field IO Length
DWORD dwSysIntr; // @field System Interrupt number for this peripheral
PUCHAR pBaseAddress; // @field Start of serial registers - mapped
// COMMTIMEOUTS CommTimeouts; // @field Copy of CommTimeouts structure
ULONG OpenCount; // @field Count of simultaneous opens.
DWORD dwIrq; // IRQ field
PVOID pVirtualStaticAddr;// Static Address.
PWCHAR RegIsrDll;// ISR Dll name.
PWCHAR RegIsrHandler;//ISR Handle Name.
volatile ISRCSD_INFO * pIsrInfoVirt;
volatile DataBuffer * pXmitBuffer;
volatile DataBuffer * pReceiveBuffer;
HANDLE hIsrHandler;
CAN_PORTSTRUCT can_portstruct;
}CAN_STRUCT;
typedef CAN_STRUCT * pCAN_STRUCT;
typedef CAN_PORTSTRUCT * pCAN_PORTSTRUCT;
//////////////////////////////////////////////////////////////////////////////
typedef struct __RX_BUFFER_INFO {
ULONG Read; /* @field Current Read index. */
ULONG Write; /* @field Current Write index. */
ULONG Length; /* @field Length of buffer */
BOOL DataAvail; /* @field BOOL reflecting existence of data. */
PUCHAR RxCharBuffer; /* @field Start of buffer */
CRITICAL_SECTION CS; /* @field Critical section */
} RX_BUFFER_INFO, *PRX_BUFFER_INFO;
#define RxResetFifo(pSH) pSH->RxBufferInfo.Write = pSH->RxBufferInfo.Read = 0
#define RxEnterCS(pSH) EnterCriticalSection (&(pSH->RxBufferInfo.CS))
#define RxLeaveCS(pSH) LeaveCriticalSection (&(pSH->RxBufferInfo.CS))
#define RxWrite(pSH) (pSH->RxBufferInfo.Write)
#define RxRead(pSH) (pSH->RxBufferInfo.Read)
#define RxLength(pSH) (pSH->RxBufferInfo.Length)
// Don't use the power of 2 trick for length, because the PDD has option of overriding
// buffer length, and may not specify a power of 2. Lets be more flexible & a very
// little bit slower.
// #define RxBytesAvail(pSH) ((RxWrite(pSH) - RxRead(pSH)) & (RxLength(pSH) - 1))
#define RxBuffWrite(pSH) (pSH->RxBufferInfo.RxCharBuffer+pSH->RxBufferInfo.Write)
#define RxBuffRead(pSH) (pSH->RxBufferInfo.RxCharBuffer+pSH->RxBufferInfo.Read)
typedef struct __TX_BUFFER_INFO {
DWORD Permissions; /* @field Current permissions */
ULONG Read; /* @field Current Read index. */
ULONG Length; /* @field Length of buffer */
PUCHAR TxCharBuffer; /* @field Start of buffer */
CRITICAL_SECTION CS; /* @field Critical section */
} TX_BUFFER_INFO, *PTX_BUFFER_INFO;
#define TxEnterCS(pSH) EnterCriticalSection (&(pSH->TxBufferInfo.CS))
#define TxLeaveCS(pSH) LeaveCriticalSection (&(pSH->TxBufferInfo.CS))
#define TxRead(pSH) (pSH->TxBufferInfo.Read)
#define TxLength(pSH) (pSH->TxBufferInfo.Length)
#define TxBytesAvail(pSH) (TxLength(pSH)-TxRead(pSH))
#define TxBuffRead(pSH) (pSH->TxBufferInfo.TxCharBuffer+pSH->TxBufferInfo.Read)
typedef struct _CAN_OPEN_INFO{
// DWORD Index;
CAN_STRUCT CSDHead;
RX_BUFFER_INFO RxBufferInfo;
TX_BUFFER_INFO TxBufferInfo;
CRITICAL_SECTION OpenCS;
// CRITICAL_SECTION TransmitCritSec1; // @field Protects tx action
// CRITICAL_SECTION ReceiveCritSec1; // @field Protects rx action
// CRITICAL_SECTION RegCritSec;
DWORD KillRxThread;
HANDLE hCSDEvent;
HANDLE hCANEvent;
HANDLE hTransmitEvent ;
// HANDLE hReadEvent; // @field Serial event, both rx and tx
HANDLE hKillDispatchThread; // @field Synchonize thread end
// HANDLE hTransmitEvent; // @field transmit event, both rx and tx
HANDLE pDispatchThread;// @field ReceiveThread
ULONG Priority256; // @field CeThreadPriority of Dispatch Thread.
DWORD OpenCnt;
DWORD TxBytesSent;
// ULONG RxBytes; // @field Record of total bytes received.
// ULONG TxBytes; // @field Record of total bytes transmitted.
// ULONG TxBytesPending; // @field Record of total bytes awaiting transmit.
}CAN_OPEN_INFO;
typedef CAN_OPEN_INFO * pCAN_OPEN_INFO;
__inline ULONG RxBytesAvail(pCAN_OPEN_INFO pSH) {
// Note: We have to copy RxRead and RxWrite index to local in order to make it atomic.
register DWORD RxWIndex=RxWrite(pSH), RxRIndex=RxRead(pSH);
return (RxWIndex>=RxRIndex?RxWIndex- RxRIndex: RxLength(pSH) - RxRIndex + RxWIndex);
}
__inline ULONG RxBufferAvail(pCAN_OPEN_INFO pSH) {
// Note: We have to copy RxRead and RxWrite index to local in order to make it atomic.
register DWORD RxWIndex=RxWrite(pSH), RxRIndex=RxRead(pSH);
return (RxWIndex>=RxRIndex? RxRIndex+ RxLength(pSH)-RxWIndex-13: RxRIndex-RxWIndex-13);
}
// This class is exported from the CSDDriver.dll
extern "C" {
CSDDRIVER_API pCAN_OPEN_INFO CSDInit(DWORD Index);
CSDDRIVER_API pCAN_OPEN_INFO CSDOpen(pCAN_OPEN_INFO pCSDHead);
CSDDRIVER_API DWORD CSDClose(pCAN_OPEN_INFO pCSDHead);
CSDDRIVER_API DWORD CSDRead(
HANDLE pHead,
PUCHAR pTargetBuffer,
ULONG BufferLength
);
CSDDRIVER_API DWORD CSDWrite(
HANDLE pHead, /*@parm [IN] HANDLE returned by COM_Open.*/
PUCHAR pSourceBytes, /*@parm [IN] Pointer to bytes to be written.*/
ULONG NumberOfBytes /*@parm [IN] Number of bytes to be written. */
);
CSDDRIVER_API DWORD CSDConfig(
pCAN_OPEN_INFO pHead,
CAN_PORTSTRUCT *ptrStruct
);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -