Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:58

0001 /*
0002  * Copyright 2020 NXP
0003  * All rights reserved.
0004  *
0005  * SPDX-License-Identifier: BSD-3-Clause
0006  */
0007 #ifndef _FSL_CDOG_H_
0008 #define _FSL_CDOG_H_
0009 
0010 #include "fsl_common.h"
0011 
0012 /*!
0013  * @addtogroup CDOG
0014  * @{
0015  */
0016 
0017 /*! @file */
0018 
0019 /*******************************************************************************
0020  * Definitions
0021  *******************************************************************************/
0022 
0023 /*! @name Driver version */
0024 /*@{*/
0025 /*! @brief Defines CDOG driver version 2.1.1.
0026  *
0027  * Change log:
0028  * - Version 2.1.1
0029  *   - Remove bit CONTROL[CONTROL_CTRL]
0030  * - Version 2.1.0
0031  *   - Rename CWT to CDOG
0032  * - Version 2.0.2
0033  *   - Fix MISRA-2012 issues
0034  * - Version 2.0.1
0035  *   - Fix doxygen issues
0036  * - Version 2.0.0
0037  *   - initial version
0038  */
0039 #define FSL_CDOG_DRIVER_VERSION (MAKE_VERSION(2, 1, 1))
0040 /*@}*/
0041 
0042 typedef struct
0043 {
0044     uint8_t lock : 2;
0045     uint8_t timeout : 3;
0046     uint8_t miscompare : 3;
0047     uint8_t sequence : 3;
0048     uint8_t state : 3;
0049     uint8_t address : 3;
0050     uint8_t reserved : 8;
0051     uint8_t irq_pause : 2;
0052     uint8_t debug_halt : 2;
0053 } cdog_config_t;
0054 
0055 enum __cdog_debug_Action_ctrl_enum
0056 {
0057     kCDOG_DebugHaltCtrl_Run   = 0x1,
0058     kCDOG_DebugHaltCtrl_Pause = 0x2,
0059 };
0060 
0061 enum __cdog_irq_pause_ctrl_enum
0062 {
0063     kCDOG_IrqPauseCtrl_Run   = 0x1,
0064     kCDOG_IrqPauseCtrl_Pause = 0x2,
0065 };
0066 
0067 enum __cdog_fault_ctrl_enum
0068 {
0069     kCDOG_FaultCtrl_EnableReset     = 0x1U,
0070     kCDOG_FaultCtrl_EnableInterrupt = 0x2U,
0071     kCDOG_FaultCtrl_NoAction        = 0x4U,
0072 };
0073 
0074 enum __code_lock_ctrl_enum
0075 {
0076     kCDOG_LockCtrl_Lock   = 0x1,
0077     kCDOG_LockCtrl_Unlock = 0x2,
0078 };
0079 
0080 typedef uint32_t secure_counter_t;
0081 
0082 #define SC_ADD(add)                          \
0083     do                                       \
0084     {                                        \
0085         CDOG->ADD = (secure_counter_t)(add); \
0086     } while (0)
0087 
0088 #define SC_ADD1                              \
0089     do                                       \
0090     {                                        \
0091         CDOG->ADD1 = (secure_counter_t)0x1U; \
0092     } while (0)
0093 
0094 #define SC_ADD16                              \
0095     do                                        \
0096     {                                         \
0097         CDOG->ADD16 = (secure_counter_t)0x1U; \
0098     } while (0)
0099 
0100 #define SC_ADD256                              \
0101     do                                         \
0102     {                                          \
0103         CDOG->ADD256 = (secure_counter_t)0x1U; \
0104     } while (0)
0105 
0106 #define SC_SUB(sub)                          \
0107     do                                       \
0108     {                                        \
0109         CDOG->SUB = (secure_counter_t)(sub); \
0110     } while (0)
0111 
0112 #define SC_SUB1                              \
0113     do                                       \
0114     {                                        \
0115         CDOG->SUB1 = (secure_counter_t)0x1U; \
0116     } while (0)
0117 
0118 #define SC_SUB16                              \
0119     do                                        \
0120     {                                         \
0121         CDOG->SUB16 = (secure_counter_t)0x1U; \
0122     } while (0)
0123 
0124 #define SC_SUB256                              \
0125     do                                         \
0126     {                                          \
0127         CDOG->SUB256 = (secure_counter_t)0x1U; \
0128     } while (0)
0129 
0130 #define SC_CHECK(val)                          \
0131     do                                         \
0132     {                                          \
0133         CDOG->RESTART = (secure_counter_t)val; \
0134     } while (0)
0135 
0136 /*******************************************************************************
0137  * API
0138  *******************************************************************************/
0139 
0140 extern void CDOG_DriverIRQHandler(void);
0141 
0142 #if defined(__cplusplus)
0143 extern "C" {
0144 #endif /* __cplusplus */
0145 
0146 /*!
0147  * @name CDOG Functional Operation
0148  * @{
0149  */
0150 
0151 /*!
0152  * @brief Initialize CDOG
0153  *
0154  * This function initializes CDOG block and setting.
0155  *
0156  * @param base CDOG peripheral base address
0157  * @param conf CDOG configuration structure
0158  * @return Status of the init operation
0159  */
0160 status_t CDOG_Init(CDOG_Type *base, cdog_config_t *conf);
0161 
0162 /*!
0163  * @brief Deinitialize CDOG
0164  *
0165  * This function deinitializes CDOG secure counter.
0166  *
0167  * @param base CDOG peripheral base address
0168  */
0169 void CDOG_Deinit(CDOG_Type *base);
0170 
0171 /*!
0172  * @brief Sets the default configuration of CDOG
0173  *
0174  * This function initialize CDOG config structure to default values.
0175  *
0176  * @param conf CDOG configuration structure
0177  */
0178 void CDOG_GetDefaultConfig(cdog_config_t *conf);
0179 
0180 /*!
0181  * @brief Stops secure counter and instruction timer
0182  *
0183  * This function stops instruction timer and secure counter.
0184  * This also change state od CDOG to IDLE.
0185  *
0186  * @param base CDOG peripheral base address
0187  * @param stop expected value which will be compared with value of secure counter
0188  */
0189 void CDOG_Stop(CDOG_Type *base, uint32_t stop);
0190 
0191 /*!
0192  * @brief Sets secure counter and instruction timer values
0193  *
0194  * This function sets value in RELOAD and START registers
0195  * for instruction timer and secure counter
0196  *
0197  * @param base CDOG peripheral base address
0198  * @param reload reload value
0199  * @param start start value
0200  */
0201 void CDOG_Start(CDOG_Type *base, uint32_t reload, uint32_t start);
0202 
0203 /*!
0204  * @brief Checks secure counter.
0205  *
0206  * This function compares stop value in handler with secure counter value
0207  * by writting to RELOAD refister.
0208  *
0209  * @param base CDOG peripheral base address
0210  * @param check expected (stop) value
0211  */
0212 void CDOG_Check(CDOG_Type *base, uint32_t check);
0213 
0214 /*!
0215  * @brief Sets secure counter and instruction timer values
0216  *
0217  * This function sets value in STOP, RELOAD and START registers
0218  * for instruction timer and secure counter.
0219  *
0220  * @param base CDOG peripheral base address
0221  * @param stop expected value which will be compared with value of secure counter
0222  * @param reload reload value for instruction timer
0223  * @param start start value for secure timer
0224  */
0225 void CDOG_Set(CDOG_Type *base, uint32_t stop, uint32_t reload, uint32_t start);
0226 
0227 /*!
0228  * @brief Add value to secure counter
0229  *
0230  * This function add specified value to secure counter.
0231  *
0232  * @param base CDOG peripheral base address.
0233  * @param add Value to be added.
0234  */
0235 void CDOG_Add(CDOG_Type *base, uint32_t add);
0236 
0237 /*!
0238  * @brief Add 1 to secure counter
0239  *
0240  * This function add 1 to secure counter.
0241  *
0242  * @param base CDOG peripheral base address.
0243  */
0244 void CDOG_Add1(CDOG_Type *base);
0245 
0246 /*!
0247  * @brief Add 16 to secure counter
0248  *
0249  * This function add 16 to secure counter.
0250  *
0251  * @param base CDOG peripheral base address.
0252  */
0253 void CDOG_Add16(CDOG_Type *base);
0254 
0255 /*!
0256  * @brief Add 256 to secure counter
0257  *
0258  * This function add 256 to secure counter.
0259  *
0260  * @param base CDOG peripheral base address.
0261  */
0262 void CDOG_Add256(CDOG_Type *base);
0263 
0264 /*!
0265  * brief Substract value to secure counter
0266  *
0267  * This function substract specified value to secure counter.
0268  *
0269  * param base CDOG peripheral base address.
0270  * param sub Value to be substracted.
0271  */
0272 void CDOG_Sub(CDOG_Type *base, uint32_t sub);
0273 
0274 /*!
0275  * @brief Substract 1 from secure counter
0276  *
0277  * This function substract specified 1 from secure counter.
0278  *
0279  * @param base CDOG peripheral base address.
0280  */
0281 void CDOG_Sub1(CDOG_Type *base);
0282 
0283 /*!
0284  * @brief Substract 16 from secure counter
0285  *
0286  * This function substract specified 16 from secure counter.
0287  *
0288  * @param base CDOG peripheral base address.
0289  */
0290 void CDOG_Sub16(CDOG_Type *base);
0291 
0292 /*!
0293  * @brief Substract 256 from secure counter
0294  *
0295  * This function substract specified 256 from secure counter.
0296  *
0297  * @param base CDOG peripheral base address.
0298  */
0299 void CDOG_Sub256(CDOG_Type *base);
0300 
0301 /*!
0302  * @brief Set the CDOG persistent word.
0303  *
0304  * @param base CDOG peripheral base address.
0305  * @param value The value to be written.
0306  */
0307 void CDOG_WritePersistent(CDOG_Type *base, uint32_t value);
0308 
0309 /*!
0310  * @brief Get the CDOG persistent word.
0311  *
0312  * @param base CDOG peripheral base address.
0313  * @return The persistent word.
0314  */
0315 uint32_t CDOG_ReadPersistent(CDOG_Type *base);
0316 
0317 /*! @}*/
0318 
0319 #if defined(__cplusplus)
0320 }
0321 #endif /* __cplusplus */
0322 
0323 /*! @}*/ /* end of group cdog */
0324 
0325 #endif /* _FSL_CDOG_H_ */