1 /* 2 * Copyright (c) 2020-2021, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __TFM_SPM_LOG_H__ 9 #define __TFM_SPM_LOG_H__ 10 11 #include <stddef.h> 12 #include <stdint.h> 13 #include "tfm_hal_defs.h" 14 #include "tfm_hal_spm_logdev.h" 15 16 /* The SPM log levels */ 17 #define TFM_SPM_LOG_LEVEL_DEBUG 3 /* All log APIs output */ 18 #define TFM_SPM_LOG_LEVEL_INFO 2 /* 19 * All log APIs output except SPMLOG_DBG 20 * and SPMLOG_DBGMSGVAL 21 */ 22 #define TFM_SPM_LOG_LEVEL_ERROR 1 /* 23 * Only SPMLOG_ERRMSG and SPMLOG_ERRMSGVAL 24 * APIs output. 25 */ 26 #define TFM_SPM_LOG_LEVEL_SILENCE 0 /* All log APIs are suppressed */ 27 28 #ifndef TFM_SPM_LOG_LEVEL 29 #error "TFM_SPM_LOG_LEVEL not defined!" 30 #endif 31 32 #if (TFM_SPM_LOG_LEVEL > TFM_SPM_LOG_LEVEL_DEBUG || \ 33 TFM_SPM_LOG_LEVEL < TFM_SPM_LOG_LEVEL_SILENCE) 34 #error "Incorrect TFM_SPM_LOG_LEVEL value!" 35 #endif 36 37 #if (TFM_SPM_LOG_LEVEL == TFM_SPM_LOG_LEVEL_DEBUG) 38 #define SPMLOG_DBGMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val) 39 #define SPMLOG_DBGMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg)) 40 #else 41 #define SPMLOG_DBGMSGVAL(msg, val) 42 #define SPMLOG_DBGMSG(msg) 43 #endif 44 45 #if (TFM_SPM_LOG_LEVEL >= TFM_SPM_LOG_LEVEL_INFO) 46 #define SPMLOG_INFMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val) 47 #define SPMLOG_INFMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg)) 48 #else 49 #define SPMLOG_INFMSGVAL(msg, val) 50 #define SPMLOG_INFMSG(msg) 51 #endif 52 53 #if (TFM_SPM_LOG_LEVEL >= TFM_SPM_LOG_LEVEL_ERROR) 54 #define SPMLOG_ERRMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val) 55 #define SPMLOG_ERRMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg)) 56 #else 57 #define SPMLOG_ERRMSGVAL(msg, val) 58 #define SPMLOG_ERRMSG(msg) 59 #endif 60 61 /** 62 * \brief SPM output API to convert digit number into HEX string and call the 63 * HAL API tfm_hal_output_spm_log. 64 * 65 * \param[in] msg A string message 66 * \param[in] len The length of the message 67 * \param[in] value A value need to be output 68 * 69 * \retval >=0 Number of chars output. 70 * \retval <0 TFM HAL error code. 71 */ 72 int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value); 73 74 #endif /* __TFM_SPM_LOG_H__ */ 75