[Xenomai-git] Alexis Berlemont : analogy: add first version of waveform generation

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 0f0dcd0c21fdddc0d539e48488aa248313bdc270
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=0f0dcd0c21fdddc0d539e48488aa248313bdc270

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Sat Oct 16 14:59:54 2010 +0200

analogy: add first version of waveform generation

This work is based on Daniele Nicolodi's work. Unfortunately, I could
not include the proprosal as is because it was limited for 16bits
acquisition devices.

So far, this work is not complete.

---

 src/utils/analogy/Makefile.am |6 ++
 src/utils/analogy/signal_generation.c |  157 +
 src/utils/analogy/signal_generation.h |   38 
 3 files changed, 201 insertions(+), 0 deletions(-)

diff --git a/src/utils/analogy/Makefile.am b/src/utils/analogy/Makefile.am
index f82942e..3d8cb5e 100644
--- a/src/utils/analogy/Makefile.am
+++ b/src/utils/analogy/Makefile.am
@@ -9,6 +9,12 @@ CPPFLAGS = \
 LDFLAGS = \
@XENO_USER_LDFLAGS@
 
+lib_LIBRARIES = libwaveform.a
+
+libwaveform_a_SOURCES = signal_generation.c
+
+noinst_HEADERS = signal_generation.h
+
 analogy_config_SOURCES = analogy_config.c
 analogy_config_LDADD = \
../../drvlib/analogy/libanalogy.la \
diff --git a/src/utils/analogy/signal_generation.c 
b/src/utils/analogy/signal_generation.c
new file mode 100644
index 000..2f443c5
--- /dev/null
+++ b/src/utils/analogy/signal_generation.c
@@ -0,0 +1,157 @@
+#include stdio.h
+#include stdlib.h
+#include assert.h
+#include errno.h
+#include math.h
+
+#include analogy/analogy.h
+
+#include signal_generation.h
+
+#ifndef PI
+#define PI 3.14159265358979323846
+#endif
+
+void a4l_sg_init_sine(struct waveform_config *config, double *values)
+{
+   int i;
+
+   double ratio = config-wf_frequency / config-spl_frequency;
+
+   for (i = 0; i  config-spl_count; i++) {
+
+   values[i] = config-wf_offset -
+   config-wf_amplitude / 2 + 
+   0.5 * config-wf_amplitude * cos(i * 2 * PI * ratio);
+   }
+}
+
+void a4l_sg_init_sawtooth(struct waveform_config *config, double *values)
+{
+   int i;
+
+   double ratio = config-wf_frequency / config-spl_frequency;
+
+   for (i = 0; i  config-spl_count; i++) {
+   
+   int period_idx = (int)floor(i * ratio);
+
+   values[i] = config-wf_offset -
+   config-wf_amplitude / 2 -
+   period_idx * config-wf_amplitude +
+   i * ratio * config-wf_amplitude;
+   }
+}
+
+void a4l_sg_init_triangular(struct waveform_config *config, double *values)
+{
+   int i;
+
+   double ratio = config-wf_frequency / config-spl_frequency;
+
+   for (i = 0; i  config-spl_count; i++) {
+
+   int period_idx = (int)floor(i * ratio);
+   int half_period_idx = (int)floor(i * 2 * ratio);
+   int rise = ((half_period_idx % 2) == 0) ? 1 : 0;
+
+   if (rise) {
+   values[i] = config-wf_offset - 
+   config-wf_amplitude / 2 -
+   2 * period_idx * config-wf_amplitude +
+   2 * i * ratio * config-wf_amplitude;
+   } else {
+   values[i] = config-wf_offset -
+   config-wf_amplitude / 2 +
+   2 * (period_idx + 1) * config-wf_amplitude - 
+   2 * i * ratio * config-wf_amplitude;
+   }
+   }
+}
+
+void a4l_sg_init_steps(struct waveform_config *config, double *values)
+{
+   int i;
+   
+   double ratio = config-wf_frequency / config-spl_frequency;
+   
+   for (i = 0; i  config-spl_count; i++) {
+   int half_period_idx = (int)floor(i * 2 * ratio);
+   int even = (half_period_idx % 2 == 0);
+   
+   values[i] = config-wf_offset - 
+   config-wf_amplitude / 2 + even * config-wf_amplitude;
+   }
+}
+
+void a4l_sg_set_sample_count(struct waveform_config *config)
+{
+   int sample_count = MIN_SAMPLE_COUNT;
+   int best_count = MIN_SAMPLE_COUNT;
+   double lowest_diff = INFINITY;
+
+   while (sample_count  MAX_SAMPLE_COUNT) {
+
+   double ratio = (double)sample_count * 
+   (config-wf_frequency / config-spl_frequency);
+   int ceiling = ceil(ratio);
+   double diff = (double)ceiling - ratio;
+
+   assert(diff = 0);
+
+   if (diff  lowest_diff) {
+   lowest_diff = diff;
+   best_count = sample_count;
+   }
+
+   if (diff == 0)
+   break;
+
+   sample_count++;
+   }
+
+   if (lowest_diff != 0) {
+   printf(Warning: unable to create a contiguous signal\n);
+   

[Xenomai-git] Alexis Berlemont : analogy: add a 1st version of wf_cmd_write

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 5a5e661762439da9b14050153f9f5b8880962ac8
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=5a5e661762439da9b14050153f9f5b8880962ac8

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Thu Dec  2 01:00:55 2010 +0100

analogy: add a 1st version of wf_cmd_write

This program takes the waveforms created by wf_generate as standard
input. So we are able to inject specific waveforms into the output
subdevice of a board.

Warning: more parameters needs to be added
Warning: it should not be used as is

---

 src/utils/analogy/Makefile.am|7 +
 src/utils/analogy/wf_cmd_write.c |  483 ++
 2 files changed, 490 insertions(+), 0 deletions(-)

diff --git a/src/utils/analogy/Makefile.am b/src/utils/analogy/Makefile.am
index 8e7734f..a2c3e96 100644
--- a/src/utils/analogy/Makefile.am
+++ b/src/utils/analogy/Makefile.am
@@ -3,6 +3,7 @@ sbin_PROGRAMS = analogy_config
 bin_PROGRAMS = \
cmd_read \
cmd_write \
+   wf_cmd_write \
cmd_bits \
insn_read \
insn_write \
@@ -42,6 +43,12 @@ cmd_write_LDADD = \
../../skins/rtdm/librtdm.la \
../../skins/common/libxenomai.la
 
+wf_cmd_write_SOURCES = wf_cmd_write.c
+wf_cmd_write_LDADD = \
+   ../../drvlib/analogy/libanalogy.la \
+   ../../skins/rtdm/librtdm.la \
+   ../../skins/common/libxenomai.la
+
 cmd_bits_SOURCES = cmd_bits.c
 cmd_bits_LDADD = \
../../drvlib/analogy/libanalogy.la \
diff --git a/src/utils/analogy/wf_cmd_write.c b/src/utils/analogy/wf_cmd_write.c
new file mode 100644
index 000..38e0c29
--- /dev/null
+++ b/src/utils/analogy/wf_cmd_write.c
@@ -0,0 +1,483 @@
+/**
+ * @file
+ * Analogy for Linux, output command test program
+ *
+ * @note Copyright (C) 1997-2000 David A. Schleef d...@schleef.org
+ * @note Copyright (C) 2008 Alexis Berlemont alexis.berlem...@free.fr
+ *
+ * Xenomai is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include stdio.h
+#include stdlib.h
+#include unistd.h
+#include sys/mman.h
+#include errno.h
+#include getopt.h
+#include string.h
+
+#include analogy/analogy.h
+
+#define BUFFER_DEPTH 1024
+
+struct config {
+
+   /* Configuration parameters
+  TODO: add real_time and use_mmap*/
+
+   int verbose;
+   
+   int subd;
+   char *str_chans;
+   unsigned int *chans;
+   int chans_count;
+   char *str_ranges;
+   int scans_count;
+
+   char *filename;
+   FILE *input;
+
+   /* Analogy stuff */
+
+   a4l_desc_t dsc;
+   a4l_chinfo_t *cinfo;
+   a4l_rnginfo_t *rinfo;
+
+   /* Buffer stuff
+  TODO: add buffer depth / size (useful for mmap) */
+   void *buffer;
+
+};
+
+/* --- Options / arguments part --- */
+
+struct option options[] = {
+   {verbose, no_argument, NULL, 'v'},
+   {device, required_argument, NULL, 'd'},
+   {subdevice, required_argument, NULL, 's'},
+   {scans-count, required_argument, NULL, 'S'},
+   {channels, required_argument, NULL, 'c'},
+   {range, required_argument, NULL, 'c'},
+   {help, no_argument, NULL, 'h'},
+   {0},
+};
+
+void print_usage(void)
+{
+   fprintf(stdout, usage:\tcmd_write [OPTS]\n);
+   fprintf(stdout, \tOPTS:\t -v, --verbose: verbose output\n);
+   fprintf(stdout,
+   \t\t -d, --device: 
+   device filename (analogy0, analogy1, ...)\n);
+   fprintf(stdout, \t\t -s, --subdevice: subdevice index\n);
+   fprintf(stdout, \t\t -S, --scans-count: count of scan to perform\n);
+   fprintf(stdout, 
+   \t\t -c, --channels: channels to use 
+   i,j,... (ex.: -c 0,1)\n);
+   fprintf(stdout, 
+   \t\t -R, --range: range to use 
+   min,max,unit (ex.: -R 0,1,V)\n);
+   fprintf(stdout, \t\t -h, --help: print this help\n);
+}
+
+/* --- Configuration related stuff --- */
+
+int init_dsc_config(struct config *cfg)
+{
+   int err = 0;
+
+   /* Here we have to open the Analogy device file */
+   err = a4l_open(cfg-dsc, cfg-filename);
+   if (err  0) {
+   fprintf(stderr,
+   cmd_write: a4l_open %s failed (ret=%d)\n,
+   cfg-filename, err);
+   goto out;
+   }
+
+   /* Allocate a buffer so 

[Xenomai-git] Alexis Berlemont : analogy: [fake] correctly manage EOA events for loop subdevices

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 14894b1311ded6c3548c307ecfd1758880cff0dd
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=14894b1311ded6c3548c307ecfd1758880cff0dd

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Sun Mar  6 00:44:39 2011 +0100

analogy: [fake] correctly manage EOA events for loop subdevices

---

 ksrc/drivers/analogy/testing/fake.c |   20 +---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ksrc/drivers/analogy/testing/fake.c 
b/ksrc/drivers/analogy/testing/fake.c
index d8f8cda..d82abb0 100644
--- a/ksrc/drivers/analogy/testing/fake.c
+++ b/ksrc/drivers/analogy/testing/fake.c
@@ -208,10 +208,12 @@ int ai2_push_values(a4l_subd_t *subd)
a4l_err(subd-dev, 
ai2_push_values: 
a4l_buf_put failed (err=%d)\n, err);
-   }
+   else {
+   priv-count = 0;
+   a4l_buf_evt(subd, 0);
+   }
 
-   if (priv-count)
-   a4l_buf_evt(subd, 0);
+   }
 
return err;
 }
@@ -330,9 +332,21 @@ int ao_trigger(a4l_subd_t *subd, lsampl_t trignum)
 int ao_cancel(a4l_subd_t *subd)
 {
struct fake_priv *priv = (struct fake_priv *)subd-dev-priv;
+   int running;
 
a4l_info(subd-dev, ao_cancel: (subd=%d)\n, subd-idx);
RTDM_EXECUTE_ATOMICALLY(priv-ao_running = 0);
+
+   RTDM_EXECUTE_ATOMICALLY(running = priv-ai2_running);
+   if (running) {
+   a4l_subd_t *ai2_subd = 
+   (a4l_subd_t *)a4l_get_subd(subd-dev, AI2_SUBD);
+   /* Here, we have not saved the required amount of
+  data; so, we cannot know whether or not, it is the
+  end of the acquisition; that is why we force it */
+   a4l_buf_evt(ai2_subd, A4L_BUF_EOA);
+   }
+
return 0;
 }
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: minor cosmetic changes in wf_facilities.c

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: fc49dc426f220d2c27d700d49b3f57fbcdd180ce
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=fc49dc426f220d2c27d700d49b3f57fbcdd180ce

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Sun Mar  6 00:53:03 2011 +0100

analogy: minor cosmetic changes in wf_facilities.c

---

 src/utils/analogy/wf_facilities.c |   15 +--
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/utils/analogy/wf_facilities.c 
b/src/utils/analogy/wf_facilities.c
index 08d105e..dd2d29f 100644
--- a/src/utils/analogy/wf_facilities.c
+++ b/src/utils/analogy/wf_facilities.c
@@ -109,8 +109,9 @@ void a4l_wf_set_sample_count(struct waveform_config *config)
}
 
if (lowest_diff != 0) {
-   printf(Warning: unable to create a contiguous signal\n);
-   printf(Warning: an approximation is performed\n);
+   fprintf(stderr, 
+   Warning: unable to create a contiguous signal\n);
+   fprintf(stderr, Warning: an approximation is performed\n);
}
 
config-spl_count = best_count;
@@ -120,11 +121,13 @@ int a4l_wf_check_config(struct waveform_config *config)
 {
 
if (config-wf_amplitude == 0)
-   printf(Warning: the signal will be constant\n);
+   fprintf(stderr, Warning: the signal will be constant\n);
 
if (config-wf_frequency * 2  config-spl_frequency) {
-   printf(Error: the sampling frequency is not correct\n);
-   printf(Error: sampling frequency = 2 * signal frequency\n);
+   fprintf(stderr, 
+   Error: the sampling frequency is not correct\n);
+   fprintf(stderr, 
+   Error: sampling frequency = 2 * signal frequency\n);
return -EINVAL;
}
 
@@ -150,6 +153,6 @@ void a4l_wf_dump_values(struct waveform_config *config, 
double *values)
int i;

for (i = 0; i  config-spl_count; i++)
-   printf(%f\n, values[i]);
+   fprintf(stderr, %f\n, values[i]);
 }
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: minor change in the test program wf_cmd_write

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 79bd88fd21eae746a5c743ed5410cf23e7b03c69
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=79bd88fd21eae746a5c743ed5410cf23e7b03c69

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Fri Apr 22 22:02:43 2011 +0200

analogy: minor change in the test program wf_cmd_write

---

 src/utils/analogy/wf_cmd_write.c |   58 ++---
 1 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/src/utils/analogy/wf_cmd_write.c b/src/utils/analogy/wf_cmd_write.c
index 6a4d507..05ac08a 100644
--- a/src/utils/analogy/wf_cmd_write.c
+++ b/src/utils/analogy/wf_cmd_write.c
@@ -296,13 +296,6 @@ int init_config(struct config *cfg, int argc, char *argv[])
};
}
 
-   /* If stdin is a terminal, we will not be able to read binary
-  data from it */
-   if (isatty(fileno(cfg-input))) {
-   fprintf(stderr, cmd_write: stdin cannot be a terminal\n);
-   return -EINVAL;
-   }
-
/* Open the analogy device and retrieve pointers on the info
   structures */
err = init_dsc_config(cfg);
@@ -336,6 +329,14 @@ int init_config(struct config *cfg, int argc, char *argv[])
fprintf(stderr, cmd_write: malloc failed\n);
goto out;
}
+
+   /* If stdin is a terminal, we will not be able to read binary
+  data from it */
+   if (isatty(fileno(cfg-input))) {
+   memset(cfg-buffer, 0, BUFFER_DEPTH * scan_size);
+   cfg-input = NULL;
+   } else
+   cfg-input = stdin;

 out:
 
@@ -345,9 +346,9 @@ out:
return err;
 }
 
-/* --- Processing functions --- */
+/* --- Input management part --- */
 
-int process_stdin(struct config *cfg)
+int process_input(struct config *cfg)
 {
int err = 0, filled = 0;
 
@@ -357,7 +358,6 @@ int process_stdin(struct config *cfg)
int scan_size = cfg-chans_count * chan_size;
 
while (filled  BUFFER_DEPTH) {
-
int i;
double value;
char tmp[128];
@@ -395,18 +395,29 @@ int process_stdin(struct config *cfg)
 
 out:
 
-   if (err = 0  filled) {
+   return err  0 ? err : filled;
+}
+
+/* --- Acquisition related stuff --- */
 
+int run_acquisition(struct config *cfg)
+{
+   int err = 0;
+
+   /* The return value of a4l_sizeof_chan() was already
+   controlled in init_config so no need to do it twice */
+   int chan_size = a4l_sizeof_chan(cfg-cinfo);
+   int scan_size = cfg-chans_count * chan_size;
+
+
+   err = cfg-input ? process_input(cfg) : BUFFER_DEPTH;
+   if (err  0)
err = a4l_async_write(cfg-dsc, 
  cfg-buffer, 
- filled * scan_size, A4L_INFINITE);
-   if (err  0)
-   fprintf(stderr, 
-   cmd_write: a4l_async_write failed (err=%d)\n,
-   err);
-   } else if (err = 0  !filled)
+ err * scan_size, A4L_INFINITE);
+   else if (err == 0)
err = -ENOENT;
-   
+
return err  0 ? err : 0;
 }
 
@@ -425,7 +436,7 @@ int init_acquisition(struct config *cfg)
.convert_arg = 0,
.scan_end_src = TRIG_COUNT,
.scan_end_arg = cfg-chans_count,
-   .stop_src = TRIG_COUNT,
+   .stop_src = cfg-scans_count ? TRIG_COUNT : TRIG_NONE,
.stop_arg = cfg-scans_count,
.nb_chan = cfg-chans_count,
.chan_descs = cfg-chans
@@ -449,13 +460,12 @@ int init_acquisition(struct config *cfg)
goto out;
}
 
-   /* Fill the asynchronous buffer with data
-  TODO: the amount of data to be prefilled should be configured */
-   err = process_stdin(cfg);
+   /* Fill the asynchronous buffer with data... */
+   err = run_acquisition(cfg);
if (err  0)
goto out;
 
-   /* Trigger the start of the output device feeding  */
+   /* ...before triggering the start of the output device feeding  */
err = a4l_snd_insn(cfg-dsc, insn);
 
 out:
@@ -478,7 +488,7 @@ int main(int argc, char *argv[])
if (err  0)
goto out;
 
-   while ((err = process_stdin(cfg)) == 0);
+   while ((err = run_acquisition(cfg)) == 0);
 
err = (err == -ENOENT) ? 0 : err;
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: [fake] fix synchronization bugs at cancel time

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 7202ff7e2cf2d41be7ed369c811d6b83c257b170
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=7202ff7e2cf2d41be7ed369c811d6b83c257b170

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Fri Apr 22 22:01:27 2011 +0200

analogy: [fake] fix synchronization bugs at cancel time

---

 ksrc/drivers/analogy/testing/fake.c |   40 +++---
 1 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/ksrc/drivers/analogy/testing/fake.c 
b/ksrc/drivers/analogy/testing/fake.c
index d82abb0..8d613db 100644
--- a/ksrc/drivers/analogy/testing/fake.c
+++ b/ksrc/drivers/analogy/testing/fake.c
@@ -91,9 +91,9 @@ static a4l_cmd_t ai_cmd_mask = {
.idx_subd = 0,
.start_src = TRIG_NOW,
.scan_begin_src = TRIG_TIMER,
-   .convert_src = TRIG_NOW|TRIG_TIMER,
+   .convert_src = TRIG_NOW | TRIG_TIMER,
.scan_end_src = TRIG_COUNT,
-   .stop_src = TRIG_COUNT|TRIG_NONE,
+   .stop_src = TRIG_COUNT | TRIG_NONE,
 };
 
 static a4l_cmd_t ao_cmd_mask = {
@@ -102,7 +102,7 @@ static a4l_cmd_t ao_cmd_mask = {
.scan_begin_src = TRIG_TIMER,
.convert_src = TRIG_NOW | TRIG_TIMER,
.scan_end_src = TRIG_COUNT,
-   .stop_src = TRIG_COUNT| TRIG_NONE,
+   .stop_src = TRIG_COUNT | TRIG_NONE,
 };
 
 /* --- Analog input simulation --- */
@@ -203,16 +203,21 @@ int ai2_push_values(a4l_subd_t *subd)
int err = 0;
 
if (priv-count) {
+
err = a4l_buf_put(subd, priv-buffer, priv-count);
+
+   /* If there is no more place in the asynchronous
+   buffer, data are likely to be dropped; it is just a
+   test driver so no need to implement trickier mechanism */
+   err = (err == -EAGAIN) ? 0 : err;
+   priv-count = 0;
+
if (err  0)
a4l_err(subd-dev, 
ai2_push_values: 
a4l_buf_put failed (err=%d)\n, err);
-   else {
-   priv-count = 0;
+   else
a4l_buf_evt(subd, 0);
-   }
-
}
 
return err;
@@ -244,7 +249,6 @@ static void task_proc(void *arg)
if (running  ao_pull_values(ao_subd)  0)
break;
 
-
RTDM_EXECUTE_ATOMICALLY(running = priv-ai2_running);
if (running  ai2_push_values(ai2_subd)  0)
break;
@@ -253,7 +257,6 @@ static void task_proc(void *arg)
}
 }
 
-
 /* --- Asynchronous AI functions --- */
 
 static int ai_cmd(a4l_subd_t *subd, a4l_cmd_t *cmd)
@@ -332,6 +335,7 @@ int ao_trigger(a4l_subd_t *subd, lsampl_t trignum)
 int ao_cancel(a4l_subd_t *subd)
 {
struct fake_priv *priv = (struct fake_priv *)subd-dev-priv;
+   struct ao_ai2_priv *ao_priv = (struct ao_ai2_priv *)subd-priv;
int running;
 
a4l_info(subd-dev, ao_cancel: (subd=%d)\n, subd-idx);
@@ -344,6 +348,8 @@ int ao_cancel(a4l_subd_t *subd)
/* Here, we have not saved the required amount of
   data; so, we cannot know whether or not, it is the
   end of the acquisition; that is why we force it */
+   RTDM_EXECUTE_ATOMICALLY(priv-ai2_running = 0);
+   RTDM_EXECUTE_ATOMICALLY(ao_priv-count = 0);
a4l_buf_evt(ai2_subd, A4L_BUF_EOA);
}
 
@@ -364,9 +370,25 @@ int ai2_cmd(a4l_subd_t *subd, a4l_cmd_t *cmd)
 int ai2_cancel(a4l_subd_t *subd)
 {
struct fake_priv *priv = (struct fake_priv *)subd-dev-priv;
+   struct ao_ai2_priv *ai2_priv = *((struct ao_ai2_priv **)subd-priv);
+
+   int running;
 
a4l_info(subd-dev, ai2_cancel: (subd=%d)\n, subd-idx);
RTDM_EXECUTE_ATOMICALLY(priv-ai2_running = 0);
+
+   RTDM_EXECUTE_ATOMICALLY(running = priv-ao_running);
+   if (running) {
+   a4l_subd_t *ao_subd = 
+   (a4l_subd_t *)a4l_get_subd(subd-dev, AO_SUBD);
+   /* Here, we have not saved the required amount of
+  data; so, we cannot know whether or not, it is the
+  end of the acquisition; that is why we force it */
+   RTDM_EXECUTE_ATOMICALLY(priv-ao_running = 0);
+   RTDM_EXECUTE_ATOMICALLY(ai2_priv-count = 0);
+   a4l_buf_evt(ao_subd, A4L_BUF_EOA);
+   }
+
return 0;
 }
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: add wf_generate tool

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 7c0bacfc88ff8884f2c1664c1543101f2203705d
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=7c0bacfc88ff8884f2c1664c1543101f2203705d

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Sun Oct 31 16:01:24 2010 +0100

analogy: add wf_generate tool

---

 src/utils/analogy/Makefile.am |   18 +++-
 src/utils/analogy/wf_facilities.c |   24 ++--
 src/utils/analogy/wf_facilities.h |   16 ++--
 src/utils/analogy/wf_generate.c   |  232 +
 4 files changed, 266 insertions(+), 24 deletions(-)

diff --git a/src/utils/analogy/Makefile.am b/src/utils/analogy/Makefile.am
index 3d8cb5e..8e7734f 100644
--- a/src/utils/analogy/Makefile.am
+++ b/src/utils/analogy/Makefile.am
@@ -1,6 +1,13 @@
 sbin_PROGRAMS = analogy_config
 
-bin_PROGRAMS = cmd_read cmd_write cmd_bits insn_read insn_write insn_bits
+bin_PROGRAMS = \
+   cmd_read \
+   cmd_write \
+   cmd_bits \
+   insn_read \
+   insn_write \
+   insn_bits \
+   wf_generate
 
 CPPFLAGS = \
@XENO_USER_CFLAGS@ \
@@ -9,11 +16,11 @@ CPPFLAGS = \
 LDFLAGS = \
@XENO_USER_LDFLAGS@
 
-lib_LIBRARIES = libwaveform.a
+noinst_HEADERS = wf_facilities.h
 
-libwaveform_a_SOURCES = signal_generation.c
+lib_LIBRARIES = libwaveform.a
 
-noinst_HEADERS = signal_generation.h
+libwaveform_a_SOURCES = wf_facilities.c
 
 analogy_config_SOURCES = analogy_config.c
 analogy_config_LDADD = \
@@ -58,3 +65,6 @@ insn_bits_LDADD = \
../../drvlib/analogy/libanalogy.la \
../../skins/rtdm/librtdm.la \
../../skins/common/libxenomai.la
+
+wf_generate_SOURCES = wf_generate.c
+wf_generate_LDADD = ./libwaveform.a -lm
diff --git a/src/utils/analogy/wf_facilities.c 
b/src/utils/analogy/wf_facilities.c
index ce250e7..08d105e 100644
--- a/src/utils/analogy/wf_facilities.c
+++ b/src/utils/analogy/wf_facilities.c
@@ -10,7 +10,7 @@
 #define PI 3.14159265358979323846
 #endif
 
-void a4l_sg_init_sine(struct waveform_config *config, double *values)
+void a4l_wf_init_sine(struct waveform_config *config, double *values)
 {
int i;
 
@@ -24,7 +24,7 @@ void a4l_sg_init_sine(struct waveform_config *config, double 
*values)
}
 }
 
-void a4l_sg_init_sawtooth(struct waveform_config *config, double *values)
+void a4l_wf_init_sawtooth(struct waveform_config *config, double *values)
 {
int i;
 
@@ -41,7 +41,7 @@ void a4l_sg_init_sawtooth(struct waveform_config *config, 
double *values)
}
 }
 
-void a4l_sg_init_triangular(struct waveform_config *config, double *values)
+void a4l_wf_init_triangular(struct waveform_config *config, double *values)
 {
int i;
 
@@ -67,7 +67,7 @@ void a4l_sg_init_triangular(struct waveform_config *config, 
double *values)
}
 }
 
-void a4l_sg_init_steps(struct waveform_config *config, double *values)
+void a4l_wf_init_steps(struct waveform_config *config, double *values)
 {
int i;

@@ -82,7 +82,7 @@ void a4l_sg_init_steps(struct waveform_config *config, double 
*values)
}
 }
 
-void a4l_sg_set_sample_count(struct waveform_config *config)
+void a4l_wf_set_sample_count(struct waveform_config *config)
 {
int sample_count = MIN_SAMPLE_COUNT;
int best_count = MIN_SAMPLE_COUNT;
@@ -116,7 +116,7 @@ void a4l_sg_set_sample_count(struct waveform_config *config)
config-spl_count = best_count;
 }
 
-int a4l_sg_check_config(struct waveform_config *config)
+int a4l_wf_check_config(struct waveform_config *config)
 {
 
if (config-wf_amplitude == 0)
@@ -134,18 +134,18 @@ int a4l_sg_check_config(struct waveform_config *config)
 }
 
 static void (* init_values[])(struct waveform_config *, double *) = {
-   a4l_sg_init_sine,
-   a4l_sg_init_sawtooth,
-   a4l_sg_init_triangular,
-   a4l_sg_init_steps,
+   a4l_wf_init_sine,
+   a4l_wf_init_sawtooth,
+   a4l_wf_init_triangular,
+   a4l_wf_init_steps,
 };
 
-void a4l_sg_init_values(struct waveform_config *config, double *values)
+void a4l_wf_init_values(struct waveform_config *config, double *values)
 {
init_values[config-wf_kind](config, values);
 }
 
-void a4l_sg_dump_values(struct waveform_config *config, double *values)
+void a4l_wf_dump_values(struct waveform_config *config, double *values)
 {
int i;

diff --git a/src/utils/analogy/wf_facilities.h 
b/src/utils/analogy/wf_facilities.h
index 6c99d51..7c9c705 100644
--- a/src/utils/analogy/wf_facilities.h
+++ b/src/utils/analogy/wf_facilities.h
@@ -24,13 +24,13 @@ struct waveform_config {
int spl_count;
 };
 
-void a4l_sg_init_sine(struct waveform_config *config, double *values);
-void a4l_sg_init_sawtooth(struct waveform_config *config, double *values);
-void a4l_sg_init_triangular(struct waveform_config *config, double *values);
-void a4l_sg_init_steps(struct waveform_config *config, double *values);
-void a4l_sg_set_sample_count(struct waveform_config *config);
-int 

[Xenomai-git] Alexis Berlemont : analogy: add verbose output in wf_generate tool

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 3c6f23ac964c7e897a4f82d0dbbed6a506edf779
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=3c6f23ac964c7e897a4f82d0dbbed6a506edf779

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Thu Dec  2 00:54:37 2010 +0100

analogy: add verbose output in wf_generate tool

---

 src/utils/analogy/wf_generate.c |   20 
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/utils/analogy/wf_generate.c b/src/utils/analogy/wf_generate.c
index 40e518b..97b19c9 100644
--- a/src/utils/analogy/wf_generate.c
+++ b/src/utils/analogy/wf_generate.c
@@ -208,6 +208,18 @@ int main(int argc, char *argv[])
goto out;
 
a4l_wf_set_sample_count(cfg.wf);
+
+   if (cfg.verbose) {
+   char *types[] = {sine, sawtooth, triangular, steps};
+   fprintf(stderr, Waveform type: %s\n, types[cfg.wf.wf_kind]);
+   fprintf(stderr, Amplitude: %F\n, cfg.wf.wf_amplitude);
+   fprintf(stderr, Frequency: %F\n, cfg.wf.wf_frequency);
+   fprintf(stderr, Offset: %F\n, cfg.wf.wf_offset);
+   fprintf(stderr, 
+   Sampling frequency: %F\n, cfg.wf.spl_frequency);
+   fprintf(stderr, Samples count: %d\n, cfg.wf.spl_count);
+   fprintf(stderr, Output file: %s\n, cfg.filename);
+   }

values = malloc(cfg.wf.spl_count * sizeof(double));
if (!values) {
@@ -225,6 +237,14 @@ int main(int argc, char *argv[])
goto out;
}   
 
+   if (cfg.verbose) {
+   int i;
+
+   fprintf(stderr, Dumping values:\n);
+   for (i = 0; i  cfg.wf.spl_count; i++)
+   fprintf(stderr, [%d]: %F\n, i, values[i]);
+   }
+
 out:
cleanup_config(cfg);
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: [fake] minor fix in attach parameters handling

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: b478fc816ab88bdefffde7aaffed4f80c4c50dc6
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=b478fc816ab88bdefffde7aaffed4f80c4c50dc6

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Fri Jan  7 00:39:53 2011 +0100

analogy: [fake] minor fix in attach parameters handling

---

 ksrc/drivers/analogy/testing/fake.c |9 +
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ksrc/drivers/analogy/testing/fake.c 
b/ksrc/drivers/analogy/testing/fake.c
index 803ff00..269981c 100644
--- a/ksrc/drivers/analogy/testing/fake.c
+++ b/ksrc/drivers/analogy/testing/fake.c
@@ -444,10 +444,11 @@ int test_attach(a4l_dev_t *dev, a4l_lnkdesc_t *arg)
 
a4l_dbg(1, drv_dbg, dev, starting attach procedure...\n);
 
-   if (arg-opts_size  sizeof(unsigned long)) {
-   priv-amplitude_div = 1;
-   priv-quanta_cnt = 1;
-   } else {
+   /* Set default values for attach parameters */
+   priv-amplitude_div = 1;
+   priv-quanta_cnt = 1;
+
+   if (arg-opts_size = sizeof(unsigned long)) {
unsigned long *args = (unsigned long *)arg-opts;
priv-amplitude_div = args[0];
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: implement the configuration of a wake-up threshold

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: deac8867bedda1ff284498f3b46435683ffe3bee
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=deac8867bedda1ff284498f3b46435683ffe3bee

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Tue May 10 23:54:25 2011 +0200

analogy: implement the configuration of a wake-up threshold

Two functions are now available to define a wake-up
threshold. a4l_set/get_wakesize() allows the developer to define the
minimal data amount needed to wake-up a sleeping process (waiting for
an event during an asynchronous acquisition).

---

 include/analogy/analogy.h |   80 --
 include/analogy/buffer.h  |   23 +
 include/analogy/ioctl.h   |7 ++-
 ksrc/drivers/analogy/buffer.c |   86 +---
 ksrc/drivers/analogy/rtdm_interface.c |8 ++-
 src/drvlib/analogy/async.c|   31 
 6 files changed, 185 insertions(+), 50 deletions(-)

diff --git a/include/analogy/analogy.h b/include/analogy/analogy.h
index 15736a8..6a81674 100644
--- a/include/analogy/analogy.h
+++ b/include/analogy/analogy.h
@@ -43,22 +43,22 @@ int a4l_sys_read(int fd, void *buf, size_t nbyte);
 
 int a4l_sys_write(int fd, void *buf, size_t nbyte);
 
-int a4l_sys_attach(int fd, a4l_lnkdesc_t * arg);
+int a4l_sys_attach(int fd, a4l_lnkdesc_t *arg);
 
 int a4l_sys_detach(int fd);
 
 int a4l_sys_bufcfg(int fd, unsigned int idx_subd, unsigned long size);
 
-int a4l_sys_desc(int fd, a4l_desc_t * dsc, int pass);
+int a4l_sys_desc(int fd, a4l_desc_t *dsc, int pass);
 
-int a4l_sys_devinfo(int fd, a4l_dvinfo_t * info);
+int a4l_sys_devinfo(int fd, a4l_dvinfo_t *info);
 
-int a4l_sys_subdinfo(int fd, a4l_sbinfo_t * info);
+int a4l_sys_subdinfo(int fd, a4l_sbinfo_t *info);
 
 int a4l_sys_nbchaninfo(int fd, unsigned int idx_subd, unsigned int *nb);
 
-int a4l_sys_chaninfo(int fd,
-unsigned int idx_subd, a4l_chinfo_t * info);
+int a4l_sys_chaninfo(int fd, 
+unsigned int idx_subd, a4l_chinfo_t *info);
 
 int a4l_sys_nbrnginfo(int fd,
  unsigned int idx_subd,
@@ -66,7 +66,7 @@ int a4l_sys_nbrnginfo(int fd,
 
 int a4l_sys_rnginfo(int fd,
unsigned int idx_subd,
-   unsigned int idx_chan, a4l_rnginfo_t * info);
+   unsigned int idx_chan, a4l_rnginfo_t *info);
 
 /* --- Level 1 API (supposed to be used) --- */
 
@@ -92,83 +92,87 @@ int a4l_get_chinfo(a4l_desc_t *dsc,
 int a4l_get_rnginfo(a4l_desc_t *dsc,
unsigned int subd,
unsigned int chan,
-   unsigned int rng, a4l_rnginfo_t ** info);
+   unsigned int rng, a4l_rnginfo_t **info);
 
 #define a4l_is_rng_global(x) ((x)-flags  A4L_RNG_GLOBAL)
 
-int a4l_snd_command(a4l_desc_t * dsc, a4l_cmd_t *cmd);
+int a4l_snd_command(a4l_desc_t *dsc, a4l_cmd_t *cmd);
+
+int a4l_snd_cancel(a4l_desc_t *dsc, unsigned int idx_subd);
 
-int a4l_snd_cancel(a4l_desc_t * dsc, unsigned int idx_subd);
-
-int a4l_set_bufsize(a4l_desc_t * dsc,
+int a4l_set_bufsize(a4l_desc_t *dsc,
unsigned int idx_subd, unsigned long size);
 
-int a4l_get_bufsize(a4l_desc_t * dsc,
+int a4l_get_bufsize(a4l_desc_t *dsc,
unsigned int idx_subd, unsigned long *size);
 
-int a4l_mark_bufrw(a4l_desc_t * dsc,
+int a4l_set_wakesize(a4l_desc_t *dsc, unsigned long size);
+
+int a4l_get_wakesize(a4l_desc_t *dsc, unsigned long *size);
+
+int a4l_mark_bufrw(a4l_desc_t *dsc,
   unsigned int idx_subd,
   unsigned long cur, unsigned long *newp);
 
-int a4l_poll(a4l_desc_t * dsc,
+int a4l_poll(a4l_desc_t *dsc,
 unsigned int idx_subd, unsigned long ms_timeout);
-
-int a4l_mmap(a4l_desc_t * dsc,
+
+int a4l_mmap(a4l_desc_t *dsc,
 unsigned int idx_subd, unsigned long size, void **ptr);
 
-int a4l_async_read(a4l_desc_t * dsc,
+int a4l_async_read(a4l_desc_t *dsc,
   void *buf, size_t nbyte, unsigned long ms_timeout);
 
-int a4l_async_write(a4l_desc_t * dsc,
+int a4l_async_write(a4l_desc_t *dsc,
void *buf, size_t nbyte, unsigned long ms_timeout);
 
-int a4l_snd_insnlist(a4l_desc_t * dsc, a4l_insnlst_t * arg);
+int a4l_snd_insnlist(a4l_desc_t *dsc, a4l_insnlst_t *arg);
 
-int a4l_snd_insn(a4l_desc_t * dsc, a4l_insn_t *arg);
+int a4l_snd_insn(a4l_desc_t *dsc, a4l_insn_t *arg);
 
 /* --- Level 2 API (supposed to be used) --- */
 
-int a4l_sync_write(a4l_desc_t * dsc,
+int a4l_sync_write(a4l_desc_t *dsc,
   unsigned int idx_subd,
   unsigned int chan_desc,
   unsigned int delay, void *buf, size_t nbyte);
-
-int a4l_sync_read(a4l_desc_t * dsc,
+   
+int a4l_sync_read(a4l_desc_t *dsc,
  unsigned int idx_subd,
  unsigned int chan_desc,
  unsigned int delay, void *buf, size_t nbyte);
 
-int 

[Xenomai-git] Alexis Berlemont : analogy: [fake] add instruction callbacks for the loop subdevices

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: c2058267b11a28026d959d4f033c6207a9d86058
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=c2058267b11a28026d959d4f033c6207a9d86058

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Sun Jan 30 22:59:10 2011 +0100

analogy: [fake] add instruction callbacks for the loop subdevices

---

 ksrc/drivers/analogy/testing/fake.c |   37 +++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/ksrc/drivers/analogy/testing/fake.c 
b/ksrc/drivers/analogy/testing/fake.c
index 4a8ce5a..d8f8cda 100644
--- a/ksrc/drivers/analogy/testing/fake.c
+++ b/ksrc/drivers/analogy/testing/fake.c
@@ -42,8 +42,11 @@ struct ai_priv {
 };
 
 struct ao_ai2_priv {
+   /* Asynchronous loop stuff */
uint8_t buffer[TRANSFER_SIZE];
int count;
+   /* Synchronous loop stuff */
+   uint16_t insn_value;
 };
 
 struct dio_priv {
@@ -388,6 +391,38 @@ static int dio_insn_bits(a4l_subd_t *subd, a4l_kinsn_t 
*insn)
return 0;
 }
 
+/* --- Synchronous AO + AI2 functions --- */
+
+int ao_insn_write(a4l_subd_t *subd, a4l_kinsn_t *insn)
+{
+   struct ao_ai2_priv *priv = (struct ao_ai2_priv *)subd-priv;
+   uint16_t *data = (uint16_t *)insn-data;
+
+   /* Checks the buffer size */
+   if (insn-data_size != sizeof(uint16_t))
+   return -EINVAL;
+
+   /* Retrieves the value to memorize */
+   priv-insn_value = data[0];
+   
+   return 0;
+}
+
+int ai2_insn_read(a4l_subd_t *subd, a4l_kinsn_t *insn)
+{
+   struct ao_ai2_priv *priv = *((struct ao_ai2_priv **)subd-priv);
+   uint16_t *data = (uint16_t *)insn-data;
+
+   /* Checks the buffer size */
+   if (insn-data_size != sizeof(uint16_t))
+   return -EINVAL;
+   
+   /* Sets the memorized value */
+   data[0] = priv-insn_value;
+   
+   return 0;
+}
+
 /* --- Initialization functions --- */
 
 void setup_ai_subd(a4l_subd_t *subd)
@@ -427,6 +462,7 @@ void setup_ao_subd(a4l_subd_t *subd)
subd-cancel = ao_cancel;
subd-trigger = ao_trigger;
subd-cmd_mask = ao_cmd_mask;
+   subd-insn_write = ao_insn_write;
 }
 
 void setup_ai2_subd(a4l_subd_t *subd)
@@ -440,6 +476,7 @@ void setup_ai2_subd(a4l_subd_t *subd)
subd-do_cmd = ai2_cmd;
subd-cancel = ai2_cancel;
subd-cmd_mask = ai_cmd_mask;
+   subd-insn_read = ai2_insn_read;
 }
 
 /* --- Attach / detach functions ---  */


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: minor fix in wf_generate

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: bd067c92943399d1e0d344a081f0f1eaf326d7ce
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=bd067c92943399d1e0d344a081f0f1eaf326d7ce

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Fri Jan 28 21:04:51 2011 +0100

analogy: minor fix in wf_generate

---

 src/utils/analogy/wf_generate.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/utils/analogy/wf_generate.c b/src/utils/analogy/wf_generate.c
index 97b19c9..0d311b8 100644
--- a/src/utils/analogy/wf_generate.c
+++ b/src/utils/analogy/wf_generate.c
@@ -199,9 +199,10 @@ int main(int argc, char *argv[])
int err = 0;
struct config cfg;
double *values = NULL;
-

err = init_config(cfg, argc, argv);
+   if (err  0)
+   goto out;
 
err = a4l_wf_check_config(cfg.wf);
if (err  0)


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: rename waveform files

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: cc4182fb3426cbca2e30e1a927acea648ef3dae6
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=cc4182fb3426cbca2e30e1a927acea648ef3dae6

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Mon Oct 18 07:53:19 2010 +0200

analogy: rename waveform files

---

 .../{signal_generation.c = wf_facilities.c}   |0 
 .../{signal_generation.h = wf_facilities.h}   |0 
 2 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/src/utils/analogy/signal_generation.c 
b/src/utils/analogy/wf_facilities.c
similarity index 100%
rename from src/utils/analogy/signal_generation.c
rename to src/utils/analogy/wf_facilities.c
diff --git a/src/utils/analogy/signal_generation.h 
b/src/utils/analogy/wf_facilities.h
similarity index 100%
rename from src/utils/analogy/signal_generation.h
rename to src/utils/analogy/wf_facilities.h


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: update cmd_read and cmd_write with a wake-count option

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: c80f2862b4b969a2df8957f8879241fa95731bf4
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=c80f2862b4b969a2df8957f8879241fa95731bf4

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Tue May 10 23:55:29 2011 +0200

analogy: update cmd_read and cmd_write with a wake-count option

---

 src/utils/analogy/cmd_read.c  |   22 +-
 src/utils/analogy/cmd_write.c |   32 +---
 2 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/src/utils/analogy/cmd_read.c b/src/utils/analogy/cmd_read.c
index e23bf9b..ff8bb48 100644
--- a/src/utils/analogy/cmd_read.c
+++ b/src/utils/analogy/cmd_read.c
@@ -54,6 +54,7 @@ static unsigned int chans[MAX_NB_CHAN];
 static int verbose = 0;
 static int real_time = 0;
 static int use_mmap = 0;
+static unsigned long wake_count = 0;
 
 static RT_TASK rt_task_desc;
 
@@ -84,6 +85,7 @@ struct option cmd_read_opts[] = {
{channels, required_argument, NULL, 'c'},
{mmap, no_argument, NULL, 'm'},
{raw, no_argument, NULL, 'w'},
+   {wake-count, required_argument, NULL, 'k'},
{help, no_argument, NULL, 'h'},
{0},
 };
@@ -101,6 +103,9 @@ void do_print_usage(void)
fprintf(stdout, \t\t -c, --channels: channels to use (ex.: -c 0,1)\n);
fprintf(stdout, \t\t -m, --mmap: mmap the buffer\n);
fprintf(stdout, \t\t -w, --raw: dump data in raw format\n);
+   fprintf(stdout, 
+   \t\t -k, --wake-count: 
+   space available before waking up the process\n);
fprintf(stdout, \t\t -h, --help: print this help\n);
 }
 
@@ -193,7 +198,8 @@ int main(int argc, char *argv[])
/* Compute arguments */
while ((ret = getopt_long(argc,
  argv,
- vrd:s:S:c:mwh, cmd_read_opts, NULL)) = 0) {
+ vrd:s:S:c:mwk:h, 
+ cmd_read_opts, NULL)) = 0) {
switch (ret) {
case 'v':
verbose = 1;
@@ -219,6 +225,9 @@ int main(int argc, char *argv[])
case 'w':
dump_function = dump_raw;
break;
+   case 'k':
+   wake_count = strtoul(optarg, NULL, 0);
+   break;
case 'h':
default:
do_print_usage();
@@ -368,6 +377,17 @@ int main(int argc, char *argv[])
 map);
}
 
+   ret = a4l_set_wakesize(dsc, wake_count);
+   if (ret  0) {
+   fprintf(stderr,
+   cmd_read: a4l_set_wakesize failed (ret=%d)\n, ret);
+   goto out_main;
+   }
+
+   if (verbose != 0)
+   printf(cmd_read: wake size successfully set (%lu)\n, 
+  wake_count);
+
/* Send the command to the input device */
ret = a4l_snd_command(dsc, cmd);
if (ret  0) {
diff --git a/src/utils/analogy/cmd_write.c b/src/utils/analogy/cmd_write.c
index 43926fd..453c033 100644
--- a/src/utils/analogy/cmd_write.c
+++ b/src/utils/analogy/cmd_write.c
@@ -44,7 +44,8 @@ struct config {
unsigned int *chans;
int chans_count;
char *str_ranges;
-   int scans_count;
+   unsigned long scans_count;
+   unsigned long wake_count;
 
char *filename;
FILE *input;
@@ -70,6 +71,7 @@ struct option options[] = {
{scans-count, required_argument, NULL, 'S'},
{channels, required_argument, NULL, 'c'},
{range, required_argument, NULL, 'c'},
+   {wake-count, required_argument, NULL, 'k'},
{help, no_argument, NULL, 'h'},
{0},
 };
@@ -84,11 +86,15 @@ void print_usage(void)
fprintf(stdout, \t\t -s, --subdevice: subdevice index\n);
fprintf(stdout, \t\t -S, --scans-count: count of scan to perform\n);
fprintf(stdout, 
-   \t\t -c, --channels: channels to use 
-   i,j,... (ex.: -c 0,1)\n);
+   \t\t -c, --channels: 
+   channels to use i,j,... (ex.: -c 0,1)\n);
fprintf(stdout, 
-   \t\t -R, --range: range to use 
-   min,max,unit (ex.: -R 0,1,V)\n);
+   \t\t -R, --range: 
+   range to use min,max,unit (ex.: -R 0,1,V)\n);
+   fprintf(stdout, 
+   \t\t -k, --wake-count: 
+   space available before waking up the process\n);
+
fprintf(stdout, \t\t -h, --help: print this help\n);
 }
 
@@ -242,7 +248,8 @@ void print_config(struct config *cfg)
printf(\tSubdevice index: %d\n, cfg-subd);
printf(\tSelected channels: %s\n, cfg-str_chans);
printf(\tSelected range: %s\n, cfg-str_ranges);
-   printf(\tScans count: %d\n, cfg-scans_count);
+   printf(\tScans count: %lu\n, cfg-scans_count);
+   printf(\tWake count: %lu\n, 

[Xenomai-git] Alexis Berlemont : analogy: add signal injection in the cmd_write tool

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 8eaf57fdb7242c4dba2cc820bc3f3228c74f2690
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=8eaf57fdb7242c4dba2cc820bc3f3228c74f2690

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Sun Apr 24 19:41:56 2011 +0200

analogy: add signal injection in the cmd_write tool

---

 src/utils/analogy/Makefile.am|7 -
 src/utils/analogy/cmd_write.c|  707 +-
 src/utils/analogy/wf_cmd_write.c |  501 ---
 src/utils/analogy/wf_generate.c  |3 +-
 4 files changed, 401 insertions(+), 817 deletions(-)

diff --git a/src/utils/analogy/Makefile.am b/src/utils/analogy/Makefile.am
index a2c3e96..8e7734f 100644
--- a/src/utils/analogy/Makefile.am
+++ b/src/utils/analogy/Makefile.am
@@ -3,7 +3,6 @@ sbin_PROGRAMS = analogy_config
 bin_PROGRAMS = \
cmd_read \
cmd_write \
-   wf_cmd_write \
cmd_bits \
insn_read \
insn_write \
@@ -43,12 +42,6 @@ cmd_write_LDADD = \
../../skins/rtdm/librtdm.la \
../../skins/common/libxenomai.la
 
-wf_cmd_write_SOURCES = wf_cmd_write.c
-wf_cmd_write_LDADD = \
-   ../../drvlib/analogy/libanalogy.la \
-   ../../skins/rtdm/librtdm.la \
-   ../../skins/common/libxenomai.la
-
 cmd_bits_SOURCES = cmd_bits.c
 cmd_bits_LDADD = \
../../drvlib/analogy/libanalogy.la \
diff --git a/src/utils/analogy/cmd_write.c b/src/utils/analogy/cmd_write.c
index 3b3f1ab..43926fd 100644
--- a/src/utils/analogy/cmd_write.c
+++ b/src/utils/analogy/cmd_write.c
@@ -28,74 +28,53 @@
 #include getopt.h
 #include string.h
 
-#include native/task.h
-
 #include analogy/analogy.h
 
-/* Default command's parameters */
-
-/* For write operation, we consider
-   the default subdevice index is 1 */
-#define ID_SUBD 1
-/* For simplicity sake, a maximum channel
-   count is defined */
-#define MAX_NB_CHAN 10
-/* Four channels used by default */
-#define NB_CHAN 4
-/* One hundred triggered scans by default */
-#define NB_SCAN 100
-
-#define FILENAME analogy0
-
-#define BUF_SIZE 1
-
-static unsigned char buf[BUF_SIZE];
-static char *filename = FILENAME;
-static char *str_chans = 0,1;
-static unsigned int chans[MAX_NB_CHAN];
-static int verbose = 0;
-static int real_time = 0;
-static int use_mmap = 0;
-
-static RT_TASK rt_task_desc;
-
-/* The command to send by default */
-a4l_cmd_t cmd = {
-   .idx_subd = ID_SUBD,
-   .flags = 0,
-   .start_src = TRIG_INT,
-   .start_arg = 0,
-   .scan_begin_src = TRIG_TIMER,
-   .scan_begin_arg = 200, /* in ns */
-   .convert_src = TRIG_NOW,
-   .convert_arg = 0, /* in ns */
-   .scan_end_src = TRIG_COUNT,
-   .scan_end_arg = 0,
-   .stop_src = TRIG_COUNT,
-   .stop_arg = NB_SCAN,
-   .nb_chan = 0,
-   .chan_descs = chans,
-};
+#define BUFFER_DEPTH 1024
+
+struct config {
+
+   /* Configuration parameters
+  TODO: add real_time and use_mmap*/
+
+   int verbose;
+   
+   int subd;
+   char *str_chans;
+   unsigned int *chans;
+   int chans_count;
+   char *str_ranges;
+   int scans_count;
+
+   char *filename;
+   FILE *input;
+
+   /* Analogy stuff */
+
+   a4l_desc_t dsc;
+   a4l_chinfo_t *cinfo;
+   a4l_rnginfo_t *rinfo;
+
+   /* Buffer stuff
+  TODO: add buffer depth / size (useful for mmap) */
+   void *buffer;
 
-a4l_insn_t insn = {
-   .type = A4L_INSN_INTTRIG,
-   .idx_subd = ID_SUBD,
-   .data_size = 0,
 };
 
-struct option cmd_write_opts[] = {
+/* --- Options / arguments part --- */
+
+struct option options[] = {
{verbose, no_argument, NULL, 'v'},
-   {real-time, no_argument, NULL, 'r'},
{device, required_argument, NULL, 'd'},
{subdevice, required_argument, NULL, 's'},
-   {scan-count, required_argument, NULL, 'S'},
+   {scans-count, required_argument, NULL, 'S'},
{channels, required_argument, NULL, 'c'},
-   {mmap, no_argument, NULL, 'm'},
+   {range, required_argument, NULL, 'c'},
{help, no_argument, NULL, 'h'},
{0},
 };
 
-void do_print_usage(void)
+void print_usage(void)
 {
fprintf(stdout, usage:\tcmd_write [OPTS]\n);
fprintf(stdout, \tOPTS:\t -v, --verbose: verbose output\n);
@@ -103,305 +82,419 @@ void do_print_usage(void)
\t\t -d, --device: 
device filename (analogy0, analogy1, ...)\n);
fprintf(stdout, \t\t -s, --subdevice: subdevice index\n);
-   fprintf(stdout, \t\t -S, --scan-count: count of scan to perform\n);
-   fprintf(stdout, \t\t -c, --channels: channels to use (ex.: -c 0,1)\n);
-   fprintf(stdout, \t\t -m, --mmap: mmap the buffer\n);
+   fprintf(stdout, \t\t -S, --scans-count: count of scan to perform\n);
+   fprintf(stdout, 
+   \t\t -c, --channels: channels to use 
+   i,j,... (ex.: -c 0,1)\n);
+   fprintf(stdout, 
+   \t\t -R, 

[Xenomai-git] Alexis Berlemont : analogy: minor changes

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 08d7468bd8e1cdd7377b9ce19689c00ab9132421
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=08d7468bd8e1cdd7377b9ce19689c00ab9132421

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Mon Oct 18 23:48:08 2010 +0200

analogy: minor changes

---

 src/utils/analogy/wf_facilities.c |4 +---
 src/utils/analogy/wf_facilities.h |2 --
 2 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/src/utils/analogy/wf_facilities.c 
b/src/utils/analogy/wf_facilities.c
index 2f443c5..ce250e7 100644
--- a/src/utils/analogy/wf_facilities.c
+++ b/src/utils/analogy/wf_facilities.c
@@ -4,9 +4,7 @@
 #include errno.h
 #include math.h
 
-#include analogy/analogy.h
-
-#include signal_generation.h
+#include wf_facilities.h
 
 #ifndef PI
 #define PI 3.14159265358979323846
diff --git a/src/utils/analogy/wf_facilities.h 
b/src/utils/analogy/wf_facilities.h
index 6f6d2cf..6c99d51 100644
--- a/src/utils/analogy/wf_facilities.h
+++ b/src/utils/analogy/wf_facilities.h
@@ -3,8 +3,6 @@
 
 #include stdio.h
 
-#include analogy/analogy.h
-
 #define MAX_SAMPLE_COUNT 8096
 #define MIN_SAMPLE_COUNT 2
 


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git


[Xenomai-git] Alexis Berlemont : analogy: 1st rework of fake driver

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: 4b673b0579110b801417c96db39558c7255f3b1c
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=4b673b0579110b801417c96db39558c7255f3b1c

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Thu Jan  6 00:37:11 2011 +0100

analogy: 1st rework of fake driver

The goal is to remove loop testing driver; fake integrates now three
subdevices to reproduce the loop behaviour. The implementation is
cleaner and that will help validate the waveform tools.

---

 ksrc/drivers/analogy/testing/fake.c |  331 +++
 1 files changed, 260 insertions(+), 71 deletions(-)

diff --git a/ksrc/drivers/analogy/testing/fake.c 
b/ksrc/drivers/analogy/testing/fake.c
index c8e8682..803ff00 100644
--- a/ksrc/drivers/analogy/testing/fake.c
+++ b/ksrc/drivers/analogy/testing/fake.c
@@ -1,24 +1,34 @@
 #include linux/module.h
 #include analogy/analogy_driver.h
 
-#define AI_TASK_PERIOD 100
+#define TASK_PERIOD 100
 
 #define AI_SUBD 0
 #define DIO_SUBD 1
+#define AO_SUBD 2
+#define AI2_SUBD 3
+
+#define TRANSFER_SIZE 0x1000
 
 /* --- Driver related structures --- */
 
 struct fake_priv {
-   /* Configuration parameters */
+   /* Attach configuration parameters 
+  (they should be relocated in ai_priv) */
unsigned long amplitude_div;
unsigned long quanta_cnt;
-};
-
-struct ai_priv {
 
/* Task descriptor */
-   a4l_task_t timer_task;
+   a4l_task_t task;
 
+   /* Statuses of the asynchronous subdevices */
+   int ai_running;
+   int ao_running;
+   int ai2_running;
+};
+
+struct ai_priv {
+  
/* Specific timing fields */
unsigned long scan_period_ns;
unsigned long convert_period_ns;
@@ -29,8 +39,11 @@ struct ai_priv {
/* Misc fields */
unsigned long amplitude_div;
unsigned long quanta_cnt;
-   int timer_running;
+};
 
+struct ao_ai2_priv {
+   uint8_t buffer[TRANSFER_SIZE];
+   int count;
 };
 
 struct dio_priv {
@@ -40,8 +53,9 @@ struct dio_priv {
 
 /* --- Channels / ranges part --- */
 
-/* Channels descriptor */
-static a4l_chdesc_t ai_chandesc = {
+/* Channels descriptors */
+
+static a4l_chdesc_t analog_chandesc = {
.mode = A4L_CHAN_GLOBAL_CHANDESC,
.length = 8,
.chans = {
@@ -58,7 +72,7 @@ static a4l_chdesc_t dio_chandesc = {
 };
 
 /* Ranges tab */
-static a4l_rngtab_t ai_rngtab = {
+static a4l_rngtab_t analog_rngtab = {
.length = 2,
.rngs = {
RANGE_V(-5,5),
@@ -66,10 +80,11 @@ static a4l_rngtab_t ai_rngtab = {
},
 };
 /* Ranges descriptor */
-static a4l_rngdesc_t ai_rngdesc = RNG_GLOBAL(ai_rngtab);
+static a4l_rngdesc_t analog_rngdesc = RNG_GLOBAL(analog_rngtab);
+
+/* Command options masks */
 
-/* Command options mask */
-static a4l_cmd_t test_cmd_mask = {
+static a4l_cmd_t ai_cmd_mask = {
.idx_subd = 0,
.start_src = TRIG_NOW,
.scan_begin_src = TRIG_TIMER,
@@ -78,9 +93,20 @@ static a4l_cmd_t test_cmd_mask = {
.stop_src = TRIG_COUNT|TRIG_NONE,
 };
 
+static a4l_cmd_t ao_cmd_mask = {
+   .idx_subd = 0,
+   .start_src = TRIG_NOW | TRIG_INT,
+   .scan_begin_src = TRIG_TIMER,
+   .convert_src = TRIG_NOW | TRIG_TIMER,
+   .scan_end_src = TRIG_COUNT,
+   .stop_src = TRIG_COUNT| TRIG_NONE,
+};
+
 /* --- Analog input simulation --- */
 
-static uint16_t ai_value_output(struct ai_priv *priv)
+/* --- Values generation for 1st AI --- */
+
+static inline uint16_t ai_value_output(struct ai_priv *priv)
 {
static uint16_t output_tab[8] = {
0x0001, 0x2000, 0x4000, 0x6000,
@@ -104,76 +130,137 @@ static uint16_t ai_value_output(struct ai_priv *priv)
return output_tab[idx] / priv-amplitude_div;
 }
 
-/* --- Task part --- */
-
-/* Timer task routine */
-static void ai_task_proc(void *arg)
+int ai_push_values(a4l_subd_t *subd)
 {
-   a4l_subd_t *subd = (a4l_subd_t *)arg;
struct ai_priv *priv = (struct ai_priv *)subd-priv;
-   a4l_cmd_t *cmd = NULL;
-   uint64_t now_ns, elapsed_ns=0;
+   a4l_cmd_t *cmd = a4l_get_cmd(subd);
+   uint64_t now_ns, elapsed_ns = 0;
+   int i = 0;
+
+   if (!cmd)
+   return -EPIPE;
+   
+   now_ns = a4l_get_time();
+   elapsed_ns += now_ns - priv-last_ns + priv-reminder_ns;
+   priv-last_ns = now_ns;
+
+   while(elapsed_ns = priv-scan_period_ns) {
+   int j;
+   
+   for(j = 0; j  cmd-nb_chan; j++) {
+   uint16_t value = ai_value_output(priv);
+   a4l_buf_put(subd, value, sizeof(uint16_t));
+   }
+   
+   elapsed_ns -= priv-scan_period_ns;
+   i++;
+   }  
 
-   while(1) {
-   int running;
+   priv-current_ns += i * priv-scan_period_ns;
+   priv-reminder_ns = elapsed_ns;
+
+   if (i 

[Xenomai-git] Alexis Berlemont : analogy: various basic bug fixes in wf_cmd_write

2011-05-12 Thread GIT version control
Module: xenomai-abe
Branch: experimental
Commit: ce8488a882eee58476a3eabb6db1934427da0c19
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=ce8488a882eee58476a3eabb6db1934427da0c19

Author: Alexis Berlemont alexis.berlem...@gmail.com
Date:   Sun Mar  6 00:51:46 2011 +0100

analogy: various basic bug fixes in wf_cmd_write

- Properly set the default ranges values
- Fix return code after reading stdin data
- Wait 1s after writing the data and before leaving

---

 src/utils/analogy/wf_cmd_write.c |   22 +++---
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/utils/analogy/wf_cmd_write.c b/src/utils/analogy/wf_cmd_write.c
index 38e0c29..6a4d507 100644
--- a/src/utils/analogy/wf_cmd_write.c
+++ b/src/utils/analogy/wf_cmd_write.c
@@ -263,7 +263,7 @@ int init_config(struct config *cfg, int argc, char *argv[])
 
memset(cfg, 0, sizeof(struct config));
cfg-str_chans = 0,1;
-   cfg-str_chans = 0,5,V;
+   cfg-str_ranges = 0,5,V;
cfg-filename = analogy0; 
cfg-input = stdin;
cfg-dsc.fd = -1;
@@ -364,8 +364,9 @@ int process_stdin(struct config *cfg)
 
/* Data from stdin are supposed to be double values
   coming from wf_generate... */
+
err = fread(value, sizeof(double), 1, cfg-input);
-   if (err != 0  !feof(cfg-input)) {
+   if (err != 1  !feof(cfg-input)) {
err = -errno;
fprintf(stderr, 
cmd_write: stdin IO error (err=%d)\n, err);
@@ -392,7 +393,10 @@ int process_stdin(struct config *cfg)
filled ++;
}
 
-   if (filled) {
+out:
+
+   if (err = 0  filled) {
+
err = a4l_async_write(cfg-dsc, 
  cfg-buffer, 
  filled * scan_size, A4L_INFINITE);
@@ -400,10 +404,10 @@ int process_stdin(struct config *cfg)
fprintf(stderr, 
cmd_write: a4l_async_write failed (err=%d)\n,
err);
-   }
+   } else if (err = 0  !filled)
+   err = -ENOENT;

-out:
-   return err;
+   return err  0 ? err : 0;
 }
 
 int init_acquisition(struct config *cfg)
@@ -476,8 +480,12 @@ int main(int argc, char *argv[])
 
while ((err = process_stdin(cfg)) == 0);
 
+   err = (err == -ENOENT) ? 0 : err;
+
+   sleep(1);
+
 out:
cleanup_config(cfg);

-   return err;
+   return err  0 ? 1 : 0;
 }


___
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git