小弟做毕设遇到个棘手问题,望各位好心人帮助
小弟用的arm开发板是友坚恒天的S3C6410,将GPIO的GPK的15-8位和GPL的7-0位从高到低组合成16位数据,但在编写驱动时报错,可能是XXX_read函数有问题,代码如下:
驱动部分代码:
DWORD GIO_Init(LPCTSTR PContext, LPCVOID lpvBuscontext
{
BOOL bResult = TRUE;
PGIO_PUBLIC_CONTEXT pPublicGIO = NULL;
PHYSICAL_ADDRESS ioPhysicalBase = {0,0};
ioPhysicalBase.LowPart = S3C6410_BASE_REG_PA_GPIO;
// 申请GIO的CONTEXT
if ( !(pPublicGIO = (PGIO_PUBLIC_CONTEXT)LocalAlloc( LPTR, sizeof(GIO_PUBLIC_CONTEXT) )) )//申请空间
{
RETAILMSG(TEXT("[GIO] Can't not allocate for GIO Context\n"));
bResult = FALSE;
goto CleanUp;
}
// 得到GPIO寄存器的地址
pPublicGIO->v_pIOPregs = (volatile S3C6410_GPIO_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(S3C6410_GPIO_REG), FALSE);
if (pPublicGIO->v_pIOPregs == NULL)
{
RETAILMSG(TEXT("[GIO] For pGPIOregs: MmMapIoSpace failed!\r\n"));
bResult = FALSE;
goto CleanUp;
}
//GPK
pPublicGIO->v_pIOPregs->GPKCON1 = pPublicGIO->v_pIOPregs->GPKCON1 & ~(0xffffffff);//GPK8...GPK15=0000=输入
pPublicGIO->v_pIOPregs->GPKPUD = pPublicGIO->v_pIOPregs->GPKPUD & ~(0xffffffff) | 0xaaaaffff;//GPK[8]...GPK[15]=10=上拉使能
pPublicGIO->v_pIOPregs->GPKDAT = pPublicGIO->v_pIOPregs->GPKDAT & 0x000000ff;//GPK8...GPK15置零
//GPL
pPublicGIO->v_pIOPregs->GPLCON0 = pPublicGIO->v_pIOPregs->GPLCON0 & ~(0xffffffff);//GPL0...GPL7=0000=输入
pPublicGIO->v_pIOPregs->GPLPUD = pPublicGIO->v_pIOPregs->GPLPUD & ~(0xffffffff) | 0xffffaaaa;//GPL[0]...GPL[7]=10=上拉使能
pPublicGIO->v_pIOPregs->GPLDAT = pPublicGIO->v_pIOPregs->GPLDAT & 0x0000ff00;//GPL0...GPL7置零
DWORD GIO_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
PGIO_PUBLIC_CONTEXT pReadGIOPublic = (PGIO_PUBLIC_CONTEXT)hOpenContext;
WORD *rd;
(WORD *)rd = (WORD *)pBuffer;
WORD KDAT = WORD((pReadGIOPublic->v_pIOPregs->GPKDAT) & 0xffff);
WORD LDAT = WORD((pReadGIOPublic->v_pIOPregs->GPLDAT) & 0xffff);
*(rd) = (KDAT & 0xff00) | (LDAT & 0x00ff);
RETAILMSG(1,(TEXT("GIO_Read: Read Success!\r\n"),*rd));
return 1;
}
应用程序代码:创建你一个工程后,使用一个button触发事件来读数据,用static text将16位显示成十进制:
void CgpioDlg::OnBnClickedButton1()
{
DWORD actlen;
BOOL ret;
WORD dt = 0;
m_hLed = CreateFile(L"GIO1:",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
ret=ReadFile(m_hLed,&dt,2,&actlen,NULL);
CString str;
str.Format(_T("%d"),dt);
CWnd *pWnd=GetDlgItem(IDC_STATIC);
pWnd->SetWindowText(str);
}
运行时当点击button时开发板界面弹出错误信息:“an invalid argument was encountered”
驱动调试窗口信息为:
+OEMSetAlarmTime(11/4/2012 2:0:0.000)
GIO_Read: Read Success!
Exception 'Raised Exception' (-1): Thread-Id=082f0002(pth=846b4c80), Proc-Id=082e0002(pprc=846b4b60) 'gpio.exe', VM-active=082e0002(pprc=846b4b60) 'gpio.exe'
PC=4006bdfc(coredll.dll+0x0005bdfc) RA=8011a4c8(kernel.dll+0x000064c8) SP=0004f5b8, BVA=0004f5ec
小弟实在不懂哪里出了问题,望各位大侠相助,先谢谢了!!!