nrfx_prs.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRFX_PRS_H__
  41. #define NRFX_PRS_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrfx_prs Peripheral Resource Sharing (PRS)
  48. * @{
  49. * @ingroup nrfx
  50. *
  51. * @brief Peripheral Resource Sharing interface (PRS).
  52. */
  53. #if defined(NRF51)
  54. // SPI0, TWI0
  55. #define NRFX_PRS_BOX_0_ADDR NRF_SPI0
  56. // SPI1, SPIS1, TWI1
  57. #define NRFX_PRS_BOX_1_ADDR NRF_SPI1
  58. #elif defined(NRF52810_XXAA)
  59. // TWIM0, TWIS0, TWI0
  60. #define NRFX_PRS_BOX_0_ADDR NRF_TWIM0
  61. // SPIM0, SPIS0, SPI0
  62. #define NRFX_PRS_BOX_1_ADDR NRF_SPIM0
  63. // UARTE0, UART0
  64. #define NRFX_PRS_BOX_2_ADDR NRF_UARTE0
  65. #elif defined(NRF52811_XXAA)
  66. // TWIM0, TWIS0, TWI0, SPIM1, SPIS1, SPI1
  67. #define NRFX_PRS_BOX_0_ADDR NRF_TWIM0
  68. // SPIM0, SPIS0, SPI0
  69. #define NRFX_PRS_BOX_1_ADDR NRF_SPIM0
  70. // UART0, UARTE0
  71. #define NRFX_PRS_BOX_2_ADDR NRF_UART0
  72. #elif defined(NRF52820_XXAA)
  73. // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
  74. #define NRFX_PRS_BOX_0_ADDR NRF_SPIM0
  75. // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
  76. #define NRFX_PRS_BOX_1_ADDR NRF_SPIM1
  77. // UARTE0, UART0
  78. #define NRFX_PRS_BOX_2_ADDR NRF_UARTE0
  79. #elif defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || \
  80. defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
  81. // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
  82. #define NRFX_PRS_BOX_0_ADDR NRF_SPIM0
  83. // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
  84. #define NRFX_PRS_BOX_1_ADDR NRF_SPIM1
  85. // SPIM2, SPIS2, SPI2
  86. #define NRFX_PRS_BOX_2_ADDR NRF_SPIM2
  87. // COMP, LPCOMP
  88. #define NRFX_PRS_BOX_3_ADDR NRF_COMP
  89. // UARTE0, UART0
  90. #define NRFX_PRS_BOX_4_ADDR NRF_UARTE0
  91. #elif defined(NRF9160_XXAA)
  92. // UARTE0, SPIM0, SPIS0, TWIM0, TWIS0
  93. #define NRFX_PRS_BOX_0_ADDR NRF_UARTE0
  94. // UARTE1, SPIM1, SPIS1, TWIM1, TWIS1
  95. #define NRFX_PRS_BOX_1_ADDR NRF_UARTE1
  96. // UARTE2, SPIM2, SPIS2, TWIM2, TWIS2
  97. #define NRFX_PRS_BOX_2_ADDR NRF_UARTE2
  98. // UARTE3, SPIM3, SPIS3, TWIM3, TWIS3
  99. #define NRFX_PRS_BOX_3_ADDR NRF_UARTE3
  100. #else
  101. #error "Unknown device."
  102. #endif
  103. /**
  104. * @brief Function for acquiring shared peripheral resources associated with
  105. * the specified peripheral.
  106. *
  107. * Certain resources and registers are shared among peripherals that have
  108. * the same ID (for example: SPI0, SPIM0, SPIS0, TWI0, TWIM0, and TWIS0 in
  109. * nRF52832). Only one of them can be utilized at a given time. This function
  110. * reserves proper resources to be used by the specified peripheral.
  111. * If NRFX_PRS_ENABLED is set to a non-zero value, IRQ handlers for peripherals
  112. * that are sharing resources with others are implemented by the @ref nrfx_prs
  113. * module instead of individual drivers. The drivers must then specify their
  114. * interrupt handling routines and register them by using this function.
  115. *
  116. * @param[in] p_base_addr Requested peripheral base pointer.
  117. * @param[in] irq_handler Interrupt handler to register.
  118. *
  119. * @retval NRFX_SUCCESS If resources were acquired successfully or the
  120. * specified peripheral is not handled by the PRS
  121. * subsystem and there is no need to acquire resources
  122. * for it.
  123. * @retval NRFX_ERROR_BUSY If resources were already acquired.
  124. */
  125. nrfx_err_t nrfx_prs_acquire(void const * p_base_addr,
  126. nrfx_irq_handler_t irq_handler);
  127. /**
  128. * @brief Function for releasing shared resources reserved previously by
  129. * @ref nrfx_prs_acquire() for the specified peripheral.
  130. *
  131. * @param[in] p_base_addr Released peripheral base pointer.
  132. */
  133. void nrfx_prs_release(void const * p_base_addr);
  134. /** @} */
  135. void nrfx_prs_box_0_irq_handler(void);
  136. void nrfx_prs_box_1_irq_handler(void);
  137. void nrfx_prs_box_2_irq_handler(void);
  138. void nrfx_prs_box_3_irq_handler(void);
  139. void nrfx_prs_box_4_irq_handler(void);
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif // NRFX_PRS_H__