blob: 5a2413ada86e13fd1f0e2b4632a814e09d73a609 [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>
Shawn Shan8fb8fda2020-09-28 13:56:38 +080013#include "tfm_hal_defs.h"
Shawn Shandee2b212020-05-18 18:10:43 +080014#include "tfm_hal_spm_logdev.h"
15
16/* The SPM log levels */
17#define TFM_SPM_LOG_LEVEL_DEBUG 2 /* All log APIs output */
18#define TFM_SPM_LOG_LEVEL_RELEASE 1 /*
19 * All log APIs output except SPMLOG_DBG
20 * and SPMLOG_DBGMSGVAL
21 */
22#define TFM_SPM_LOG_LEVEL_SILENCE 0 /* All log APIs are suppressed */
23
24#ifndef TFM_SPM_LOG_LEVEL
25#error "TFM_SPM_LOG_LEVEL not defined!"
26#endif
27
28#if (TFM_SPM_LOG_LEVEL > TFM_SPM_LOG_LEVEL_DEBUG || \
29 TFM_SPM_LOG_LEVEL < TFM_SPM_LOG_LEVEL_SILENCE)
30#error "Incorrect TFM_SPM_LOG_LEVEL value!"
31#endif
32
33#if (TFM_SPM_LOG_LEVEL == TFM_SPM_LOG_LEVEL_DEBUG)
Shawn Shan8fb8fda2020-09-28 13:56:38 +080034#define SPMLOG_DBGMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
35#define SPMLOG_DBGMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
Shawn Shandee2b212020-05-18 18:10:43 +080036#else
37#define SPMLOG_DBGMSGVAL(msg, val)
38#define SPMLOG_DBGMSG(msg)
39#endif
40
41#if (TFM_SPM_LOG_LEVEL >= TFM_SPM_LOG_LEVEL_RELEASE)
42#define SPMLOG_INFMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
43#define SPMLOG_ERRMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
44#define SPMLOG_INFMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
45#define SPMLOG_ERRMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
46#else
Shawn Shan8fb8fda2020-09-28 13:56:38 +080047#define SPMLOG_INFMSGVAL(msg, val)
48#define SPMLOG_ERRMSGVAL(msg, val)
Shawn Shandee2b212020-05-18 18:10:43 +080049#define SPMLOG_INFMSG(msg)
50#define SPMLOG_ERRMSG(msg)
51#endif
52
53/**
Shawn Shan8fb8fda2020-09-28 13:56:38 +080054 * \brief SPM output API to convert digit number into HEX string and call the
55 * HAL API tfm_hal_output_spm_log.
Shawn Shandee2b212020-05-18 18:10:43 +080056 *
57 * \param[in] msg A string message
58 * \param[in] len The length of the message
59 * \param[in] value A value need to be output
60 *
61 * \retval >=0 Number of chars output.
62 * \retval <0 TFM HAL error code.
63 */
Shawn Shanb1eb42b2020-09-10 18:01:32 +080064int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value);
Shawn Shandee2b212020-05-18 18:10:43 +080065
66#endif /* __TFM_SPM_LOG_H__ */