1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019 Intel Corporation. All rights reserved.
4  *
5  * Author: Marcin Rajwa <marcin.rajwa@linux.intel.com>
6  */
7 
8 #ifndef __SOF_DEBUG_GDB_RINGBUFFER_H__
9 #define __SOF_DEBUG_GDB_RINGBUFFER_H__
10 
11 #include <sof/lib/mailbox.h>
12 
13 #define RING_SIZE 128
14 #define DEBUG_RX_BASE (mailbox_get_debug_base())
15 #define DEBUG_TX_BASE (mailbox_get_debug_base() + 0x100)
16 
17 unsigned char get_debug_char(void);
18 void put_debug_char(unsigned char c);
19 void put_exception_char(char c);
20 void init_buffers(void);
21 struct ring {
22 	unsigned char head;
23 	unsigned char fill1[63];
24 	unsigned char tail;
25 	unsigned char fill2[63];
26 	unsigned char data[RING_SIZE];
27 };
28 
ring_next_head(const volatile struct ring * ring)29 static inline unsigned int ring_next_head(const volatile struct ring *ring)
30 {
31 	return (ring->head + 1) & (RING_SIZE - 1);
32 }
33 
ring_next_tail(const volatile struct ring * ring)34 static inline unsigned int ring_next_tail(const volatile struct ring *ring)
35 {
36 	return (ring->tail + 1) & (RING_SIZE - 1);
37 }
38 
ring_have_space(const volatile struct ring * ring)39 static inline int ring_have_space(const volatile struct ring *ring)
40 {
41 	return ring_next_head(ring) != ring->tail;
42 }
43 
ring_have_data(const volatile struct ring * ring)44 static inline int ring_have_data(const volatile struct ring *ring)
45 {
46 	return ring->head != ring->tail;
47 }
48 
49 #endif /* __SOF_DEBUG_GDB_RINGBUFFER_H__ */
50