1 /*
2 * Trace Recorder for Tracealyzer v4.5.1
3 * Copyright 2021 Percepio AB
4 * www.percepio.com
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Supporting functions for trace streaming, used by the "stream ports"
9 * for reading and writing data to the interface.
10 *
11 * Note that this stream port is more complex than the typical case, since
12 * the J-Link interface uses a separate RAM buffer in SEGGER_RTT.c, instead
13 * of the default buffer included in the recorder core. The other stream ports
14 * offer more typical examples of how to define a custom streaming interface.
15 */
16
17 #include "trcRecorder.h"
18
19 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
20 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
21
readFromRTT(void * ptrData,uint32_t size,int32_t * ptrBytesRead)22 int32_t readFromRTT(void* ptrData, uint32_t size, int32_t* ptrBytesRead)
23 {
24 uint32_t bytesRead = 0;
25
26 if (SEGGER_RTT_HASDATA(TRC_CFG_RTT_DOWN_BUFFER_INDEX))
27 {
28 bytesRead = SEGGER_RTT_Read((TRC_CFG_RTT_DOWN_BUFFER_INDEX), (char*)ptrData, size);
29
30 if (ptrBytesRead != NULL)
31 *ptrBytesRead = (int32_t)bytesRead;
32
33 }
34
35 return 0;
36 }
37
writeToRTT(void * ptrData,uint32_t size,int32_t * ptrBytesWritten)38 int32_t writeToRTT(void* ptrData, uint32_t size, int32_t* ptrBytesWritten)
39 {
40 uint32_t bytesWritten = SEGGER_RTT_Write((TRC_CFG_RTT_UP_BUFFER_INDEX), (const char*)ptrData, size);
41
42 if (ptrBytesWritten != NULL)
43 *ptrBytesWritten = (int32_t)bytesWritten;
44
45 return 0;
46 }
47
48 #endif
49 #endif
50