123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- #ifndef NRF_TEMP_H__
- #define NRF_TEMP_H__
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define MASK_SIGN (0x00000200UL)
- #define MASK_SIGN_EXTENSION (0xFFFFFC00UL)
- static __INLINE void nrf_temp_init(void)
- {
-
- *(uint32_t *) 0x4000C504 = 0;
- }
- static __INLINE int32_t nrf_temp_read(void)
- {
-
- return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ?
- (int32_t)(NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP);
- }
- typedef enum
- {
- NRF_TEMP_TASK_START = offsetof(NRF_TEMP_Type, TASKS_START),
- NRF_TEMP_TASK_STOP = offsetof(NRF_TEMP_Type, TASKS_STOP)
- } nrf_temp_task_t;
- typedef enum
- {
- NRF_TEMP_EVENT_DATARDY = offsetof(NRF_TEMP_Type, EVENTS_DATARDY)
- } nrf_temp_event_t;
- typedef enum
- {
- NRF_TEMP_INT_DATARDY_MASK = TEMP_INTENSET_DATARDY_Msk
- } nrf_temp_int_mask_t;
- __STATIC_INLINE void nrf_temp_int_enable(NRF_TEMP_Type * p_reg, uint32_t mask);
- __STATIC_INLINE void nrf_temp_int_disable(NRF_TEMP_Type * p_reg, uint32_t mask);
- __STATIC_INLINE bool nrf_temp_int_enable_check(NRF_TEMP_Type const * p_reg,
- nrf_temp_int_mask_t temp_int);
- __STATIC_INLINE uint32_t nrf_temp_task_address_get(NRF_TEMP_Type const * p_reg,
- nrf_temp_task_t task);
- __STATIC_INLINE void nrf_temp_task_trigger(NRF_TEMP_Type * p_reg, nrf_temp_task_t task);
- __STATIC_INLINE uint32_t nrf_temp_event_address_get(NRF_TEMP_Type const * p_reg,
- nrf_temp_event_t event);
- __STATIC_INLINE void nrf_temp_event_clear(NRF_TEMP_Type * p_reg, nrf_temp_event_t event);
- __STATIC_INLINE bool nrf_temp_event_check(NRF_TEMP_Type const * p_reg, nrf_temp_event_t event);
- __STATIC_INLINE int32_t nrf_temp_result_get(NRF_TEMP_Type const * p_reg);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_temp_int_enable(NRF_TEMP_Type * p_reg, uint32_t mask)
- {
- p_reg->INTENSET = mask;
- }
- __STATIC_INLINE void nrf_temp_int_disable(NRF_TEMP_Type * p_reg, uint32_t mask)
- {
- p_reg->INTENCLR = mask;
- }
- __STATIC_INLINE bool nrf_temp_int_enable_check(NRF_TEMP_Type const * p_reg,
- nrf_temp_int_mask_t temp_int)
- {
- return (bool)(p_reg->INTENSET & temp_int);
- }
- __STATIC_INLINE uint32_t nrf_temp_task_address_get(NRF_TEMP_Type const * p_reg,
- nrf_temp_task_t task)
- {
- return (uint32_t)((uint8_t *)p_reg + (uint32_t)task);
- }
- __STATIC_INLINE void nrf_temp_task_trigger(NRF_TEMP_Type * p_reg, nrf_temp_task_t task)
- {
- *(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task) = 1;
- }
- __STATIC_INLINE uint32_t nrf_temp_event_address_get(NRF_TEMP_Type const * p_reg,
- nrf_temp_event_t event)
- {
- return (uint32_t)((uint8_t *)p_reg + (uint32_t)event);
- }
- __STATIC_INLINE void nrf_temp_event_clear(NRF_TEMP_Type * p_reg, nrf_temp_event_t event)
- {
- *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE bool nrf_temp_event_check(NRF_TEMP_Type const * p_reg, nrf_temp_event_t event)
- {
- return (bool)*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event));
- }
- __STATIC_INLINE int32_t nrf_temp_result_get(NRF_TEMP_Type const * p_reg)
- {
- int32_t raw_measurement = p_reg->TEMP;
- #if defined(NRF51)
-
- if ((raw_measurement & 0x00000200) != 0)
- {
- raw_measurement |= 0xFFFFFC00UL;
- }
- #endif
- return raw_measurement;
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|