[Xenomai-git] Alexis Berlemont : analogy: review the conversion routines in the user library
Module: xenomai-head Branch: master Commit: cca3eaa0adf25bc27bba449601c7d01a0080e495 URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=cca3eaa0adf25bc27bba449601c7d01a0080e495 Author: Alexis Berlemont Date: Sat Dec 19 20:59:09 2009 +0100 analogy: review the conversion routines in the user library The conversion routines (raw data from driver <-> physical values: V, mA) did not behave well with specific acquisition widths (12 and 24 bits). Furthermore, there was an ambiguity in the functions declarations; the functions are now more explicit. --- include/analogy/analogy.h | 40 +++-- src/drvlib/analogy/range.c | 335 +++- src/utils/analogy/insn_read.c | 180 +- src/utils/analogy/insn_write.c |8 +- 4 files changed, 466 insertions(+), 97 deletions(-) diff --git a/include/analogy/analogy.h b/include/analogy/analogy.h index 79bd69c..bc778b1 100644 --- a/include/analogy/analogy.h +++ b/include/analogy/analogy.h @@ -68,33 +68,33 @@ int a4l_sys_rnginfo(int fd, /* --- Level 1 API (supposed to be used) --- */ -int a4l_get_desc(int fd, a4l_desc_t * dsc, int pass); +int a4l_get_desc(int fd, a4l_desc_t *dsc, int pass); -int a4l_open(a4l_desc_t * dsc, const char *fname); +int a4l_open(a4l_desc_t *dsc, const char *fname); -int a4l_close(a4l_desc_t * dsc); +int a4l_close(a4l_desc_t *dsc); -int a4l_fill_desc(a4l_desc_t * dsc); +int a4l_fill_desc(a4l_desc_t *dsc); -int a4l_get_subdinfo(a4l_desc_t * dsc, -unsigned int subd, a4l_sbinfo_t ** info); +int a4l_get_subdinfo(a4l_desc_t *dsc, +unsigned int subd, a4l_sbinfo_t **info); -int a4l_get_chinfo(a4l_desc_t * dsc, +int a4l_get_chinfo(a4l_desc_t *dsc, unsigned int subd, - unsigned int chan, a4l_chinfo_t ** info); + unsigned int chan, a4l_chinfo_t **info); #define a4l_get_chan_max(x) (1ULL << (x)->nb_bits) #define a4l_is_chan_global(x) ((x)->chan_flags & A4L_CHAN_GLOBAL) -int a4l_get_rnginfo(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); #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); @@ -116,7 +116,7 @@ int a4l_mmap(a4l_desc_t * dsc, 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) --- */ @@ -138,11 +138,21 @@ int a4l_find_range(a4l_desc_t * dsc, unsigned long unit, double min, double max, a4l_rnginfo_t ** rng); -int a4l_from_phys(a4l_chinfo_t * chan, - a4l_rnginfo_t * rng, double *dst, void *src, int cnt); +int a4l_rawtoul(a4l_chinfo_t * chan, unsigned long *dst, void *src, int cnt); -int a4l_to_phys(a4l_chinfo_t * chan, - a4l_rnginfo_t * rng, void *dst, double *src, int cnt); +int a4l_rawtof(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, float *dst, void *src, int cnt); + +int a4l_rawtod(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, double *dst, void *src, int cnt); + +int a4l_ultoraw(a4l_chinfo_t * chan, void *dst, unsigned long *src, int cnt); + +int a4l_ftoraw(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, void *dst, float *src, int cnt); + +int a4l_dtoraw(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, void *dst, double *src, int cnt); #endif /* !DOXYGEN_CPP */ diff --git a/src/drvlib/analogy/range.c b/src/drvlib/analogy/range.c index 05615bd..9490c71 100644 --- a/src/drvlib/analogy/range.c +++ b/src/drvlib/analogy/range.c @@ -96,7 +96,6 @@ int a4l_sizeof_chan(a4l_chinfo_t * chan) return (i == 3) ? -EINVAL : sizes[i] / 8; } - /** * @brief Find the must suitable range * @@ -175,7 +174,71 @@ out_get_range: } /** - * @brief Convert physical units to samples + * @brief Unpack raw data (from the driver) into unsigned long values + * + * This function takes as input driver-specific data and scatters each + * element into an entry of an unsigned long table. It is a + * convenience routine which performs no conversion, just copy. + * + * @param[in] chan Channel descriptor + * @param[in] rng Range descriptor + * @param[out] dst Ouput buffer + * @param[in] src Input buffer + * @param[in] cnt Count of transfer to copy + * + * @return the count of copy performed, otherwise a negative error + * code: + * + * - -EINVAL is returned if some argument is missing or wrong; + *chan, rng and the pointers should be checked; check also the + *kernel log ("dmesg"); WARNING: a4l_fill_desc() should be called + *before using a4
[Xenomai-git] Alexis Berlemont : analogy: review the conversion routines in the user library
Module: xenomai-abe Branch: analogy Commit: cca3eaa0adf25bc27bba449601c7d01a0080e495 URL: http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=cca3eaa0adf25bc27bba449601c7d01a0080e495 Author: Alexis Berlemont Date: Sat Dec 19 20:59:09 2009 +0100 analogy: review the conversion routines in the user library The conversion routines (raw data from driver <-> physical values: V, mA) did not behave well with specific acquisition widths (12 and 24 bits). Furthermore, there was an ambiguity in the functions declarations; the functions are now more explicit. --- include/analogy/analogy.h | 40 +++-- src/drvlib/analogy/range.c | 335 +++- src/utils/analogy/insn_read.c | 180 +- src/utils/analogy/insn_write.c |8 +- 4 files changed, 466 insertions(+), 97 deletions(-) diff --git a/include/analogy/analogy.h b/include/analogy/analogy.h index 79bd69c..bc778b1 100644 --- a/include/analogy/analogy.h +++ b/include/analogy/analogy.h @@ -68,33 +68,33 @@ int a4l_sys_rnginfo(int fd, /* --- Level 1 API (supposed to be used) --- */ -int a4l_get_desc(int fd, a4l_desc_t * dsc, int pass); +int a4l_get_desc(int fd, a4l_desc_t *dsc, int pass); -int a4l_open(a4l_desc_t * dsc, const char *fname); +int a4l_open(a4l_desc_t *dsc, const char *fname); -int a4l_close(a4l_desc_t * dsc); +int a4l_close(a4l_desc_t *dsc); -int a4l_fill_desc(a4l_desc_t * dsc); +int a4l_fill_desc(a4l_desc_t *dsc); -int a4l_get_subdinfo(a4l_desc_t * dsc, -unsigned int subd, a4l_sbinfo_t ** info); +int a4l_get_subdinfo(a4l_desc_t *dsc, +unsigned int subd, a4l_sbinfo_t **info); -int a4l_get_chinfo(a4l_desc_t * dsc, +int a4l_get_chinfo(a4l_desc_t *dsc, unsigned int subd, - unsigned int chan, a4l_chinfo_t ** info); + unsigned int chan, a4l_chinfo_t **info); #define a4l_get_chan_max(x) (1ULL << (x)->nb_bits) #define a4l_is_chan_global(x) ((x)->chan_flags & A4L_CHAN_GLOBAL) -int a4l_get_rnginfo(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); #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); @@ -116,7 +116,7 @@ int a4l_mmap(a4l_desc_t * dsc, 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) --- */ @@ -138,11 +138,21 @@ int a4l_find_range(a4l_desc_t * dsc, unsigned long unit, double min, double max, a4l_rnginfo_t ** rng); -int a4l_from_phys(a4l_chinfo_t * chan, - a4l_rnginfo_t * rng, double *dst, void *src, int cnt); +int a4l_rawtoul(a4l_chinfo_t * chan, unsigned long *dst, void *src, int cnt); -int a4l_to_phys(a4l_chinfo_t * chan, - a4l_rnginfo_t * rng, void *dst, double *src, int cnt); +int a4l_rawtof(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, float *dst, void *src, int cnt); + +int a4l_rawtod(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, double *dst, void *src, int cnt); + +int a4l_ultoraw(a4l_chinfo_t * chan, void *dst, unsigned long *src, int cnt); + +int a4l_ftoraw(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, void *dst, float *src, int cnt); + +int a4l_dtoraw(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, void *dst, double *src, int cnt); #endif /* !DOXYGEN_CPP */ diff --git a/src/drvlib/analogy/range.c b/src/drvlib/analogy/range.c index 05615bd..9490c71 100644 --- a/src/drvlib/analogy/range.c +++ b/src/drvlib/analogy/range.c @@ -96,7 +96,6 @@ int a4l_sizeof_chan(a4l_chinfo_t * chan) return (i == 3) ? -EINVAL : sizes[i] / 8; } - /** * @brief Find the must suitable range * @@ -175,7 +174,71 @@ out_get_range: } /** - * @brief Convert physical units to samples + * @brief Unpack raw data (from the driver) into unsigned long values + * + * This function takes as input driver-specific data and scatters each + * element into an entry of an unsigned long table. It is a + * convenience routine which performs no conversion, just copy. + * + * @param[in] chan Channel descriptor + * @param[in] rng Range descriptor + * @param[out] dst Ouput buffer + * @param[in] src Input buffer + * @param[in] cnt Count of transfer to copy + * + * @return the count of copy performed, otherwise a negative error + * code: + * + * - -EINVAL is returned if some argument is missing or wrong; + *chan, rng and the pointers should be checked; check also the + *kernel log ("dmesg"); WARNING: a4l_fill_desc() should be called + *before using a4l
[Xenomai-git] Alexis Berlemont : analogy: review the conversion routines in the user library
Module: xenomai-abe Branch: analogy Commit: b161ffb3e8410d10389bcc963b6b48157c1458e0 URL: http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=b161ffb3e8410d10389bcc963b6b48157c1458e0 Author: Alexis Berlemont Date: Sat Dec 19 20:59:09 2009 +0100 analogy: review the conversion routines in the user library The conversion routines (raw data from driver <-> physical values: V, mA) did not behave well with specific acquisition widths (12 and 24 bits). Furthermore, there was an ambiguity in the functions declarations; the functions are now more explicit. --- include/analogy/analogy.h | 40 +++-- src/drvlib/analogy/range.c | 335 +++- src/utils/analogy/insn_read.c | 180 +- src/utils/analogy/insn_write.c |8 +- 4 files changed, 466 insertions(+), 97 deletions(-) diff --git a/include/analogy/analogy.h b/include/analogy/analogy.h index 79bd69c..bc778b1 100644 --- a/include/analogy/analogy.h +++ b/include/analogy/analogy.h @@ -68,33 +68,33 @@ int a4l_sys_rnginfo(int fd, /* --- Level 1 API (supposed to be used) --- */ -int a4l_get_desc(int fd, a4l_desc_t * dsc, int pass); +int a4l_get_desc(int fd, a4l_desc_t *dsc, int pass); -int a4l_open(a4l_desc_t * dsc, const char *fname); +int a4l_open(a4l_desc_t *dsc, const char *fname); -int a4l_close(a4l_desc_t * dsc); +int a4l_close(a4l_desc_t *dsc); -int a4l_fill_desc(a4l_desc_t * dsc); +int a4l_fill_desc(a4l_desc_t *dsc); -int a4l_get_subdinfo(a4l_desc_t * dsc, -unsigned int subd, a4l_sbinfo_t ** info); +int a4l_get_subdinfo(a4l_desc_t *dsc, +unsigned int subd, a4l_sbinfo_t **info); -int a4l_get_chinfo(a4l_desc_t * dsc, +int a4l_get_chinfo(a4l_desc_t *dsc, unsigned int subd, - unsigned int chan, a4l_chinfo_t ** info); + unsigned int chan, a4l_chinfo_t **info); #define a4l_get_chan_max(x) (1ULL << (x)->nb_bits) #define a4l_is_chan_global(x) ((x)->chan_flags & A4L_CHAN_GLOBAL) -int a4l_get_rnginfo(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); #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); @@ -116,7 +116,7 @@ int a4l_mmap(a4l_desc_t * dsc, 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) --- */ @@ -138,11 +138,21 @@ int a4l_find_range(a4l_desc_t * dsc, unsigned long unit, double min, double max, a4l_rnginfo_t ** rng); -int a4l_from_phys(a4l_chinfo_t * chan, - a4l_rnginfo_t * rng, double *dst, void *src, int cnt); +int a4l_rawtoul(a4l_chinfo_t * chan, unsigned long *dst, void *src, int cnt); -int a4l_to_phys(a4l_chinfo_t * chan, - a4l_rnginfo_t * rng, void *dst, double *src, int cnt); +int a4l_rawtof(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, float *dst, void *src, int cnt); + +int a4l_rawtod(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, double *dst, void *src, int cnt); + +int a4l_ultoraw(a4l_chinfo_t * chan, void *dst, unsigned long *src, int cnt); + +int a4l_ftoraw(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, void *dst, float *src, int cnt); + +int a4l_dtoraw(a4l_chinfo_t * chan, + a4l_rnginfo_t * rng, void *dst, double *src, int cnt); #endif /* !DOXYGEN_CPP */ diff --git a/src/drvlib/analogy/range.c b/src/drvlib/analogy/range.c index 05615bd..9490c71 100644 --- a/src/drvlib/analogy/range.c +++ b/src/drvlib/analogy/range.c @@ -96,7 +96,6 @@ int a4l_sizeof_chan(a4l_chinfo_t * chan) return (i == 3) ? -EINVAL : sizes[i] / 8; } - /** * @brief Find the must suitable range * @@ -175,7 +174,71 @@ out_get_range: } /** - * @brief Convert physical units to samples + * @brief Unpack raw data (from the driver) into unsigned long values + * + * This function takes as input driver-specific data and scatters each + * element into an entry of an unsigned long table. It is a + * convenience routine which performs no conversion, just copy. + * + * @param[in] chan Channel descriptor + * @param[in] rng Range descriptor + * @param[out] dst Ouput buffer + * @param[in] src Input buffer + * @param[in] cnt Count of transfer to copy + * + * @return the count of copy performed, otherwise a negative error + * code: + * + * - -EINVAL is returned if some argument is missing or wrong; + *chan, rng and the pointers should be checked; check also the + *kernel log ("dmesg"); WARNING: a4l_fill_desc() should be called + *before using a4l