1 /*******************************************************************************
\r
2 * Trace Recorder Library for Tracealyzer v4.1.1
\r
3 * Percepio AB, www.percepio.com
\r
7 * Supporting functions for trace streaming, used by the "stream ports"
\r
8 * for reading and writing data to the interface.
\r
9 * Existing ports can easily be modified to fit another setup, e.g., a
\r
10 * different TCP/IP stack, or to define your own stream port.
\r
13 * This file is part of the trace recorder library (RECORDER), which is the
\r
14 * intellectual property of Percepio AB (PERCEPIO) and provided under a
\r
15 * license as follows.
\r
16 * The RECORDER may be used free of charge for the purpose of recording data
\r
17 * intended for analysis in PERCEPIO products. It may not be used or modified
\r
18 * for other purposes without explicit permission from PERCEPIO.
\r
19 * You may distribute the RECORDER in its original source code form, assuming
\r
20 * this text (terms of use, disclaimer, copyright notice) is unchanged. You are
\r
21 * allowed to distribute the RECORDER with minor modifications intended for
\r
22 * configuration or porting of the RECORDER, e.g., to allow using it on a
\r
23 * specific processor, processor family or with a specific communication
\r
24 * interface. Any such modifications should be documented directly below
\r
25 * this comment block.
\r
28 * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
\r
29 * as to its use or performance. PERCEPIO does not and cannot warrant the
\r
30 * performance or results you may obtain by using the RECORDER or documentation.
\r
31 * PERCEPIO make no warranties, express or implied, as to noninfringement of
\r
32 * third party rights, merchantability, or fitness for any particular purpose.
\r
33 * In no event will PERCEPIO, its technology partners, or distributors be liable
\r
34 * to you for any consequential, incidental or special damages, including any
\r
35 * lost profits or lost savings, even if a representative of PERCEPIO has been
\r
36 * advised of the possibility of such damages, or for any claim by any third
\r
37 * party. Some jurisdictions do not allow the exclusion or limitation of
\r
38 * incidental, consequential or special damages, or the exclusion of implied
\r
39 * warranties or limitations on how long an implied warranty may last, so the
\r
40 * above limitations may not apply to you.
\r
42 * Tabs are used for indent in this file (1 tab = 4 spaces)
\r
44 * Copyright Percepio AB, 2018.
\r
46 ******************************************************************************/
\r
48 #include "trcRecorder.h"
\r
50 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
\r
51 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
\r
53 FILE* traceFile = NULL;
\r
55 void openFile(char* fileName)
\r
57 if (traceFile == NULL)
\r
59 errno_t err = fopen_s(&traceFile, fileName, "wb");
\r
62 printf("Could not open trace file, error code %d.\n", err);
\r
66 printf("Trace file created.\n");
\r
71 int32_t writeToFile(void* data, uint32_t size, int32_t *ptrBytesWritten)
\r
73 int32_t written = 0;
\r
74 if (traceFile != NULL)
\r
76 written = fwrite(data, 1, size, traceFile);
\r
83 if (ptrBytesWritten != 0)
\r
84 *ptrBytesWritten = written;
\r
86 if ((int32_t)size == written)
\r
92 void closeFile(void)
\r
94 if (traceFile != NULL)
\r
98 printf("Trace file closed.\n");
\r
102 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
\r
103 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
\r