From 98ead7a4f903d966a54b80320a14427ac230e8bd Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 15 Jul 2001 19:57:32 +0000 Subject: [PATCH] Major hacking, just like cmd.c --- demo/mmap.c | 273 +++++++++++++++++----------------------------------- 1 file changed, 89 insertions(+), 184 deletions(-) diff --git a/demo/mmap.c b/demo/mmap.c index 301e19e..719befd 100644 --- a/demo/mmap.c +++ b/demo/mmap.c @@ -20,241 +20,146 @@ #include #include #include -#include -#include -#include #include #include #include "examples.h" -#define N_SCANS 10 -#define N_CHANS 16 +int comedi_get_front_count(comedi_t *it, unsigned int subdev); -#define BUFSZ 1000 -char buf[BUFSZ]; +unsigned int chanlist[256]; -sampl_t *map; +void *map; + +int prepare_cmd_lib(comedi_t *dev,int subdevice,comedi_cmd *cmd); +int prepare_cmd(comedi_t *dev,int subdevice,comedi_cmd *cmd); -void do_cmd_1(comedi_t *dev); -void do_cmd_2(comedi_t *dev); -void do_cmd(comedi_t *dev,comedi_cmd *cmd); int main(int argc, char *argv[]) { - char *fn = NULL; comedi_t *dev; + comedi_cmd c,*cmd=&c; + int size; + int front, back; + int ret; + int i; - fn = "/dev/comedi0"; + parse_options(argc,argv); - dev = comedi_open(fn); + dev = comedi_open(filename); if(!dev){ - perror(fn); + comedi_perror(filename); exit(1); } - fcntl(comedi_fileno(dev),F_SETFL,O_NONBLOCK); + size = comedi_get_buffer_size(dev,subdevice); + fprintf(stderr,"buffer size is %d\n",size); - map=mmap(NULL,0x1000,PROT_READ,MAP_SHARED,comedi_fileno(dev),0); - printf("map=%p\n",map); - - do_cmd_1(dev); - - return 0; -} - -void do_cmd(comedi_t *dev,comedi_cmd *cmd) -{ - int total=0; - int ret; - int go; - int i; + map=mmap(NULL,size,PROT_READ,MAP_SHARED,comedi_fileno(dev),0); + fprintf(stderr,"map=%p\n",map); - ret = comedi_command_test(dev,cmd); - - printf("test ret=%d\n",ret); - if(ret<0){ - printf("errno=%d\n",errno); - comedi_perror("comedi_command_test"); - return; + for(i=0;ichanlist = chanlist; + cmd->chanlist_len = n_chan; + cmd->scan_end_arg = n_chan; - /* the subdevice that the command is sent to */ - cmd.subdev = subdevice; + if(cmd->stop_src==TRIG_COUNT)cmd->stop_arg = n_scan; + + return 0; +} - /* flags */ - cmd.flags = 0; +int prepare_cmd(comedi_t *dev,int subdevice,comedi_cmd *cmd) +{ + memset(cmd,0,sizeof(*cmd)); - /* each event requires a trigger, which is specified - by a source and an argument. For example, to specify - an external digital line 3 as a source, you would use - src=TRIG_EXT and arg=3. */ + cmd->subdev = subdevice; - cmd.start_src = TRIG_NOW; - cmd.start_arg = 0; + cmd->flags = 0; - cmd.scan_begin_src = TRIG_TIMER; - cmd.scan_begin_arg = 1; /* in ns */ + cmd->start_src = TRIG_NOW; + cmd->start_arg = 0; - cmd.convert_src = TRIG_TIMER; - cmd.convert_arg = 1; /* in ns */ + cmd->scan_begin_src = TRIG_TIMER; + cmd->scan_begin_arg = 1e9/freq; - cmd.scan_end_src = TRIG_COUNT; - cmd.scan_end_arg = 4; /* number of channels */ + cmd->convert_src = TRIG_TIMER; + cmd->convert_arg = 1; -#if 1 - cmd.stop_src = TRIG_COUNT; - cmd.stop_arg = 100; -#else - cmd.stop_src = TRIG_NONE; - cmd.stop_arg = 0; -#endif + cmd->scan_end_src = TRIG_COUNT; + cmd->scan_end_arg = n_chan; - /* the channel list determined which channels are sampled. - In general, chanlist_len is the same as scan_end_arg. Most - boards require this. */ - cmd.chanlist = chanlist; - cmd.chanlist_len = 4; + cmd->stop_src = TRIG_COUNT; + cmd->stop_arg = n_scan; - chanlist[0]=CR_PACK(0,range,aref); - chanlist[1]=CR_PACK(1,range,aref); - chanlist[2]=CR_PACK(2,range,aref); - chanlist[3]=CR_PACK(3,range,aref); + cmd->chanlist = chanlist; + cmd->chanlist_len = n_chan; - do_cmd(dev,&cmd); + return 0; } + + -- 2.26.2