Commit 117cf8b7 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:generic_buffer example - handle endian differences

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a7f7c364
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <string.h> #include <string.h>
#include <poll.h> #include <poll.h>
#include <endian.h>
#include "iio_utils.h" #include "iio_utils.h"
/** /**
...@@ -56,6 +57,13 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels) ...@@ -56,6 +57,13 @@ 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 */
if (info->be)
input = be16toh((uint_16t)input);
else
input = le16toh((uint_16t)input);
/* shift before conversion to avoid sign extension /* shift before conversion to avoid sign extension
of left aligned data */ of left aligned data */
input = input >> info->shift; input = input >> info->shift;
......
...@@ -74,6 +74,7 @@ struct iio_channel_info { ...@@ -74,6 +74,7 @@ struct iio_channel_info {
unsigned bits_used; unsigned bits_used;
unsigned shift; unsigned shift;
uint64_t mask; uint64_t mask;
unsigned be;
unsigned is_signed; unsigned is_signed;
unsigned enabled; unsigned enabled;
unsigned location; unsigned location;
...@@ -84,6 +85,7 @@ struct iio_channel_info { ...@@ -84,6 +85,7 @@ struct iio_channel_info {
* @is_signed: output whether channel is signed * @is_signed: output whether channel is signed
* @bytes: output how many bytes the channel storage occupies * @bytes: output how many bytes the channel storage occupies
* @mask: output a bit mask for the raw data * @mask: output a bit mask for the raw data
* @be: big endian
* @device_dir: the iio device directory * @device_dir: the iio device directory
* @name: the channel name * @name: the channel name
* @generic_name: the channel type name * @generic_name: the channel type name
...@@ -93,6 +95,7 @@ inline int iioutils_get_type(unsigned *is_signed, ...@@ -93,6 +95,7 @@ inline int iioutils_get_type(unsigned *is_signed,
unsigned *bits_used, unsigned *bits_used,
unsigned *shift, unsigned *shift,
uint64_t *mask, uint64_t *mask,
unsigned *be,
const char *device_dir, const char *device_dir,
const char *name, const char *name,
const char *generic_name) const char *generic_name)
...@@ -101,7 +104,7 @@ inline int iioutils_get_type(unsigned *is_signed, ...@@ -101,7 +104,7 @@ inline int iioutils_get_type(unsigned *is_signed,
int ret; int ret;
DIR *dp; DIR *dp;
char *scan_el_dir, *builtname, *builtname_generic, *filename = 0; char *scan_el_dir, *builtname, *builtname_generic, *filename = 0;
char signchar; char signchar, endianchar;
unsigned padint; unsigned padint;
const struct dirent *ent; const struct dirent *ent;
...@@ -156,6 +159,7 @@ inline int iioutils_get_type(unsigned *is_signed, ...@@ -156,6 +159,7 @@ inline int iioutils_get_type(unsigned *is_signed,
printf("failed to pass scan type description\n"); printf("failed to pass scan type description\n");
return ret; return ret;
} }
*be = (endianchar == 'b');
*bytes = padint / 8; *bytes = padint / 8;
if (*bits_used == 64) if (*bits_used == 64)
*mask = ~0; *mask = ~0;
...@@ -399,6 +403,7 @@ inline int build_channel_array(const char *device_dir, ...@@ -399,6 +403,7 @@ inline int build_channel_array(const char *device_dir,
&current->bits_used, &current->bits_used,
&current->shift, &current->shift,
&current->mask, &current->mask,
&current->be,
device_dir, device_dir,
current->name, current->name,
current->generic_name); current->generic_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment