1 /*
2  * Copyright (c) 2019 Intel corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/sys/ring_buffer.h>
8 
9 static struct ring_buf tracing_ring_buf;
10 static uint8_t tracing_buffer[CONFIG_TRACING_BUFFER_SIZE + 1];
11 static uint8_t tracing_cmd_buffer[CONFIG_TRACING_CMD_BUFFER_SIZE];
12 
tracing_cmd_buffer_alloc(uint8_t ** data)13 uint32_t tracing_cmd_buffer_alloc(uint8_t **data)
14 {
15 	*data = &tracing_cmd_buffer[0];
16 
17 	return sizeof(tracing_cmd_buffer);
18 }
19 
tracing_buffer_put_claim(uint8_t ** data,uint32_t size)20 uint32_t tracing_buffer_put_claim(uint8_t **data, uint32_t size)
21 {
22 	return ring_buf_put_claim(&tracing_ring_buf, data, size);
23 }
24 
tracing_buffer_put_finish(uint32_t size)25 int tracing_buffer_put_finish(uint32_t size)
26 {
27 	return ring_buf_put_finish(&tracing_ring_buf, size);
28 }
29 
tracing_buffer_put(uint8_t * data,uint32_t size)30 uint32_t tracing_buffer_put(uint8_t *data, uint32_t size)
31 {
32 	return ring_buf_put(&tracing_ring_buf, data, size);
33 }
34 
tracing_buffer_get_claim(uint8_t ** data,uint32_t size)35 uint32_t tracing_buffer_get_claim(uint8_t **data, uint32_t size)
36 {
37 	return ring_buf_get_claim(&tracing_ring_buf, data, size);
38 }
39 
tracing_buffer_get_finish(uint32_t size)40 int tracing_buffer_get_finish(uint32_t size)
41 {
42 	return ring_buf_get_finish(&tracing_ring_buf, size);
43 }
44 
tracing_buffer_get(uint8_t * data,uint32_t size)45 uint32_t tracing_buffer_get(uint8_t *data, uint32_t size)
46 {
47 	return ring_buf_get(&tracing_ring_buf, data, size);
48 }
49 
tracing_buffer_init(void)50 void tracing_buffer_init(void)
51 {
52 	ring_buf_init(&tracing_ring_buf,
53 		      sizeof(tracing_buffer), tracing_buffer);
54 }
55 
tracing_buffer_is_empty(void)56 bool tracing_buffer_is_empty(void)
57 {
58 	return ring_buf_is_empty(&tracing_ring_buf);
59 }
60 
tracing_buffer_capacity_get(void)61 uint32_t tracing_buffer_capacity_get(void)
62 {
63 	return ring_buf_capacity_get(&tracing_ring_buf);
64 }
65 
tracing_buffer_space_get(void)66 uint32_t tracing_buffer_space_get(void)
67 {
68 	return ring_buf_space_get(&tracing_ring_buf);
69 }
70