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