1 /*
2 * Percepio Trace Recorder for Tracealyzer v4.6.6
3 * Copyright 2021 Percepio AB
4 * www.percepio.com
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * The implementation for the static buffer.
9 */
10 
11 #include <trcRecorder.h>
12 
13 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
14 
15 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
16 
17 TraceStaticBufferTable_t *pxTraceStaticBufferTable;
18 
xTraceStaticBufferInitialize(TraceStaticBufferBuffer_t * pxBuffer)19 traceResult xTraceStaticBufferInitialize(TraceStaticBufferBuffer_t *pxBuffer)
20 {
21 	TRC_ASSERT_EQUAL_SIZE(TraceStaticBufferBuffer_t, TraceStaticBufferTable_t);
22 
23 	/* This should never fail */
24 	TRC_ASSERT(pxBuffer != 0);
25 
26 	pxTraceStaticBufferTable = (TraceStaticBufferTable_t*)pxBuffer;
27 
28 	xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_STATIC_BUFFER);
29 
30 	return TRC_SUCCESS;
31 }
32 
33 #if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
34 
35 /* Returns a pointer to a maximum sized static buffer */
xTraceStaticBufferGet(void ** ppvBuffer)36 traceResult xTraceStaticBufferGet(void **ppvBuffer)
37 {
38 	int32_t ISR_nesting;
39 
40 	/* This should never fail */
41 	TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_STATIC_BUFFER));
42 
43 	TRC_ASSERT(ppvBuffer != 0);
44 
45 	TRC_ASSERT(xTraceISRGetCurrentNesting(&ISR_nesting) ==  TRC_SUCCESS);
46 
47 	/* Task dummy events begin at 0, ISR dummy events begin at index 1 */
48 	*ppvBuffer = (void*)&pxTraceStaticBufferTable->coreDummyEvents[TRC_CFG_GET_CURRENT_CORE()].dummyEvents[ISR_nesting + 1];
49 
50 	return TRC_SUCCESS;
51 }
52 
53 #endif /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
54 
55 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
56 
57 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
58