Blame |
Last modification |
View Log
| RSS feed
#include <ansi_c.h>
#include <utility.h>
#include <cvirte.h>
#include <userint.h>
#include "mergerjtag.h"
static int panelHandle
;
void bin2hex
(const char * str
, char *target
)
{
char target0
[0xFF],target1
[0xFF];
int i
;
int end
= strlen(str
);
target0
[0]=0;
if (end
>32) strncpy (target0
, &str
[end
-32-1] , 32);
target0
[32]=0;
end
-=32;
if (end
>0) {
strncpy (target1
, &str
[0] , end
);
target1
[end
-1] = 0;
}
// printf("==>%s %s\n==>%s\n", target1, target0, str);
sprintf(target
,"0x%08X%08X",strtoul (target1
, NULL
, 2) ,strtoul (target0
, NULL
, 2) );
}
char impact_output
[255]= "impact_merger.txt";
int jtagexecute
(const char *impactcmd
, int wait
){
char cmd
[255];
int jtagchainid
= 1;
FILE
*fp
=fopen("impact.cmd","w");
fprintf(fp
,"setmode -bscan\n");
fprintf(fp
,"setcable -port usb21 -baud 3000000\n");
fprintf(fp
,"identify\n");
fprintf(fp
,"%s\n", impactcmd
);
fprintf(fp
,"exit\n");
fclose(fp
);
sprintf(cmd
,"impact.bat impact.cmd %s ", impact_output
);
printf("%s\n",cmd
);
if (wait
) return system(cmd
);
else return LaunchExecutableEx
(cmd
, LE_SHOWNORMAL
, NULL
);
}
int loadbit
( int wait
){
const char impactcmd
[255]="impact.cmd";
char cmd
[255];
int jtagchainid
= 1;
char bitfile
[255]="arich_merger_rev01.bit";
//GetCtrlVal(pnl, PANEL_BITFILE,bitfile);
char foutput
[255]="impacttest_feb";
FILE
*fp
=fopen(impactcmd
,"w");
fprintf(fp
,
"setmode -bscan\n"
"setcable -port usb21 -baud 3000000\n"
"identify\n");
//fprintf(fp, "readdna -p %d\n", jtagchainid );
fprintf(fp
, "assignfile -p %d -file %s\n",jtagchainid
, bitfile
);
fprintf(fp
, "program -p %d -prog\n" ,jtagchainid
);
// fprintf(fp, "verify -p %d\n",jtagchainid );
fprintf(fp
,"exit\n");
fclose(fp
);
sprintf(cmd
,"impact.bat %s %s ", impactcmd
,impact_output
);
printf("%s\n",cmd
);
if (wait
) system(cmd
);
else LaunchExecutableEx
(cmd
, LE_SHOWNORMAL
, NULL
);
return 0;
}
int ImpactOutputInspect
( const char *fname
, const char *opt
){
FILE
*fout
;
const int ndim
=400;
char buff
[ndim
];
char fpgasn
[0xFF], hexsn
[0XFF];
char impactout
[255];
char *ret
;
char *ret0
;
char *ret1
;
char *ret2
;
int downloadok
=0;
int xc6slx45
=0;
FILE
*fp
= NULL
;
if (fname
!=NULL
) fp
= fopen (fname
, opt
);
fout
= fopen (impact_output
, "r");
while (fgets(buff
,ndim
,fout
)!=NULL
) {
// printf("%s",buff);
ret
=strstr(buff
, "INFO:iMPACT:188 - '1': Programming completed successfully.");
if (ret
!=NULL
){
printf("Download OK!\n");
//SetCtrlVal(pnl,firmware_control[febboard], 1);
downloadok
=1;
}
ret
=strstr(buff
, "INFO:iMPACT:501 - '1': Added Device xc5vlx50t successfully.");
if (ret
!=NULL
){
printf("Device xc5vlx50t found!\n");
//SetCtrlVal(pnl,fpga_control[febboard], 1);
xc6slx45
=1;
}
ret
=strstr(buff
, "Temperature");
for (int k
=0;k
<2;k
++){
if (ret
!=NULL
){
char t0
[0xFF]="";
printf("#%s#\n",ret
);
for (int i
=0;i
<3;i
++){
ret
=strstr(ret
, "Reading:");
if (ret
!=NULL
) {
ret
=(ret
+8);
sscanf(ret
,"%s", t0
);
printf("t=%ul sens=%d T=%s\n",time(NULL
), i
+k
*2, t0
);
if (fp
){
fprintf(fp
, "%ul %d %s\n",time(NULL
), i
+k
*2, t0
);
}
} else break;
}
if (k
==0) {
fgets(buff
,ndim
,fout
);
ret
=strstr(buff
, "Reading:");
}
}
}
ret
=strstr(buff
, "'1': DNA =");
if (ret
!=NULL
){
sscanf(ret
,"'1': DNA = '%s", fpgasn
);
bin2hex
(fpgasn
,hexsn
);
printf("%s",hexsn
);
//SetCtrlVal(pnl,target_control[febboard], hexsn);
} else {
sprintf(hexsn
,"");
}
}
if (fp
) fclose (fp
);
fclose(fout
);
return 0;
}
FILE
*fmon
=NULL
;
int main
(int argc
, char *argv
[]) {
if (InitCVIRTE
(0, argv
, 0) == 0)
return -1; /* out of memory */
if ((panelHandle
= LoadPanel
(0, "mergerjtag.uir", PANEL
)) < 0)
return -1;
double tinterval
;
GetCtrlVal
(panelHandle
, PANEL_TINTERVAL
, &tinterval
);
SetCtrlAttribute
(panelHandle
, PANEL_TIMER
, ATTR_INTERVAL
, tinterval
);
TimerOnOffCB
(panelHandle
, PANEL_TIMERON
, EVENT_COMMIT
,NULL
,0,0);
DisplayPanel
(panelHandle
);
RunUserInterface
();
DiscardPanel
(panelHandle
);
if (fmon
) fclose(fmon
);
return 0;
}
int CVICALLBACK ExitCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:
QuitUserInterface
(0);
break;
}
return 0;
}
int CVICALLBACK ReadCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:
jtagexecute
("readTemperatureAndVoltage -p 1\n", 1);
ImpactOutputInspect
("read_out.txt","w");
break;
}
return 0;
}
int CVICALLBACK LoadCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:
loadbit
(1);
ImpactOutputInspect
("loadbit_out.txt","w");
break;
}
return 0;
}
int CVICALLBACK TimerOnOffCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
int state
;
switch (event
)
{
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &state
);
if (state
){
printf ("Enabling timer....\n");
ResumeTimerCallbacks
();
} else {
SuspendTimerCallbacks
();
printf ("Disabling timer....\n");
}
break;
}
return 0;
}
int CVICALLBACK SetIntervalCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
double tinterval
;
switch (event
) {
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &tinterval
);
SetCtrlAttribute
(panel
, PANEL_TIMER
, ATTR_INTERVAL
, tinterval
);
break;
}
return 0;
}
int CVICALLBACK TimerCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_TIMER_TICK
:
jtagexecute
("readTemperatureAndVoltage -p 1\n", 1);
ImpactOutputInspect
("merger_temperature.txt","a");
break;
}
return 0;
}
int CVICALLBACK DrawCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:{
char name
[MAX_PATHNAME_LEN
];
// char dfile[MAX_PATHNAME_LEN];
// char efile[MAX_PATHNAME_LEN];
// status = FileSelectPopup ("dat", "*.dat", ".dat",
// "Izberi datoteko s podatki",
// VAL_LOAD_BUTTON, 0, 0, 1, 0, efile);
// EscapeString(efile,dfile);
sprintf(name
,"C:/root/bin/root.exe TDraw.cxx(\\\"%s\\\")", "merger_temperature.txt");
// sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx");
printf("%s\n",name
);
LaunchExecutable
(name
);
break;
}
}
return 0;
}