ble_mesh: Add push functions for supported bit-variants [Zephyr]

Add push functions for bit-widths supported by add and pull functions.
This commit is contained in:
lly 2020-03-26 10:49:07 +08:00 committed by bot
parent 0522ce7cf3
commit bb09078b65
2 changed files with 240 additions and 0 deletions

View File

@ -382,6 +382,94 @@ void net_buf_simple_push_be16(struct net_buf_simple *buf, u16_t val);
*/ */
void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val); void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val);
/**
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le24(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be24(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le32(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be32(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le48(struct net_buf_simple *buf, u64_t val);
/**
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be48(struct net_buf_simple *buf, u64_t val);
/**
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le64(struct net_buf_simple *buf, u64_t val);
/**
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be64(struct net_buf_simple *buf, u64_t val);
/** /**
* @brief Remove data from the beginning of the buffer. * @brief Remove data from the beginning of the buffer.
* *
@ -1179,6 +1267,102 @@ static inline void *net_buf_user_data(struct net_buf *buf)
*/ */
#define net_buf_push_u8(buf, val) net_buf_simple_push_u8(&(buf)->b, val) #define net_buf_push_u8(buf, val) net_buf_simple_push_u8(&(buf)->b, val)
/**
* @def net_buf_push_le24
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
#define net_buf_push_le24(buf, val) net_buf_simple_push_le24(&(buf)->b, val)
/**
* @def net_buf_push_be24
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
#define net_buf_push_be24(buf, val) net_buf_simple_push_be24(&(buf)->b, val)
/**
* @def net_buf_push_le32
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
#define net_buf_push_le32(buf, val) net_buf_simple_push_le32(&(buf)->b, val)
/**
* @def net_buf_push_be32
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
#define net_buf_push_be32(buf, val) net_buf_simple_push_be32(&(buf)->b, val)
/**
* @def net_buf_push_le48
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
#define net_buf_push_le48(buf, val) net_buf_simple_push_le48(&(buf)->b, val)
/**
* @def net_buf_push_be48
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
#define net_buf_push_be48(buf, val) net_buf_simple_push_be48(&(buf)->b, val)
/**
* @def net_buf_push_le64
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
#define net_buf_push_le64(buf, val) net_buf_simple_push_le64(&(buf)->b, val)
/**
* @def net_buf_push_be64
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
#define net_buf_push_be64(buf, val) net_buf_simple_push_be64(&(buf)->b, val)
/** /**
* @def net_buf_pull * @def net_buf_pull
* @brief Remove data from the beginning of the buffer. * @brief Remove data from the beginning of the buffer.

View File

@ -176,6 +176,62 @@ void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val)
*data = val; *data = val;
} }
void net_buf_simple_push_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_push(buf, 3));
}
void net_buf_simple_push_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_push(buf, 3));
}
void net_buf_simple_push_le32(struct net_buf_simple *buf, u32_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
sys_put_le32(val, net_buf_simple_push(buf, sizeof(val)));
}
void net_buf_simple_push_be32(struct net_buf_simple *buf, u32_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
sys_put_be32(val, net_buf_simple_push(buf, sizeof(val)));
}
void net_buf_simple_push_le48(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_le48(val, net_buf_simple_push(buf, 6));
}
void net_buf_simple_push_be48(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_be48(val, net_buf_simple_push(buf, 6));
}
void net_buf_simple_push_le64(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_le64(val, net_buf_simple_push(buf, sizeof(val)));
}
void net_buf_simple_push_be64(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_be64(val, net_buf_simple_push(buf, sizeof(val)));
}
void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len) void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len)
{ {
NET_BUF_SIMPLE_DBG("buf %p len %u", buf, len); NET_BUF_SIMPLE_DBG("buf %p len %u", buf, len);