Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
mpsc_pbuf.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_SYS_MPSC_PBUF_H_
7#define ZEPHYR_INCLUDE_SYS_MPSC_PBUF_H_
8
9#include <kernel.h>
10#include <sys/mpsc_packet.h>
11#include <string.h>
12#include <stdint.h>
13#include <stdbool.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
26/*
27 * Multi producer, single consumer packet buffer allows to allocate variable
28 * length consecutive space for storing a packet. When space is allocated
29 * it can be filled by the user (except for the first 2 bits) and when packet
30 * is ready it is committed. It is allowed to allocate another packet before
31 * committing the previous one.
32 *
33 * If buffer is full and packet cannot be allocated then null is returned unless
34 * overwrite mode is selected. In that mode, oldest entry are dropped (user is
35 * notified) until allocation succeeds. It can happen that candidate for
36 * dropping is currently being claimed. In that case, it is ommited and next
37 * packet is dropped and claimed packet is marked as invalid when freeing.
38 *
39 * Reading packets is performed in two steps. First packet is claimed. Claiming
40 * returns pointer to the packet within the buffer. Packet is freed when no
41 * longer in use.
42 */
43
52#define MPSC_PBUF_SIZE_POW2 BIT(0)
53
59#define MPSC_PBUF_MODE_OVERWRITE BIT(1)
60
63/* Forward declaration */
64struct mpsc_pbuf_buffer;
65
73
81 union mpsc_pbuf_generic *packet);
82
87
90
93
96
99
102
105
108
109 /* Buffer. */
111
112 /* Buffer size in 32 bit words. */
114
115 struct k_sem sem;
116};
117
120 /* Pointer to a memory used for storing packets. */
122
123 /* Buffer size in 32 bit words. */
125
126 /* Callbacks. */
129
130 /* Configuration flags. */
132};
133
141 const struct mpsc_pbuf_buffer_config *config);
142
160 size_t wlen, k_timeout_t timeout);
161
169 union mpsc_pbuf_generic *packet);
170
182 union mpsc_pbuf_generic word);
183
197 union mpsc_pbuf_generic word, void *data);
198
211 uint32_t *data, size_t wlen);
212
218
226 union mpsc_pbuf_generic *packet);
227
236
241#ifdef __cplusplus
242}
243#endif
244
245#endif /* ZEPHYR_INCLUDE_SYS_MPSC_PBUF_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
void
Definition: eswifi_shell.c:15
static ZTEST_BMEM char buffer[8]
Test mailbox enhance capabilities.
Definition: test_mbox_api.c:566
void mpsc_pbuf_put_word_ext(struct mpsc_pbuf_buffer *buffer, union mpsc_pbuf_generic word, void *data)
Put a packet consisting of a word and a pointer.Function is optimized for storing packet consisting o...
void mpsc_pbuf_put_word(struct mpsc_pbuf_buffer *buffer, union mpsc_pbuf_generic word)
Put single word packet into a buffer.
void(* mpsc_pbuf_notify_drop)(struct mpsc_pbuf_buffer *buffer, union mpsc_pbuf_generic *packet)
Callback called when packet is dropped.
Definition: mpsc_pbuf.h:80
bool mpsc_pbuf_is_pending(struct mpsc_pbuf_buffer *buffer)
Check if there are any message pending.
void mpsc_pbuf_put_data(struct mpsc_pbuf_buffer *buffer, uint32_t *data, size_t wlen)
Put a packet into a buffer.
void mpsc_pbuf_free(struct mpsc_pbuf_buffer *buffer, union mpsc_pbuf_generic *packet)
Free a packet.
union mpsc_pbuf_generic * mpsc_pbuf_alloc(struct mpsc_pbuf_buffer *buffer, size_t wlen, k_timeout_t timeout)
Allocate a packet.
union mpsc_pbuf_generic * mpsc_pbuf_claim(struct mpsc_pbuf_buffer *buffer)
Claim the first pending packet.
void mpsc_pbuf_init(struct mpsc_pbuf_buffer *buffer, const struct mpsc_pbuf_buffer_config *config)
Initnialize a packet buffer.
uint32_t(* mpsc_pbuf_get_wlen)(union mpsc_pbuf_generic *packet)
Callback prototype for getting length of a packet.
Definition: mpsc_pbuf.h:72
void mpsc_pbuf_commit(struct mpsc_pbuf_buffer *buffer, union mpsc_pbuf_generic *packet)
Commit a packet.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Kernel Spin Lock.
Definition: spinlock.h:29
Kernel timeout type.
Definition: sys_clock.h:65
MPSC packet buffer configuration.
Definition: mpsc_pbuf.h:119
uint32_t * buf
Definition: mpsc_pbuf.h:121
mpsc_pbuf_notify_drop notify_drop
Definition: mpsc_pbuf.h:127
mpsc_pbuf_get_wlen get_wlen
Definition: mpsc_pbuf.h:128
uint32_t flags
Definition: mpsc_pbuf.h:131
uint32_t size
Definition: mpsc_pbuf.h:124
MPSC packet buffer structure.
Definition: mpsc_pbuf.h:84
uint32_t flags
Definition: mpsc_pbuf.h:98
struct k_spinlock lock
Definition: mpsc_pbuf.h:101
uint32_t * buf
Definition: mpsc_pbuf.h:110
uint32_t wr_idx
Definition: mpsc_pbuf.h:89
uint32_t tmp_wr_idx
Definition: mpsc_pbuf.h:86
uint32_t size
Definition: mpsc_pbuf.h:113
mpsc_pbuf_notify_drop notify_drop
Definition: mpsc_pbuf.h:104
mpsc_pbuf_get_wlen get_wlen
Definition: mpsc_pbuf.h:107
struct k_sem sem
Definition: mpsc_pbuf.h:115
uint32_t tmp_rd_idx
Definition: mpsc_pbuf.h:92
uint32_t rd_idx
Definition: mpsc_pbuf.h:95
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Generic packet header.
Definition: mpsc_packet.h:49