1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017 NXP
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * o Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #ifndef _FSL_COP_H_
31 #define _FSL_COP_H_
32
33 #include "fsl_common.h"
34
35 /*!
36 * @addtogroup cop
37 * @{
38 */
39
40
41 /*******************************************************************************
42 * Definitions
43 *******************************************************************************/
44
45 /*! @name Driver version */
46 /*@{*/
47 /*! @brief COP driver version 2.0.0. */
48 #define FSL_COP_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
49 /*@}*/
50
51 /*! @name COP refresh sequence. */
52 /*@{*/
53 #define COP_FIRST_BYTE_OF_REFRESH (0x55U) /*!< First byte of refresh sequence */
54 #define COP_SECOND_BYTE_OF_REFRESH (0xAAU) /*!< Second byte of refresh sequence */
55 /*@}*/
56
57 /*! @brief COP clock source selection. */
58 typedef enum _cop_clock_source
59 {
60 kCOP_LpoClock = 0U, /*!< COP clock sourced from LPO */
61 #if defined(FSL_FEATURE_COP_HAS_MORE_CLKSRC) && FSL_FEATURE_COP_HAS_MORE_CLKSRC
62 kCOP_McgIrClock = 1U, /*!< COP clock sourced from MCGIRCLK */
63 kCOP_OscErClock = 2U, /*!< COP clock sourced from OSCERCLK */
64 #endif /* FSL_FEATURE_COP_HAS_MORE_CLKSRC */
65 kCOP_BusClock = 3U, /*!< COP clock sourced from Bus clock */
66 } cop_clock_source_t;
67
68 /*! @brief Define the COP timeout cycles. */
69 typedef enum _cop_timeout_cycles
70 {
71 kCOP_2Power5CyclesOr2Power13Cycles = 1U, /*!< 2^5 or 2^13 clock cycles */
72 kCOP_2Power8CyclesOr2Power16Cycles = 2U, /*!< 2^8 or 2^16 clock cycles */
73 kCOP_2Power10CyclesOr2Power18Cycles = 3U, /*!< 2^10 or 2^18 clock cycles */
74 } cop_timeout_cycles_t;
75
76 #if defined(FSL_FEATURE_COP_HAS_LONGTIME_MODE) && FSL_FEATURE_COP_HAS_LONGTIME_MODE
77 /*! @breif Define the COP timeout mode. */
78 typedef enum _cop_timeout_mode
79 {
80 kCOP_ShortTimeoutMode = 0U, /*!< COP selects long timeout */
81 kCOP_LongTimeoutMode = 1U, /*!< COP selects short timeout */
82 } cop_timeout_mode_t;
83 #endif /* FSL_FEATURE_COP_HAS_LONGTIME_MODE */
84
85 /*! @brief Describes COP configuration structure. */
86 typedef struct _cop_config
87 {
88 bool enableWindowMode; /*!< COP run mode: window mode or normal mode */
89 #if defined(FSL_FEATURE_COP_HAS_LONGTIME_MODE) && FSL_FEATURE_COP_HAS_LONGTIME_MODE
90 cop_timeout_mode_t timeoutMode; /*!< COP timeout mode: long timeout or short timeout */
91 bool enableStop; /*!< Enable or disable COP in STOP mode */
92 bool enableDebug; /*!< Enable or disable COP in DEBUG mode */
93 #endif /* FSL_FEATURE_COP_HAS_LONGTIME_MODE */
94 cop_clock_source_t clockSource; /*!< Set COP clock source */
95 cop_timeout_cycles_t timeoutCycles; /*!< Set COP timeout value */
96 } cop_config_t;
97
98 /*******************************************************************************
99 * API
100 *******************************************************************************/
101
102 #if defined(__cplusplus)
103 extern "C" {
104 #endif /* __cplusplus*/
105
106 /*!
107 * @name COP Functional Operation
108 * @{
109 */
110
111 /*!
112 * @brief Initializes the COP configuration structure.
113 *
114 * This function initializes the COP configuration structure to default values. The default
115 * values are:
116 * @code
117 * copConfig->enableWindowMode = false;
118 * copConfig->timeoutMode = kCOP_LongTimeoutMode;
119 * copConfig->enableStop = false;
120 * copConfig->enableDebug = false;
121 * copConfig->clockSource = kCOP_LpoClock;
122 * copConfig->timeoutCycles = kCOP_2Power10CyclesOr2Power18Cycles;
123 * @endcode
124 *
125 * @param config Pointer to the COP configuration structure.
126 * @see cop_config_t
127 */
128 void COP_GetDefaultConfig(cop_config_t *config);
129
130 /*!
131 * @brief Initializes the COP module.
132 *
133 * This function configures the COP. After it is called, the COP
134 * starts running according to the configuration.
135 * Because all COP control registers are write-once only, the COP_Init function
136 * and the COP_Disable function can be called only once. A second call has no effect.
137 *
138 * Example:
139 * @code
140 * cop_config_t config;
141 * COP_GetDefaultConfig(&config);
142 * config.timeoutCycles = kCOP_2Power8CyclesOr2Power16Cycles;
143 * COP_Init(sim_base,&config);
144 * @endcode
145 *
146 * @param base SIM peripheral base address.
147 * @param config The configuration of COP.
148 */
149 void COP_Init(SIM_Type *base, const cop_config_t *config);
150
151 /*!
152 * @brief De-initializes the COP module.
153 * This dedicated function is not provided. Instead, the COP_Disable function can be used to disable the COP.
154 */
155
156 /*!
157 * @brief Disables the COP module.
158 *
159 * This function disables the COP Watchdog.
160 * Note: The COP configuration register is a write-once after reset.
161 * To disable the COP Watchdog, call this function first.
162 *
163 * @param base SIM peripheral base address.
164 */
COP_Disable(SIM_Type * base)165 static inline void COP_Disable(SIM_Type *base)
166 {
167 base->COPC &= ~SIM_COPC_COPT_MASK;
168 }
169
170 /*!
171 * @brief Refreshes the COP timer
172 *
173 * This function feeds the COP.
174 *
175 * @param base SIM peripheral base address.
176 */
177 void COP_Refresh(SIM_Type *base);
178
179 /*@}*/
180
181 #if defined(__cplusplus)
182 }
183 #endif /* __cplusplus */
184
185 /*! @}*/
186
187 #endif /* _FSL_COP_H_ */
188