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 #ifndef LOG_RTT_BUFFER_INDEX 56 #define LOG_RTT_BUFFER_INDEX 0 57 #endif 58 59 /** 60 * @def LOG_RTT_BUFFER_NAME 61 * 62 * RTT's name. Only used if LOG_RTT_BUFFER_INDEX is not 0. Otherwise, 63 * the buffer name is fixed to "Terminal". 64 */ 65 #ifndef LOG_RTT_BUFFER_NAME 66 #define LOG_RTT_BUFFER_NAME "Terminal" 67 #endif 68 69 /** 70 * @def LOG_RTT_BUFFER_SIZE 71 * 72 * LOG RTT's buffer size. Only used if LOG_RTT_BUFFER_INDEX is not 0. To 73 * configure buffer #0 size, check the BUFFER_SIZE_UP definition in 74 * SEGGER_RTT_Conf.h 75 */ 76 #ifndef LOG_RTT_BUFFER_SIZE 77 #define LOG_RTT_BUFFER_SIZE 256 78 #endif 79 80 /** 81 * @def LOG_RTT_COLOR_ENABLE 82 * 83 * Enable colors on RTT Viewer. 84 */ 85 #ifndef LOG_RTT_COLOR_ENABLE 86 #define LOG_RTT_COLOR_ENABLE 1 87 #endif 88 89 /** 90 * @def LOG_PARSE_BUFFER_SIZE 91 * 92 * LOG buffer used to parse print format. It will be locally allocated on the 93 * stack. 94 */ 95 #ifndef LOG_PARSE_BUFFER_SIZE 96 #define LOG_PARSE_BUFFER_SIZE \ 97 (19 /* Timestamp */ + 8 /* RTT color code */ + OPENTHREAD_CONFIG_LOG_MAX_SIZE + 1 /* \n */) 98 #endif 99 100 /** 101 * @def LOG_TIMESTAMP_ENABLE 102 * 103 * Enable timestamp in the logs. 104 */ 105 #ifndef LOG_TIMESTAMP_ENABLE 106 #define LOG_TIMESTAMP_ENABLE 1 107 #endif 108 109 /** 110 * Initialization of Logger driver. 111 */ 112 void utilsLogRttInit(void); 113 114 /** 115 * Deinitialization of Logger driver. 116 */ 117 void utilsLogRttDeinit(void); 118 119 /** 120 * Outputs logs to SEGGER RTT. 121 * 122 * @param[in] aLogLevel The log level. 123 * @param[in] aLogRegion The log region. 124 * @param[in] aFormat A pointer to the format string. 125 * @param[in] ap va_list matching information for aFormat 126 */ 127 void utilsLogRttOutput(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list ap); 128 129 #ifdef __cplusplus 130 } // extern "C" 131 #endif 132 133 #endif // UTILS_LOGGING_RTT_H 134