staging: iio: generic_buffer cleanup
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
b42f2a0c65
commit
d8da0eeed7
|
@ -33,8 +33,8 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* size_from_channelarray() - calculate the storage size of a scan
|
* size_from_channelarray() - calculate the storage size of a scan
|
||||||
* @channels: the channel info array
|
* @channels: the channel info array
|
||||||
* @num_channels: size of the channel info array
|
* @num_channels: number of channels
|
||||||
*
|
*
|
||||||
* Has the side effect of filling the channels[i].location values used
|
* Has the side effect of filling the channels[i].location values used
|
||||||
* in processing the buffer output.
|
* in processing the buffer output.
|
||||||
|
@ -58,14 +58,15 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
|
||||||
void print2byte(int input, struct iio_channel_info *info)
|
void print2byte(int input, struct iio_channel_info *info)
|
||||||
{
|
{
|
||||||
/* First swap if incorrect endian */
|
/* First swap if incorrect endian */
|
||||||
|
|
||||||
if (info->be)
|
if (info->be)
|
||||||
input = be16toh((uint16_t)input);
|
input = be16toh((uint16_t)input);
|
||||||
else
|
else
|
||||||
input = le16toh((uint16_t)input);
|
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;
|
input = input >> info->shift;
|
||||||
if (info->is_signed) {
|
if (info->is_signed) {
|
||||||
int16_t val = input;
|
int16_t val = input;
|
||||||
|
@ -82,39 +83,39 @@ void print2byte(int input, struct iio_channel_info *info)
|
||||||
/**
|
/**
|
||||||
* process_scan() - print out the values in SI units
|
* process_scan() - print out the values in SI units
|
||||||
* @data: pointer to the start of the scan
|
* @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
|
* size_from_channelarray must have been called first to fill the
|
||||||
* location offsets.
|
* location offsets.
|
||||||
* @num_channels: the number of active channels
|
* @num_channels: number of channels
|
||||||
**/
|
**/
|
||||||
void process_scan(char *data,
|
void process_scan(char *data,
|
||||||
struct iio_channel_info *infoarray,
|
struct iio_channel_info *channels,
|
||||||
int num_channels)
|
int num_channels)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
for (k = 0; k < num_channels; k++)
|
for (k = 0; k < num_channels; k++)
|
||||||
switch (infoarray[k].bytes) {
|
switch (channels[k].bytes) {
|
||||||
/* only a few cases implemented so far */
|
/* only a few cases implemented so far */
|
||||||
case 2:
|
case 2:
|
||||||
print2byte(*(uint16_t *)(data + infoarray[k].location),
|
print2byte(*(uint16_t *)(data + channels[k].location),
|
||||||
&infoarray[k]);
|
&channels[k]);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
if (infoarray[k].is_signed) {
|
if (channels[k].is_signed) {
|
||||||
int64_t val = *(int64_t *)
|
int64_t val = *(int64_t *)
|
||||||
(data +
|
(data +
|
||||||
infoarray[k].location);
|
channels[k].location);
|
||||||
if ((val >> infoarray[k].bits_used) & 1)
|
if ((val >> channels[k].bits_used) & 1)
|
||||||
val = (val & infoarray[k].mask) |
|
val = (val & channels[k].mask) |
|
||||||
~infoarray[k].mask;
|
~channels[k].mask;
|
||||||
/* special case for timestamp */
|
/* special case for timestamp */
|
||||||
if (infoarray[k].scale == 1.0f &&
|
if (channels[k].scale == 1.0f &&
|
||||||
infoarray[k].offset == 0.0f)
|
channels[k].offset == 0.0f)
|
||||||
printf(" %lld", val);
|
printf(" %lld", val);
|
||||||
else
|
else
|
||||||
printf("%05f ", ((float)val +
|
printf("%05f ", ((float)val +
|
||||||
infoarray[k].offset)*
|
channels[k].offset)*
|
||||||
infoarray[k].scale);
|
channels[k].scale);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -129,7 +130,6 @@ int main(int argc, char **argv)
|
||||||
unsigned long timedelay = 1000000;
|
unsigned long timedelay = 1000000;
|
||||||
unsigned long buf_len = 128;
|
unsigned long buf_len = 128;
|
||||||
|
|
||||||
|
|
||||||
int ret, c, i, j, toread;
|
int ret, c, i, j, toread;
|
||||||
int fp;
|
int fp;
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ int main(int argc, char **argv)
|
||||||
int noevents = 0;
|
int noevents = 0;
|
||||||
char *dummy;
|
char *dummy;
|
||||||
|
|
||||||
struct iio_channel_info *infoarray;
|
struct iio_channel_info *channels;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) {
|
while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -189,7 +189,7 @@ int main(int argc, char **argv)
|
||||||
asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
|
asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
|
||||||
if (trigger_name == NULL) {
|
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
|
* name is <device_name>_dev[n] where n matches the device
|
||||||
* number found above
|
* number found above
|
||||||
*/
|
*/
|
||||||
|
@ -214,7 +214,7 @@ int main(int argc, char **argv)
|
||||||
* Parse the files in scan_elements to identify what channels are
|
* Parse the files in scan_elements to identify what channels are
|
||||||
* present
|
* present
|
||||||
*/
|
*/
|
||||||
ret = build_channel_array(dev_dir_name, &infoarray, &num_channels);
|
ret = build_channel_array(dev_dir_name, &channels, &num_channels);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("Problem reading scan element information\n");
|
printf("Problem reading scan element information\n");
|
||||||
printf("diag %s\n", dev_dir_name);
|
printf("diag %s\n", dev_dir_name);
|
||||||
|
@ -233,7 +233,7 @@ int main(int argc, char **argv)
|
||||||
goto error_free_triggername;
|
goto error_free_triggername;
|
||||||
}
|
}
|
||||||
printf("%s %s\n", dev_dir_name, trigger_name);
|
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",
|
ret = write_sysfs_string_and_verify("trigger/current_trigger",
|
||||||
dev_dir_name,
|
dev_dir_name,
|
||||||
trigger_name);
|
trigger_name);
|
||||||
|
@ -251,7 +251,7 @@ int main(int argc, char **argv)
|
||||||
ret = write_sysfs_int("enable", buf_dir_name, 1);
|
ret = write_sysfs_int("enable", buf_dir_name, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error_free_buf_dir_name;
|
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);
|
data = malloc(scan_size*buf_len);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
@ -266,7 +266,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* Attempt to open non blocking the access dev */
|
/* Attempt to open non blocking the access dev */
|
||||||
fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
|
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);
|
printf("Failed to open %s\n", buffer_access);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
goto error_free_buffer_access;
|
goto error_free_buffer_access;
|
||||||
|
@ -297,16 +297,16 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
for (i = 0; i < read_size/scan_size; i++)
|
for (i = 0; i < read_size/scan_size; i++)
|
||||||
process_scan(data + scan_size*i,
|
process_scan(data + scan_size*i,
|
||||||
infoarray,
|
channels,
|
||||||
num_channels);
|
num_channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the ring buffer */
|
/* Stop the buffer */
|
||||||
ret = write_sysfs_int("enable", buf_dir_name, 0);
|
ret = write_sysfs_int("enable", buf_dir_name, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error_close_buffer_access;
|
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",
|
write_sysfs_string("trigger/current_trigger",
|
||||||
dev_dir_name, "NULL");
|
dev_dir_name, "NULL");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue