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 /// \tag::reset_funcs[]
60 
61 /*! \brief Reset the specified HW blocks
62  *  \ingroup hardware_resets
63  *
64  * \param bits Bit pattern indicating blocks to reset. See \ref reset_bitmask
65  */
reset_block(uint32_t bits)66 static inline void reset_block(uint32_t bits) {
67     hw_set_bits(&resets_hw->reset, bits);
68 }
69 
70 /*! \brief bring specified HW blocks out of reset
71  *  \ingroup hardware_resets
72  *
73  * \param bits Bit pattern indicating blocks to unreset. See \ref reset_bitmask
74  */
unreset_block(uint32_t bits)75 static inline void unreset_block(uint32_t bits) {
76     hw_clear_bits(&resets_hw->reset, bits);
77 }
78 
79 /*! \brief Bring specified HW blocks out of reset and wait for completion
80  *  \ingroup hardware_resets
81  *
82  * \param bits Bit pattern indicating blocks to unreset. See \ref reset_bitmask
83  */
unreset_block_wait(uint32_t bits)84 static inline void unreset_block_wait(uint32_t bits) {
85     hw_clear_bits(&resets_hw->reset, bits);
86     while (~resets_hw->reset_done & bits)
87         tight_loop_contents();
88 }
89 /// \end::reset_funcs[]
90 
91 #endif
92