v2.0.0
resets.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _HARDWARE_RESETS_H
8#define _HARDWARE_RESETS_H
9
10#include "pico.h"
11#include "hardware/structs/resets.h"
12
59// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_RESETS, Enable/disable assertions in the hardware_resets module, type=bool, default=0, group=hardware_adc
60#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_RESETS
61#ifdef PARAM_ASSERTIONS_ENABLED_RESET // backwards compatibility with SDK < 2.0.0
62#define PARAM_ASSERTIONS_ENABLED_HARDWARE_RESETS PARAM_ASSERTIONS_ENABLED_RESET
63#else
64#define PARAM_ASSERTIONS_ENABLED_HARDWARE_RESETS 0
65#endif
66#endif
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71static __force_inline void reset_block_reg_mask(io_rw_32 *reset, uint32_t mask) {
72 hw_set_bits(reset, mask);
73}
74
75static __force_inline void unreset_block_reg_mask(io_rw_32 *reset, uint32_t mask) {
76 hw_clear_bits(reset, mask);
77}
78
79static __force_inline void unreset_block_reg_mask_wait_blocking(io_rw_32 *reset, io_ro_32 *reset_done, uint32_t mask) {
80 hw_clear_bits(reset, mask);
81 while (~*reset_done & mask)
82 tight_loop_contents();
83}
84
86
92 static __force_inline void reset_block_mask(uint32_t bits) {
93 reset_block_reg_mask(&resets_hw->reset, bits);
94}
95
101 static __force_inline void unreset_block_mask(uint32_t bits) {
102 unreset_block_reg_mask(&resets_hw->reset, bits);
103}
104
110 static __force_inline void unreset_block_mask_wait_blocking(uint32_t bits) {
111 unreset_block_reg_mask_wait_blocking(&resets_hw->reset, &resets_hw->reset_done, bits);
112}
113
115
116#ifndef HARDWARE_RESETS_ENABLE_SDK1XX_COMPATIBILITY
117#define HARDWARE_RESETS_ENABLE_SDK1XX_COMPATIBILITY 1
118#endif
119
120#if HARDWARE_RESETS_ENABLE_SDK1XX_COMPATIBILITY
121static __force_inline void reset_block(uint32_t bits) {
122 reset_block_mask(bits);
123}
124
125static __force_inline void unreset_block(uint32_t bits) {
126 unreset_block_mask(bits);
127}
128
129static __force_inline void unreset_block_wait(uint32_t bits) {
130 return unreset_block_mask_wait_blocking(bits);
131}
132#endif
133
139 static inline void reset_block_num(uint32_t block_num) {
140 reset_block_reg_mask(&resets_hw->reset, 1u << block_num);
141}
142
148 static inline void unreset_block_num(uint block_num) {
149 invalid_params_if(HARDWARE_RESETS, block_num > NUM_RESETS);
150 unreset_block_reg_mask(&resets_hw->reset, 1u << block_num);
151}
152
158 static inline void unreset_block_num_wait_blocking(uint block_num) {
159 invalid_params_if(HARDWARE_RESETS, block_num > NUM_RESETS);
160 unreset_block_reg_mask_wait_blocking(&resets_hw->reset, &resets_hw->reset_done, 1u << block_num);
161}
162
168 static inline void reset_unreset_block_num_wait_blocking(uint block_num) {
169 invalid_params_if(HARDWARE_RESETS, block_num > NUM_RESETS);
170 reset_block_reg_mask(&resets_hw->reset, 1u << block_num);
171 unreset_block_reg_mask_wait_blocking(&resets_hw->reset, &resets_hw->reset_done, 1u << block_num);
172}
173
174#ifdef __cplusplus
175}
176#endif
177
178#endif
hw_set_bits
static __force_inline void hw_set_bits(io_rw_32 *addr, uint32_t mask)
Atomically set the specified bits to 1 in a HW register.
Definition: address_mapped.h:135
hw_clear_bits
static __force_inline void hw_clear_bits(io_rw_32 *addr, uint32_t mask)
Atomically clear the specified bits to 0 in a HW register.
Definition: address_mapped.h:145
unreset_block_num
static void unreset_block_num(uint block_num)
bring specified HW block out of reset
Definition: resets.h:148
unreset_block_mask
static __force_inline void unreset_block_mask(uint32_t bits)
bring specified HW blocks out of reset
Definition: resets.h:101
reset_block_num
static void reset_block_num(uint32_t block_num)
Reset the specified HW block.
Definition: resets.h:139
reset_block_mask
static __force_inline void reset_block_mask(uint32_t bits)
Reset the specified HW blocks.
Definition: resets.h:92
reset_unreset_block_num_wait_blocking
static void reset_unreset_block_num_wait_blocking(uint block_num)
Reset the specified HW block, and then bring at back out of reset and wait for completion.
Definition: resets.h:168
unreset_block_num_wait_blocking
static void unreset_block_num_wait_blocking(uint block_num)
Bring specified HW block out of reset and wait for completion.
Definition: resets.h:158
unreset_block_mask_wait_blocking
static __force_inline void unreset_block_mask_wait_blocking(uint32_t bits)
Bring specified HW blocks out of reset and wait for completion.
Definition: resets.h:110
__force_inline
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition: compiler.h:125
tight_loop_contents
static __force_inline void tight_loop_contents(void)
No-op function for the body of tight loops.
Definition: platform.h:67
pico.h