nrf_temp.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #ifndef NRF_TEMP_H__
  13. #define NRF_TEMP_H__
  14. #include "nrf.h"
  15. /**
  16. * @defgroup nrf_temperature TEMP (temperature) abstraction
  17. * @{
  18. * @ingroup nrf_drivers temperature_example
  19. * @brief Temperature module init and read functions.
  20. *
  21. */
  22. /**@cond NO_DOXYGEN */
  23. #define MASK_SIGN (0x00000200UL)
  24. #define MASK_SIGN_EXTENSION (0xFFFFFC00UL)
  25. /**
  26. * @brief Function for preparing the temp module for temperature measurement.
  27. *
  28. * This function initializes the TEMP module and writes to the hidden configuration register.
  29. */
  30. static __INLINE void nrf_temp_init(void)
  31. {
  32. /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */
  33. *(uint32_t *) 0x4000C504 = 0;
  34. }
  35. /**
  36. * @brief Function for reading temperature measurement.
  37. *
  38. * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value.
  39. */
  40. static __INLINE int32_t nrf_temp_read(void)
  41. {
  42. /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */
  43. return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP);
  44. }
  45. /**@endcond */
  46. /** @} */
  47. #endif