nrf_acl.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Copyright (c) 2018 - 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 NRF_ACL_H__
  41. #define NRF_ACL_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. #define NRF_ACL_REGION_SIZE_MAX (512 * 1024UL)
  47. /**
  48. * @defgroup nrf_acl_hal ACL HAL
  49. * @{
  50. * @ingroup nrf_acl
  51. * @brief Hardware access layer for managing the Access Control List (ACL) peripheral.
  52. */
  53. /** @brief ACL permissions. */
  54. typedef enum
  55. {
  56. NRF_ACL_PERM_READ_NO_WRITE = ACL_ACL_PERM_WRITE_Msk, /**< Read allowed, write disallowed. */
  57. NRF_ACL_PERM_NO_READ_WRITE = ACL_ACL_PERM_READ_Msk, /**< Read disallowed, write allowed. */
  58. NRF_ACL_PERM_NO_READ_NO_WRITE = ACL_ACL_PERM_READ_Msk | ACL_ACL_PERM_WRITE_Msk /**< Read disallowed, write disallowed. */
  59. } nrf_acl_perm_t;
  60. /**
  61. * @brief Function for setting region parameters for given ACL region.
  62. *
  63. * Address must be word and page aligned. Size must be page aligned.
  64. *
  65. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  66. * @param[in] region_id ACL region index.
  67. * @param[in] address Start address.
  68. * @param[in] size Size of region to protect in bytes.
  69. * @param[in] perm Permissions to set for region to protect.
  70. */
  71. __STATIC_INLINE void nrf_acl_region_set(NRF_ACL_Type * p_reg,
  72. uint32_t region_id,
  73. uint32_t address,
  74. size_t size,
  75. nrf_acl_perm_t perm);
  76. /**
  77. * @brief Function for getting the configured region address of a specific ACL region.
  78. *
  79. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  80. * @param[in] region_id ACL region index.
  81. *
  82. * @return Configured region address of given ACL region.
  83. */
  84. __STATIC_INLINE uint32_t nrf_acl_region_address_get(NRF_ACL_Type * p_reg, uint32_t region_id);
  85. /**
  86. * @brief Function for getting the configured region size of a specific ACL region.
  87. *
  88. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  89. * @param[in] region_id ACL region index.
  90. *
  91. * @return Configured region size of given ACL region.
  92. */
  93. __STATIC_INLINE size_t nrf_acl_region_size_get(NRF_ACL_Type * p_reg, uint32_t region_id);
  94. /**
  95. * @brief Function for getting the configured region permissions of a specific ACL region.
  96. *
  97. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  98. * @param[in] region_id ACL region index.
  99. *
  100. * @return Configured region permissions of given ACL region.
  101. */
  102. __STATIC_INLINE nrf_acl_perm_t nrf_acl_region_perm_get(NRF_ACL_Type * p_reg, uint32_t region_id);
  103. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  104. __STATIC_INLINE void nrf_acl_region_set(NRF_ACL_Type * p_reg,
  105. uint32_t region_id,
  106. uint32_t address,
  107. size_t size,
  108. nrf_acl_perm_t perm)
  109. {
  110. NRFX_ASSERT(region_id < ACL_REGIONS_COUNT);
  111. NRFX_ASSERT(address % NRF_FICR->CODEPAGESIZE == 0);
  112. NRFX_ASSERT(size <= NRF_ACL_REGION_SIZE_MAX);
  113. NRFX_ASSERT(size != 0);
  114. p_reg->ACL[region_id].ADDR = address;
  115. p_reg->ACL[region_id].SIZE = size;
  116. p_reg->ACL[region_id].PERM = perm;
  117. }
  118. __STATIC_INLINE uint32_t nrf_acl_region_address_get(NRF_ACL_Type * p_reg, uint32_t region_id)
  119. {
  120. return (uint32_t)p_reg->ACL[region_id].ADDR;
  121. }
  122. __STATIC_INLINE size_t nrf_acl_region_size_get(NRF_ACL_Type * p_reg, uint32_t region_id)
  123. {
  124. return (size_t)p_reg->ACL[region_id].SIZE;
  125. }
  126. __STATIC_INLINE nrf_acl_perm_t nrf_acl_region_perm_get(NRF_ACL_Type * p_reg, uint32_t region_id)
  127. {
  128. return (nrf_acl_perm_t)p_reg->ACL[region_id].PERM;
  129. }
  130. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  131. /** @} */
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif // NRF_ACL_H__