123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- #ifndef NRF_RINGBUF_H
- #define NRF_RINGBUF_H
- #include <stdint.h>
- #include "nrf_atomic.h"
- #include "sdk_errors.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- nrf_atomic_flag_t wr_flag;
- nrf_atomic_flag_t rd_flag;
- uint32_t wr_idx;
- uint32_t tmp_wr_idx;
- uint32_t rd_idx;
- uint32_t tmp_rd_idx;
- } nrf_ringbuf_cb_t;
- typedef struct
- {
- uint8_t * p_buffer;
- uint32_t bufsize_mask;
- nrf_ringbuf_cb_t * p_cb;
- } nrf_ringbuf_t;
- #define NRF_RINGBUF_DEF(_name, _size) \
- STATIC_ASSERT(IS_POWER_OF_TWO(_size)); \
- static uint8_t CONCAT_2(_name,_buf)[_size]; \
- static nrf_ringbuf_cb_t CONCAT_2(_name,_cb); \
- static const nrf_ringbuf_t _name = { \
- .p_buffer = CONCAT_2(_name,_buf), \
- .bufsize_mask = _size - 1, \
- .p_cb = &CONCAT_2(_name,_cb), \
- }
- void nrf_ringbuf_init(nrf_ringbuf_t const * p_ringbuf);
- ret_code_t nrf_ringbuf_alloc(nrf_ringbuf_t const * p_ringbuf, uint8_t * * pp_data, size_t * p_length, bool start);
- ret_code_t nrf_ringbuf_put(nrf_ringbuf_t const * p_ringbuf, size_t length);
- ret_code_t nrf_ringbuf_cpy_put(nrf_ringbuf_t const * p_ringbuf,
- uint8_t const* p_data,
- size_t * p_length);
- ret_code_t nrf_ringbuf_get(nrf_ringbuf_t const * p_ringbuf, uint8_t * * pp_data, size_t * p_length, bool start);
- ret_code_t nrf_ringbuf_free(nrf_ringbuf_t const * p_ringbuf, size_t length);
- ret_code_t nrf_ringbuf_cpy_get(nrf_ringbuf_t const * p_ringbuf,
- uint8_t * p_data,
- size_t * p_length);
- #ifdef __cplusplus
- }
- #endif
- #endif
|