diff options
Diffstat (limited to 'drivers/staging/iio/Documentation/generic_buffer.c')
-rw-r--r-- | drivers/staging/iio/Documentation/generic_buffer.c | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c index df23aeb9d529..3cc18ab4ebfd 100644 --- a/drivers/staging/iio/Documentation/generic_buffer.c +++ b/drivers/staging/iio/Documentation/generic_buffer.c @@ -26,11 +26,9 @@ #include <sys/stat.h> #include <sys/dir.h> #include <linux/types.h> +#include <string.h> #include "iio_utils.h" -const int buf_len = 128; -const int num_loops = 2; - /** * size_from_channelarray() - calculate the storage size of a scan * @channels: the channel info array @@ -118,6 +116,11 @@ void process_scan(char *data, int main(int argc, char **argv) { + unsigned long num_loops = 2; + unsigned long timedelay = 1000000; + unsigned long buf_len = 128; + + int ret, c, i, j, toread; FILE *fp_ev; @@ -134,10 +137,12 @@ int main(int argc, char **argv) int dev_num, trig_num; char *buffer_access, *buffer_event; int scan_size; + int noevents = 0; + char *dummy; struct iio_channel_info *infoarray; - while ((c = getopt(argc, argv, "t:n:")) != -1) { + while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) { switch (c) { case 'n': device_name = optarg; @@ -146,11 +151,26 @@ int main(int argc, char **argv) trigger_name = optarg; datardytrigger = 0; break; + case 'e': + noevents = 1; + break; + case 'c': + num_loops = strtoul(optarg, &dummy, 10); + break; + case 'w': + timedelay = strtoul(optarg, &dummy, 10); + break; + case 'l': + buf_len = strtoul(optarg, &dummy, 10); + break; case '?': return -1; } } + if (device_name == NULL) + return -1; + /* Find the device requested */ dev_num = find_type_by_name(device_name, "device"); if (dev_num < 0) { @@ -260,22 +280,30 @@ int main(int argc, char **argv) /* Wait for events 10 times */ for (j = 0; j < num_loops; j++) { - read_size = fread(&dat, 1, sizeof(struct iio_event_data), - fp_ev); - switch (dat.id) { - case IIO_EVENT_CODE_RING_100_FULL: - toread = buf_len; - break; - case IIO_EVENT_CODE_RING_75_FULL: - toread = buf_len*3/4; - break; - case IIO_EVENT_CODE_RING_50_FULL: - toread = buf_len/2; - break; - default: - printf("Unexpecteded event code\n"); - continue; + if (!noevents) { + read_size = fread(&dat, + 1, + sizeof(struct iio_event_data), + fp_ev); + switch (dat.id) { + case IIO_EVENT_CODE_RING_100_FULL: + toread = buf_len; + break; + case IIO_EVENT_CODE_RING_75_FULL: + toread = buf_len*3/4; + break; + case IIO_EVENT_CODE_RING_50_FULL: + toread = buf_len/2; + break; + default: + printf("Unexpecteded event code\n"); + continue; + } + } else { + usleep(timedelay); + toread = 64; } + read_size = read(fp, data, toread*scan_size); |