Re: Spliting u16, u32 to u8 array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

> I am sure at least some of you were faced to split a u16 or u32 value
> in u8 array without being affected by host endianness. My search
> turned empty for a standardized function for this task, but this seems
> quite improbable. My task is to send 16 bit LE data through i2c.
> 
> I am looking for something like:
> static void u16_to_u8_array(u16 value, u8 *array)
> {
>         *array = cpu_to_le16(value) >> 8;
>         *(++array) = (u8) cpu_to_le16(value);
> }

how about

static void u16_to_le16_array(u16 value, __le16 *array)
{
	*array++ = cpu_to_le16(value);
}

and calling it with a cast if need be, such as

char *u8array;
u16_to_le16_array(123, (__le16 *) u8array)

an issue could be alignment of the u8array

I'd try to avoid u8 altogether and work with le16 as a datatype

p.

-- 

Peter Meerwald
+43-664-2444418 (mobile)
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux