1 /*
2  *  Copyright (c) 2018, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  * @brief
32  *   This file defines the logging rtt interfaces and default constants used by logging_rtt.c.
33  */
34 
35 #ifndef UTILS_LOGGING_RTT_H
36 #define UTILS_LOGGING_RTT_H
37 
38 #include <stdarg.h>
39 #include <stdint.h>
40 #include <stdio.h>
41 
42 #include "openthread-core-config.h"
43 #include <openthread/config.h>
44 #include <openthread/platform/logging.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /**
51  * @def LOG_RTT_BUFFER_INDEX
52  *
53  * RTT's buffer index.
54  *
55  */
56 #ifndef LOG_RTT_BUFFER_INDEX
57 #define LOG_RTT_BUFFER_INDEX 0
58 #endif
59 
60 /**
61  * @def LOG_RTT_BUFFER_NAME
62  *
63  * RTT's name. Only used if LOG_RTT_BUFFER_INDEX is not 0. Otherwise,
64  * the buffer name is fixed to "Terminal".
65  *
66  */
67 #ifndef LOG_RTT_BUFFER_NAME
68 #define LOG_RTT_BUFFER_NAME "Terminal"
69 #endif
70 
71 /**
72  * @def LOG_RTT_BUFFER_SIZE
73  *
74  * LOG RTT's buffer size. Only used if LOG_RTT_BUFFER_INDEX is not 0. To
75  * configure buffer #0 size, check the BUFFER_SIZE_UP definition in
76  * SEGGER_RTT_Conf.h
77  *
78  */
79 #ifndef LOG_RTT_BUFFER_SIZE
80 #define LOG_RTT_BUFFER_SIZE 256
81 #endif
82 
83 /**
84  * @def LOG_RTT_COLOR_ENABLE
85  *
86  * Enable colors on RTT Viewer.
87  *
88  */
89 #ifndef LOG_RTT_COLOR_ENABLE
90 #define LOG_RTT_COLOR_ENABLE 1
91 #endif
92 
93 /**
94  * @def LOG_PARSE_BUFFER_SIZE
95  *
96  * LOG buffer used to parse print format. It will be locally allocated on the
97  * stack.
98  *
99  */
100 #ifndef LOG_PARSE_BUFFER_SIZE
101 #define LOG_PARSE_BUFFER_SIZE 128
102 #endif
103 
104 /**
105  * @def LOG_TIMESTAMP_ENABLE
106  *
107  * Enable timestamp in the logs.
108  *
109  */
110 #ifndef LOG_TIMESTAMP_ENABLE
111 #define LOG_TIMESTAMP_ENABLE 1
112 #endif
113 
114 /**
115  * Initialization of Logger driver.
116  *
117  */
118 void utilsLogRttInit(void);
119 
120 /**
121  * Deinitialization of Logger driver.
122  *
123  */
124 void utilsLogRttDeinit(void);
125 
126 /**
127  * Outputs logs to SEGGER RTT.
128  *
129  * @param[in]  aLogLevel   The log level.
130  * @param[in]  aLogRegion  The log region.
131  * @param[in]  aFormat     A pointer to the format string.
132  * @param[in]  ap          va_list matching information for aFormat
133  *
134  */
135 void utilsLogRttOutput(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list ap);
136 
137 #ifdef __cplusplus
138 } // extern "C"
139 #endif
140 
141 #endif // UTILS_LOGGING_RTT_H
142