nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
data_fifo.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
11#ifndef _DATA_FIFO_H_
12#define _DATA_FIFO_H_
13
22#include <stddef.h>
23#include <stdint.h>
24#include <zephyr/kernel.h>
25
26/* The queue elements hold a pointer to a memory block in a slab and the
27 * number of bytes written to that block.
28 */
30 void *block_ptr;
31 size_t size;
32};
33
34struct data_fifo {
37 struct k_mem_slab mem_slab;
38 struct k_msgq msgq;
39 uint32_t elements_max;
42};
43
44#define DATA_FIFO_DEFINE(name, elements_max_in, block_size_max_in) \
45 char __aligned(WB_UP( \
46 1)) _msgq_buffer_##name[(elements_max_in) * sizeof(struct data_fifo_msgq)] = {0}; \
47 char __aligned(WB_UP(1)) _slab_buffer_##name[(elements_max_in) * (block_size_max_in)] = { \
48 0}; \
49 struct data_fifo name = {.msgq_buffer = _msgq_buffer_##name, \
50 .slab_buffer = _slab_buffer_##name, \
51 .block_size_max = block_size_max_in, \
52 .elements_max = elements_max_in, \
53 .initialized = false}
54
74 k_timeout_t timeout);
75
96int data_fifo_block_lock(struct data_fifo *data_fifo, void **data, size_t size);
97
116int data_fifo_pointer_last_filled_get(struct data_fifo *data_fifo, void **data, size_t *size,
117 k_timeout_t timeout);
118
127void data_fifo_block_free(struct data_fifo *data_fifo, void *data);
128
141int data_fifo_num_used_get(struct data_fifo *data_fifo, uint32_t *alloced_num,
142 uint32_t *locked_num);
143
152
164
174
184
189#endif /* _DATA_FIFO_H_ */
int data_fifo_empty(struct data_fifo *data_fifo)
Empty all items from data_fifo.
int data_fifo_num_used_get(struct data_fifo *data_fifo, uint32_t *alloced_num, uint32_t *locked_num)
See how many alloced and locked blocks are in the system.
void data_fifo_block_free(struct data_fifo *data_fifo, void *data)
Free the data block after reading.
bool data_fifo_state(struct data_fifo *data_fifo)
Test if the data_fifo state.
int data_fifo_block_lock(struct data_fifo *data_fifo, void **data, size_t size)
Confirm that the memory block use has finished and the block is put into the message queue.
int data_fifo_uninit(struct data_fifo *data_fifo)
Deinitialize data_fifo.
int data_fifo_pointer_last_filled_get(struct data_fifo *data_fifo, void **data, size_t *size, k_timeout_t timeout)
Get pointer to first (oldest) filled block in slab.
int data_fifo_init(struct data_fifo *data_fifo)
Initialize the data_fifo.
int data_fifo_pointer_first_vacant_get(struct data_fifo *data_fifo, void **data, k_timeout_t timeout)
Get pointer to the first vacant block in slab.
void * block_ptr
Definition data_fifo.h:30
size_t size
Definition data_fifo.h:31
Definition data_fifo.h:29
uint32_t elements_max
Definition data_fifo.h:39
char * slab_buffer
Definition data_fifo.h:36
struct k_mem_slab mem_slab
Definition data_fifo.h:37
char * msgq_buffer
Definition data_fifo.h:35
struct k_msgq msgq
Definition data_fifo.h:38
bool initialized
Definition data_fifo.h:41
size_t block_size_max
Definition data_fifo.h:40
Definition data_fifo.h:34