ssi_pal_log.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**************************************************************************************
  2. * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved *
  3. * *
  4. * This file and the related binary are licensed under the following license: *
  5. * *
  6. * ARM Object Code and Header Files License, v1.0 Redistribution. *
  7. * *
  8. * Redistribution and use of object code, header files, and documentation, without *
  9. * modification, are permitted provided that the following conditions are met: *
  10. * *
  11. * 1) Redistributions must reproduce the above copyright notice and the *
  12. * following disclaimer in the documentation and/or other materials *
  13. * provided with the distribution. *
  14. * *
  15. * 2) Unless to the extent explicitly permitted by law, no reverse *
  16. * engineering, decompilation, or disassembly of is permitted. *
  17. * *
  18. * 3) Redistribution and use is permitted solely for the purpose of *
  19. * developing or executing applications that are targeted for use *
  20. * on an ARM-based product. *
  21. * *
  22. * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  23. * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT *
  24. * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, *
  25. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
  26. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
  28. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
  33. **************************************************************************************/
  34. #ifndef _SSI_PAL_LOG_H_
  35. #define _SSI_PAL_LOG_H_
  36. #include "ssi_pal_types.h"
  37. /*!
  38. @file
  39. @brief This file contains the PAL layer log definitions, by default the log is disabled.
  40. @defgroup ssi_pal_log CryptoCell PAL logging APIs and definitions
  41. @{
  42. @ingroup ssi_pal
  43. */
  44. /* PAL log levels (to be used in SASI_PAL_logLevel) */
  45. /*! PAL log level - disabled. */
  46. #define SASI_PAL_LOG_LEVEL_NULL -1 /*!< \internal Disable logging */
  47. /*! PAL log level - error. */
  48. #define SASI_PAL_LOG_LEVEL_ERR 0
  49. /*! PAL log level - warning. */
  50. #define SASI_PAL_LOG_LEVEL_WARN 1
  51. /*! PAL log level - info. */
  52. #define SASI_PAL_LOG_LEVEL_INFO 2
  53. /*! PAL log level - debug. */
  54. #define SASI_PAL_LOG_LEVEL_DEBUG 3
  55. /*! PAL log level - trace. */
  56. #define SASI_PAL_LOG_LEVEL_TRACE 4
  57. /*! PAL log level - data. */
  58. #define SASI_PAL_LOG_LEVEL_DATA 5
  59. #ifndef SASI_PAL_LOG_CUR_COMPONENT
  60. /* Setting default component mask in case caller did not define */
  61. /* (a mask that is always on for every log mask value but full masking) */
  62. /*! Default log debugged component.*/
  63. #define SASI_PAL_LOG_CUR_COMPONENT 0xFFFFFFFF
  64. #endif
  65. #ifndef SASI_PAL_LOG_CUR_COMPONENT_NAME
  66. /*! Default log component name.*/
  67. #define SASI_PAL_LOG_CUR_COMPONENT_NAME "Dx"
  68. #endif
  69. /* Select compile time log level (default if not explicitly specified by caller) */
  70. #ifndef SASI_PAL_MAX_LOG_LEVEL /* Can be overriden by external definition of this constant */
  71. #ifdef DEBUG
  72. /*! Default debug log level (when debug is set to on).*/
  73. #define SASI_PAL_MAX_LOG_LEVEL SASI_PAL_LOG_LEVEL_ERR /*SASI_PAL_LOG_LEVEL_DEBUG*/
  74. #else /* Disable logging */
  75. /*! Default debug log level (when debug is set to off).*/
  76. #define SASI_PAL_MAX_LOG_LEVEL SASI_PAL_LOG_LEVEL_NULL
  77. #endif
  78. #endif /*SASI_PAL_MAX_LOG_LEVEL*/
  79. /*! Evaluate SASI_PAL_MAX_LOG_LEVEL in case provided by caller */
  80. #define __SASI_PAL_LOG_LEVEL_EVAL(level) level
  81. /*! Maximal log level defintion.*/
  82. #define _SASI_PAL_MAX_LOG_LEVEL __SASI_PAL_LOG_LEVEL_EVAL(SASI_PAL_MAX_LOG_LEVEL)
  83. #ifdef ARM_DSM //not support ARM DSM log feature
  84. /*! Log init function. */
  85. #define SaSi_PalLogInit() do {} while (0)
  86. /*! Log set level function - sets the level of logging in case of debug. */
  87. #define SaSi_PalLogLevelSet(setLevel) do {} while (0)
  88. /*! Log set mask function - sets the component masking in case of debug. */
  89. #define SaSi_PalLogMaskSet(setMask) do {} while (0)
  90. /*! Log log funtion based on various platform */
  91. #define SaSi_PalLogPlatsampan(level, msg) do {} while (0)
  92. #else
  93. #if _SASI_PAL_MAX_LOG_LEVEL > SASI_PAL_LOG_LEVEL_NULL
  94. /*! Log init function. */
  95. void SaSi_PalLogInit(void);
  96. /*! Log set level function - sets the level of logging in case of debug. */
  97. void SaSi_PalLogLevelSet(int setLevel);
  98. /*! Log set mask function - sets the component masking in case of debug. */
  99. void SaSi_PalLogMaskSet(uint32_t setMask);
  100. /*! Log log funtion based on various platform */
  101. void SaSi_PalLogPlat(uint32_t level, const char *msg);
  102. /*! Global variable for log level */
  103. extern int SaSi_PAL_logLevel;
  104. /*! Global variable for log mask */
  105. extern uint32_t SaSi_PAL_logMask;
  106. #else /* No log */
  107. /*! Log init function. */
  108. #define SaSi_PalLogInit() do {} while (0)
  109. /*! Log set level function - sets the level of logging in case of debug. */
  110. #define SaSi_PalLogLevelSet(setLevel) do {} while (0)
  111. /*! Log set mask function - sets the component masking in case of debug. */
  112. #define SaSi_PalLogMaskSet(setMask) do {} while (0)
  113. /*! Log log funtion based on various platform */
  114. #define SaSi_PalLogPlat(level, msg) do {} while (0)
  115. #endif
  116. #endif
  117. /*! Filter logging based on logMask and dispatch to platform specific logging mechanism */
  118. #define _SASI_PAL_LOG(level, msg) \
  119. if (SaSi_PAL_logMask & SASI_PAL_LOG_CUR_COMPONENT) \
  120. SaSi_PalLogPlat(SASI_PAL_LOG_LEVEL_ ## level, msg )
  121. #if (_SASI_PAL_MAX_LOG_LEVEL >= SASI_PAL_LOG_LEVEL_ERR)
  122. /*! Log messages according to log level.*/
  123. #define SASI_PAL_LOG_ERR(msg) \
  124. _SASI_PAL_LOG(ERR, msg)
  125. #else
  126. /*! Log messages according to log level.*/
  127. #define SASI_PAL_LOG_ERR( ... ) do {} while (0)
  128. #endif
  129. #if (_SASI_PAL_MAX_LOG_LEVEL >= SASI_PAL_LOG_LEVEL_WARN)
  130. /*! Log messages according to log level.*/
  131. #define SASI_PAL_LOG_WARN(msg) \
  132. if (SaSi_PAL_logLevel >= SASI_PAL_LOG_LEVEL_WARN) \
  133. _SASI_PAL_LOG(WARN, msg)
  134. #else
  135. /*! Log messages according to log level.*/
  136. #define SASI_PAL_LOG_WARN( ... ) do {} while (0)
  137. #endif
  138. #if (_SASI_PAL_MAX_LOG_LEVEL >= SASI_PAL_LOG_LEVEL_INFO)
  139. /*! Log messages according to log level.*/
  140. #define SASI_PAL_LOG_INFO(msg) \
  141. if (SaSi_PAL_logLevel >= SASI_PAL_LOG_LEVEL_INFO) \
  142. _SASI_PAL_LOG(INFO, msg)
  143. #else
  144. /*! Log messages according to log level.*/
  145. #define SASI_PAL_LOG_INFO( ... ) do {} while (0)
  146. #endif
  147. #if (_SASI_PAL_MAX_LOG_LEVEL >= SASI_PAL_LOG_LEVEL_DEBUG)
  148. /*! Log messages according to log level.*/
  149. #define SASI_PAL_LOG_DEBUG(msg) \
  150. if (SaSi_PAL_logLevel >= SASI_PAL_LOG_LEVEL_DEBUG) \
  151. _SASI_PAL_LOG(DEBUG, msg)
  152. /*! Log message buffer.*/
  153. #define SASI_PAL_LOG_DUMP_BUF(msg, buf, size) \
  154. do { \
  155. int i; \
  156. uint8_t *pData = (uint8_t*)buf; \
  157. \
  158. PRINTF("%s (%d):\n", msg, size); \
  159. for (i = 0; i < size; i++) { \
  160. PRINTF("0x%02X ", pData[i]); \
  161. if ((i & 0xF) == 0xF) { \
  162. PRINTF("\n"); \
  163. } \
  164. } \
  165. PRINTF("\n"); \
  166. } while (0)
  167. #else
  168. /*! Log debug messages.*/
  169. #define SASI_PAL_LOG_DEBUG( ... ) do {} while (0)
  170. /*! Log debug buffer.*/
  171. #define SASI_PAL_LOG_DUMP_BUF(msg, buf, size) do {} while (0)
  172. #endif
  173. #if (_SASI_PAL_MAX_LOG_LEVEL >= SASI_PAL_LOG_LEVEL_TRACE)
  174. /*! Log debug trace.*/
  175. #define SASI_PAL_LOG_TRACE(msg) \
  176. if (SaSi_PAL_logLevel >= SASI_PAL_LOG_LEVEL_TRACE) \
  177. _SASI_PAL_LOG(TRACE, format, msg)
  178. #else
  179. /*! Log debug trace.*/
  180. #define SASI_PAL_LOG_TRACE(...) do {} while (0)
  181. #endif
  182. #if (_SASI_PAL_MAX_LOG_LEVEL >= SASI_PAL_LOG_LEVEL_TRACE)
  183. /*! Log debug data.*/
  184. #define SASI_PAL_LOG_DATA(msg) \
  185. if (SaSi_PAL_logLevel >= SASI_PAL_LOG_LEVEL_TRACE) \
  186. _SASI_PAL_LOG(DATA, format, msg)
  187. #else
  188. /*! Log debug data.*/
  189. #define SASI_PAL_LOG_DATA( ...) do {} while (0)
  190. #endif
  191. /**
  192. @}
  193. */
  194. #endif /*_SSI_PAL_LOG_H_*/