IO口流驱动

white_lotus 2010-08-26 03:29:21
输出引脚合适,读引脚去读不进来,(输入输出用的是不同的引脚)!
下面是读端口的流驱动:
DWORD GPI_Read(DWORD dwData, LPVOID pBuf, DWORD Len)
{
BYTE* pdatabuf;
BYTE gpioNum;
BYTE gpioState;
pdatabuf = (BYTE*)pBuf;
gpioState= *pdatabuf ;
gpioNum = *pdatabuf++;
RETAILMSG(1,(TEXT("*****GPILED: GPI_Read\r\n")));
if(gpioNum == 0 || gpioNum == 1 || gpioNum == 2|| gpioNum == 3)
{
*pdatabuf =(v_pIOPregs->GPFDAT & (1<<gpioNum))?1:0;
}

RETAILMSG(1,(TEXT("state: %d\r\n"),*pdatabuf));


//---read pins-----
//------------PB7------12-----read single ---in 0-----
if(gpioNum == 12)
{
v_pIOPregs->GPBCON &= ~(1<<(14));//00 input
v_pIOPregs->GPBCON &= ~(1<<(15));
v_pIOPregs->GPBUP &= ~(1<< 7);

if(v_pIOPregs->GPBDAT & ( 1 <<7))
gpioState = 1;
else
gpioState = 0;

RETAILMSG(1,(TEXT("state: %d\r\n"),gpioNum));

}
//--------------PB9----13----read single -----in 1---
if(gpioNum == 13)
{
v_pIOPregs->GPBCON &= ~(1<<(18));
v_pIOPregs->GPBCON &= ~(1<<(19));
v_pIOPregs->GPBUP &= ~(1<<9);

if(v_pIOPregs->GPBDAT & ( 1 <<9))
gpioState = 1;
else
gpioState = 0;
RETAILMSG(1,(TEXT("state: %d\r\n"),gpioNum));

}

//---------PE11--------14-----read single------in 2---------
if(gpioNum == 14)
{
v_pIOPregs->GPECON &= ~(1<<(22));
v_pIOPregs->GPECON &= ~(1<<(23));
v_pIOPregs->GPEUP &= ~(1<<11);

if(v_pIOPregs->GPEDAT & ( 1 <<11))
gpioState = 1;
else
gpioState = 0;

RETAILMSG(1,(TEXT("state: %d\r\n"),gpioNum));

}
//---------PE12------15------read single-----in 3---------
if(gpioNum == 15)
{
v_pIOPregs->GPECON &= ~ (1<<(24));
v_pIOPregs->GPECON &= ~(1<<(25));
v_pIOPregs->GPEUP &= ~(1<<12);

if(v_pIOPregs->GPEDAT & ( 1 <<12))
gpioState = 1;
else
gpioState = 0;

RETAILMSG(1,(TEXT("state: %d\r\n"),gpioNum));

}
//---------PE13-----16--------read single---in 4--------
if(gpioNum == 16)
{
v_pIOPregs->GPECON &= ~ (1<<(26));
v_pIOPregs->GPECON &= ~ (1<<(27));
v_pIOPregs->GPEUP &= ~ (1<<13);

if(v_pIOPregs->GPEDAT & ( 1 <<13))
gpioState = 1;
else
gpioState = 0;

RETAILMSG(1,(TEXT("state: %d\r\n"),gpioNum));

}
return 1;
}
...全文
149 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
博说医械研发 2010-08-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 luchuxi12345 的回复:]

我看串口打印信息,他能把端口的状态读出来。是不是应用程序的问题啊?
[/Quote]
如果串口打印信息能读出来说明硬件和驱动是没问题的,查查应用程序是否有问题,应用程序和驱动交互是否有问题
white_lotus 2010-08-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 gooogleman 的回复:]
用sunrain_hjb老师的那个小软件看看能不能读出来。
呵呵。如果不能,那么是不能读的了。
[/Quote]
我看串口打印信息,他能把端口的状态读出来。是不是应用程序的问题啊?
gooogleman 2010-08-27
  • 打赏
  • 举报
回复
用sunrain_hjb老师的那个小软件看看能不能读出来。
呵呵。如果不能,那么是不能读的了。
white_lotus 2010-08-27
  • 打赏
  • 举报
回复
我看了几个驱动,都有PREADBUF=MAPPTRTOPROCESS(PBUFF,GETCALLERPROCESS());是不是这个原因?
white_lotus 2010-08-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 chinesedragon2010 的回复:]
楼主可以简介一下你GPI_Read这个函数的功能吗
[/Quote]
把这几个端口设为输入端口,,主要是应用程序需要读取这几个端口的值,以便做出下一步反映
white_lotus 2010-08-27
  • 打赏
  • 举报
回复
谢谢各位,应该是应用程序的错误!
jason_ye 2010-08-27
  • 打赏
  • 举报
回复
考虑使用以下两个函数
LPVOID pMarshalled;
HRESULT hr;

hr = CeOpenCallerBuffer((PVOID*) &pdatabuf, lpOutBuf, nOutBufSize, ARG_IO_PTR, FALSE);
hr = CeAllocAsynchronousBuffer((PVOID*) &pMarshalled, pdatabuf, nOutBufSize, ARG_IO_PTR);

然后操作pMarshalled指针就可以了。
下面引用MSDN帮助中的一段:
It is possible for a malicious application to pass an embedded pointer to a kernel address space and have a driver read or write to the buffer, potentially modifying the kernel. A driver must use the CeOpenCallerBuffer and CeCloseCallerBuffer functions to verify that the caller has access to the memory that is pointed to by embedded pointers.

Use CeAllocAsynchronousBuffer and SEH when an internal thread accesses an externally provided buffer. This function marshals the buffer of the caller into the virtual memory of the kernel. In Windows Embedded CE 6.0, you do not need to change the permission of the thread to access the externally provided buffer.

chinesedragon2010 2010-08-26
  • 打赏
  • 举报
回复
楼主可以简介一下你GPI_Read这个函数的功能吗
zhenxing2000 2010-08-26
  • 打赏
  • 举报
回复
帮忙顶,等待高手解决。我也这样的问题。
king1314lhxj 2010-08-26
  • 打赏
  • 举报
回复
我也遇到同样的问题。我仿照着提供的输出引脚的驱动,改的输入引脚的流驱动,但是还没有合适,一起学习一下。下面是我的代码。只贴出其中一个引脚,其他的类似。望大家指导一下。
DWORD GPI_Read(DWORD dwData, LPVOID pBuf, DWORD Len)
{
BYTE* pdatabuf;
BYTE gpioNum;
BYTE gpioState;
pdatabuf = (BYTE*)pBuf;
gpioState= *pdatabuf ;
gpioNum = *pdatabuf++;
RETAILMSG(1,(TEXT("*****GPILED: GPI_Read\r\n")));
if(gpioNum == 0 || gpioNum == 1 || gpioNum == 2|| gpioNum == 3)
{
*pdatabuf =(v_pIOPregs->GPFDAT & (1<<gpioNum))?1:0;
}

RETAILMSG(1,(TEXT("state: %d\r\n"),*pdatabuf));

//---read pins-----
//------------PB7------12-----read single ---in 0-----
if(gpioNum == 12)
{
v_pIOPregs->GPBCON &= ~(1<<(14));//00 input
v_pIOPregs->GPBCON &= ~(1<<(15));
v_pIOPregs->GPBUP &= ~(1<< 7);

if(v_pIOPregs->GPBDAT & ( 1 <<7))
gpioState = 1;
else
gpioState = 0;
}
return 1;
}

19,502

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧