summaryrefslogtreecommitdiff
path: root/ports/nrf/common-hal
diff options
context:
space:
mode:
authorarturo182 <arturo182@tlen.pl>2018-02-02 20:33:21 +0100
committerarturo182 <arturo182@tlen.pl>2018-02-02 20:33:21 +0100
commit6731b47d5aee2c90b4eb15cfd3dc283427dc0ef8 (patch)
treedf40def47bd6558fef265a46d6feafe60fb1ab17 /ports/nrf/common-hal
parentc6a542d1669bac049a8b1bdd3c4abaaac46151f5 (diff)
nrf: Implement MCU temperature reading
If softdevice is available and enabled the SD function will be used, otherwise use MCU registers.
Diffstat (limited to 'ports/nrf/common-hal')
-rw-r--r--ports/nrf/common-hal/microcontroller/Processor.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c
index ba5aa0932..cf808cdf4 100644
--- a/ports/nrf/common-hal/microcontroller/Processor.c
+++ b/ports/nrf/common-hal/microcontroller/Processor.c
@@ -25,10 +25,45 @@
*/
#include "common-hal/microcontroller/Processor.h"
+#include "py/runtime.h"
+
+#ifdef BLUETOOTH_SD
+#include "nrf_sdm.h"
+#endif
+
+#include "nrf.h"
-// TODO port common_hal_mcu_processor
float common_hal_mcu_processor_get_temperature(void) {
- return 0;
+ int32_t temp = 0;
+
+#ifdef BLUETOOTH_SD
+ uint8_t sd_en = 0;
+
+ (void) sd_softdevice_is_enabled(&sd_en);
+
+ if (sd_en) {
+ uint32_t err_code = sd_temp_get(&temp);
+ if (err_code != NRF_SUCCESS) {
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
+ "Can not get temperature. status: 0x" HEX2_FMT, (uint16_t)err_code));
+
+ return 0;
+ }
+ }
+#endif
+
+ NRF_TEMP->TASKS_START = 1;
+
+ while (NRF_TEMP->EVENTS_DATARDY == 0)
+ ;
+
+ NRF_TEMP->EVENTS_DATARDY = 0;
+
+ temp = NRF_TEMP->TEMP;
+
+ NRF_TEMP->TASKS_STOP = 1;
+
+ return temp / 4.0f;
}
uint32_t common_hal_mcu_processor_get_frequency(void) {