TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
spm_log.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "tfm_spm_log.h"
9 
10 #define MAX_DIGIT_BITS 12 /* 8 char for number, 2 for '0x' and 2 for '\r\n' */
11 const static char HEX_TABLE[] = {'0', '1', '2', '3', '4', '5', '6', '7',
12  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
13 
23 static void to_hex(uint32_t value, char msg[])
24 {
25  int i = MAX_DIGIT_BITS - 1;
26 
27  msg[i--] = '\n';
28  msg[i--] = '\r';
29  for (; i > 1; i--, value >>= 4) {
30  msg[i] = HEX_TABLE[value & 0xF];
31  }
32  msg[i--] = 'x';
33  msg[i--] = '0';
34 }
35 
36 int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value)
37 {
38  int32_t result_msg = 0, result_val;
39  char value_str[MAX_DIGIT_BITS];
40 
41  if (msg && len) {
42  result_msg = tfm_hal_output_spm_log(msg, len);
43  if (result_msg < TFM_HAL_SUCCESS) {
44  return result_msg;
45  }
46  }
47 
48  to_hex(value, value_str);
49 
50  result_val = tfm_hal_output_spm_log(value_str,
52  if (result_val < TFM_HAL_SUCCESS) {
53  return result_val;
54  }
55  return (result_msg + result_val);
56 }
#define MAX_DIGIT_BITS
Definition: spm_log.c:10
int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value)
SPM output API to convert digit number into HEX string and call the HAL API tfm_hal_output_spm_log.
Definition: spm_log.c:36