]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c
edd71d9b5eb9a71168bc4173645d915de13be1b2
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace / streamports / File / trcStreamingPort.c
1 /*******************************************************************************\r
2  * Trace Recorder Library for Tracealyzer v4.1.1\r
3  * Percepio AB, www.percepio.com\r
4  *\r
5  * trcStreamingPort.c\r
6  *\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
11  *\r
12   * Terms of Use\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
26  *\r
27  * Disclaimer\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
41  *\r
42  * Tabs are used for indent in this file (1 tab = 4 spaces)\r
43  *\r
44  * Copyright Percepio AB, 2018.\r
45  * www.percepio.com\r
46  ******************************************************************************/\r
47 \r
48 #include "trcRecorder.h"\r
49 \r
50 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)  \r
51 #if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
52 \r
53 FILE* traceFile = NULL;\r
54 \r
55 void openFile(char* fileName)\r
56 {\r
57         if (traceFile == NULL)\r
58         {\r
59                 errno_t err = fopen_s(&traceFile, fileName, "wb");\r
60                 if (err != 0)\r
61                 {\r
62                         printf("Could not open trace file, error code %d.\n", err);\r
63                         exit(-1);\r
64                 }\r
65                 else {\r
66                         printf("Trace file created.\n");\r
67                 }\r
68         }\r
69 }\r
70 \r
71 int32_t writeToFile(void* data, uint32_t size, int32_t *ptrBytesWritten)\r
72 {\r
73         int32_t written = 0;\r
74         if (traceFile != NULL)\r
75         {\r
76                 written = fwrite(data, 1, size, traceFile);\r
77         }\r
78         else\r
79         {\r
80                 written = 0;\r
81         }\r
82 \r
83         if (ptrBytesWritten != 0)\r
84                 *ptrBytesWritten = written;\r
85 \r
86         if ((int32_t)size == written)\r
87                 return 0;\r
88         else\r
89                 return -1;\r
90 }\r
91 \r
92 void closeFile(void)\r
93 {\r
94         if (traceFile != NULL)\r
95         {\r
96                 fclose(traceFile);\r
97                 traceFile = NULL;\r
98                 printf("Trace file closed.\n");\r
99         }\r
100 }\r
101 \r
102 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
103 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r