/* driver-performance-test.c */ /* Created by Enomoto Sanshiro on 3 July 2002. */ /* Last updated by Enomoto Sanshiro on 3 July 2002. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "vmedrv.h" #define DEV_FILE_MEM "/dev/vmedrv32d32dma" #define ADDRESS_1 0x01000000 #define ADDRESS_2 0x02000000 #define SIZE 0x10000 #define DEV_FILE_INT "/dev/vmedrv16d16" #define IRQ 3 #define VECTOR 0xfff0 #define RPV130_ADDRESS 0x8000 #define RPV130_MAPSIZE 0x1000 #define TIMEOUT_SEC 10 #define RPV130_BASE_ADDRESS 0x8000 static char buffer[SIZE]; int main(int argc, char** argv) { int fdi, fdm; int result; struct vmedrv_interrupt_property_t interrupt_property; void* mapped_address; if ((fdm = open(DEV_FILE_MEM, O_RDWR)) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if ((fdi = open(DEV_FILE_INT, O_RDWR)) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if ((mapped_address = mmap(0, RPV130_MAPSIZE, PROT_WRITE, MAP_SHARED, fdi, RPV130_ADDRESS)) == MAP_FAILED) { fprintf(stderr, "ERROR: mmap(): %s\n", strerror(errno)); exit(EXIT_FAILURE); } /* clear */ *((short*) (mapped_address + (off_t) 0x000c)) |= 0x03; *((short*) (mapped_address + (off_t) 0x000e)) |= 0x03; /* enable interrupt */ *((short*) (mapped_address + (off_t) 0x000c)) |= 0x50; *((short*) (mapped_address + (off_t) 0x000e)) |= 0x50; interrupt_property.irq = IRQ; interrupt_property.vector = VECTOR; interrupt_property.signal_id = 0; if (ioctl(fdi, VMEDRV_IOC_REGISTER_INTERRUPT, &interrupt_property) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (ioctl(fdi, VMEDRV_IOC_ENABLE_INTERRUPT) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } interrupt_property.timeout = TIMEOUT_SEC; while (1) { result = ioctl(fdi, VMEDRV_IOC_WAIT_FOR_INTERRUPT, &interrupt_property); if (result > 0) { if (lseek(fdm, ADDRESS_1, SEEK_SET) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (read(fdm, buffer, SIZE) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (lseek(fdm, ADDRESS_2, SEEK_SET) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (read(fdm, buffer, SIZE) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } printf("interrupt handled.\n"); /* clear */ *((short*) (mapped_address + (off_t) 0x000c)) |= 0x03; *((short*) (mapped_address + (off_t) 0x000e)) |= 0x03; } else if (errno == ETIMEDOUT) { printf("timed out.\n"); } else if (errno == EINTR) { printf("interrupted.\n"); } else { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } } if (ioctl(fdi, VMEDRV_IOC_DISABLE_INTERRUPT) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (ioctl(fdi, VMEDRV_IOC_UNREGISTER_INTERRUPT, &interrupt_property) < 0) { fprintf(stderr, "ERROR: %s\n", strerror(errno)); exit(EXIT_FAILURE); } munmap(mapped_address, RPV130_MAPSIZE); close(fdi); close(fdm); return 0; }