// This is a Sample Driver
#include <windows.h>
#include "TCC79x_Virtual.h"
#define IOCTL_WRITE1 1
#define IOCTL_WRITE0 0
#define IOCTL_READBIT 2
DWORD DDM_Init(LPCTSTR pContext, LPCVOID lpvBusContext);
BOOL DDM_Deinit( DWORD hDeviceContext );
DWORD DDM_Open( DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode );
BOOL DDM_Close( DWORD hOpenContext );
BOOL DDM_IOControl( DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut );
void DDM_PowerUp( DWORD hDeviceContext );
void DDM_PowerDown( DWORD hDeviceContext );
DWORD DDM_Read( DWORD hOpenContext, LPVOID pBuffer, DWORD Count );
DWORD DDM_Write( DWORD hOpenContext, LPCVOID pBuffer, DWORD Count );
DWORD DDM_Seek( DWORD hOpenContext, long Amount, WORD Type );
BOOL CustomFunction(void);
BOOL CustomFunctionEx(LPTSTR lpBuffer);
void DBGOut(DWORD dwValue);
#define IOCTL_DRIVER_REVSTR 0x1000
HANDLE hMem; // Storage for Inbound Strings
DWORD dwCount; // Size of current String
// ----------------------------------------------------
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch(ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
OutputDebugString(L"DriverDemo - DLL_PROCESS_ATTACH\n");
break;
case DLL_PROCESS_DETACH:
OutputDebugString(L"DriverDemo - DLL_PROCESS_DETACH\n");
break;
case DLL_THREAD_ATTACH:
OutputDebugString(L"DriverDemo - DLL_THREAD_ATTACH\n");
break;
case DLL_THREAD_DETACH:
OutputDebugString(L"DriverDemo - DLL_THREAD_DETACH\n");
break;
default:
break;
}
return TRUE;
}
// Driver Init...
DWORD DDM_Init( LPCTSTR pContext, LPCVOID lpvBusContext)
{
OutputDebugString(L"DriverDemo - DEM_Init - Context: ");
OutputDebugString(pContext);
OutputDebugString(L"\n");
hMem=LocalAlloc(LPTR,0x2000); // 0x1000 Unicode Characters
OutputDebugString(L"DemoDriver - ~ DDM_Init\n");
return 0x1234;
}
BOOL DDM_Deinit( DWORD hDeviceContext )
{
OutputDebugString(L"DriverDemo - DDM_Deinit\n");
OutputDebugString(L"DriverDemo - ~ DDM_Deinit\n");
return TRUE;
}
// Driver Open
DWORD DDM_Open( DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode )
{
OutputDebugString(L"DemoDriver - DDM_Open\n");
OutputDebugString(L"hDeviceContext - ");
DBGOut(hDeviceContext);
OutputDebugString(L"\n");
OutputDebugString(L"DemoDriver - ~ DDM_Open\n");
return 0x5678;
}
BOOL DDM_Close( DWORD hOpenContext )
{
OutputDebugString(L"DriverDemo - DEM_Close\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
OutputDebugString(L"DriverDemo - ~ DEM_Close\n");
return TRUE;
}
BOOL DDM_IOControl( DWORD hOpenContext, DWORD dwCode,\
PBYTE pBufIn, DWORD dwLenIn, \
PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut )
{
unsigned int tmp;
OutputDebugString(L"DriverDemo - DDM_IOControl\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
switch (dwCode) {
case IOCTL_WRITE1:
{
BITSET(HwPORTCFG3,Hw12);
BITSET(HwGPFEN,Hw2);
BITSET(HwGPFDAT,Hw2);
// OutputDebugString(L"IOCTL_WRITE1 IOCTL...\n");
// // reverse the string...
// HANDLE hTemp=LocalAlloc(LPTR,dwLenIn+sizeof(TCHAR));
// memset(hTemp,0x00,dwLenIn+1);
// TCHAR *tcOut=(TCHAR*)hTemp;
// TCHAR *tcIn=(TCHAR*)pBufIn;
// DWORD dwChars=dwLenIn/2;
// for (DWORD x=0;x < dwChars;x++) {
// tcOut[x]=tcIn[dwChars-x-1];
// }
// memcpy(pBufOut,hTemp,dwLenIn);
// LocalFree(hTemp);
// *pdwActualOut=dwLenIn;
break;
}
case IOCTL_WRITE0:
{
BITSET(HwPORTCFG3,Hw12);
BITSET(HwGPFEN,Hw2);
BITCLR(HwGPFDAT,Hw2);
break;
}
case IOCTL_READBIT:
{
BITSET(HwPORTCFG3,Hw12);
BITCLR(HwGPFEN,Hw2);
tmp = HwGPFDAT;
tmp &= 0x00000004;
*pBufOut = (tmp == 0)?0:1;
*pdwActualOut = 1;
break;
}
default:
OutputDebugString(L"Unknown IOCTL\n");
break;
}
OutputDebugString(L"DriverDemo - ~ DEM_IOControl\n");
return TRUE;
}
void DDM_PowerUp( DWORD hDeviceContext )
{
OutputDebugString(L"DriverDemo - DDM_PowerUp\n");
OutputDebugString(L"hDeviceContext - ");
DBGOut(hDeviceContext);
OutputDebugString(L"\n");
OutputDebugString(L"DriverDemo - ~ DDM_PowerUp\n");
}
void DDM_PowerDown( DWORD hDeviceContext )
{
OutputDebugString(L"DriverDemo - DDM_PowerDown\n");
OutputDebugString(L"hDeviceContext - ");
DBGOut(hDeviceContext);
OutputDebugString(L"\n");
OutputDebugString(L"DriverDemo - ~ DDM_PowerDown\n");
}
DWORD DDM_Read( DWORD hOpenContext, LPVOID pBuffer, DWORD Count )
{
DWORD dwRetCount=0xffff; // default to error
OutputDebugString(L"DriverDemo - DDM_Read\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
if (NULL != hMem) {
dwRetCount=dwCount;
memcpy(pBuffer,hMem,dwCount);
}
OutputDebugString(L"DriverDemo - ~ DDM_Read\n");
return dwRetCount;
}
DWORD DDM_Write( DWORD hOpenContext, LPCVOID pBuffer, DWORD Count )
{
OutputDebugString(L"DriverDemo - DDM_Write\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
if (NULL != hMem) {
LocalFree(hMem);
}
hMem=LocalAlloc(LPTR,Count);
memcpy(hMem,pBuffer,Count);
dwCount=Count;
OutputDebugString(L"DriverDemo - ~ DDM_Write\n");
return Count;
}
DWORD DDM_Seek( DWORD hOpenContext, long Amount, WORD Type )
{
OutputDebugString(L"DriverDemo - DDM_Seek\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
OutputDebugString(L"DriverDemo - ~ DDM_Seek\n");
return 0;
}
BOOL CustomFunction(void)
{
OutputDebugString(L"DriverDemo - CustomFunction\n");
OutputDebugString(L"DriverDemo - ~ CustomFunction\n");
return TRUE;
}
BOOL CustomFunctionEx(LPTSTR lpBuffer )
{
OutputDebugString(L"DriverDemo - CustomFunctionEx\n");
TCHAR buffer[16];
_tcscpy(buffer, lpBuffer);
OutputDebugString(buffer);
OutputDebugString(_T("\n"));
OutputDebugString(L"DriverDemo - ~ CustomFunctionEx\n");
return TRUE;
}
void DBGOut(DWORD dwValue)
{
TCHAR tcTemp[10];
wsprintf(tcTemp,L"%ld",dwValue);
OutputDebugString(tcTemp);
}