net: buf: Add net_buf_simple_init_with_data

This adds net_bug_simple_init_with_data which can be used to initialize
a net_buf_simple pointer with an external data pointer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-11-10 17:07:20 +02:00 committed by Johan Hedberg
commit 53784479b3
2 changed files with 22 additions and 4 deletions

View file

@ -140,6 +140,18 @@ static inline void net_buf_simple_init(struct net_buf_simple *buf,
buf->len = 0U; buf->len = 0U;
} }
/**
* @brief Initialize a net_buf_simple object with data.
*
* Initialized buffer object with external data.
*
* @param buf Buffer to initialize.
* @param data External data pointer
* @param size Amount of data the pointed data buffer if able to fit.
*/
void net_buf_simple_init_with_data(struct net_buf_simple *buf,
void *data, size_t size);
/** /**
* @brief Reset buffer * @brief Reset buffer
* *

View file

@ -385,10 +385,7 @@ struct net_buf *net_buf_alloc_with_data(struct net_buf_pool *pool,
return NULL; return NULL;
} }
buf->__buf = data; net_buf_simple_init_with_data(&buf->b, data, size);
buf->data = data;
buf->size = size;
buf->len = size;
buf->flags = NET_BUF_EXTERNAL_DATA; buf->flags = NET_BUF_EXTERNAL_DATA;
return buf; return buf;
@ -427,6 +424,15 @@ struct net_buf *net_buf_get(struct k_fifo *fifo, s32_t timeout)
return buf; return buf;
} }
void net_buf_simple_init_with_data(struct net_buf_simple *buf,
void *data, size_t size)
{
buf->__buf = data;
buf->data = data;
buf->size = size;
buf->len = size;
}
void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve) void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve)
{ {
NET_BUF_ASSERT(buf); NET_BUF_ASSERT(buf);