1 /* 2 * Copyright (c) 2021 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef ZEPHYR_INCLUDE_SYS_MPSC_PACKET_H_ 7 #define ZEPHYR_INCLUDE_SYS_MPSC_PACKET_H_ 8 9 #include <string.h> 10 #include <stdint.h> 11 #include <stdbool.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** 18 * @brief Multi producer, single consumer packet header 19 * @defgroup mpsc_packet MPSC (Multi producer, single consumer) packet header 20 * @ingroup mpsc_buf 21 * @{ 22 */ 23 24 /** @brief Number of bits in the first word which are used by the buffer. */ 25 #define MPSC_PBUF_HDR_BITS 2 26 27 /** @brief Header that must be added to the first word in each packet. 28 * 29 * This fields are controlled by the packet buffer and unless specified must 30 * not be used. Fields must be added at the top of the packet header structure. 31 */ 32 #define MPSC_PBUF_HDR \ 33 uint32_t valid: 1; \ 34 uint32_t busy: 1 35 36 /** @brief Generic packet header. */ 37 struct mpsc_pbuf_hdr { 38 MPSC_PBUF_HDR; 39 uint32_t data: 32 - MPSC_PBUF_HDR_BITS; 40 }; 41 42 /** @brief Skip packet used internally by the packet buffer. */ 43 struct mpsc_pbuf_skip { 44 MPSC_PBUF_HDR; 45 uint32_t len: 32 - MPSC_PBUF_HDR_BITS; 46 }; 47 48 /** @brief Generic packet header. */ 49 union mpsc_pbuf_generic { 50 struct mpsc_pbuf_hdr hdr; 51 struct mpsc_pbuf_skip skip; 52 uint32_t raw; 53 }; 54 55 /** 56 * @} 57 */ 58 59 #ifdef __cplusplus 60 } 61 #endif 62 63 #endif /* ZEPHYR_INCLUDE_SYS_MPSC_PACKET_H_ */ 64