blob: 3a00838c1862903fabc634c038c4fbb8c64a07a9 [file] [log] [blame]
Shawn Shandee2b212020-05-18 18:10:43 +08001/*
2 * Copyright (c) 2020, 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_spm_logdev.h"
14
15/* The SPM log levels */
16#define TFM_SPM_LOG_LEVEL_DEBUG 2 /* All log APIs output */
17#define TFM_SPM_LOG_LEVEL_RELEASE 1 /*
18 * All log APIs output except SPMLOG_DBG
19 * and SPMLOG_DBGMSGVAL
20 */
21#define TFM_SPM_LOG_LEVEL_SILENCE 0 /* All log APIs are suppressed */
22
23#ifndef TFM_SPM_LOG_LEVEL
24#error "TFM_SPM_LOG_LEVEL not defined!"
25#endif
26
27#if (TFM_SPM_LOG_LEVEL > TFM_SPM_LOG_LEVEL_DEBUG || \
28 TFM_SPM_LOG_LEVEL < TFM_SPM_LOG_LEVEL_SILENCE)
29#error "Incorrect TFM_SPM_LOG_LEVEL value!"
30#endif
31
32#if (TFM_SPM_LOG_LEVEL == TFM_SPM_LOG_LEVEL_DEBUG)
33#define SPMLOG_DBGMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
34#define SPMLOG_DBGMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
35#else
36#define SPMLOG_DBGMSGVAL(msg, val)
37#define SPMLOG_DBGMSG(msg)
38#endif
39
40#if (TFM_SPM_LOG_LEVEL >= TFM_SPM_LOG_LEVEL_RELEASE)
41#define SPMLOG_INFMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
42#define SPMLOG_ERRMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
43#define SPMLOG_INFMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
44#define SPMLOG_ERRMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
45#else
46#define SPMLOG_INFMSGVAL(msg, val)
47#define SPMLOG_ERRMSGVAL(msg, val)
48#define SPMLOG_INFMSG(msg)
49#define SPMLOG_ERRMSG(msg)
50#endif
51
52/**
53 * \brief SPM output API to combine message and value together as a joint
54 * message, and call the log HAL API tfm_hal_output_spm_log.
55 *
56 * \param[in] msg A string message
57 * \param[in] len The length of the message
58 * \param[in] value A value need to be output
59 *
60 * \retval >=0 Number of chars output.
61 * \retval <0 TFM HAL error code.
62 */
Shawn Shanb1eb42b2020-09-10 18:01:32 +080063int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value);
Shawn Shandee2b212020-05-18 18:10:43 +080064
65#endif /* __TFM_SPM_LOG_H__ */