@@ -47,20 +47,23 @@ extern "C" {
4747 * The structure contains configuration data.
4848 */
4949struct pbuf_cfg {
50- volatile uint32_t * rd_idx_loc ; /* Address of the variable holding
51- * index value of the first valid byte
52- * in data[].
53- */
54- volatile uint32_t * wr_idx_loc ; /* Address of the variable holding
55- * index value of the first free byte
56- * in data[].
57- */
58- uint32_t dcache_alignment ; /* CPU data cache line size in bytes.
59- * Used for validation - TODO: To be
60- * replaced by flags.
61- */
62- uint32_t len ; /* Length of data[] in bytes. */
63- uint8_t * data_loc ; /* Location of the data[]. */
50+ volatile uint32_t * rd_idx_loc ; /* Address of the variable holding
51+ * index value of the first valid byte
52+ * in data[].
53+ */
54+ volatile uint32_t * handshake_loc ;/* Address of the variable holding
55+ * handshake information.
56+ */
57+ volatile uint32_t * wr_idx_loc ; /* Address of the variable holding
58+ * index value of the first free byte
59+ * in data[].
60+ */
61+ uint32_t dcache_alignment ; /* CPU data cache line size in bytes.
62+ * Used for validation - TODO: To be
63+ * replaced by flags.
64+ */
65+ uint32_t len ; /* Length of data[] in bytes. */
66+ uint8_t * data_loc ; /* Location of the data[]. */
6467};
6568
6669/**
@@ -111,16 +114,21 @@ struct pbuf {
111114 * @param mem_addr Memory address for pbuf.
112115 * @param size Size of the memory.
113116 * @param dcache_align Data cache alignment.
117+ * @param use_handshake Add handshake word inside shared memory that can be access with
118+ * @ref pbuf_handshake_read and @ref pbuf_handshake_write.
114119 */
115- #define PBUF_CFG_INIT (mem_addr , size , dcache_align ) \
120+ #define PBUF_CFG_INIT (mem_addr , size , dcache_align , use_handshake ) \
116121{ \
117122 .rd_idx_loc = (uint32_t *)(mem_addr), \
118- .wr_idx_loc = (uint32_t *)((uint8_t *)(mem_addr) + \
119- MAX(dcache_align, _PBUF_IDX_SIZE)), \
123+ .handshake_loc = use_handshake ? (uint32_t *)((uint8_t *)(mem_addr) + \
124+ _PBUF_IDX_SIZE) : NULL, \
125+ .wr_idx_loc = (uint32_t *)((uint8_t *)(mem_addr) + MAX(dcache_align, \
126+ (use_handshake ? 2 : 1) * _PBUF_IDX_SIZE)), \
120127 .data_loc = (uint8_t *)((uint8_t *)(mem_addr) + \
121- MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE), \
122- .len = (uint32_t)((uint32_t)(size) - MAX(dcache_align, _PBUF_IDX_SIZE) - \
123- _PBUF_IDX_SIZE), \
128+ MAX(dcache_align, (use_handshake ? 2 : 1) * \
129+ _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE), \
130+ .len = (uint32_t)((uint32_t)(size) - MAX(dcache_align, \
131+ (use_handshake ? 2 : 1) * _PBUF_IDX_SIZE) - _PBUF_IDX_SIZE), \
124132 .dcache_alignment = (dcache_align), \
125133}
126134
@@ -140,9 +148,11 @@ struct pbuf {
140148 * @param name Name of the pbuf.
141149 * @param mem_addr Memory address for pbuf.
142150 * @param size Size of the memory.
143- * @param dcache_align Data cache line size.
151+ * @param dcache_align Data cache line size.
152+ * @param use_handshake Add handshake word inside shared memory that can be access with
153+ * @ref pbuf_handshake_read and @ref pbuf_handshake_write.
144154 */
145- #define PBUF_DEFINE (name , mem_addr , size , dcache_align ) \
155+ #define PBUF_DEFINE (name , mem_addr , size , dcache_align , use_handshake , compatibility ) \
146156 BUILD_ASSERT(dcache_align >= 0, \
147157 "Cache line size must be non negative."); \
148158 BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \
@@ -151,8 +161,10 @@ struct pbuf {
151161 "Misaligned memory."); \
152162 BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \
153163 _PBUF_MIN_DATA_LEN), "Insufficient size."); \
164+ BUILD_ASSERT(!(compatibility) || (dcache_align) >= 8, \
165+ "Data cache alignment must be at least 8 if compatibility is enabled.");\
154166 static PBUF_MAYBE_CONST struct pbuf_cfg cfg_##name = \
155- PBUF_CFG_INIT(mem_addr, size, dcache_align); \
167+ PBUF_CFG_INIT(mem_addr, size, dcache_align, use_handshake); \
156168 static struct pbuf name = { \
157169 .cfg = &cfg_##name, \
158170 }
@@ -223,6 +235,40 @@ int pbuf_write(struct pbuf *pb, const char *buf, uint16_t len);
223235 */
224236int pbuf_read (struct pbuf * pb , char * buf , uint16_t len );
225237
238+ /**
239+ * @brief Read handshake word from pbuf.
240+ *
241+ * The pb must be defined with "PBUF_DEFINE" with "use_handshake" set.
242+ *
243+ * @param pb A buffer from which data will be read.
244+ * @retval uint32_t The handshake word value.
245+ */
246+ uint32_t pbuf_handshake_read (struct pbuf * pb );
247+
248+ /**
249+ * @brief Write handshake word to pbuf.
250+ *
251+ * The pb must be defined with "PBUF_DEFINE" with "use_handshake" set.
252+ *
253+ * @param pb A buffer to which data will be written.
254+ * @param value A handshake value.
255+ */
256+ void pbuf_handshake_write (struct pbuf * pb , uint32_t value );
257+
258+ /**
259+ * @brief Get first buffer from pbuf.
260+ *
261+ * This function retrieves buffer located at the beginning of queue.
262+ * It will be continuous block since it is the first buffer.
263+ *
264+ * @param pb A buffer from which data will be read.
265+ * @param[out] buf A pointer to output pointer to the date of the first buffer.
266+ * @param[out] len A pointer to output length the first buffer.
267+ * @retval 0 on success.
268+ * -EINVAL when there is no buffer at the beginning of queue.
269+ */
270+ int pbuf_get_initial_buf (struct pbuf * pb , volatile char * * buf , uint16_t * len );
271+
226272/**
227273 * @}
228274 */
0 commit comments