程序能够编译通过,但是DO卡没有输出,基地址已经找到.谢谢!在线等.
我的ADLINK 的CPCI-7434R, 64路DO 卡.
/*************** standard system specific header files *****************/
#include <sys/stat.h>
#include <signal.h>
#include <sys/procmgr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/uio.h>
#include <dirent.h> //manipulate DIR
#include <time.h> //time structure
#include <sys/netmgr.h> //net manager routines
#include <sys/iofunc.h> //name_attach()
#include <sys/dispatch.h> //name_attach()
#include <sys/neutrino.h> //MsgReceive()…
#include <unistd.h> //delay(),
#include <inttypes.h> //clockcycles()…
#include <sys/syspage.h> //system info
#include <process.h> //fork()
#include <sys/mman.h> //memory manager
#include <fcntl.h> //flags definition
#include <sys/siginfo.h> //signal information
#include <sched.h> //scheduling operation
#include <hw/pci.h> //PCI functions
#include <hw/inout.h> //I/O operation
#include <pthread.h> //about threads
#include <stddef.h>
#include <ioctl.h> //for set udp unblock
#include <math.h>
#include <sys/socket.h> //socket communication
#include <arpa/inet.h> //htons(),etc.
#include <sys/socket.h> //socket communication
#include <sys/ioctl.h> //ioctl()…
#include <arpa/inet.h> //htons(),etc.
#include <netdb.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/types.h>
#include <limits.h>
#include <errno.h>
#include <mqueue.h>
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
typedef struct {
unsigned vendor_id;
unsigned device_id;
unsigned index;
unsigned offset;
}pciinfo;
dword iobase;
void pf_perror(char *strerr, char *filename, int line);
dword find_pci_dev(pciinfo pcidev );
int main(void)
{
int i;
pciinfo DO_7434;
DO_7434.vendor_id = 0x144a;
DO_7434.device_id = 0x7434 ;
DO_7434.index = 0 ;
DO_7434.offset = 0x18 ;
ThreadCtl(_NTO_TCTL_IO, 0);
iobase = find_pci_dev( DO_7434); // for control do
if( iobase == -1 )
{
pf_perror(“find_pci_dev”, FILE, LINE);
return;
}
printf("\n7434 iobase is:%x\t",iobase);
//for (i=0;i<8;i++)
out32(iobase + 0x00, 0x00); printf(“ok\n”);
out32(iobase + 0x01, 0xff); printf(“ok\n”);
out32(iobase + 0x02, 0xFF); printf(“ok\n”);
out32(iobase + 0x03, 0xFF); printf(“ok\n”);
out32(iobase + 0x04, 0xFF); printf(“ok\n”);
out32(iobase + 0x05, 0xFF); printf(“ok\n”);
out32(iobase + 0x06, 0xFF); printf(“ok\n”);
out32(iobase + 0x07, 0xFF); printf(“ok\n”);
}
/*****************************************************
*
- Function Name: find_pci_dev
- Description: To find the iobase of a specifical card.
- Input : pciinfo pcidev
- Return : dword iobase
-
-1-->Failure
- Global Var :
- ***************************************************/
dword find_pci_dev(pciinfo pcidev )
{
struct pci_dev_info info;
void *hdl;
unsigned int buf;
dword io_baseaddress = 0;
memset(&info, 0, sizeof(info));
//Connect to the PCI server
if (pci_attach(0) < 0)
{
perror(“pci_attach in lib file”);
return -1;
}
//attache a driver to a PCI device
info.VendorId = pcidev.vendor_id;
info.DeviceId = pcidev.device_id;
hdl = pci_attach_device (0, PCI_SHARE|PCI_INIT_ALL, pcidev.index, &info);
if (hdl == 0)
{
perror(“pci_attach_device in lib file”);
printf("%x\n",pcidev.device_id);
return -1;
}
if(pci_read_config(hdl,pcidev.offset,1,sizeof(buf),&buf) == PCI_SUCCESS)
io_baseaddress = PCI_IO_ADDR(buf);
else
{
perror(“read iobase register”);
printf("%x\n",pcidev.device_id);
return -1;
}
pci_detach_device(hdl);
return(io_baseaddress);
}
void pf_perror(char *strerr, char *filename, int line)
{
printf("\n\n%s <%s,%d>:\n",strerr, filename, line-2);
perror("");//print system err info
return;
}
1)不要调pci_detach_device(hdl);
2)8比特操作要用out8,而不是out32
我的卡是32位的,我试试,谢谢了.
修改以后,还是不行啊,高手指教一下.