From c673de7c79ba910a891ecf8653971a263f232cbc Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sat, 24 Jul 2004 16:09:01 +0000 Subject: [PATCH] fix internal trigger when testing write command, and fix test when write command uses stop_src==TRIG_NONE instead of TRIG_COUNT --- testing/cmd_1.c | 48 ++++++++++++++++++++++++++++++------------- testing/comedi_test.h | 3 +++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/testing/cmd_1.c b/testing/cmd_1.c index 6b16a51..843f672 100644 --- a/testing/cmd_1.c +++ b/testing/cmd_1.c @@ -161,7 +161,16 @@ int test_cmd_write_fast_1chan(void) int total=0; int ret; unsigned int flags = comedi_get_subdevice_flags(device,subdevice); - + static const int num_samples = 100000; + int num_bytes; + + if((flags & SDF_LSAMPL)) + { + num_bytes = num_samples * sizeof(lsampl_t); + }else + { + num_bytes = num_samples * sizeof(sampl_t); + } if(!(flags&SDF_CMD) || !(flags&SDF_WRITEABLE)){ printf("not applicable\n"); return 0; @@ -175,7 +184,7 @@ int test_cmd_write_fast_1chan(void) if(realtime)cmd.flags |= TRIG_RT; cmd.chanlist = chanlist; cmd.scan_end_arg = 1; - cmd.stop_arg = 1000000; + cmd.stop_arg = num_samples; cmd.chanlist_len = 1; chanlist[0] = CR_PACK(0,0,0); @@ -202,18 +211,13 @@ int test_cmd_write_fast_1chan(void) if(verbose)printf("write %d %d\n",ret,total); } - { - comedi_insn insn; - memset(&insn, 0, sizeof(comedi_insn)); - insn.insn = INSN_INTTRIG; - insn.subdev = subdevice; - ret = comedi_do_insn(device, &insn); - if(ret<0){ - perror("comedi_inttrig"); - return 0; - } - if(verbose)printf("inttrig\n"); + ret = comedi_internal_trigger(device, subdevice, 0); + if(ret<0){ + perror("E: comedi_inttrig"); + comedi_cancel(device, subdevice); + return 0; } + if(verbose)printf("inttrig\n"); go=1; while(go){ @@ -230,9 +234,25 @@ int test_cmd_write_fast_1chan(void) }else{ total += ret; if(verbose)printf("write %d %d\n",ret,total); + //deal with case where output doesn't support stop_src=TRIG_COUNT + if(total >= num_bytes) + { + go = 0; + } } } - + // make sure all samples have been written out + while(1) + { + ret = comedi_get_buffer_contents(device, subdevice); + if(ret < 0) + { + printf("E: comedi_get_buffer_contents() returned %i\n", ret); + }else if(ret == 0) break; + } + // cancel needed in the case of stop_src==TRIG_NONE + if(comedi_cancel(device, subdevice)) + printf("E: comedi_cancel() failed"); return 0; } diff --git a/testing/comedi_test.h b/testing/comedi_test.h index 58f084d..eab6e0a 100644 --- a/testing/comedi_test.h +++ b/testing/comedi_test.h @@ -13,5 +13,8 @@ extern unsigned int capabilities; extern int realtime; +extern int comedi_internal_trigger(comedi_t *device,unsigned int subdevice, + unsigned int trignum); + #endif -- 2.26.2