summaryrefslogtreecommitdiff
path: root/drivers/staging/iio/Documentation/generic_buffer.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-26 18:14:49 (GMT)
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-26 18:14:49 (GMT)
commitb13bc8dda81c54a66a1c84e66f60b8feba659f28 (patch)
tree100a26eada424fa5d9b0e5eaaf4e23b8fa036fc8 /drivers/staging/iio/Documentation/generic_buffer.c
parent9fc377799bc9bfd8d5cb35d0d1ea2e2458cbdbb3 (diff)
parent419e9266884fa853179ab726c27a63a9d3ae46e3 (diff)
downloadlinux-fsl-qoriq-b13bc8dda81c54a66a1c84e66f60b8feba659f28.tar.xz
Merge tag 'staging-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging tree patches from Greg Kroah-Hartman: "Here's the big staging tree merge for the 3.6-rc1 merge window. There are some patches in here outside of drivers/staging/, notibly the iio code (which is still stradeling the staging / not staging boundry), the pstore code, and the tracing code. All of these have gotten acks from the various subsystem maintainers to be included in this tree. The pstore and tracing patches are related, and are coming here as they replace one of the android staging drivers. Otherwise, the normal staging mess. Lots of cleanups and a few new drivers (some iio drivers, and the large csr wireless driver abomination.) Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>" Fixed up trivial conflicts in drivers/staging/comedi/drivers/s626.h and drivers/staging/gdm72xx/netlink_k.c * tag 'staging-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (1108 commits) staging: csr: delete a bunch of unused library functions staging: csr: remove csr_utf16.c staging: csr: remove csr_pmem.h staging: csr: remove CsrPmemAlloc staging: csr: remove CsrPmemFree() staging: csr: remove CsrMemAllocDma() staging: csr: remove CsrMemCalloc() staging: csr: remove CsrMemAlloc() staging: csr: remove CsrMemFree() and CsrMemFreeDma() staging: csr: remove csr_util.h staging: csr: remove CsrOffSetOf() stating: csr: remove unneeded #includes in csr_util.c staging: csr: make CsrUInt16ToHex static staging: csr: remove CsrMemCpy() staging: csr: remove CsrStrLen() staging: csr: remove CsrVsnprintf() staging: csr: remove CsrStrDup staging: csr: remove CsrStrChr() staging: csr: remove CsrStrNCmp staging: csr: remove CsrStrCmp ...
Diffstat (limited to 'drivers/staging/iio/Documentation/generic_buffer.c')
-rw-r--r--drivers/staging/iio/Documentation/generic_buffer.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c
index bf55335..827e92d 100644
--- a/drivers/staging/iio/Documentation/generic_buffer.c
+++ b/drivers/staging/iio/Documentation/generic_buffer.c
@@ -18,6 +18,8 @@
*
*/
+#define _GNU_SOURCE
+
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
@@ -29,12 +31,14 @@
#include <string.h>
#include <poll.h>
#include <endian.h>
+#include <getopt.h>
+#include <inttypes.h>
#include "iio_utils.h"
/**
* size_from_channelarray() - calculate the storage size of a scan
- * @channels: the channel info array
- * @num_channels: size of the channel info array
+ * @channels: the channel info array
+ * @num_channels: number of channels
*
* Has the side effect of filling the channels[i].location values used
* in processing the buffer output.
@@ -58,22 +62,22 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
void print2byte(int input, struct iio_channel_info *info)
{
/* First swap if incorrect endian */
-
if (info->be)
input = be16toh((uint16_t)input);
else
input = le16toh((uint16_t)input);
- /* shift before conversion to avoid sign extension
- of left aligned data */
+ /*
+ * Shift before conversion to avoid sign extension
+ * of left aligned data
+ */
input = input >> info->shift;
if (info->is_signed) {
int16_t val = input;
val &= (1 << info->bits_used) - 1;
val = (int16_t)(val << (16 - info->bits_used)) >>
(16 - info->bits_used);
- printf("%05f ", val,
- (float)(val + info->offset)*info->scale);
+ printf("%05f ", ((float)val + info->offset)*info->scale);
} else {
uint16_t val = input;
val &= (1 << info->bits_used) - 1;
@@ -83,39 +87,39 @@ void print2byte(int input, struct iio_channel_info *info)
/**
* process_scan() - print out the values in SI units
* @data: pointer to the start of the scan
- * @infoarray: information about the channels. Note
+ * @channels: information about the channels. Note
* size_from_channelarray must have been called first to fill the
* location offsets.
- * @num_channels: the number of active channels
+ * @num_channels: number of channels
**/
void process_scan(char *data,
- struct iio_channel_info *infoarray,
+ struct iio_channel_info *channels,
int num_channels)
{
int k;
for (k = 0; k < num_channels; k++)
- switch (infoarray[k].bytes) {
+ switch (channels[k].bytes) {
/* only a few cases implemented so far */
case 2:
- print2byte(*(uint16_t *)(data + infoarray[k].location),
- &infoarray[k]);
+ print2byte(*(uint16_t *)(data + channels[k].location),
+ &channels[k]);
break;
case 8:
- if (infoarray[k].is_signed) {
+ if (channels[k].is_signed) {
int64_t val = *(int64_t *)
(data +
- infoarray[k].location);
- if ((val >> infoarray[k].bits_used) & 1)
- val = (val & infoarray[k].mask) |
- ~infoarray[k].mask;
+ channels[k].location);
+ if ((val >> channels[k].bits_used) & 1)
+ val = (val & channels[k].mask) |
+ ~channels[k].mask;
/* special case for timestamp */
- if (infoarray[k].scale == 1.0f &&
- infoarray[k].offset == 0.0f)
- printf(" %lld", val);
+ if (channels[k].scale == 1.0f &&
+ channels[k].offset == 0.0f)
+ printf("%" PRId64 " ", val);
else
printf("%05f ", ((float)val +
- infoarray[k].offset)*
- infoarray[k].scale);
+ channels[k].offset)*
+ channels[k].scale);
}
break;
default:
@@ -130,10 +134,7 @@ int main(int argc, char **argv)
unsigned long timedelay = 1000000;
unsigned long buf_len = 128;
-
int ret, c, i, j, toread;
-
- FILE *fp_ev;
int fp;
int num_channels;
@@ -149,7 +150,7 @@ int main(int argc, char **argv)
int noevents = 0;
char *dummy;
- struct iio_channel_info *infoarray;
+ struct iio_channel_info *channels;
while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) {
switch (c) {
@@ -192,7 +193,7 @@ int main(int argc, char **argv)
asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
if (trigger_name == NULL) {
/*
- * Build the trigger name. If it is device associated it's
+ * Build the trigger name. If it is device associated its
* name is <device_name>_dev[n] where n matches the device
* number found above
*/
@@ -217,7 +218,7 @@ int main(int argc, char **argv)
* Parse the files in scan_elements to identify what channels are
* present
*/
- ret = build_channel_array(dev_dir_name, &infoarray, &num_channels);
+ ret = build_channel_array(dev_dir_name, &channels, &num_channels);
if (ret) {
printf("Problem reading scan element information\n");
printf("diag %s\n", dev_dir_name);
@@ -236,7 +237,7 @@ int main(int argc, char **argv)
goto error_free_triggername;
}
printf("%s %s\n", dev_dir_name, trigger_name);
- /* Set the device trigger to be the data rdy trigger found above */
+ /* Set the device trigger to be the data ready trigger found above */
ret = write_sysfs_string_and_verify("trigger/current_trigger",
dev_dir_name,
trigger_name);
@@ -254,7 +255,7 @@ int main(int argc, char **argv)
ret = write_sysfs_int("enable", buf_dir_name, 1);
if (ret < 0)
goto error_free_buf_dir_name;
- scan_size = size_from_channelarray(infoarray, num_channels);
+ scan_size = size_from_channelarray(channels, num_channels);
data = malloc(scan_size*buf_len);
if (!data) {
ret = -ENOMEM;
@@ -269,7 +270,7 @@ int main(int argc, char **argv)
/* Attempt to open non blocking the access dev */
fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
- if (fp == -1) { /*If it isn't there make the node */
+ if (fp == -1) { /* If it isn't there make the node */
printf("Failed to open %s\n", buffer_access);
ret = -errno;
goto error_free_buffer_access;
@@ -300,16 +301,16 @@ int main(int argc, char **argv)
}
for (i = 0; i < read_size/scan_size; i++)
process_scan(data + scan_size*i,
- infoarray,
+ channels,
num_channels);
}
- /* Stop the ring buffer */
+ /* Stop the buffer */
ret = write_sysfs_int("enable", buf_dir_name, 0);
if (ret < 0)
goto error_close_buffer_access;
- /* Disconnect from the trigger - just write a dummy name.*/
+ /* Disconnect the trigger - just write a dummy name. */
write_sysfs_string("trigger/current_trigger",
dev_dir_name, "NULL");