转载请标明:作者 menuconfig
分为两部分应用和驱动
驱动部分在IOControl中实现
static volatile S3C6410_GPIO_REG *v_pIOPregs ;
DWORD LED_Init(LPCTSTR pContext, LPCVOID lpvBusContext) {
//Virtual address mapping
v_pIOPregs = (volatile S3C6410_GPIO_REG*)DrvLib_MapIoSpace(S3C6410_BASE_REG_PA_GPIO,
sizeof(S3C6410_GPIO_REG),
FALSE);
return 1;
}
BOOL LED_Deinit(DWORD hDeviceContext) {
VirtualFree((PVOID)v_pIOPregs, 0, MEM_RELEASE);
v_pIOPregs = NULL;
return TRUE;
}
BOOL LED_IOControl(DWORD Handle,
DWORD dwIoControlCode,
PBYTE pInBuf,
DWORD nInBufSize,
PBYTE pOutBuf,
DWORD nOutBufSize,
PDWORD pBytesReturned) {
switch (dwIoControlCode) {
case IOCTL_LED_CASHDRAWER_OPEN: //CASHDRAWER_OPEN
v_pIOPregs->GPMCON&=(~(0x0f<<4));
v_pIOPregs->GPMCON|=0x1<<4;
v_pIOPregs->GPMDAT|=(0x01<<1);
OutputDebugString(L"CASHDRAWER_OPEN IO Control/n");
break;
case IOCTL_LED_CASHDRAWER_CLOSE: //CASHDRAWER_OPEN
v_pIOPregs->GPMCON&=(~(0x0f<<4));
v_pIOPregs->GPMCON|=0x1<<4;
v_pIOPregs->GPMDAT&=~(0x01<<1);
OutputDebugString(L"IOCTL_LED_CASHDRAWER_CLOSE IO Control/n");
}
return TRUE;
}
应用部分
#define IOCTL_LED_CASHDRAWER_OPEN 0x04001092
#define IOCTL_LED_CASHDRAWER_CLOSE 0x04001093
void OpenDrawer(void)
{
DWORD dwReturn = 0;
HANDLE hLed;
hLed = CreateFile(TEXT("LED1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (hLed != INVALID_HANDLE_VALUE)
{
DeviceIoControl(hLed,
IOCTL_LED_CASHDRAWER_OPEN,
NULL,
sizeof(DWORD),
NULL,
0,
&dwReturn,
NULL);
DeviceIoControl(hLed,
IOCTL_LED_CASHDRAWER_CLOSE,
NULL,
sizeof(DWORD),
NULL,
0,
&dwReturn,
NULL);
Sleep(200);
RETAILMSG (1, (TEXT("APP CASHDRAWER_OPEN OK!/r/n"))) ;
}
else
{
RETAILMSG (1, (TEXT("APP CASHDRAWER_OPEN false!/r/n"))) ;
}
CloseHandle(hLed);
}