#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;
target0[0]=0;
if (end
>32) strncpy (target0
, &str
[end
-32-1] , 32);
target0[32]=0;
end-=32;
if (end>0) {
target1[end-1] = 0;
}
// printf("==>%s %s\n==>%s\n", target1, target0, str);
}
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
,"setcable -port usb21 -baud 3000000\n");
sprintf(cmd
,"impact.bat impact.cmd %s ", impact_output
);
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");
"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 );
sprintf(cmd
,"impact.bat %s %s ", impactcmd
,impact_output
);
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){
//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]="";
for (int i=0;i<3;i++){
if (ret!=NULL) {
ret=(ret+8);
printf("t=%ul sens=%d T=%s\n",time(NULL
), i
+k
*2, t0
);
if (fp){
}
} else break;
}
if (k==0) {
}
}
}
ret
=strstr(buff
, "'1': DNA =");
if (ret !=NULL){
sscanf(ret
,"'1': DNA = '%s", fpgasn
);
bin2hex(fpgasn,hexsn);
//SetCtrlVal(pnl,target_control[febboard], hexsn);
} else {
}
}
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);
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");
LaunchExecutable(name);
break;
}
}
return 0;
}