Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 309 | f9daq | 1 | #include <ansi_c.h> |
| 2 | #include <utility.h> |
||
| 3 | #include <cvirte.h> |
||
| 4 | #include <userint.h> |
||
| 5 | #include "mergerjtag.h" |
||
| 6 | |||
| 7 | static int panelHandle; |
||
| 8 | |||
| 9 | void bin2hex (const char * str, char *target) |
||
| 10 | { |
||
| 11 | char target0[0xFF],target1[0xFF]; |
||
| 12 | int i; |
||
| 13 | int end= strlen(str); |
||
| 14 | target0[0]=0; |
||
| 15 | if (end>32) strncpy (target0, &str[end-32-1] , 32); |
||
| 16 | target0[32]=0; |
||
| 17 | |||
| 18 | end-=32; |
||
| 19 | |||
| 20 | if (end>0) { |
||
| 21 | strncpy (target1, &str[0] , end); |
||
| 22 | target1[end-1] = 0; |
||
| 23 | } |
||
| 24 | // printf("==>%s %s\n==>%s\n", target1, target0, str); |
||
| 25 | sprintf(target,"0x%08X%08X",strtoul (target1, NULL, 2) ,strtoul (target0, NULL, 2) ); |
||
| 26 | } |
||
| 27 | |||
| 28 | char impact_output[255]= "impact_merger.txt"; |
||
| 29 | |||
| 30 | int jtagexecute(const char *impactcmd, int wait){ |
||
| 31 | char cmd[255]; |
||
| 32 | int jtagchainid = 1; |
||
| 33 | FILE *fp =fopen("impact.cmd","w"); |
||
| 34 | fprintf(fp,"setmode -bscan\n"); |
||
| 35 | fprintf(fp,"setcable -port usb21 -baud 3000000\n"); |
||
| 36 | fprintf(fp,"identify\n"); |
||
| 37 | fprintf(fp,"%s\n", impactcmd ); |
||
| 38 | fprintf(fp,"exit\n"); |
||
| 39 | fclose(fp); |
||
| 40 | sprintf(cmd,"impact.bat impact.cmd %s ", impact_output); |
||
| 41 | printf("%s\n",cmd); |
||
| 42 | if (wait) return system(cmd); |
||
| 43 | else return LaunchExecutableEx (cmd, LE_SHOWNORMAL, NULL); |
||
| 44 | } |
||
| 45 | |||
| 46 | int loadbit( int wait){ |
||
| 47 | |||
| 48 | const char impactcmd[255]="impact.cmd"; |
||
| 49 | char cmd[255]; |
||
| 50 | int jtagchainid = 1; |
||
| 51 | char bitfile[255]="arich_merger_rev01.bit"; |
||
| 52 | //GetCtrlVal(pnl, PANEL_BITFILE,bitfile); |
||
| 53 | char foutput[255]="impacttest_feb"; |
||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | FILE *fp =fopen(impactcmd,"w"); |
||
| 58 | |||
| 59 | fprintf(fp, |
||
| 60 | "setmode -bscan\n" |
||
| 61 | "setcable -port usb21 -baud 3000000\n" |
||
| 62 | "identify\n"); |
||
| 63 | |||
| 64 | //fprintf(fp, "readdna -p %d\n", jtagchainid ); |
||
| 65 | fprintf(fp, "assignfile -p %d -file %s\n",jtagchainid, bitfile ); |
||
| 66 | fprintf(fp, "program -p %d -prog\n" ,jtagchainid ); |
||
| 67 | // fprintf(fp, "verify -p %d\n",jtagchainid ); |
||
| 68 | |||
| 69 | fprintf(fp,"exit\n"); |
||
| 70 | fclose(fp); |
||
| 71 | |||
| 72 | sprintf(cmd,"impact.bat %s %s ", impactcmd,impact_output); |
||
| 73 | printf("%s\n",cmd); |
||
| 74 | if (wait) system(cmd); |
||
| 75 | else LaunchExecutableEx (cmd, LE_SHOWNORMAL, NULL); |
||
| 76 | |||
| 77 | return 0; |
||
| 78 | |||
| 79 | } |
||
| 80 | |||
| 81 | int ImpactOutputInspect( const char *fname, const char *opt){ |
||
| 82 | FILE *fout; |
||
| 83 | |||
| 84 | const int ndim=400; |
||
| 85 | char buff[ndim]; |
||
| 86 | char fpgasn[0xFF], hexsn[0XFF]; |
||
| 87 | char impactout[255]; |
||
| 88 | char *ret; |
||
| 89 | char *ret0; |
||
| 90 | char *ret1; |
||
| 91 | char *ret2; |
||
| 92 | int downloadok=0; |
||
| 93 | int xc6slx45=0; |
||
| 94 | FILE *fp = NULL; |
||
| 95 | if (fname!=NULL) fp = fopen (fname, opt); |
||
| 96 | fout = fopen (impact_output, "r"); |
||
| 97 | while (fgets(buff,ndim,fout)!=NULL) { |
||
| 98 | // printf("%s",buff); |
||
| 99 | ret=strstr(buff, "INFO:iMPACT:188 - '1': Programming completed successfully."); |
||
| 100 | if (ret !=NULL){ |
||
| 101 | printf("Download OK!\n"); |
||
| 102 | //SetCtrlVal(pnl,firmware_control[febboard], 1); |
||
| 103 | downloadok=1; |
||
| 104 | } |
||
| 105 | ret=strstr(buff, "INFO:iMPACT:501 - '1': Added Device xc5vlx50t successfully."); |
||
| 106 | if (ret !=NULL){ |
||
| 107 | printf("Device xc5vlx50t found!\n"); |
||
| 108 | //SetCtrlVal(pnl,fpga_control[febboard], 1); |
||
| 109 | xc6slx45=1; |
||
| 110 | } |
||
| 111 | |||
| 112 | ret=strstr(buff, "Temperature"); |
||
| 113 | for (int k=0;k<2;k++){ |
||
| 114 | if (ret !=NULL){ |
||
| 115 | |||
| 116 | char t0[0xFF]=""; |
||
| 117 | printf("#%s#\n",ret); |
||
| 118 | for (int i=0;i<3;i++){ |
||
| 119 | ret=strstr(ret, "Reading:"); |
||
| 120 | if (ret!=NULL) { |
||
| 121 | ret=(ret+8); |
||
| 122 | sscanf(ret,"%s", t0); |
||
| 123 | printf("t=%ul sens=%d T=%s\n",time(NULL), i+k*2, t0); |
||
| 124 | if (fp){ |
||
| 125 | fprintf(fp, "%ul %d %s\n",time(NULL), i+k*2, t0); |
||
| 126 | } |
||
| 127 | } else break; |
||
| 128 | } |
||
| 129 | |||
| 130 | if (k==0) { |
||
| 131 | fgets(buff,ndim,fout); |
||
| 132 | ret=strstr(buff, "Reading:"); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | |||
| 138 | ret=strstr(buff, "'1': DNA ="); |
||
| 139 | if (ret !=NULL){ |
||
| 140 | sscanf(ret,"'1': DNA = '%s", fpgasn); |
||
| 141 | |||
| 142 | bin2hex(fpgasn,hexsn); |
||
| 143 | printf("%s",hexsn); |
||
| 144 | //SetCtrlVal(pnl,target_control[febboard], hexsn); |
||
| 145 | } else { |
||
| 146 | sprintf(hexsn,""); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | if (fp) fclose (fp); |
||
| 150 | fclose(fout); |
||
| 151 | |||
| 152 | return 0; |
||
| 153 | } |
||
| 154 | |||
| 155 | |||
| 156 | FILE *fmon=NULL; |
||
| 157 | int main (int argc, char *argv[]) { |
||
| 158 | if (InitCVIRTE (0, argv, 0) == 0) |
||
| 159 | return -1; /* out of memory */ |
||
| 160 | if ((panelHandle = LoadPanel (0, "mergerjtag.uir", PANEL)) < 0) |
||
| 161 | return -1; |
||
| 162 | double tinterval; |
||
| 163 | GetCtrlVal(panelHandle, PANEL_TINTERVAL, &tinterval); |
||
| 164 | SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_INTERVAL, tinterval); |
||
| 165 | TimerOnOffCB(panelHandle, PANEL_TIMERON, EVENT_COMMIT,NULL,0,0); |
||
| 166 | |||
| 167 | DisplayPanel (panelHandle); |
||
| 168 | RunUserInterface (); |
||
| 169 | DiscardPanel (panelHandle); |
||
| 170 | if (fmon) fclose(fmon); |
||
| 171 | return 0; |
||
| 172 | } |
||
| 173 | |||
| 174 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
| 175 | void *callbackData, int eventData1, int eventData2) { |
||
| 176 | switch (event) { |
||
| 177 | case EVENT_COMMIT: |
||
| 178 | QuitUserInterface (0); |
||
| 179 | break; |
||
| 180 | } |
||
| 181 | return 0; |
||
| 182 | } |
||
| 183 | |||
| 184 | int CVICALLBACK ReadCB (int panel, int control, int event, |
||
| 185 | void *callbackData, int eventData1, int eventData2) { |
||
| 186 | switch (event) { |
||
| 187 | case EVENT_COMMIT: |
||
| 188 | jtagexecute("readTemperatureAndVoltage -p 1\n", 1); |
||
| 189 | ImpactOutputInspect("read_out.txt","w"); |
||
| 190 | break; |
||
| 191 | } |
||
| 192 | return 0; |
||
| 193 | } |
||
| 194 | |||
| 195 | int CVICALLBACK LoadCB (int panel, int control, int event, |
||
| 196 | void *callbackData, int eventData1, int eventData2) { |
||
| 197 | switch (event) { |
||
| 198 | case EVENT_COMMIT: |
||
| 199 | loadbit(1); |
||
| 200 | ImpactOutputInspect("loadbit_out.txt","w"); |
||
| 201 | break; |
||
| 202 | } |
||
| 203 | return 0; |
||
| 204 | } |
||
| 205 | |||
| 206 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
||
| 207 | void *callbackData, int eventData1, int eventData2) |
||
| 208 | { |
||
| 209 | int state; |
||
| 210 | switch (event) |
||
| 211 | { |
||
| 212 | case EVENT_COMMIT: |
||
| 213 | GetCtrlVal(panel, control, &state); |
||
| 214 | if (state){ |
||
| 215 | printf ("Enabling timer....\n"); |
||
| 216 | ResumeTimerCallbacks(); |
||
| 217 | } else { |
||
| 218 | SuspendTimerCallbacks (); |
||
| 219 | printf ("Disabling timer....\n"); |
||
| 220 | } |
||
| 221 | break; |
||
| 222 | } |
||
| 223 | return 0; |
||
| 224 | } |
||
| 225 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
||
| 226 | void *callbackData, int eventData1, int eventData2) { |
||
| 227 | double tinterval; |
||
| 228 | switch (event) { |
||
| 229 | case EVENT_COMMIT: |
||
| 230 | GetCtrlVal(panel, control, &tinterval); |
||
| 231 | SetCtrlAttribute (panel, PANEL_TIMER, ATTR_INTERVAL, tinterval); |
||
| 232 | break; |
||
| 233 | } |
||
| 234 | return 0; |
||
| 235 | } |
||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | int CVICALLBACK TimerCB (int panel, int control, int event, |
||
| 240 | void *callbackData, int eventData1, int eventData2) { |
||
| 241 | switch (event) { |
||
| 242 | case EVENT_TIMER_TICK: |
||
| 243 | jtagexecute("readTemperatureAndVoltage -p 1\n", 1); |
||
| 244 | ImpactOutputInspect("merger_temperature.txt","a"); |
||
| 245 | break; |
||
| 246 | } |
||
| 247 | return 0; |
||
| 248 | } |
||
| 249 | |||
| 250 | int CVICALLBACK DrawCB (int panel, int control, int event, |
||
| 251 | void *callbackData, int eventData1, int eventData2) { |
||
| 252 | switch (event) { |
||
| 253 | case EVENT_COMMIT:{ |
||
| 254 | |||
| 255 | char name[MAX_PATHNAME_LEN]; |
||
| 256 | // char dfile[MAX_PATHNAME_LEN]; |
||
| 257 | // char efile[MAX_PATHNAME_LEN]; |
||
| 258 | // status = FileSelectPopup ("dat", "*.dat", ".dat", |
||
| 259 | // "Izberi datoteko s podatki", |
||
| 260 | // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
||
| 261 | // EscapeString(efile,dfile); |
||
| 262 | sprintf(name ,"C:/root/bin/root.exe TDraw.cxx(\\\"%s\\\")", "merger_temperature.txt"); |
||
| 263 | // sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx"); |
||
| 264 | printf("%s\n",name); |
||
| 265 | LaunchExecutable(name); |
||
| 266 | break; |
||
| 267 | } |
||
| 268 | } |
||
| 269 | return 0; |
||
| 270 | } |