2006-10-23 19:35:24 +00:00
|
|
|
/*
|
2007-01-03 15:43:06 +00:00
|
|
|
* INSN_CONFIG_SET_CLOCK_SRC example
|
2006-10-23 19:35:24 +00:00
|
|
|
* Part of Comedilib
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
|
2007-01-03 15:43:06 +00:00
|
|
|
* Copyright (c) 2007 Frank Mori Hess <fmhess@users.sourceforge.net>
|
2006-10-23 19:35:24 +00:00
|
|
|
*
|
|
|
|
* This file may be freely modified, distributed, and combined with
|
|
|
|
* other software, as long as proper attribution is given in the
|
|
|
|
* source code.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Requirements: A board with a subdevice that supports
|
|
|
|
* INSN_CONFIG_CLOCK_SRC
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <comedilib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "examples.h"
|
|
|
|
|
|
|
|
|
|
|
|
comedi_t *device;
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2007-01-03 15:43:06 +00:00
|
|
|
unsigned period_ns;
|
|
|
|
int retval;
|
2007-01-03 21:14:53 +00:00
|
|
|
lsampl_t clock_selection;
|
|
|
|
struct parsed_options options;
|
2007-01-03 15:43:06 +00:00
|
|
|
|
2007-01-03 21:14:53 +00:00
|
|
|
init_parsed_options(&options);
|
|
|
|
options.freq = 0.;
|
|
|
|
parse_options(&options, argc, argv);
|
2006-10-23 19:35:24 +00:00
|
|
|
|
2007-01-03 21:14:53 +00:00
|
|
|
device = comedi_open(options.filename);
|
2006-10-23 19:35:24 +00:00
|
|
|
if(!device){
|
2007-01-03 21:14:53 +00:00
|
|
|
comedi_perror(options.filename);
|
|
|
|
exit(-1);
|
2006-10-23 19:35:24 +00:00
|
|
|
}
|
2007-01-03 21:14:53 +00:00
|
|
|
if(options.freq > 0.)
|
|
|
|
period_ns = 1e9 / options.freq;
|
2006-10-23 19:35:24 +00:00
|
|
|
else
|
|
|
|
period_ns = 0;
|
2007-01-03 21:14:53 +00:00
|
|
|
clock_selection = options.value;
|
2012-05-14 14:45:37 +01:00
|
|
|
printf("Selecting master clock %d for channel %d on subdevice %d.\n", clock_selection, options.channel, options.subdevice);
|
2006-10-23 19:35:24 +00:00
|
|
|
if(period_ns)
|
|
|
|
{
|
|
|
|
printf("Clock period = %d nanoseconds.\n", period_ns);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
printf("Clock period unspecified.\n");
|
|
|
|
}
|
|
|
|
|
2010-03-19 13:44:56 +00:00
|
|
|
retval = comedi_set_clock_source(device, options.subdevice, options.channel, clock_selection, period_ns);
|
2008-01-17 17:10:07 +00:00
|
|
|
if(retval < 0) comedi_perror("comedi_set_clock_source");
|
|
|
|
|
|
|
|
comedi_close(device);
|
2006-10-23 19:35:24 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|