fsl_cdog.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Copyright 2020 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_CDOG_H_
  8. #define _FSL_CDOG_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup CDOG
  12. * @{
  13. */
  14. /*! @file */
  15. /*******************************************************************************
  16. * Definitions
  17. *******************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief Defines CDOG driver version 2.1.0.
  21. *
  22. * Change log:
  23. * - Version 2.1.0
  24. * - Rename CWT to CDOG
  25. * - Version 2.0.2
  26. * - Fix MISRA-2012 issues
  27. * - Version 2.0.1
  28. * - Fix doxygen issues
  29. * - Version 2.0.0
  30. * - initial version
  31. */
  32. #define FSL_CDOG_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
  33. /*@}*/
  34. typedef struct
  35. {
  36. uint8_t lock : 2;
  37. uint8_t timeout : 3;
  38. uint8_t miscompare : 3;
  39. uint8_t sequence : 3;
  40. uint8_t control : 3;
  41. uint8_t state : 3;
  42. uint8_t address : 3;
  43. uint8_t reserved : 8;
  44. uint8_t irq_pause : 2;
  45. uint8_t debug_halt : 2;
  46. } cdog_config_t;
  47. enum __cdog_debug_Action_ctrl_enum
  48. {
  49. kCDOG_DebugHaltCtrl_Run = 0x1,
  50. kCDOG_DebugHaltCtrl_Pause = 0x2,
  51. };
  52. enum __cdog_irq_pause_ctrl_enum
  53. {
  54. kCDOG_IrqPauseCtrl_Run = 0x1,
  55. kCDOG_IrqPauseCtrl_Pause = 0x2,
  56. };
  57. enum __cdog_fault_ctrl_enum
  58. {
  59. kCDOG_FaultCtrl_EnableReset = 0x1U,
  60. kCDOG_FaultCtrl_EnableInterrupt = 0x2U,
  61. kCDOG_FaultCtrl_NoAction = 0x4U,
  62. };
  63. enum __code_lock_ctrl_enum
  64. {
  65. kCDOG_LockCtrl_Lock = 0x1,
  66. kCDOG_LockCtrl_Unlock = 0x2,
  67. };
  68. typedef uint32_t secure_counter_t;
  69. #define SC_ADD(add) \
  70. do \
  71. { \
  72. CDOG->ADD = (secure_counter_t)(add); \
  73. } while (0)
  74. #define SC_ADD1 \
  75. do \
  76. { \
  77. CDOG->ADD1 = (secure_counter_t)0x1U; \
  78. } while (0)
  79. #define SC_ADD16 \
  80. do \
  81. { \
  82. CDOG->ADD16 = (secure_counter_t)0x1U; \
  83. } while (0)
  84. #define SC_ADD256 \
  85. do \
  86. { \
  87. CDOG->ADD256 = (secure_counter_t)0x1U; \
  88. } while (0)
  89. #define SC_SUB(sub) \
  90. do \
  91. { \
  92. CDOG->SUB = (secure_counter_t)(sub); \
  93. } while (0)
  94. #define SC_SUB1 \
  95. do \
  96. { \
  97. CDOG->SUB1 = (secure_counter_t)0x1U; \
  98. } while (0)
  99. #define SC_SUB16 \
  100. do \
  101. { \
  102. CDOG->SUB16 = (secure_counter_t)0x1U; \
  103. } while (0)
  104. #define SC_SUB256 \
  105. do \
  106. { \
  107. CDOG->SUB256 = (secure_counter_t)0x1U; \
  108. } while (0)
  109. #define SC_CHECK(val) \
  110. do \
  111. { \
  112. CDOG->RESTART = (secure_counter_t)val; \
  113. } while (0)
  114. /*******************************************************************************
  115. * API
  116. *******************************************************************************/
  117. extern void CDOG_DriverIRQHandler(void);
  118. #if defined(__cplusplus)
  119. extern "C" {
  120. #endif /* __cplusplus */
  121. /*!
  122. * @name CDOG Functional Operation
  123. * @{
  124. */
  125. /*!
  126. * @brief Initialize CDOG
  127. *
  128. * This function initializes CDOG block and setting.
  129. *
  130. * @param base CDOG peripheral base address
  131. * @param conf CDOG configuration structure
  132. * @return Status of the init operation
  133. */
  134. status_t CDOG_Init(CDOG_Type *base, cdog_config_t *conf);
  135. /*!
  136. * @brief Deinitialize CDOG
  137. *
  138. * This function deinitializes CDOG secure counter.
  139. *
  140. * @param base CDOG peripheral base address
  141. */
  142. void CDOG_Deinit(CDOG_Type *base);
  143. /*!
  144. * @brief Sets the default configuration of CDOG
  145. *
  146. * This function initialize CDOG config structure to default values.
  147. *
  148. * @param conf CDOG configuration structure
  149. */
  150. void CDOG_GetDefaultConfig(cdog_config_t *conf);
  151. /*!
  152. * @brief Stops secure counter and instruction timer
  153. *
  154. * This function stops instruction timer and secure counter.
  155. * This also change state od CDOG to IDLE.
  156. *
  157. * @param base CDOG peripheral base address
  158. * @param stop expected value which will be compared with value of secure counter
  159. */
  160. void CDOG_Stop(CDOG_Type *base, uint32_t stop);
  161. /*!
  162. * @brief Sets secure counter and instruction timer values
  163. *
  164. * This function sets value in RELOAD and START registers
  165. * for instruction timer and secure counter
  166. *
  167. * @param base CDOG peripheral base address
  168. * @param reload reload value
  169. * @param start start value
  170. */
  171. void CDOG_Start(CDOG_Type *base, uint32_t reload, uint32_t start);
  172. /*!
  173. * @brief Checks secure counter.
  174. *
  175. * This function compares stop value in handler with secure counter value
  176. * by writting to RELOAD refister.
  177. *
  178. * @param base CDOG peripheral base address
  179. * @param check expected (stop) value
  180. */
  181. void CDOG_Check(CDOG_Type *base, uint32_t check);
  182. /*!
  183. * @brief Sets secure counter and instruction timer values
  184. *
  185. * This function sets value in STOP, RELOAD and START registers
  186. * for instruction timer and secure counter.
  187. *
  188. * @param base CDOG peripheral base address
  189. * @param stop expected value which will be compared with value of secure counter
  190. * @param reload reload value for instruction timer
  191. * @param start start value for secure timer
  192. */
  193. void CDOG_Set(CDOG_Type *base, uint32_t stop, uint32_t reload, uint32_t start);
  194. /*!
  195. * @brief Add value to secure counter
  196. *
  197. * This function add specified value to secure counter.
  198. *
  199. * @param base CDOG peripheral base address.
  200. * @param add Value to be added.
  201. */
  202. void CDOG_Add(CDOG_Type *base, uint32_t add);
  203. /*!
  204. * @brief Add 1 to secure counter
  205. *
  206. * This function add 1 to secure counter.
  207. *
  208. * @param base CDOG peripheral base address.
  209. */
  210. void CDOG_Add1(CDOG_Type *base);
  211. /*!
  212. * @brief Add 16 to secure counter
  213. *
  214. * This function add 16 to secure counter.
  215. *
  216. * @param base CDOG peripheral base address.
  217. */
  218. void CDOG_Add16(CDOG_Type *base);
  219. /*!
  220. * @brief Add 256 to secure counter
  221. *
  222. * This function add 256 to secure counter.
  223. *
  224. * @param base CDOG peripheral base address.
  225. */
  226. void CDOG_Add256(CDOG_Type *base);
  227. /*!
  228. * brief Substract value to secure counter
  229. *
  230. * This function substract specified value to secure counter.
  231. *
  232. * param base CDOG peripheral base address.
  233. * param sub Value to be substracted.
  234. */
  235. void CDOG_Sub(CDOG_Type *base, uint32_t sub);
  236. /*!
  237. * @brief Substract 1 from secure counter
  238. *
  239. * This function substract specified 1 from secure counter.
  240. *
  241. * @param base CDOG peripheral base address.
  242. */
  243. void CDOG_Sub1(CDOG_Type *base);
  244. /*!
  245. * @brief Substract 16 from secure counter
  246. *
  247. * This function substract specified 16 from secure counter.
  248. *
  249. * @param base CDOG peripheral base address.
  250. */
  251. void CDOG_Sub16(CDOG_Type *base);
  252. /*!
  253. * @brief Substract 256 from secure counter
  254. *
  255. * This function substract specified 256 from secure counter.
  256. *
  257. * @param base CDOG peripheral base address.
  258. */
  259. void CDOG_Sub256(CDOG_Type *base);
  260. /*!
  261. * @brief Set the CDOG persistent word.
  262. *
  263. * @param base CDOG peripheral base address.
  264. * @param value The value to be written.
  265. */
  266. void CDOG_WritePersistent(CDOG_Type *base, uint32_t value);
  267. /*!
  268. * @brief Get the CDOG persistent word.
  269. *
  270. * @param base CDOG peripheral base address.
  271. * @return The persistent word.
  272. */
  273. uint32_t CDOG_ReadPersistent(CDOG_Type *base);
  274. /*! @}*/
  275. #if defined(__cplusplus)
  276. }
  277. #endif /* __cplusplus */
  278. /*! @}*/ /* end of group cdog */
  279. #endif /* _FSL_CDOG_H_ */