-int cmd_do_runnung_meas(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]){
- volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
- int32_t values[1024];
- uint32_t status, status_old, bank,i;
- int32_t val;
- status_old = *testaddr;
- status = *testaddr;
- while((status_old & (1<<2))==(status & (1<<2))) {status=*testaddr; printf("dely %i %i",status_old & (1<<2),status & (1<<2));}
- if (status&(1<<2)){
- testaddr = (volatile uint32_t *)0x80009000;
- } else {
- testaddr = (volatile uint32_t *)0x80008000;
- }
- for(i=0;i<1024;i++){
- // values[i]=*testaddr++;
- val=*testaddr++;
- val+=(1<<17);
- val&=(1<<18)-1;
- val -= (1<<17);
- values[i]=-1*val;
- }
- if (status&(1<<2)){
- printf("bank1\n");
- //testaddr = (volatile uint32_t *)0x80008000;
- } else {
- printf("bank0\n");
- }
- //printf("zacatek\n");
- for (i=0;i<1024;i++){
- printf("%d\n",values[i]);
- }
- printf("konec\n");
- return 0;
+int cmd_do_running_meas(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]){
+ volatile uint32_t *testaddr;
+ int32_t values[1024];
+ uint32_t status, status_old, i;
+ int32_t val;
+ int32_t wcycles = 0;
+ FILE *F;
+
+ F = cmd_io_as_direct_file(cmd_io, "r+");
+ //F = stdout;
+ if (F == NULL)
+ return CMDERR_EIO;
+
+ testaddr = fpga_dad_ctrl_reg;
+ status_old = *testaddr;
+ status = *testaddr;
+ while((status_old & FPGA_DAD_CTRL_BANK_m) == (status & FPGA_DAD_CTRL_BANK_m)) {
+ status = *testaddr;
+ wcycles++;
+ if (wcycles > 10000000) {
+ fprintf(F, "scan wait timeout\r\n");
+ fprintf(F, "timeout status 0x%02"PRIx32" old 0x%02"PRIx32"\r\n",
+ status, status_old);
+ fclose(F);
+ return CMDERR_TIMEOUT;
+ }
+ }
+ if (status & (1 << 2)) {
+ testaddr = fpga_dad_result_bank1;
+ } else {
+ testaddr = fpga_dad_result_bank0;
+ }
+ for(i=0; i<1024; i++) {
+ // values[i]=*testaddr++;
+ val = *testaddr++;
+ val += (1 << 17);
+ val &= (1 << 18) - 1;
+ val -= (1 << 17);
+ values[i] = -1 * val;
+ }
+ fprintf(F, "bank%d status 0x%02"PRIx32" old 0x%02"PRIx32
+ " wait cycles %"PRId32"\r\n",
+ status & FPGA_DAD_CTRL_BANK_m? 1: 0,
+ status, status_old, wcycles);
+ for (i=0;i<1024;i++){
+ fprintf(F, "%"PRId32"\r\n",values[i]);
+ }
+ fprintf(F, "end\r\n");
+
+ fclose(F);
+
+ return 0;