2 #include "trcRecorder.h"
\r
4 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
\r
5 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
\r
7 static void itm_write_32(uint32_t data);
\r
9 volatile int32_t tz_host_command_bytes_to_read = 0; // This is set by the Tracealyzer host application (to the number of bytes written), after having written to tz_host_commands. Set to zero by the read function after the message in tz_host_commands has been read.
\r
10 volatile char tz_host_command_data[32];
\r
12 /* This reads "command" data from a RAM buffer, written by a host macro in the debugger */
\r
13 int32_t read_from_host(void* ptrData, uint32_t size, int32_t* ptrBytesRead)
\r
15 if ( tz_host_command_bytes_to_read > 0)
\r
18 uint8_t * bytesBuffer = (uint8_t*) ptrData;
\r
20 if (ptrBytesRead != NULL)
\r
21 *ptrBytesRead = (int32_t)tz_host_command_bytes_to_read;
\r
23 if (tz_host_command_bytes_to_read != size)
\r
28 for (i=0; i < tz_host_command_bytes_to_read; i++)
\r
30 bytesBuffer[i] = tz_host_command_data[i];
\r
33 tz_host_command_bytes_to_read = 0;
\r
39 static void itm_write_32(uint32_t data)
\r
41 if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && // Trace enabled
\r
42 (ITM->TCR & ITM_TCR_ITMENA_Msk) && // ITM enabled
\r
43 (ITM->TER & (1UL << 0))) // ITM Port #0 enabled
\r
45 while (ITM->PORT[TRC_CFG_ITM_PORT].u32 == 0); // Block until room in ITM FIFO - This stream port is always in "blocking mode", since intended for high-speed ITM!
\r
46 ITM->PORT[TRC_CFG_ITM_PORT].u32 = data; // Write the data
\r
50 /* This is assumed to execute from within the recorder, with interrupts disabled */
\r
51 int32_t itm_write(void* ptrData, uint32_t size, int32_t* ptrBytesWritten)
\r
53 uint32_t bytesWritten = 0;
\r
54 uint32_t* ptr32 = (uint32_t*)ptrData;
\r
56 if (size % 4 != 0) return -2;
\r
58 while(bytesWritten < size)
\r
60 itm_write_32(*ptr32);
\r
65 *ptrBytesWritten = bytesWritten;
\r