nrf_temp.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * Copyright (c) 2012 - 2018, 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_TEMP_H__
  41. #define NRF_TEMP_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrf_temp_hal TEMP HAL
  48. * @{
  49. * @ingroup nrf_temp temperature_example
  50. * @brief Temperature module init and read functions.
  51. */
  52. #define MASK_SIGN (0x00000200UL)
  53. #define MASK_SIGN_EXTENSION (0xFFFFFC00UL)
  54. /**
  55. * @brief temperature measurement converter tasks.
  56. */
  57. typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
  58. {
  59. NRF_TEMP_TASK_START = offsetof(NRF_TEMP_Type, TASKS_START), ///< Start the TEMP and prepare the result buffer in RAM.
  60. NRF_TEMP_TASK_STOP = offsetof(NRF_TEMP_Type, TASKS_STOP), ///< Stop the TEMP and terminate any on-going conversion.
  61. } nrf_temp_task_t;
  62. /**
  63. * @brief temperature measurement converter events.
  64. */
  65. typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
  66. {
  67. NRF_TEMP_EVENT_DATARDY = offsetof(NRF_TEMP_Type, EVENTS_DATARDY), ///< Temperature measurement complete, data ready.
  68. } nrf_temp_event_t;
  69. /**
  70. * @brief temperature measurement converter interrupt masks.
  71. */
  72. typedef enum
  73. {
  74. NRF_TEMP_INT_DATARDY = TEMP_INTENSET_DATARDY_Msk, ///< Interrupt on EVENTS_STARTED event.
  75. } nrf_temp_int_mask_t;
  76. /**
  77. * @brief Function for preparing the temp module for temperature measurement.
  78. *
  79. * This function initializes the TEMP module and writes to the hidden configuration register.
  80. */
  81. static __INLINE void nrf_temp_init(void)
  82. {
  83. /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */
  84. *(uint32_t *) 0x4000C504 = 0;
  85. }
  86. /**
  87. * @brief Function for triggering a specific TEMP task.
  88. *
  89. * @param[in] temp_task TEMP task.
  90. */
  91. __STATIC_INLINE void nrf_temp_task_trigger(nrf_temp_task_t temp_task)
  92. {
  93. *((volatile uint32_t *)((uint8_t *)NRF_TEMP + (uint32_t)temp_task)) = 0x1UL;
  94. }
  95. /**
  96. * @brief Function for getting the address of a specific TEMP task register.
  97. *
  98. * @param[in] temp_task TEMP task.
  99. *
  100. * @return Address of the specified TEMP task.
  101. */
  102. __STATIC_INLINE uint32_t nrf_temp_task_address_get(nrf_temp_task_t temp_task)
  103. {
  104. return (uint32_t)((uint8_t *)NRF_TEMP + (uint32_t)temp_task);
  105. }
  106. /**
  107. * @brief Function for getting the state of a specific TEMP event.
  108. *
  109. * @param[in] temp_event TEMP event.
  110. *
  111. * @return State of the specified TEMP event.
  112. */
  113. __STATIC_INLINE bool nrf_temp_event_check(nrf_temp_event_t temp_event)
  114. {
  115. return (bool)*(volatile uint32_t *)((uint8_t *)NRF_TEMP + (uint32_t)temp_event);
  116. }
  117. /**
  118. * @brief Function for clearing the specific TEMP event.
  119. *
  120. * @param[in] temp_event TEMP event.
  121. */
  122. __STATIC_INLINE void nrf_temp_event_clear(nrf_temp_event_t temp_event)
  123. {
  124. *((volatile uint32_t *)((uint8_t *)NRF_TEMP + (uint32_t)temp_event)) = 0x0UL;
  125. #if __CORTEX_M == 0x04
  126. volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_TEMP + (uint32_t)temp_event));
  127. (void)dummy;
  128. #endif
  129. }
  130. /**
  131. * @brief Function for getting the address of a specific TEMP event register.
  132. *
  133. * @param[in] temp_event TEMP event.
  134. *
  135. * @return Address of the specified TEMP event.
  136. */
  137. __STATIC_INLINE uint32_t nrf_temp_event_address_get(nrf_temp_event_t temp_event)
  138. {
  139. return (uint32_t )((uint8_t *)NRF_TEMP + (uint32_t)temp_event);
  140. }
  141. /**
  142. * @brief Function for enabling specified TEMP interrupts.
  143. *
  144. * @param[in] temp_int_mask Interrupt(s) to enable.
  145. */
  146. __STATIC_INLINE void nrf_temp_int_enable(uint32_t temp_int_mask)
  147. {
  148. NRF_TEMP->INTENSET = temp_int_mask;
  149. }
  150. /**
  151. * @brief Function for retrieving the state of specified TEMP interrupts.
  152. *
  153. * @param[in] temp_int_mask Interrupt(s) to check.
  154. *
  155. * @retval true If all specified interrupts are enabled.
  156. * @retval false If at least one of the given interrupts is not enabled.
  157. */
  158. __STATIC_INLINE bool nrf_temp_int_enable_check(uint32_t temp_int_mask)
  159. {
  160. return (bool)(NRF_TEMP->INTENSET & temp_int_mask);
  161. }
  162. /**
  163. * @brief Function for disabling specified interrupts.
  164. *
  165. * @param temp_int_mask Interrupt(s) to disable.
  166. */
  167. __STATIC_INLINE void nrf_temp_int_disable(uint32_t temp_int_mask)
  168. {
  169. NRF_TEMP->INTENCLR = temp_int_mask;
  170. }
  171. /** @} */
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif