Specifications
Example PCI User-Level Device Drive
r
A-5
goto error_exit;
}
/* bind phys address of PCI dev to shm_id */
if (shmbind(bar1_shm_id, bar1.cpu_addr) == -1) {
rc = errno;
perror("PCIud - unable to bind PCI base address 1 ");
goto error_exit;
}
/* map the PCI memory space into process */
/* virtual memory */
dio_regs = (DIO96_t *) shmat(bar1_shm_id, 0, 0);
if ((int) dio_regs == -1) {
rc = errno;
dio_regs = NULL;
perror("PCIud - unable attach PCI base address 1 ");
goto error_exit;
}
fprintf(stdout,"Toggling Parallel Port APA0 output port\n");
/* start accessing PCI device */
/* macros from ioacc.h */
/* config 8255 port A for outputs */
BUS_PUTC(&(dio_regs->ppi_A.config_reg), 0x80);
for (x = 0; x<60; x++) {
/* set port A outputs low state (LED ON)*/
BUS_PUTC(&(dio_regs->ppi_A.port_A), 0xfe);
sleep(2);/* sleep 1 to 2 seconds */
/* set port A outputs to high state (LED OFF)*/
BUS_PUTC(&(dio_regs->ppi_A.port_A), 0xff);
sleep(2);/* sleep 1 to 2 seconds */
}
BUS_PUTC(&(dio_regs->ppi_A.port_A), 0xff); /* LED off */
error_exit:
pci_cfg_cmd(tag, PCI_CMD_MEM, PCI_DISABLE); /* disable PCI device */
/* release resources for BAR 1 */
if (dio_regs != NULL) {/* check if BAR virt addr set */
shmdt((const void *) dio_regs);/* free virt map for BAR1 */
dio_regs = NULL;
}
if (bar1_shm_id != NULL) {/* check if shmid valid */
shmctl(bar1_shm_id, IPC_RMID, NULL);/* yes, free it */
bar1_shm_id = NULL;
}
/* release resources for BAR 0 */
if (PCImite != NULL) {/* check if BAR virt addr set */
shmdt((const void *) PCImite);/* free virt map for BAR1 */
PCImite = NULL;