net: buf: Add support for 24 bit data type
This enables pulling and pushing values in 24 bit format. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
7747033fee
commit
4c06a9f577
2 changed files with 138 additions and 0 deletions
|
@ -243,6 +243,30 @@ void net_buf_simple_add_le16(struct net_buf_simple *buf, u16_t val);
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_add_be16(struct net_buf_simple *buf, u16_t val);
|
void net_buf_simple_add_be16(struct net_buf_simple *buf, u16_t val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add 24-bit value at the end of the buffer
|
||||||
|
*
|
||||||
|
* Adds 24-bit value in little endian format at the end of buffer.
|
||||||
|
* Increments the data length of a buffer to account for more data
|
||||||
|
* at the end.
|
||||||
|
*
|
||||||
|
* @param buf Buffer to update.
|
||||||
|
* @param val 24-bit value to be added.
|
||||||
|
*/
|
||||||
|
void net_buf_simple_add_le24(struct net_buf_simple *buf, u32_t val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add 24-bit value at the end of the buffer
|
||||||
|
*
|
||||||
|
* Adds 24-bit value in big endian format at the end of buffer.
|
||||||
|
* Increments the data length of a buffer to account for more data
|
||||||
|
* at the end.
|
||||||
|
*
|
||||||
|
* @param buf Buffer to update.
|
||||||
|
* @param val 24-bit value to be added.
|
||||||
|
*/
|
||||||
|
void net_buf_simple_add_be24(struct net_buf_simple *buf, u32_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add 32-bit value at the end of the buffer
|
* @brief Add 32-bit value at the end of the buffer
|
||||||
*
|
*
|
||||||
|
@ -374,6 +398,30 @@ u16_t net_buf_simple_pull_le16(struct net_buf_simple *buf);
|
||||||
*/
|
*/
|
||||||
u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf);
|
u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove and convert 24 bits from the beginning of the buffer.
|
||||||
|
*
|
||||||
|
* Same idea as with net_buf_simple_pull(), but a helper for operating
|
||||||
|
* on 24-bit little endian data.
|
||||||
|
*
|
||||||
|
* @param buf A valid pointer on a buffer.
|
||||||
|
*
|
||||||
|
* @return 24-bit value converted from little endian to host endian.
|
||||||
|
*/
|
||||||
|
u32_t net_buf_simple_pull_le24(struct net_buf_simple *buf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove and convert 24 bits from the beginning of the buffer.
|
||||||
|
*
|
||||||
|
* Same idea as with net_buf_simple_pull(), but a helper for operating
|
||||||
|
* on 24-bit big endian data.
|
||||||
|
*
|
||||||
|
* @param buf A valid pointer on a buffer.
|
||||||
|
*
|
||||||
|
* @return 24-bit value converted from big endian to host endian.
|
||||||
|
*/
|
||||||
|
u32_t net_buf_simple_pull_be24(struct net_buf_simple *buf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
||||||
*
|
*
|
||||||
|
@ -1112,6 +1160,32 @@ static inline void *net_buf_user_data(const struct net_buf *buf)
|
||||||
*/
|
*/
|
||||||
#define net_buf_add_be16(buf, val) net_buf_simple_add_be16(&(buf)->b, val)
|
#define net_buf_add_be16(buf, val) net_buf_simple_add_be16(&(buf)->b, val)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def net_buf_add_le24
|
||||||
|
* @brief Add 24-bit value at the end of the buffer
|
||||||
|
*
|
||||||
|
* Adds 24-bit value in little endian format at the end of buffer.
|
||||||
|
* Increments the data length of a buffer to account for more data
|
||||||
|
* at the end.
|
||||||
|
*
|
||||||
|
* @param buf Buffer to update.
|
||||||
|
* @param val 24-bit value to be added.
|
||||||
|
*/
|
||||||
|
#define net_buf_add_le24(buf, val) net_buf_simple_add_le24(&(buf)->b, val)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def net_buf_add_be24
|
||||||
|
* @brief Add 24-bit value at the end of the buffer
|
||||||
|
*
|
||||||
|
* Adds 24-bit value in big endian format at the end of buffer.
|
||||||
|
* Increments the data length of a buffer to account for more data
|
||||||
|
* at the end.
|
||||||
|
*
|
||||||
|
* @param buf Buffer to update.
|
||||||
|
* @param val 24-bit value to be added.
|
||||||
|
*/
|
||||||
|
#define net_buf_add_be24(buf, val) net_buf_simple_add_be24(&(buf)->b, val)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def net_buf_add_le32
|
* @def net_buf_add_le32
|
||||||
* @brief Add 32-bit value at the end of the buffer
|
* @brief Add 32-bit value at the end of the buffer
|
||||||
|
@ -1254,6 +1328,32 @@ static inline void *net_buf_user_data(const struct net_buf *buf)
|
||||||
*/
|
*/
|
||||||
#define net_buf_pull_be16(buf) net_buf_simple_pull_be16(&(buf)->b)
|
#define net_buf_pull_be16(buf) net_buf_simple_pull_be16(&(buf)->b)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def net_buf_pull_le24
|
||||||
|
* @brief Remove and convert 24 bits from the beginning of the buffer.
|
||||||
|
*
|
||||||
|
* Same idea as with net_buf_pull(), but a helper for operating on
|
||||||
|
* 24-bit little endian data.
|
||||||
|
*
|
||||||
|
* @param buf A valid pointer on a buffer.
|
||||||
|
*
|
||||||
|
* @return 24-bit value converted from little endian to host endian.
|
||||||
|
*/
|
||||||
|
#define net_buf_pull_le24(buf) net_buf_simple_pull_le24(&(buf)->b)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def net_buf_pull_be24
|
||||||
|
* @brief Remove and convert 24 bits from the beginning of the buffer.
|
||||||
|
*
|
||||||
|
* Same idea as with net_buf_pull(), but a helper for operating on
|
||||||
|
* 24-bit big endian data.
|
||||||
|
*
|
||||||
|
* @param buf A valid pointer on a buffer.
|
||||||
|
*
|
||||||
|
* @return 24-bit value converted from big endian to host endian.
|
||||||
|
*/
|
||||||
|
#define net_buf_pull_be24(buf) net_buf_simple_pull_be24(&(buf)->b)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def net_buf_pull_le32
|
* @def net_buf_pull_le32
|
||||||
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
||||||
|
|
|
@ -818,6 +818,20 @@ void net_buf_simple_add_be16(struct net_buf_simple *buf, u16_t val)
|
||||||
sys_put_be16(val, net_buf_simple_add(buf, sizeof(val)));
|
sys_put_be16(val, net_buf_simple_add(buf, sizeof(val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void net_buf_simple_add_le24(struct net_buf_simple *buf, u32_t val)
|
||||||
|
{
|
||||||
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
sys_put_le24(val, net_buf_simple_add(buf, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_buf_simple_add_be24(struct net_buf_simple *buf, u32_t val)
|
||||||
|
{
|
||||||
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
sys_put_be24(val, net_buf_simple_add(buf, 3));
|
||||||
|
}
|
||||||
|
|
||||||
void net_buf_simple_add_le32(struct net_buf_simple *buf, u32_t val)
|
void net_buf_simple_add_le32(struct net_buf_simple *buf, u32_t val)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
@ -918,6 +932,30 @@ u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf)
|
||||||
return sys_be16_to_cpu(val);
|
return sys_be16_to_cpu(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32_t net_buf_simple_pull_le24(struct net_buf_simple *buf)
|
||||||
|
{
|
||||||
|
struct uint24 {
|
||||||
|
u32_t u24:24;
|
||||||
|
} __packed val;
|
||||||
|
|
||||||
|
val = UNALIGNED_GET((struct uint24 *)buf->data);
|
||||||
|
net_buf_simple_pull(buf, sizeof(val));
|
||||||
|
|
||||||
|
return sys_le24_to_cpu(val.u24);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32_t net_buf_simple_pull_be24(struct net_buf_simple *buf)
|
||||||
|
{
|
||||||
|
struct uint24 {
|
||||||
|
u32_t u24:24;
|
||||||
|
} __packed val;
|
||||||
|
|
||||||
|
val = UNALIGNED_GET((struct uint24 *)buf->data);
|
||||||
|
net_buf_simple_pull(buf, sizeof(val));
|
||||||
|
|
||||||
|
return sys_be24_to_cpu(val.u24);
|
||||||
|
}
|
||||||
|
|
||||||
u32_t net_buf_simple_pull_le32(struct net_buf_simple *buf)
|
u32_t net_buf_simple_pull_le32(struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
u32_t val;
|
u32_t val;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue