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