1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2018 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8 #ifndef _FSL_COP_H_
9 #define _FSL_COP_H_
10
11 #include "fsl_common.h"
12
13 /*!
14 * @addtogroup cop
15 * @{
16 */
17
18 /*******************************************************************************
19 * Definitions
20 *******************************************************************************/
21
22 /*! @name Driver version */
23 /*@{*/
24 /*! @brief COP driver version 2.0.1. */
25 #define FSL_COP_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
26 /*@}*/
27
28 /*! @name COP refresh sequence. */
29 /*@{*/
30 #define COP_FIRST_BYTE_OF_REFRESH (0x55U) /*!< First byte of refresh sequence */
31 #define COP_SECOND_BYTE_OF_REFRESH (0xAAU) /*!< Second byte of refresh sequence */
32 /*@}*/
33
34 /*! @brief COP clock source selection. */
35 typedef enum _cop_clock_source
36 {
37 kCOP_LpoClock = 0U, /*!< COP clock sourced from LPO */
38 #if defined(FSL_FEATURE_COP_HAS_MORE_CLKSRC) && FSL_FEATURE_COP_HAS_MORE_CLKSRC
39 kCOP_McgIrClock = 1U, /*!< COP clock sourced from MCGIRCLK */
40 kCOP_OscErClock = 2U, /*!< COP clock sourced from OSCERCLK */
41 #endif /* FSL_FEATURE_COP_HAS_MORE_CLKSRC */
42 kCOP_BusClock = 3U, /*!< COP clock sourced from Bus clock */
43 } cop_clock_source_t;
44
45 /*! @brief Define the COP timeout cycles. */
46 typedef enum _cop_timeout_cycles
47 {
48 kCOP_2Power5CyclesOr2Power13Cycles = 1U, /*!< 2^5 or 2^13 clock cycles */
49 kCOP_2Power8CyclesOr2Power16Cycles = 2U, /*!< 2^8 or 2^16 clock cycles */
50 kCOP_2Power10CyclesOr2Power18Cycles = 3U, /*!< 2^10 or 2^18 clock cycles */
51 } cop_timeout_cycles_t;
52
53 #if defined(FSL_FEATURE_COP_HAS_LONGTIME_MODE) && FSL_FEATURE_COP_HAS_LONGTIME_MODE
54 /*! @brief Define the COP timeout mode. */
55 typedef enum _cop_timeout_mode
56 {
57 kCOP_ShortTimeoutMode = 0U, /*!< COP selects long timeout */
58 kCOP_LongTimeoutMode = 1U, /*!< COP selects short timeout */
59 } cop_timeout_mode_t;
60 #endif /* FSL_FEATURE_COP_HAS_LONGTIME_MODE */
61
62 /*! @brief Describes COP configuration structure. */
63 typedef struct _cop_config
64 {
65 bool enableWindowMode; /*!< COP run mode: window mode or normal mode */
66 #if defined(FSL_FEATURE_COP_HAS_LONGTIME_MODE) && FSL_FEATURE_COP_HAS_LONGTIME_MODE
67 cop_timeout_mode_t timeoutMode; /*!< COP timeout mode: long timeout or short timeout */
68 bool enableStop; /*!< Enable or disable COP in STOP mode */
69 bool enableDebug; /*!< Enable or disable COP in DEBUG mode */
70 #endif /* FSL_FEATURE_COP_HAS_LONGTIME_MODE */
71 cop_clock_source_t clockSource; /*!< Set COP clock source */
72 cop_timeout_cycles_t timeoutCycles; /*!< Set COP timeout value */
73 } cop_config_t;
74
75 /*******************************************************************************
76 * API
77 *******************************************************************************/
78
79 #if defined(__cplusplus)
80 extern "C" {
81 #endif /* __cplusplus*/
82
83 /*!
84 * @name COP Functional Operation
85 * @{
86 */
87
88 /*!
89 * @brief Initializes the COP configuration structure.
90 *
91 * This function initializes the COP configuration structure to default values. The default
92 * values are:
93 * @code
94 * copConfig->enableWindowMode = false;
95 * copConfig->timeoutMode = kCOP_LongTimeoutMode;
96 * copConfig->enableStop = false;
97 * copConfig->enableDebug = false;
98 * copConfig->clockSource = kCOP_LpoClock;
99 * copConfig->timeoutCycles = kCOP_2Power10CyclesOr2Power18Cycles;
100 * @endcode
101 *
102 * @param config Pointer to the COP configuration structure.
103 * @see cop_config_t
104 */
105 void COP_GetDefaultConfig(cop_config_t *config);
106
107 /*!
108 * @brief Initializes the COP module.
109 *
110 * This function configures the COP. After it is called, the COP
111 * starts running according to the configuration.
112 * Because all COP control registers are write-once only, the COP_Init function
113 * and the COP_Disable function can be called only once. A second call has no effect.
114 *
115 * Example:
116 * @code
117 * cop_config_t config;
118 * COP_GetDefaultConfig(&config);
119 * config.timeoutCycles = kCOP_2Power8CyclesOr2Power16Cycles;
120 * COP_Init(sim_base,&config);
121 * @endcode
122 *
123 * @param base SIM peripheral base address.
124 * @param config The configuration of COP.
125 */
126 void COP_Init(SIM_Type *base, const cop_config_t *config);
127
128 /*!
129 * @brief De-initializes the COP module.
130 * This dedicated function is not provided. Instead, the COP_Disable function can be used to disable the COP.
131 */
132
133 /*!
134 * @brief Disables the COP module.
135 *
136 * This function disables the COP Watchdog.
137 * Note: The COP configuration register is a write-once after reset.
138 * To disable the COP Watchdog, call this function first.
139 *
140 * @param base SIM peripheral base address.
141 */
COP_Disable(SIM_Type * base)142 static inline void COP_Disable(SIM_Type *base)
143 {
144 base->COPC &= ~SIM_COPC_COPT_MASK;
145 }
146
147 /*!
148 * @brief Refreshes the COP timer
149 *
150 * This function feeds the COP.
151 *
152 * @param base SIM peripheral base address.
153 */
154 void COP_Refresh(SIM_Type *base);
155
156 /*@}*/
157
158 #if defined(__cplusplus)
159 }
160 #endif /* __cplusplus */
161
162 /*! @}*/
163
164 #endif /* _FSL_COP_H_ */
165