47#include "platform/nrf_802154_temperature.h"
48#include "hal/nrf_temp.h"
53#ifndef NRF_802154_TEMPERATURE_UPDATE_ENABLED
54#define NRF_802154_TEMPERATURE_UPDATE_ENABLED 1
59#ifndef NRF_802154_TEMPERATURE_DEFAULT
60#define NRF_802154_TEMPERATURE_DEFAULT 20
63#if NRF_802154_TEMPERATURE_UPDATE_ENABLED
68#ifndef NRF_802154_TEMPERATURE_UPDATE_INTERVAL
69#define NRF_802154_TEMPERATURE_UPDATE_INTERVAL CLOCK_SECOND
72static struct ctimer update_timer;
75static int8_t cached_temperature = NRF_802154_TEMPERATURE_DEFAULT;
77#if NRF_802154_TEMPERATURE_UPDATE_ENABLED
79temperature_measure(
void)
86 nrf_temp_event_clear(NRF_TEMP, NRF_TEMP_EVENT_DATARDY);
87 nrf_temp_task_trigger(NRF_TEMP, NRF_TEMP_TASK_START);
88 while(!nrf_temp_event_check(NRF_TEMP, NRF_TEMP_EVENT_DATARDY)) {
90 nrf_temp_event_clear(NRF_TEMP, NRF_TEMP_EVENT_DATARDY);
91 nrf_temp_task_trigger(NRF_TEMP, NRF_TEMP_TASK_STOP);
95 raw = nrf_temp_result_get(NRF_TEMP);
96 return (int8_t)((raw >= 0 ? raw + 2 : raw - 2) / 4);
100temperature_update(
void *ptr)
102 int8_t now = temperature_measure();
106 if(now != cached_temperature) {
107 cached_temperature = now;
108 nrf_802154_temperature_changed();
116nrf_802154_temperature_init(
void)
118#if NRF_802154_TEMPERATURE_UPDATE_ENABLED
122 cached_temperature = temperature_measure();
123 ctimer_set(&update_timer, NRF_802154_TEMPERATURE_UPDATE_INTERVAL,
124 temperature_update, NULL);
129nrf_802154_temperature_deinit(
void)
131#if NRF_802154_TEMPERATURE_UPDATE_ENABLED
137nrf_802154_temperature_get(
void)
139 return cached_temperature;
Header file for the callback timer.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
void ctimer_reset(struct ctimer *c)
Reset a callback timer with the same interval as was previously set.
static void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.