请教大家:cpci设备驱动从linux向qnx移植的问题

中文QNX 讨论: 欢迎大家灌水,讨论有关QNX 问题。

请教大家:cpci设备驱动从linux向qnx移植的问题

帖子siceaner » 周日 12月 11, 2011 6:08 pm

大家好:
我是一个qnx驱动开发的新手。原来做过一些linux的驱动开发。
现在,我有一个cpci的板卡的linux驱动,要把它移植到qnx系统上运行。
原来,使用Linux驱动,在linux系统下,板卡运行正常,中断也都很正常。
但是移植到qnx后,板卡就不工作了,中断状态寄存器也不置位。但是读控制寄存器,读出的值却是正确的。
请教各位看看是什么原因。
代码如下:

typedef struct
{
...
volatile u32 vIObase;
...

} DEVHANDLE;

DEVHANDLE devHdl[MAX_SLOT];

#define outreg(reg, val) *(volatile u16 *)(devHdl[idx].vIObase+(reg)) = (val)
#define inreg(reg, val) (val) = *(volatile u16 *)(devHdl[idx].vIObase+(reg))

int men_pp04_probe(int BoardNo, u16 vId, u16 dId)
{
int hdl, err, i;
u32 busnum, devfuncnum;
unsigned long membase;
int idx = BoardNo - 1;
struct pci_dev_info info;
void *ahdl;

printf("\nBoard %d: Function MenPP04_Probe()\n", idx+1);

if ( ThreadCtl (_NTO_TCTL_IO, 0) == -1)
{
printf("Error: Fail to request I/O in ThreadCtl for MVB card %d\n", idx);
return EXIT_FAILURE;
}

hdl = pci_attach( 0 );
if( hdl == -1 )
{
printf("Error: Fail to connect to PCI server for MVB card %d\n", idx);
return EXIT_FAILURE;
}

err = pci_find_device(dId, vId, idx, &busnum, &devfuncnum);
if(err != PCI_SUCCESS)
{
printf("Error: Fail to find pci device MVB card %d\n", idx);
pci_detach(hdl);
return EXIT_FAILURE;
}

info.VendorId = vId;
info.DeviceId = dId;

if ((ahdl = pci_attach_device(0,
PCI_SHARE|PCI_INIT_ALL,
0, &info)) == 0)
{
perror("pci_attach_device");
exit(EXIT_FAILURE);
}
else
{
pci_detach_device(ahdl);
}

err = pci_read_config32(busnum,devfuncnum,
offsetof(struct _pci_config_regs,
Interrupt_Line),
6, (u8 *)&devHdl[idx].cfgInfo.Interrupt_Line);
if(err != PCI_SUCCESS)
{

printf("Error: Fail to read pci config space for MVB card %d \n", idx);

pci_detach_device(ahdl);
pci_detach(hdl);
return EXIT_FAILURE;
}
devHdl[idx].irq = devHdl[idx].cfgInfo.Interrupt_Line;

err = pci_read_config32(busnum,devfuncnum,
offsetof(struct _pci_config_regs,
Base_Address_Regs[0]),
6, (u8 *)&devHdl[idx].cfgInfo.Base_Address_Regs[0]);
if(err != PCI_SUCCESS)
{

printf("Error: Fail to read pci config space for MVB card %d \n", idx);

pci_detach_device(ahdl);
pci_detach(hdl);
return EXIT_FAILURE;
}

for(i=0; i<6; i++) {
printf("Board %d: cfgInfo.Base_Address_Regs[%d] = %x.\n",
idx+1, i, devHdl[idx].cfgInfo.Base_Address_Regs[i]);
}

membase = (u32)mmap_device_memory(NULL, MVB_TM_LEN,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS,
PCI_MEM_ADDR(devHdl[idx].cfgInfo.Base_Address_Regs[1]));
if((u8 *)membase == MAP_FAILED)
{
printf("Error: Fial to map device memory for MVB card %d \n", idx);
return EXIT_FAILURE;
}
devHdl[idx].vIObase = membase;

devHdl[idx].id = 0;
devHdl[idx].id = InterruptAttach(_NTO_INTR_CLASS_EXTERNAL | devHdl[idx].irq,
men_pp04_interrupt,
&(devHdl[idx]),
sizeof(struct men_pp04_devhandle),
_NTO_INTR_FLAGS_END | _NTO_INTR_FLAGS_TRK_MSK);

memset(&(devHdl[idx].spinlock), 0, sizeof(intrspin_t));

printf("Exit MenPP04_Probe()\n");

return 0;

} /* end men_pp04_probe() */


const struct sigevent *men_pp04_interrupt(void *arg, int id)
{
struct sigevent event;
volatile u16 isr0 = 0;
volatile u16 isr1 = 0;

idx = ((struct men_pp04_devhandle *)dev_id)->bidx;

InterruptLock(&(devHdl[idx].spinlock));

inreg(MVB_SA_OFFS_F000 + MVB_REG_ISR0, isr0);
inreg(MVB_SA_OFFS_F000 + MVB_REG_ISR1, isr1);

if (!(isr0 || isr1)){
InterruptUnlock(&(devHdl[idx].spinlock));

return NULL;
}

if ( isr1 ){
counter++;
}

if(isr0) {
counter++;
}

return &event;
}
siceaner
New Member
 
帖子: 3
注册: 周日 12月 11, 2011 4:40 pm

回到 四海同心QNX论坛

在线用户

正在浏览此版面的用户:没有注册用户 和 4 位游客

cron