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 #elif defined(NRF9160_XXAA) 82 // UARTE0, SPIM0, SPIS0, TWIM0, TWIS0 83 #define NRFX_PRS_BOX_0_ADDR NRF_UARTE0 84 // UARTE1, SPIM1, SPIS1, TWIM1, TWIS1 85 #define NRFX_PRS_BOX_1_ADDR NRF_UARTE1 86 // UARTE2, SPIM2, SPIS2, TWIM2, TWIS2 87 #define NRFX_PRS_BOX_2_ADDR NRF_UARTE2 88 // UARTE3, SPIM3, SPIS3, TWIM3, TWIS3 89 #define NRFX_PRS_BOX_3_ADDR NRF_UARTE3 90 #else 91 #error "Unknown device." 92 #endif 93 94 /** 95 * @brief Function for acquiring shared peripheral resources associated with 96 * the specified peripheral. 97 * 98 * Certain resources and registers are shared among peripherals that have 99 * the same ID (for example: SPI0, SPIM0, SPIS0, TWI0, TWIM0, and TWIS0 in 100 * nRF52832). Only one of them can be utilized at a given time. This function 101 * reserves proper resources to be used by the specified peripheral. 102 * If NRFX_PRS_ENABLED is set to a non-zero value, IRQ handlers for peripherals 103 * that are sharing resources with others are implemented by the @ref nrfx_prs 104 * module instead of individual drivers. The drivers must then specify their 105 * interrupt handling routines and register them by using this function. 106 * 107 * @param[in] p_base_addr Requested peripheral base pointer. 108 * @param[in] irq_handler Interrupt handler to register. 109 * 110 * @retval NRFX_SUCCESS If resources were acquired successfully or the 111 * specified peripheral is not handled by the PRS 112 * subsystem and there is no need to acquire resources 113 * for it. 114 * @retval NRFX_ERROR_BUSY If resources were already acquired. 115 */ 116 nrfx_err_t nrfx_prs_acquire(void const * p_base_addr, 117 nrfx_irq_handler_t irq_handler); 118 119 /** 120 * @brief Function for releasing shared resources reserved previously by 121 * @ref nrfx_prs_acquire() for the specified peripheral. 122 * 123 * @param[in] p_base_addr Released peripheral base pointer. 124 */ 125 void nrfx_prs_release(void const * p_base_addr); 126 127 128 void nrfx_prs_box_0_irq_handler(void); 129 void nrfx_prs_box_1_irq_handler(void); 130 void nrfx_prs_box_2_irq_handler(void); 131 void nrfx_prs_box_3_irq_handler(void); 132 void nrfx_prs_box_4_irq_handler(void); 133 134 /** @} */ 135 136 #ifdef __cplusplus 137 } 138 #endif 139 140 #endif // NRFX_PRS_H__ 141