|
小弟正在做一个vxWorks系统下的I/O卡驱动,因为是第一次接触驱动,所以我先写了一个测试程序来测试板卡能否被检测到并正常工作,程序的功能是这样的,首先获得I/O映射后的地址,因为该卡共两个寄存器,偏移地址分别为0和2,前者的不同输入值决定了I/O卡不同通道的开和关(由板卡上16个红色指示灯的亮灭来指示),现在的问题是,板卡能被检测到,向0地址输入值也有响应,但却非常奇怪。当我输入的值是0时,指示灯一个都不亮,当是一个奇数值是,会有几个灯不停的闪烁,而此时输入的值再换成一个偶数值,则闪烁停止,会有几个固定的灯在亮着。
我不知道是因为我没有配置或配置不对,还是我向寄存器写数据的方式不对造成的,请各位大虾不吝赐教,小弟感激不尽。
板卡情况是这样的,该板卡用来连接一个端子板,板卡上有16路A/D、D/A输入输出通道,通道的关闭和打开由板卡上16个指示灯来指示。
链接中是我的板卡的资料:
[url=http://mail.qq.com/cgi-bin/ftnExs_download?k=7166613388bd939ccfad4f3c1637564c045250555505515a1e075057071a505551524c520105514e52050750515251520600565030396433702f4c0206675555614831777637&t=exs_ftn_download&code=3fa307dc][/url]
以下是我的测试代码:
- #include
- #include
- #include
- #include
- #include
- #include "drvtest.h"
- int findDeviceTest()
- {
- int status = ERROR;
- short data = 0;
- short back = 0;
- UINT8 tmp = 0;
- UINT16 vendor = 0x0;
-
- int vendorId = 0x10b5;
- int deviceId = 0x1180;
-
- int busNo = -1;
- int devNo = -1;
- int funNo = -1;
-
- UINT32 membaseCsr = 0x0;
- UINT32 iobaseCsr = 0x0;
- UINT32 tmpd = 0x0;
-
- if ((ERROR) == pciFindDevice(vendorId, deviceId, 0, &busNo, &devNo, &funNo))
- {
- printf("Find device failed!\n");
- return 1;
- }
-
- #if 0
- if ((ERROR) == pciHeaderShow(busNo, devNo, funNo))
- {
- printf("Show device header failed!\n");
- return 1;
- }
- #endif
-
- /*pciConfigInWord(busNo, devNo, funNo, 0, &vendor);
- printf("Vendor Id: 0x%x\n", vendor);
- */
-
- /* 配置IO空间基地址 */
- /*pciConfigOutLong(busNo, devNo, funNo, PCI_CFG_BASE_ADDRESS_1, iobaseCsr | PCI_BASE_IO);*/
-
- /* 配置内存空间基地址 */
- /*pciConfigOutLong(busNo, devNo, funNo, PCI_CFG_BASE_ADDRESS_0, membaseCsr);*/
-
-
- /* 读取IO空间基地址 */
- pciConfigInLong(busNo, devNo, funNo, PCI_CFG_BASE_ADDRESS_1, &iobaseCsr);
-
- /* 读取内存空间基地址 */
- pciConfigInLong(busNo, devNo, funNo, PCI_CFG_BASE_ADDRESS_0, &membaseCsr);
-
- membaseCsr &= PCI_MEMBASE_MASK;
- iobaseCsr &= PCI_IOBASE_MASK;
-
- /* enable mapped memory and IO addresses */
- pciConfigOutWord(busNo, devNo, funNo, PCI_CFG_COMMAND, PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE | PCI_CMD_MASTER_ENABLE);
- /* disable sleep mode */
- pciConfigOutWord(busNo, devNo, funNo, PCI_CFG_MODE, SLEEP_MODE_DIS);
-
- printf("Mem Base: 0x%x\n", membaseCsr);
- printf("IO Base: 0x%x\n", iobaseCsr);
-
-
- /*
- * 读取
- */
- data = sysInWord(iobaseCsr + 2);
- printf("Read Data: 0x%x\n", data);
-
- printf("====================================\n");
-
-
- /* 向iobaseCsr地址写入不同的数据,测试指示灯的亮灭情况 */
- for (status = 0; status < 16; status++)
- {
- printf("Write Data: 0x%x\n", data);
- logMsg("Write Data: 0x%x\n", data, 0, 0, 0, 0, 0);
-
- tmp = (UINT8)(data & 0x00ff);
- sysOutByte(iobaseCsr, tmp);
- tmp = (UINT8)((data >> 8) & 0x00ff);
- sysOutByte(iobaseCsr + 1, tmp);
-
- tmp = sysInByte(iobaseCsr + 2);
-
- printf("IO_2: 0x%x\n", tmp);
- logMsg("IO_2: 0x%x\n", tmp, 0, 0, 0, 0, 0);
- tmp = sysInByte(iobaseCsr + 3);
-
- printf("IO_3: 0x%x\n\n\n", tmp);
- logMsg("IO_3: 0x%x\n\n\n", tmp, 0, 0, 0, 0, 0);
-
- data++;
-
-
- timeDelay(2, 0);
- }
-
-
- return 0;
- }
- void timeDelay(int sec, int nsec)
- {
- struct timespec tm; /* 声明一个时钟结构体,包括s和ns成员 */
-
- if (nsec >= 1000000000)
- {
- sec += nsec / 1000000000;
- nsec %= 1000000000;
- }
-
- tm.tv_sec = sec;
- tm.tv_nsec = nsec;
- nanosleep(&tm, NULL);
- }
复制代码
|
|