Well, you didn’t say it was QNX4 and since you didn’t post in the QNX4 forum, it’s only natural for cdm to assume you are using QNX 6
Below is a sample code somebody posted in the past. It communicates with a PCI memory card. Some PCI* functions as declared in /usr/include/pci.h are used. Basically you open the shared memory object “Physical” and mmap int your registers.
As usual, you need root privillage for hardware access, and the program has to be linked with -T1 flag for sufficient privity.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/pci.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "card.h"
/************************/
/* Global Variables */
/************************/
unsigned busnum, device, lastbus, version, hardware, index=0;
int fd, i, j, flags=MAP_SHARED;
int prots=PROT_READ | PROT_WRITE | PROT_NOCACHE;
volatile uint32_t *scr_mem_ptr1, *scr_mem_ptr;
volatile uint16_t *scr_reg_ptr;
uint32_t csr_base;
struct _pci_config_regs scr_reg;
unsigned DEVICE_ID=0x4750;
unsigned VENDOR_ID=0x11B0;
start_pci(void)
{
if(_CA_PCI_BIOS_Present (&lastbus, &version, &hardware) !=PCI_SUCCESS)
{
printf("Error no PCI Bios found!!!\n");
exit (0);
}
if (_CA_PCI_Find_Device(DEVICE_ID,VENDOR_ID,index,&busnum,
&device)!=PCI_SUCCESS){
printf ("PCI card not found!!\n");
exit (0);
}
if (_CA_PCI_Read_Config_DWord(busnum,device,0,64,(char*)&scr_reg)
!=PCI_SUCCESS){
printf("Could not read from PCI configuration space\n");
exit(0);
}
fd=shm_open("Physical", O_RDWR, 0777);
if (fd==-1){
printf ("Physical file descriptor invalid\n");
exit(-101);
}
/*else{
printf ("File Descriptor open successful\n");
}*/
scr_reg.Base_Address_Regs[1]=scr_reg.Base_Address_Regs[1]&0xFFFFFF00;
scr_reg.Base_Address_Regs[2]=scr_reg.Base_Address_Regs[2]&0xFFFFFF00;
scr_mem_ptr1=mmap(0,0x400000,prots,flags,fd,scr_reg.Base_Address_Regs[1]);
scr_mem_ptr=mmap(0,0x400000,prots,flags,fd,scr_reg.Base_Address_Regs[2]);
csr_base=(scr_reg.Base_Address_Regs[1]+0x800000);
scr_reg_ptr=mmap(0,0x1000,prots,flags,fd,csr_base);
if ((scr_mem_ptr||scr_reg_ptr)==-1){
printf ("Could not map apertures for PCI\n");
fprintf (stderr, "Mmap failed: %s \n", strerror(errno));
shm_unlink("Physical");
exit(-201);
}
else{
printf ("PCI scr_mem_pointer is at 0x%x and scr_reg_ptr 0x%x\n",
scr_mem_ptr,scr_reg_ptr);
}
return(SUCCESS);
}
stop_pci(void)
{
shm_unlink("Physical");
munmap((void*)scr_mem_ptr1,0x400000);
munmap((void*)scr_mem_ptr,0x400000);
munmap((void*)scr_reg_ptr,0x1000);
return (SUCCESS);
}