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 
13 /** \file hardware/resets.h
14  *  \defgroup hardware_resets hardware_resets
15  *
16  * Hardware Reset API
17  *
18  * The reset controller allows software control of the resets to all of the peripherals that are not
19  * critical to boot the processor in the RP2040.
20  *
21  * \subsubsection reset_bitmask
22  * \addtogroup hardware_resets
23  *
24  * Multiple blocks are referred to using a bitmask as follows:
25  *
26  * Block to reset | Bit
27  * ---------------|----
28  * USB | 24
29  * UART 1 | 23
30  * UART 0 | 22
31  * Timer | 21
32  * TB Manager | 20
33  * SysInfo | 19
34  * System Config | 18
35  * SPI 1 | 17
36  * SPI 0 | 16
37  * RTC | 15
38  * PWM | 14
39  * PLL USB | 13
40  * PLL System | 12
41  * PIO 1 | 11
42  * PIO 0 | 10
43  * Pads - QSPI | 9
44  * Pads - bank 0 | 8
45  * JTAG | 7
46  * IO Bank 1 | 6
47  * IO Bank 0 | 5
48  * I2C 1 | 4
49  * I2C 0 | 3
50  * DMA | 2
51  * Bus Control | 1
52  * ADC 0 | 0
53  *
54  * \subsection reset_example Example
55  * \addtogroup hardware_resets
56  * \include hello_reset.c
57  */
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /// \tag::reset_funcs[]
64 
65 /*! \brief Reset the specified HW blocks
66  *  \ingroup hardware_resets
67  *
68  * \param bits Bit pattern indicating blocks to reset. See \ref reset_bitmask
69  */
reset_block(uint32_t bits)70 static inline void reset_block(uint32_t bits) {
71     hw_set_bits(&resets_hw->reset, bits);
72 }
73 
74 /*! \brief bring specified HW blocks out of reset
75  *  \ingroup hardware_resets
76  *
77  * \param bits Bit pattern indicating blocks to unreset. See \ref reset_bitmask
78  */
unreset_block(uint32_t bits)79 static inline void unreset_block(uint32_t bits) {
80     hw_clear_bits(&resets_hw->reset, bits);
81 }
82 
83 /*! \brief Bring specified HW blocks out of reset and wait for completion
84  *  \ingroup hardware_resets
85  *
86  * \param bits Bit pattern indicating blocks to unreset. See \ref reset_bitmask
87  */
unreset_block_wait(uint32_t bits)88 static inline void unreset_block_wait(uint32_t bits) {
89     hw_clear_bits(&resets_hw->reset, bits);
90     while (~resets_hw->reset_done & bits)
91         tight_loop_contents();
92 }
93 /// \end::reset_funcs[]
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif
100