1 /*
2 * Copyright (c) 2019 - 2020, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. 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"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef NRF_RESET_H__
33 #define NRF_RESET_H__
34
35 #include <nrfx.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #if defined(NRF5340_XXAA_NETWORK) || defined(__NRFX_DOXYGEN__)
42 /** @brief Presence of Network core RESET functionality. */
43 #define NRF_RESET_HAS_NETWORK 1
44 #else
45 #define NRF_RESET_HAS_NETWORK 0
46 #endif
47
48 #if defined(NRF5340_XXAA_APPLICATION) || defined(__NRFX_DOXYGEN__)
49 /** @brief Presence of Application core RESET functionality. */
50 #define NRF_RESET_HAS_APPLICATION 1
51 #else
52 #define NRF_RESET_HAS_APPLICATION 0
53 #endif
54
55 /**
56 * @defgroup nrf_reset_hal RESET HAL
57 * @{
58 * @ingroup nrf_reset
59 * @brief Hardware access layer for managing the RESET peripheral.
60 */
61
62 /** @brief Reset reason bit masks. */
63 typedef enum
64 {
65 NRF_RESET_RESETREAS_RESETPIN_MASK = RESET_RESETREAS_RESETPIN_Msk, ///< Bit mask of RESETPIN field.
66 NRF_RESET_RESETREAS_DOG0_MASK = RESET_RESETREAS_DOG0_Msk, ///< Bit mask of DOG0 field.
67 NRF_RESET_RESETREAS_CTRLAP_MASK = RESET_RESETREAS_CTRLAP_Msk, ///< Bit mask of CTRLAP field.
68 NRF_RESET_RESETREAS_SREQ_MASK = RESET_RESETREAS_SREQ_Msk, ///< Bit mask of SREQ field.
69 NRF_RESET_RESETREAS_LOCKUP_MASK = RESET_RESETREAS_LOCKUP_Msk, ///< Bit mask of LOCKUP field.
70 NRF_RESET_RESETREAS_OFF_MASK = RESET_RESETREAS_OFF_Msk, ///< Bit mask of OFF field.
71 NRF_RESET_RESETREAS_LPCOMP_MASK = RESET_RESETREAS_LPCOMP_Msk, ///< Bit mask of LPCOMP field.
72 NRF_RESET_RESETREAS_DIF_MASK = RESET_RESETREAS_DIF_Msk, ///< Bit mask of DIF field.
73 #if NRF_RESET_HAS_NETWORK
74 NRF_RESET_RESETREAS_LSREQ_MASK = RESET_RESETREAS_LSREQ_Msk, ///< Bit mask of LSREQ field.
75 NRF_RESET_RESETREAS_LLOCKUP_MASK = RESET_RESETREAS_LLOCKUP_Msk, ///< Bit mask of LLOCKUP field.
76 NRF_RESET_RESETREAS_LDOG_MASK = RESET_RESETREAS_LDOG_Msk, ///< Bit mask of LDOG field.
77 NRF_RESET_RESETREAS_MFORCEOFF_MASK = RESET_RESETREAS_MFORCEOFF_Msk, ///< Bit mask of MFORCEOFF field.
78 #endif
79 NRF_RESET_RESETREAS_NFC_MASK = RESET_RESETREAS_NFC_Msk, ///< Bit mask of NFC field.
80 NRF_RESET_RESETREAS_DOG1_MASK = RESET_RESETREAS_DOG1_Msk, ///< Bit mask of DOG1 field.
81 NRF_RESET_RESETREAS_VBUS_MASK = RESET_RESETREAS_VBUS_Msk, ///< Bit mask of VBUS field.
82 #if NRF_RESET_HAS_NETWORK
83 NRF_RESET_RESETREAS_LCTRLAP_MASK = RESET_RESETREAS_LCTRLAP_Msk, ///< Bit mask of LCTRLAP field.
84 #endif
85 } nrf_reset_resetreas_mask_t;
86
87 /**
88 * @brief Function for getting the reset reason bitmask.
89 *
90 * This function returns the reset reason bitmask.
91 * Unless cleared, the RESETREAS register is cumulative.
92 * If none of the reset sources is flagged, the chip was reset from the on-chip reset generator.
93 * This indicates a power-on-reset or a brown out reset.
94 *
95 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
96 *
97 * @return The mask of reset reasons constructed with @ref nrf_reset_resetreas_mask_t.
98 */
99 NRF_STATIC_INLINE uint32_t nrf_reset_resetreas_get(NRF_RESET_Type const * p_reg);
100
101 /**
102 * @brief Function for clearing the selected reset reason field.
103 *
104 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
105 * @param[in] mask The mask constructed from @ref nrf_reset_resetreas_mask_t enumerator values.
106 */
107 NRF_STATIC_INLINE void nrf_reset_resetreas_clear(NRF_RESET_Type * p_reg, uint32_t mask);
108
109 #if NRF_RESET_HAS_APPLICATION
110 /**
111 * @brief Function for setting the force off signal for the Network core.
112 *
113 * A force off will reset the Network core and switch off its power and clocks.
114 *
115 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
116 * @param[in] hold True if the force off signal is to be held.
117 * False if the force off signal is to be released.
118 */
119 NRF_STATIC_INLINE void nrf_reset_network_force_off(NRF_RESET_Type * p_reg, bool hold);
120 #endif // NRF_RESET_HAS_APPLICATION
121
122 #ifndef NRF_DECLARE_ONLY
123
nrf_reset_resetreas_get(NRF_RESET_Type const * p_reg)124 NRF_STATIC_INLINE uint32_t nrf_reset_resetreas_get(NRF_RESET_Type const * p_reg)
125 {
126 return p_reg->RESETREAS;
127 }
128
nrf_reset_resetreas_clear(NRF_RESET_Type * p_reg,uint32_t mask)129 NRF_STATIC_INLINE void nrf_reset_resetreas_clear(NRF_RESET_Type * p_reg, uint32_t mask)
130 {
131 p_reg->RESETREAS = mask;
132 }
133
134 #if NRF_RESET_HAS_APPLICATION
nrf_reset_network_force_off(NRF_RESET_Type * p_reg,bool hold)135 NRF_STATIC_INLINE void nrf_reset_network_force_off(NRF_RESET_Type * p_reg, bool hold)
136 {
137 p_reg->NETWORK.FORCEOFF = (hold ? RESET_NETWORK_FORCEOFF_FORCEOFF_Hold :
138 RESET_NETWORK_FORCEOFF_FORCEOFF_Release);
139 }
140 #endif // NRF_RESET_HAS_APPLICATION
141
142 #endif // NRF_DECLARE_ONLY
143
144 /** @} */
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif // NRF_RESET_H__
151