#include #include #include #include #include #include #include #include #include #include "u2f/u2f.h" u_int atoh( char *str ) { u_int val = 0; /* Resulting Value */ u_int valid = 0; while ( *str == ' ' && *str != '\n' && *str != 0){ // printf("*%c\n",*str); str++; } while ( (*str >= '0' && *str <= '9') || (*str >= 'a' && *str <= 'f') || (*str >= 'A' && *str <= 'F') ) { //printf("#%c\n",*str); valid = 1; if ( *str >= 'a' && *str <= 'z' ) val = (val * 16) + (*str & 0xff) - 0x57; if ( *str >= 'A' && *str <= 'Z' ) val = (val * 16) + (*str & 0xff) - 0x37; if ( *str >= '0' && *str <= '9' ) val = (val * 16) + (*str & 0xff) - 0x30; str++; } if ( valid && (*str == 0 || *str == '\n' )) return ( (int) val ); /* Good Value */ else { perror( "atoh: Conversion Error" ); return ( -1 ); /* Bad Value */ } } static int init(char *fname, char *maskfile){ u_int ret, rcode = 0, rdata = 0, fdata[200048] = {0}, fsize = 5, ccode = 0, cdata = 0; u_int offset = 0, rsize = 10, memdata[200048] = {0}; u_int loop; FILE *fp; int ndim=400; char line[ndim]; /* Open U2F_LIB */ ret = U2F_Open(HW, DEFAULT_NODE); if (ret) rcc_error_print(stdout, ret); /* Open the rcc_time_stamp library */ ret = ts_open(1, TS_DUMMY); if (ret) rcc_error_print(stdout, ret); /* DISABLE HW TRIGGER */ /* Switch on FEC with Address = 0 */ rcode = O_ACTFEC; rdata = 0x1; ret = U2F_Reg_Write(rcode, rdata); if (ret) rcc_error_print(stdout, ret); /* delay 1000000 us */ ts_delay(1000000); /* Reset FEC */ ccode = C_FECRST; cdata = 0; ret = U2F_Exec_Command(ccode, cdata); ccode = C_FECRST; cdata = 0; ret = U2F_Exec_Command(ccode, cdata); if (ret) rcc_error_print(stdout, ret); /* delay 100 us */ ts_delay(100); /* Load the Instruction Memory data */ printf("Reading instructions from file %s\n", fname); ret = U2F_File_Read(fname, fsize, fdata); if (ret) rcc_error_print(stdout, ret); /* write into the Instruction Memory */ rsize = fsize; offset = 0; printf("Initializing instruction memory\n"); for(loop=0; loop \n",argv[0]); exit(0); } if (argc>1) strcpy(fname,argv[1]); if (argc>2) mdsize = atoi(argv[2])*1000000; if (argc>3) swtrig = atoi(argv[3]); if (argc>4) strcpy(finit,argv[4]); if (argc>5) strcpy(fmask,argv[5]); fprintf(stderr, "Memory Size =0x%x bytes\n",mdsize); fprintf(stderr, "SW Trigger =%d\n",swtrig); fprintf(stderr, "Data Filename=%s\n",fname); fprintf(stderr, "Mask Filename=%s\n",fmask); fprintf(stderr, "Ginit2 Filename=%s\n",finit); init(finit,fmask); rodata = (u_short *)malloc(mdsize); if (rodata == 0) { printf("Error from malloc()\n"); return(-1); } fprintf(stderr, "Starting ...\n"); ts_clock(&ts1); if (swtrig) ret = U2F_ReadOut(mdsize, &osize, (u_char *)rodata, M_FIRST | M_LAST | M_TRIGGER); else ret = U2F_ReadOut(mdsize, &osize, (u_char *)rodata, M_FIRST | M_LAST); if (ret) { rcc_error_print(stdout, ret); return(-1); } ts_clock(&ts2); delta_t = ts_duration(ts1, ts2); printf("%d bytes received in %f seconds\n", osize, delta_t); printf("Dumping data to file %s\n",fname); file = fopen(fname, "w"); if (file == 0) { printf("Can't open output file\n"); return(-1); } fwrite (rodata,osize,1,file); fclose(file); free((void *)rodata); return 0; }