#include #include #include #include #include #include #include #include #include "ppci.h" void dump_reg(struct ppci *ppci, int minor ) { printf("Output data = %x\n", ppci->data); printf("LED = %x\n", ppci->led); printf("Switch Register = %x\n", ppci->sw); printf("Transfer Address = %x\n", ppci->address); printf("Transfer Count = %x\n", ppci->length); printf("Mode = %x\n", ppci->mode); printf("Status = %x\n", ppci->status); printf("RetLength = %x\n", ppci->retlen); } int e_time(struct timeval *first, struct timeval *second) { if (first->tv_usec > second->tv_usec) { second->tv_usec += 1000000; second->tv_sec--; } return( (int)(second->tv_sec - first->tv_sec)*1000000 + (int)(second->tv_usec - first->tv_usec)); } main(int argc, char **argv) { int fd; unsigned int i = 0; int minor, direction; struct ppci ppci; int length, retlen; int *w_buffer; int count; int default_etime; struct timeval start, stop; struct timezone tzpstart, tzpstop; if( argc != 3 ) { printf("usage : write minor_number count\n"); exit(0); } minor = atoi(argv[1]); count = atoi(argv[2]); if( minor == 0 ) fd = open("/dev/ppci0", O_RDWR); else if( minor == 1 ) fd = open("/dev/ppci1", O_RDWR); else { printf("Illegal minor number! 0 or 1\n"); exit(0); } w_buffer = (int *)malloc(count*sizeof(int)); for(i = 0; i< count; i++) { if((i%2) == 0 ) w_buffer[i] = 0xaaaaaaaa; if((i%2) == 1 ) w_buffer[i] = 0x55555555; } direction = 1; if( ioctl(fd, PPCIIOC_RESET, direction) == -1 ) { printf("ioctl PPCIIOC_RESET error...\n"); exit(0); } if( ioctl(fd, PPCIIOC_DUMP_REGISTERS, &ppci) == -1 ) { printf("ioctl PPCIIOC_GET_CONTROL error...\n"); exit(0); } dump_reg(&ppci, minor); /* sleep(10); exit(0); */ length = count*sizeof(int); while(1) { // gettimeofday (&start, &tzpstart); if( write(fd, w_buffer, length) < 0) { printf("write error occurred...\n"); free(w_buffer); close(fd); exit(0); } // gettimeofday (&stop, &tzpstop); } /* printf("elapsed time = %d in microsec.\n", e_time( &start, &stop)/10000); if( ioctl(fd, PPCIIOC_DUMP_REGISTERS, &ppci) == -1 ) { printf("ioctl PPCIIOC_GET_CONTROL error...\n"); exit(0); } dump_reg(&ppci, minor); */ }