123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- #ifndef NRF_ATFIFO_H__
- #define NRF_ATFIFO_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "sdk_config.h"
- #include "nordic_common.h"
- #include "nrf_assert.h"
- #include "sdk_errors.h"
- #include "nrf_log_instance.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct nrf_atfifo_postag_pos_s
- {
- uint16_t wr;
- uint16_t rd;
- }nrf_atfifo_postag_pos_t;
- typedef union nrf_atfifo_postag_u
- {
- uint32_t tag;
- nrf_atfifo_postag_pos_t pos;
- }nrf_atfifo_postag_t;
- typedef struct nrf_atfifo_s
- {
- void * p_buf;
- nrf_atfifo_postag_t tail;
- nrf_atfifo_postag_t head;
- uint16_t buf_size;
- uint16_t item_size;
- NRF_LOG_INSTANCE_PTR_DECLARE(p_log)
- }nrf_atfifo_t;
- typedef struct nrf_atfifo_item_put_s
- {
- nrf_atfifo_postag_t last_tail;
- }nrf_atfifo_item_put_t;
- typedef struct nrf_atfifo_rcontext_s
- {
- nrf_atfifo_postag_t last_head;
- }nrf_atfifo_item_get_t;
- #define NRF_ATFIFO_LOG_NAME atfifo
-
- #define NRF_ATFIFO_BUF_NAME(fifo_id) CONCAT_2(fifo_id, _data)
-
- #define NRF_ATFIFO_INST_NAME(fifo_id) CONCAT_2(fifo_id, _inst)
-
- #define NRF_ATFIFO_DEF(fifo_id, storage_type, item_cnt) \
- static storage_type NRF_ATFIFO_BUF_NAME(fifo_id)[(item_cnt)+1]; \
- NRF_LOG_INSTANCE_REGISTER(NRF_ATFIFO_LOG_NAME, fifo_id, \
- NRF_ATFIFO_CONFIG_INFO_COLOR, \
- NRF_ATFIFO_CONFIG_DEBUG_COLOR, \
- NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL, \
- NRF_ATFIFO_CONFIG_LOG_ENABLED ? \
- NRF_ATFIFO_CONFIG_LOG_LEVEL : NRF_LOG_SEVERITY_NONE); \
- static nrf_atfifo_t NRF_ATFIFO_INST_NAME(fifo_id) = { \
- .p_buf = NULL, \
- NRF_LOG_INSTANCE_PTR_INIT(p_log, NRF_ATFIFO_LOG_NAME, fifo_id) \
- }; \
- static nrf_atfifo_t * const fifo_id = &NRF_ATFIFO_INST_NAME(fifo_id)
-
- #define NRF_ATFIFO_INIT(fifo_id) \
- nrf_atfifo_init( \
- fifo_id, \
- NRF_ATFIFO_BUF_NAME(fifo_id), \
- sizeof(NRF_ATFIFO_BUF_NAME(fifo_id)), \
- sizeof(NRF_ATFIFO_BUF_NAME(fifo_id)[0]) \
- )
- ret_code_t nrf_atfifo_init(nrf_atfifo_t * const p_fifo, void * p_buf, uint16_t buf_size, uint16_t item_size);
- ret_code_t nrf_atfifo_clear(nrf_atfifo_t * const p_fifo);
- ret_code_t nrf_atfifo_alloc_put(nrf_atfifo_t * const p_fifo, void const * const p_var, size_t size, bool * const p_visible);
- void * nrf_atfifo_item_alloc(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context);
- bool nrf_atfifo_item_put(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context);
- ret_code_t nrf_atfifo_get_free(nrf_atfifo_t * const p_fifo, void * const p_var, size_t size, bool * p_released);
- void * nrf_atfifo_item_get(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context);
- bool nrf_atfifo_item_free(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context);
- #ifdef __cplusplus
- }
- #endif
- #endif
|