blob: 4ad749ea5aad443238ab7383c6a8719e64519228 [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 */
Shawn Shan50996c42020-10-30 15:07:47 +080017#define TFM_SPM_LOG_LEVEL_DEBUG 3 /* All log APIs output */
18#define TFM_SPM_LOG_LEVEL_INFO 2 /*
Shawn Shandee2b212020-05-18 18:10:43 +080019 * All log APIs output except SPMLOG_DBG
20 * and SPMLOG_DBGMSGVAL
21 */
Shawn Shan50996c42020-10-30 15:07:47 +080022#define TFM_SPM_LOG_LEVEL_ERROR 1 /*
23 * Only SPMLOG_ERRMSG and SPMLOG_ERRMSGVAL
24 * APIs output.
25 */
Shawn Shandee2b212020-05-18 18:10:43 +080026#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)
Shawn Shan8fb8fda2020-09-28 13:56:38 +080038#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))
Shawn Shandee2b212020-05-18 18:10:43 +080040#else
41#define SPMLOG_DBGMSGVAL(msg, val)
42#define SPMLOG_DBGMSG(msg)
43#endif
44
Shawn Shan50996c42020-10-30 15:07:47 +080045#if (TFM_SPM_LOG_LEVEL >= TFM_SPM_LOG_LEVEL_INFO)
Shawn Shandee2b212020-05-18 18:10:43 +080046#define SPMLOG_INFMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
Shawn Shandee2b212020-05-18 18:10:43 +080047#define SPMLOG_INFMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
Shawn Shandee2b212020-05-18 18:10:43 +080048#else
Shawn Shan8fb8fda2020-09-28 13:56:38 +080049#define SPMLOG_INFMSGVAL(msg, val)
Shawn Shandee2b212020-05-18 18:10:43 +080050#define SPMLOG_INFMSG(msg)
Shawn Shan50996c42020-10-30 15:07:47 +080051#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)
Shawn Shandee2b212020-05-18 18:10:43 +080058#define SPMLOG_ERRMSG(msg)
59#endif
60
61/**
Shawn Shan8fb8fda2020-09-28 13:56:38 +080062 * \brief SPM output API to convert digit number into HEX string and call the
63 * HAL API tfm_hal_output_spm_log.
Shawn Shandee2b212020-05-18 18:10:43 +080064 *
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 */
Shawn Shanb1eb42b2020-09-10 18:01:32 +080072int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value);
Shawn Shandee2b212020-05-18 18:10:43 +080073
74#endif /* __TFM_SPM_LOG_H__ */