1 /*
2  * Copyright (c) 2017 - 2018, 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 NRFX_PRS_H__
33 #define NRFX_PRS_H__
34 
35 #include <nrfx.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @defgroup nrfx_prs Peripheral Resource Sharing (PRS)
43  * @{
44  * @ingroup nrfx
45  *
46  * @brief Peripheral Resource Sharing interface (PRS).
47  */
48 
49 #if defined(NRF51)
50     // SPI0, TWI0
51     #define NRFX_PRS_BOX_0_ADDR     NRF_SPI0
52     // SPI1, SPIS1, TWI1
53     #define NRFX_PRS_BOX_1_ADDR     NRF_SPI1
54 #elif defined(NRF52810_XXAA)
55     // TWIM0, TWIS0
56     #define NRFX_PRS_BOX_0_ADDR     NRF_TWIM0
57     // SPIM0, SPIS0
58     #define NRFX_PRS_BOX_1_ADDR     NRF_SPIM0
59 #elif defined(NRF52832_XXAA) || defined (NRF52832_XXAB)
60     // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
61     #define NRFX_PRS_BOX_0_ADDR     NRF_SPIM0
62     // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
63     #define NRFX_PRS_BOX_1_ADDR     NRF_SPIM1
64     // SPIM2, SPIS2, SPI2
65     #define NRFX_PRS_BOX_2_ADDR     NRF_SPIM2
66     // COMP, LPCOMP
67     #define NRFX_PRS_BOX_3_ADDR     NRF_COMP
68     // UARTE0, UART0
69     #define NRFX_PRS_BOX_4_ADDR     NRF_UARTE0
70 #elif defined(NRF52840_XXAA)
71     // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
72     #define NRFX_PRS_BOX_0_ADDR     NRF_SPIM0
73     // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
74     #define NRFX_PRS_BOX_1_ADDR     NRF_SPIM1
75     // SPIM2, SPIS2, SPI2
76     #define NRFX_PRS_BOX_2_ADDR     NRF_SPIM2
77     // COMP, LPCOMP
78     #define NRFX_PRS_BOX_3_ADDR     NRF_COMP
79     // UARTE0, UART0
80     #define NRFX_PRS_BOX_4_ADDR     NRF_UARTE0
81 #else
82     #error "Unknown device."
83 #endif
84 
85 /**
86  * @brief Function for acquiring shared peripheral resources associated with
87  *        the specified peripheral.
88  *
89  * Certain resources and registers are shared among peripherals that have
90  * the same ID (for example: SPI0, SPIM0, SPIS0, TWI0, TWIM0, and TWIS0 in
91  * nRF52832). Only one of them can be utilized at a given time. This function
92  * reserves proper resources to be used by the specified peripheral.
93  * If NRFX_PRS_ENABLED is set to a non-zero value, IRQ handlers for peripherals
94  * that are sharing resources with others are implemented by the @ref nrfx_prs
95  * module instead of individual drivers. The drivers must then specify their
96  * interrupt handling routines and register them by using this function.
97  *
98  * @param[in] p_base_addr Requested peripheral base pointer.
99  * @param[in] irq_handler Interrupt handler to register.
100  *
101  * @retval NRFX_SUCCESS    If resources were acquired successfully or the
102  *                         specified peripheral is not handled by the PRS
103  *                         subsystem and there is no need to acquire resources
104  *                         for it.
105  * @retval NRFX_ERROR_BUSY If resources were already acquired.
106  */
107 nrfx_err_t nrfx_prs_acquire(void       const * p_base_addr,
108                             nrfx_irq_handler_t irq_handler);
109 
110 /**
111  * @brief Function for releasing shared resources reserved previously by
112  *        @ref nrfx_prs_acquire() for the specified peripheral.
113  *
114  * @param[in] p_base_addr Released peripheral base pointer.
115  */
116 void nrfx_prs_release(void const * p_base_addr);
117 
118 
119 void nrfx_prs_box_0_irq_handler(void);
120 void nrfx_prs_box_1_irq_handler(void);
121 void nrfx_prs_box_2_irq_handler(void);
122 void nrfx_prs_box_3_irq_handler(void);
123 void nrfx_prs_box_4_irq_handler(void);
124 
125 /** @} */
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif // NRFX_PRS_H__
132