diff --git a/include/net/buf.h b/include/net/buf.h index 097626579a34..c010ac673fca 100644 --- a/include/net/buf.h +++ b/include/net/buf.h @@ -22,9 +22,8 @@ #include #include -#include #include -#include +#include #ifdef __cplusplus extern "C" { @@ -407,7 +406,7 @@ struct net_buf { uint8_t flags; /** Where the buffer should go when freed up. */ - struct nano_fifo * const free; + struct k_fifo * const free; /** Function to be called when the buffer is freed. */ void (*const destroy)(struct net_buf *buf); @@ -447,7 +446,7 @@ struct net_buf { * * If provided with a custom destroy callback this callback is * responsible for eventually returning the buffer back to the free - * buffers FIFO through nano_fifo_put(buf->free, buf). + * buffers FIFO through k_fifo_put(buf->free, buf). * * @param _name Name of buffer pool. * @param _count Number of buffers in the pool. @@ -483,10 +482,10 @@ struct net_buf { do { \ int i; \ \ - nano_fifo_init(pool[0].buf.free); \ + k_fifo_init(pool[0].buf.free); \ \ for (i = 0; i < ARRAY_SIZE(pool); i++) { \ - nano_fifo_put(pool[i].buf.free, &pool[i]); \ + k_fifo_put(pool[i].buf.free, &pool[i]); \ } \ } while (0) @@ -506,9 +505,9 @@ struct net_buf { * @warning If there are no available buffers and the function is * called from a task or fiber the call will block until a buffer * becomes available in the FIFO. If you want to make sure no blocking - * happens use net_buf_get_timeout() instead with TICKS_NONE. + * happens use net_buf_get_timeout() instead with K_NO_WAIT. */ -struct net_buf *net_buf_get(struct nano_fifo *fifo, size_t reserve_head); +struct net_buf *net_buf_get(struct k_fifo *fifo, size_t reserve_head); /** * @brief Get a new buffer from a FIFO. @@ -521,13 +520,13 @@ struct net_buf *net_buf_get(struct nano_fifo *fifo, size_t reserve_head); * @param fifo Which FIFO to take the buffer from. * @param reserve_head How much headroom to reserve. * @param timeout Affects the action taken should the FIFO be empty. - * If TICKS_NONE, then return immediately. If TICKS_UNLIMITED, then - * wait as long as necessary. Otherwise, wait up to the specified - * number of ticks before timing out. + * If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as + * long as necessary. Otherwise, wait up to the specified number of + * miliseconds before timing out. * * @return New buffer or NULL if out of buffers. */ -struct net_buf *net_buf_get_timeout(struct nano_fifo *fifo, +struct net_buf *net_buf_get_timeout(struct k_fifo *fifo, size_t reserve_head, int32_t timeout); /** @@ -551,7 +550,7 @@ void net_buf_reserve(struct net_buf *buf, size_t reserve); * @param fifo Which FIFO to put the buffer to. * @param buf Buffer. */ -void net_buf_put(struct nano_fifo *fifo, struct net_buf *buf); +void net_buf_put(struct k_fifo *fifo, struct net_buf *buf); /** * @brief Decrements the reference count of a buffer. diff --git a/net/buf.c b/net/buf.c index a6422866bfeb..f1a28504ab42 100644 --- a/net/buf.c +++ b/net/buf.c @@ -16,8 +16,6 @@ * limitations under the License. */ -#include -#include #include #include #include @@ -50,7 +48,7 @@ #define NET_BUF_ASSERT(cond) #endif /* CONFIG_NET_BUF_DEBUG */ -struct net_buf *net_buf_get_timeout(struct nano_fifo *fifo, +struct net_buf *net_buf_get_timeout(struct k_fifo *fifo, size_t reserve_head, int32_t timeout) { struct net_buf *buf, *frag; @@ -58,7 +56,7 @@ struct net_buf *net_buf_get_timeout(struct nano_fifo *fifo, NET_BUF_DBG("fifo %p reserve %u timeout %d", fifo, reserve_head, timeout); - buf = nano_fifo_get(fifo, timeout); + buf = k_fifo_get(fifo, timeout); if (!buf) { NET_BUF_ERR("Failed to get free buffer"); return NULL; @@ -82,7 +80,7 @@ struct net_buf *net_buf_get_timeout(struct nano_fifo *fifo, /* Get any fragments belonging to this buffer */ for (frag = buf; (frag->flags & NET_BUF_FRAGS); frag = frag->frags) { - frag->frags = nano_fifo_get(fifo, TICKS_NONE); + frag->frags = k_fifo_get(fifo, K_NO_WAIT); NET_BUF_ASSERT(frag->frags); /* The fragments flag is only for FIFO-internal usage */ @@ -95,20 +93,20 @@ struct net_buf *net_buf_get_timeout(struct nano_fifo *fifo, return buf; } -struct net_buf *net_buf_get(struct nano_fifo *fifo, size_t reserve_head) +struct net_buf *net_buf_get(struct k_fifo *fifo, size_t reserve_head) { struct net_buf *buf; NET_BUF_DBG("fifo %p reserve %u", fifo, reserve_head); - buf = net_buf_get_timeout(fifo, reserve_head, TICKS_NONE); + buf = net_buf_get_timeout(fifo, reserve_head, K_NO_WAIT); if (buf || k_is_in_isr()) { return buf; } NET_BUF_WARN("Low on buffers. Waiting (fifo %p)", fifo); - return net_buf_get_timeout(fifo, reserve_head, TICKS_UNLIMITED); + return net_buf_get_timeout(fifo, reserve_head, K_FOREVER); } void net_buf_reserve(struct net_buf *buf, size_t reserve) @@ -119,7 +117,7 @@ void net_buf_reserve(struct net_buf *buf, size_t reserve) buf->data = buf->__buf + reserve; } -void net_buf_put(struct nano_fifo *fifo, struct net_buf *buf) +void net_buf_put(struct k_fifo *fifo, struct net_buf *buf) { struct net_buf *tail; @@ -127,7 +125,7 @@ void net_buf_put(struct nano_fifo *fifo, struct net_buf *buf) tail->flags |= NET_BUF_FRAGS; } - nano_fifo_put_list(fifo, buf, tail); + k_fifo_put_list(fifo, buf, tail); } void net_buf_unref(struct net_buf *buf) @@ -144,7 +142,7 @@ void net_buf_unref(struct net_buf *buf) if (buf->destroy) { buf->destroy(buf); } else { - nano_fifo_put(buf->free, buf); + k_fifo_put(buf->free, buf); } buf = frags; diff --git a/net/ip/net_core.c b/net/ip/net_core.c index 22844d6a8a41..1e102848500b 100644 --- a/net/ip/net_core.c +++ b/net/ip/net_core.c @@ -699,7 +699,7 @@ struct net_buf *net_receive(struct net_context *context, int32_t timeout) switch (timeout) { case TICKS_UNLIMITED: case TICKS_NONE: - buf = net_buf_get_timeout(rx_queue, 0, timeout); + buf = net_buf_get_timeout(rx_queue, 0, _ticks_to_ms(timeout)); break; default: #ifdef CONFIG_NANO_TIMEOUTS diff --git a/samples/testing/unit/main.c b/samples/testing/unit/main.c index 56264f1de42c..a54010c1ce10 100644 --- a/samples/testing/unit/main.c +++ b/samples/testing/unit/main.c @@ -18,20 +18,20 @@ #include -void nano_fifo_init(struct nano_fifo *fifo) {} -void nano_fifo_put_list(struct nano_fifo *fifo, void *head, void *tail) {} +void k_fifo_init(struct k_fifo *fifo) {} +void k_fifo_put_list(struct k_fifo *fifo, void *head, void *tail) {} int k_is_in_isr(void) { return 0; } -void *nano_fifo_get(struct nano_fifo *fifo, int32_t timeout) +void *k_fifo_get(struct k_fifo *fifo, int32_t timeout) { return ztest_get_return_value_ptr(); } -void nano_fifo_put(struct nano_fifo *fifo, void *data) +void k_fifo_put(struct k_fifo *fifo, void *data) { ztest_check_expected_value(data); } @@ -39,13 +39,13 @@ void nano_fifo_put(struct nano_fifo *fifo, void *data) #define BUF_COUNT 1 #define BUF_SIZE 74 -static struct nano_fifo bufs_fifo; +static struct k_fifo bufs_fifo; static NET_BUF_POOL(bufs_pool, BUF_COUNT, BUF_SIZE, &bufs_fifo, NULL, sizeof(int)); static void init_pool(void) { - ztest_expect_value(nano_fifo_put, data, &bufs_pool); + ztest_expect_value(k_fifo_put, data, &bufs_pool); net_buf_pool_init(bufs_pool); } @@ -55,8 +55,8 @@ static void test_get_single_buffer(void) init_pool(); - ztest_returns_value(nano_fifo_get, bufs_pool); - buf = net_buf_get_timeout(&bufs_fifo, 0, TICKS_NONE); + ztest_returns_value(k_fifo_get, bufs_pool); + buf = net_buf_get_timeout(&bufs_fifo, 0, K_NO_WAIT); assert_equal_ptr(buf, &bufs_pool[0], "Returned buffer not from pool"); assert_equal(buf->ref, 1, "Invalid refcount"); diff --git a/tests/net/buf/src/main.c b/tests/net/buf/src/main.c index 93210fda2136..c92acc5a6771 100644 --- a/tests/net/buf/src/main.c +++ b/tests/net/buf/src/main.c @@ -109,7 +109,7 @@ static void net_buf_test_1(void) int i; for (i = 0; i < ARRAY_SIZE(bufs_pool); i++) { - buf = net_buf_get_timeout(&bufs_fifo, 0, TICKS_NONE); + buf = net_buf_get_timeout(&bufs_fifo, 0, K_NO_WAIT); assert_not_null(buf, "Failed to get buffer"); bufs[i] = buf; } @@ -128,19 +128,19 @@ static void net_buf_test_2(void) struct nano_fifo fifo; int i; - head = net_buf_get_timeout(&bufs_fifo, 0, TICKS_NONE); + head = net_buf_get_timeout(&bufs_fifo, 0, K_NO_WAIT); assert_not_null(head, "Failed to get fragment list head"); frag = head; for (i = 0; i < ARRAY_SIZE(bufs_pool) - 1; i++) { - frag->frags = net_buf_get_timeout(&bufs_fifo, 0, TICKS_NONE); + frag->frags = net_buf_get_timeout(&bufs_fifo, 0, K_NO_WAIT); assert_not_null(frag->frags, "Failed to get fragment"); frag = frag->frags; } nano_fifo_init(&fifo); net_buf_put(&fifo, head); - head = net_buf_get_timeout(&fifo, 0, TICKS_NONE); + head = net_buf_get_timeout(&fifo, 0, K_NO_WAIT); destroy_called = 0; net_buf_unref(head); @@ -175,12 +175,12 @@ static void net_buf_test_3(void) struct nano_sem sema; int i; - head = net_buf_get_timeout(&bufs_fifo, 0, TICKS_NONE); + head = net_buf_get_timeout(&bufs_fifo, 0, K_NO_WAIT); assert_not_null(head, "Failed to get fragment list head"); frag = head; for (i = 0; i < ARRAY_SIZE(bufs_pool) - 1; i++) { - frag->frags = net_buf_get_timeout(&bufs_fifo, 0, TICKS_NONE); + frag->frags = net_buf_get_timeout(&bufs_fifo, 0, K_NO_WAIT); assert_not_null(frag->frags, "Failed to get fragment"); frag = frag->frags; } diff --git a/tests/unit/net/buf/main.c b/tests/unit/net/buf/main.c index 56264f1de42c..a54010c1ce10 100644 --- a/tests/unit/net/buf/main.c +++ b/tests/unit/net/buf/main.c @@ -18,20 +18,20 @@ #include -void nano_fifo_init(struct nano_fifo *fifo) {} -void nano_fifo_put_list(struct nano_fifo *fifo, void *head, void *tail) {} +void k_fifo_init(struct k_fifo *fifo) {} +void k_fifo_put_list(struct k_fifo *fifo, void *head, void *tail) {} int k_is_in_isr(void) { return 0; } -void *nano_fifo_get(struct nano_fifo *fifo, int32_t timeout) +void *k_fifo_get(struct k_fifo *fifo, int32_t timeout) { return ztest_get_return_value_ptr(); } -void nano_fifo_put(struct nano_fifo *fifo, void *data) +void k_fifo_put(struct k_fifo *fifo, void *data) { ztest_check_expected_value(data); } @@ -39,13 +39,13 @@ void nano_fifo_put(struct nano_fifo *fifo, void *data) #define BUF_COUNT 1 #define BUF_SIZE 74 -static struct nano_fifo bufs_fifo; +static struct k_fifo bufs_fifo; static NET_BUF_POOL(bufs_pool, BUF_COUNT, BUF_SIZE, &bufs_fifo, NULL, sizeof(int)); static void init_pool(void) { - ztest_expect_value(nano_fifo_put, data, &bufs_pool); + ztest_expect_value(k_fifo_put, data, &bufs_pool); net_buf_pool_init(bufs_pool); } @@ -55,8 +55,8 @@ static void test_get_single_buffer(void) init_pool(); - ztest_returns_value(nano_fifo_get, bufs_pool); - buf = net_buf_get_timeout(&bufs_fifo, 0, TICKS_NONE); + ztest_returns_value(k_fifo_get, bufs_pool); + buf = net_buf_get_timeout(&bufs_fifo, 0, K_NO_WAIT); assert_equal_ptr(buf, &bufs_pool[0], "Returned buffer not from pool"); assert_equal(buf->ref, 1, "Invalid refcount");