#include main(int argc, char** argv) { FILE *f; char line[120], *filename, *p, *pp; int b[12],tbl,tbl_max = -1,init_ptr,initp_ptr; int rom,total,row,column,i,j,tmp,tbl_array[256][72]; char init_value[65],initp_value[65],output[4]; if(argc == 2) filename = argv[1]; else filename = "romRPC.txt"; // open input file with conversion tables f = fopen(filename,"r"); if (!f) { printf("oslb_rom: Cannot open file %s\n",filename); exit(1); } for(i = 0; i < 256; i++) for(j = 0; j < 60; j++) //0x3f is always '0' tbl_array[i][j] = 0x3f; while ( fgets(line, 120, f) != NULL) { int length,gol,tp; if(length = strlen(line)){ //convert to lower case for(i = 0; i < length; i++) if(line[i] > 64 && line[i] < 91) line[i] += 32; } if((p = strstr(line,"table")) != NULL){ if((tbl = strtol(p+5,&pp,10)) > 0x3f){ printf(" table number should not be greater than 127\n"); exit(1); } if(tbl > tbl_max) tbl_max = tbl; } if((p = strstr(line,"gol")) != NULL){ if((gol = strtol(p+3,&pp,10)) > 2){ printf(" GOL number should not be greater than 2\n"); exit(1); } if((i = strtol(p+6,&pp,10)) > 23){ printf(" GOL data bit number should not be greater than 23\n"); exit(1); } i += gol*24; if((p = strstr(line,"tp_a")) != NULL){ if((j = strtol(p+4,&pp,10)) > 23){ printf(" TP pin number should not be greater than 23\n"); exit(1); } tbl_array[tbl][i] = j; } if((p = strstr(line,"tp_b")) != NULL){ if((j = strtol(p+4,&pp,10)) > 23){ printf(" TP pin number should not be greater than 23\n"); exit(1); } tbl_array[tbl][i] = j+24; } } } fclose(f); //now tbl_array contains the mapping of TP_x to GOLx_data for all specified tables printf("tbl_max = %d\n",tbl_max); //initialize test vectors /* for(i = 252; i < 256; i++) for(j = 0; j < 60 ; j++){ if(j < 56 && (j%19) != 18){ if(i == 252) tbl_array[i][j] = j%19; if(i == 253 && (j%19) < 6) tbl_array[i][j] = j%19 + 18; tbl_array[i][j] = j%19+24; if(i == 255 && (j%19) < 6) tbl_array[i][j] = j%19 + 42; } } */ f = fopen("oslb_initRPC.txt","w"); //must do it a ROM at a time for(rom = 0; rom < 6;rom++){ //create init values init_value[64] = '\0'; initp_value[64] = '\0'; init_ptr = 0; initp_ptr = 0; //scan through all tables for(tbl = 0; tbl <= tbl_max;tbl++){ //i equivalent to the lowest ROM address bit for (i = 0; i < 2; i++){ //each GOLx_data bit takes 6 bits to select, so each ROM location(36 bits) can select 6 GOL_x_data bits total = tbl_array[tbl][rom*12+i*6] + (tbl_array[tbl][rom*12+i*6+1] << 6); for(j = 2; j < 6;j++){ total += tbl_array[tbl][rom*12+i*6+j] << (16 - 2*j); sprintf(output,"%02X",total%256); init_value[63-init_ptr++] = output[1]; init_value[63-init_ptr++] = output[0]; total >>= 8; } sprintf(output,"%02X",total); initp_value[63-initp_ptr++] = output[1]; } if(init_ptr == 64){ fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INIT_%02x = %s;\n",rom,tbl/4,init_value); init_ptr = 0; } if(initp_ptr == 64){ fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INITP_%02x = %s;\n",rom,tbl/32,initp_value); initp_ptr = 0; } } if(init_ptr != 0){ for(i = init_ptr; i < 64; i++) init_value[63-i] = 70; fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INIT_%02x = %s;\n",rom,tbl_max/4,init_value); } if(initp_ptr != 0){ for(i = initp_ptr; i < 64; i++) initp_value[63-i] = 70; fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INITP_%02x = %s;\n",rom,tbl_max/32,initp_value); } //print test vector table /* initp_value[64] = '\0'; init_ptr = 0; initp_ptr = 56; for(i = 8; i < 64;i++) initp_value[i] = '0'; init_value[64] = '\0'; for (tbl = 252; tbl < 256; tbl++){ //i equivalent to the lowest ROM address bit for (i = 0; i < 2; i++){ //each GOLx_data bit takes 6 bits to select, so each ROM location(36 bits) can select 6 GOL_x_data bits total = tbl_array[tbl][rom*12+i*6] + (tbl_array[tbl][rom*12+i*6+1] << 6); for(j = 2; j < 6;j++){ total += tbl_array[tbl][rom*12+i*6+j] << (16 - 2*j); sprintf(output,"%02X",total%256); init_value[63-init_ptr++] = output[1]; init_value[63-init_ptr++] = output[0]; total >>= 8; } sprintf(output,"%02X",total); initp_value[63-initp_ptr++] = output[1]; } if(init_ptr == 64){ fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INIT_%02x = %s;\n",rom,tbl/4,init_value); init_ptr = 0; } if(initp_ptr == 64){ fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INITP_%02x = %s;\n",rom,tbl/32,initp_value); initp_ptr = 0; } } if(init_ptr != 0) fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INIT_%02x = %s;\n",rom,tbl_max/4,&init_value[64-init_ptr]); if(initp_ptr != 0) fprintf(f,"INST \"i_g_rom[%01d].i_rom\" INITP_%02x = %s;\n",rom,tbl_max/32,&initp_value[64-initp_ptr]); */ } //following is used in vhdl instantiation instead of ucf files for(rom = 0; rom < 6;rom++){ //create init values init_value[64] = '\0'; initp_value[64] = '\0'; init_ptr = 0; initp_ptr = 0; //scan through all tables fprintf(f,"generic map(\n"); for(tbl = 0; tbl <= tbl_max;tbl++){ //i equivalent to the lowest ROM address bit for (i = 0; i < 2; i++){ //each GOLx_data bit takes 6 bits to select, so each ROM location(36 bits) can select 6 GOL_x_data bits total = tbl_array[tbl][rom*12+i*6] + (tbl_array[tbl][rom*12+i*6+1] << 6); for(j = 2; j < 6;j++){ total += tbl_array[tbl][rom*12+i*6+j] << (16 - 2*j); sprintf(output,"%02X",total%256); init_value[63-init_ptr++] = output[1]; init_value[63-init_ptr++] = output[0]; total >>= 8; } sprintf(output,"%02X",total); initp_value[63-initp_ptr++] = output[1]; } if(init_ptr == 64){ fprintf(f,"INIT_%02x => X\"%s\",\n",tbl/4,init_value); init_ptr = 0; } if(initp_ptr == 64){ fprintf(f,"INITP_%02x => X\"%s\",\n",tbl/32,initp_value); initp_ptr = 0; } } if(init_ptr != 0){ for(i = init_ptr; i < 64; i++) init_value[63-i] = 70; fprintf(f,"INIT_%02x => X\"%s\",\n",tbl_max/4,init_value); } if(initp_ptr != 0){ for(i = initp_ptr; i < 64; i++) initp_value[63-i] = 70; fprintf(f,"INITP_%02x => X\"%s\"\n",tbl_max/32,initp_value); } fprintf(f,")\n"); } fclose(f); }