TEMP: Switched to level interrupts, readied for nrf53

* Switched to level interrupts
* Added DPPI connections
* Added nrf53 glue and config
* HAL: Added event and subscription overrides
* Used code templates for common logic

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2023-09-19 17:39:42 +02:00
parent 6ef00694e4
commit 709f82bb69
11 changed files with 512 additions and 191 deletions

View File

@ -18,7 +18,7 @@ src/HW_models/NHW_RTC.c
src/HW_models/bstest_ticker.c
src/HW_models/NRF_NVMC.c
src/HW_models/NRF_GPIO.c
src/HW_models/NRF_TEMP.c
src/HW_models/NHW_TEMP.c
src/HW_models/NRF_RADIO_tasks_regs.c
src/HW_models/NHW_TIMER.c
src/HW_models/bs_compat.c

View File

@ -17,4 +17,5 @@ src/HW_models/NHW_RNG.c
src/HW_models/NHW_RTC.c
src/HW_models/NHW_SWI.c
src/HW_models/NHW_TIMER.c
src/HW_models/NHW_TEMP.c
src/HW_models/weak_stubs.c

View File

@ -7,5 +7,6 @@ src/nrfx/hal/nrf_ecb.c
src/nrfx/hal/nrf_egu.c
src/nrfx/hal/nrf_rng.c
src/nrfx/hal/nrf_rtc.c
src/nrfx/hal/nrf_temp.c
src/nrfx/hal/nrf_timer.c
src/nrfx/hal/nrf_hal_originals.c

166
src/HW_models/NHW_TEMP.c Normal file
View File

@ -0,0 +1,166 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* TEMP - Temperature sensor
* https://infocenter.nordicsemi.com/topic/ps_nrf52833/temp.html?cp=4_1_0_5_25
*
* A very simple and rough model
*
* Notes:
* * At this point the device is always at 25 C
* * The measurement result will just be 25 +- 0.25 C
* * There is no per device variability
* * There is no modeling of possible calibration errors or inaccuracies due to no non-linearities compensation
*/
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include "bs_rand_main.h"
#include "nsi_tasks.h"
#include "nsi_hws_models_if.h"
#include "nsi_hw_scheduler.h"
#include "NHW_common_types.h"
#include "NHW_config.h"
#include "NHW_templates.h"
#include "NHW_TEMP.h"
#include "NHW_peri_types.h"
#include "NHW_xPPI.h"
#include "irq_ctrl.h"
#if NHW_TEMP_TOTAL_INST > 1
#error "This model only supports 1 instance so far"
#endif
NRF_TEMP_Type NRF_TEMP_regs;
#if (NHW_HAS_DPPI)
/* Mapping of peripheral instance to DPPI instance */
static uint nhw_TEMP_dppi_map[NHW_TEMP_TOTAL_INST] = NHW_TEMP_DPPI_MAP;
#endif
static bs_time_t Timer_TEMP = TIME_NEVER; //Time when the next temperature measurement will be ready
static bool TEMP_hw_started;
static uint32_t TEMP_INTEN; //interrupt enable
static double temperature = 25.0; /* Actual temperature the device is at */
/**
* Initialize the TEMP model
*/
static void nhw_temp_init(void) {
memset(&NRF_TEMP_regs, 0, sizeof(NRF_TEMP_regs));
#if defined(NRF52833)
NRF_TEMP_regs.A0 = 0x00000326;
NRF_TEMP_regs.A1 = 0x00000348;
NRF_TEMP_regs.A2 = 0x000003AA;
NRF_TEMP_regs.A3 = 0x0000040E;
NRF_TEMP_regs.A4 = 0x000004BD;
NRF_TEMP_regs.A5 = 0x000005A3;
NRF_TEMP_regs.B0 = 0x00003FEF;
NRF_TEMP_regs.B1 = 0x00003FBE;
NRF_TEMP_regs.B2 = 0x00003FBE;
NRF_TEMP_regs.B3 = 0x00000012;
NRF_TEMP_regs.B4 = 0x00000124;
NRF_TEMP_regs.B5 = 0x0000027C;
NRF_TEMP_regs.T0 = 0x000000E2;
NRF_TEMP_regs.T1 = 0x00000000;
NRF_TEMP_regs.T2 = 0x00000019;
NRF_TEMP_regs.T3 = 0x0000003C;
NRF_TEMP_regs.T4 = 0x00000050;
#elif defined(NRF5340)
NRF_TEMP_regs.A0 = 0x000002D9;
NRF_TEMP_regs.A1 = 0x00000322;
NRF_TEMP_regs.A2 = 0x00000355;
NRF_TEMP_regs.A3 = 0x000003DF;
NRF_TEMP_regs.A4 = 0x0000044E;
NRF_TEMP_regs.A5 = 0x000004B7;
NRF_TEMP_regs.B0 = 0x00000FC7;
NRF_TEMP_regs.B1 = 0x00000F71;
NRF_TEMP_regs.B2 = 0x00000F6C;
NRF_TEMP_regs.B3 = 0x00000FCB;
NRF_TEMP_regs.B4 = 0x0000004B;
NRF_TEMP_regs.B5 = 0x000000F6;
NRF_TEMP_regs.T0 = 0x000000E1;
NRF_TEMP_regs.T1 = 0x000000F9;
NRF_TEMP_regs.T2 = 0x00000010;
NRF_TEMP_regs.T3 = 0x00000026;
NRF_TEMP_regs.T4 = 0x0000003F;
#endif
TEMP_hw_started = false;
TEMP_INTEN = 0;
Timer_TEMP = TIME_NEVER;
}
NSI_TASK(nhw_temp_init, HW_INIT, 100);
/**
* TASK_START triggered handler
*/
void nhw_TEMP_TASK_START(void) {
if (TEMP_hw_started) {
return;
}
TEMP_hw_started = true;
Timer_TEMP = nsi_hws_get_time() + NHW_TEMP_t_TEMP;
nsi_hws_find_next_event();
}
/**
* TASK_STOP triggered handler
*/
void nhw_TEMP_TASK_STOP(void) {
TEMP_hw_started = false;
Timer_TEMP = TIME_NEVER;
nsi_hws_find_next_event();
}
static void nhw_TEMP_eval_interrupt(uint inst) {
static bool temp_int_line[NHW_TEMP_TOTAL_INST]; /* Is the TEMP currently driving its interrupt line high */
/* Mapping of peripheral instance to {int controller instance, int number} */
static struct nhw_irq_mapping nhw_temp_irq_map[NHW_TEMP_TOTAL_INST] = NHW_TEMP_INT_MAP;
bool new_int_line = false;
NHW_CHECK_INTERRUPT_si(TEMP, DATARDY, TEMP_INTEN)
hw_irq_ctrl_toggle_level_irq_line_if(&temp_int_line[inst],
new_int_line,
&nhw_temp_irq_map[inst]);
}
NHW_SIDEEFFECTS_INTSET_si(TEMP, NRF_TEMP_regs., TEMP_INTEN)
NHW_SIDEEFFECTS_INTCLR_si(TEMP, NRF_TEMP_regs., TEMP_INTEN)
NHW_SIDEEFFECTS_EVENTS(TEMP)
NHW_SIDEEFFECTS_TASKS_si(TEMP, START)
NHW_SIDEEFFECTS_TASKS_si(TEMP, STOP)
#if (NHW_HAS_DPPI)
NHW_SIDEEFFECTS_SUBSCRIBE_si(TEMP, START)
NHW_SIDEEFFECTS_SUBSCRIBE_si(TEMP, STOP)
#endif /* NHW_HAS_DPPI */
NHW_SIGNAL_EVENT_si(TEMP, DATARDY)
/**
* Time has come when the temperature measurement is ready
*/
static void nhw_temp_timer_triggered(void) {
NRF_TEMP_regs.TEMP = temperature*(1 << NHW_TEMP_FBITS) + bs_random_uniformRi(-1,1);
TEMP_hw_started = false;
Timer_TEMP = TIME_NEVER;
nsi_hws_find_next_event();
nhw_TEMP_signal_EVENTS_DATARDY(0);
}
NSI_HW_EVENT(Timer_TEMP, nhw_temp_timer_triggered, 50);

27
src/HW_models/NHW_TEMP.h Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _NRF_HW_MODEL_TEMP_H
#define _NRF_HW_MODEL_TEMP_H
#ifdef __cplusplus
extern "C"{
#endif
void nhw_TEMP_regw_sideeffects_TASKS_START(void);
void nhw_TEMP_regw_sideeffects_TASKS_STOP(void);
void nhw_TEMP_regw_sideeffects_INTENSET(void);
void nhw_TEMP_regw_sideeffects_INTENCLEAR(void);
void nhw_TEMP_TASK_START(void);
void nhw_TEMP_TASK_STOP(void);
void nhw_TEMP_regw_sideeffects_SUBSCRIBE_START(unsigned int inst);
void nhw_TEMP_regw_sideeffects_SUBSCRIBE_STOP(unsigned int inst);
void nhw_TEMP_regw_sideeffects_EVENTS_all(unsigned int inst);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -142,6 +142,8 @@
#define NHW_TEMP_TOTAL_INST 1
#define NHW_TEMP_0 0
#define NHW_TEMP_INT_MAP {{0 , 12}} /*Only core,TEMP_IRQn*/
#define NHW_TEMP_t_TEMP 36 /* microseconds */
#define NHW_TEMP_FBITS 2 /* fractional bits => 0.25C resolution */
#define NHW_TIMER_TOTAL_INST 5
#define NHW_TIMER_0 0
@ -348,6 +350,13 @@
#define NHW_SWI_NET2 2
#define NHW_SWI_NET3 3
#define NHW_TEMP_TOTAL_INST 1
#define NHW_TEMP_NET0 0
#define NHW_TEMP_INT_MAP {{1 , 16}} /*Net core,TEMP_IRQn*/
#define NHW_TEMP_DPPI_MAP {1} /*Network core*/
#define NHW_TEMP_t_TEMP 36 /* microseconds */
#define NHW_TEMP_FBITS 2 /* fractional bits => 0.25C resolution */
#define NHW_TIMER_TOTAL_INST 6
#define NHW_TIMER_APP0 0
#define NHW_TIMER_APP1 1

View File

@ -2491,6 +2491,267 @@ typedef struct { /*!< (@ 0x41011000) RTC0_NS Stru
#define RTC_CC_COMPARE_Msk (0xFFFFFFUL << RTC_CC_COMPARE_Pos) /*!< Bit mask of COMPARE field. */
/* =========================================================================================================================== */
/* ================ TEMP ================ */
/* =========================================================================================================================== */
/**
* @brief Temperature Sensor (TEMP)
*/
typedef struct { /*!< (@ 0x41010000) TEMP_NS Structure */
__OM uint32_t TASKS_START; /*!< (@ 0x00000000) Start temperature measurement */
__OM uint32_t TASKS_STOP; /*!< (@ 0x00000004) Stop temperature measurement */
__IM uint32_t RESERVED[30];
__IOM uint32_t SUBSCRIBE_START; /*!< (@ 0x00000080) Subscribe configuration for task START */
__IOM uint32_t SUBSCRIBE_STOP; /*!< (@ 0x00000084) Subscribe configuration for task STOP */
__IM uint32_t RESERVED1[30];
__IOM uint32_t EVENTS_DATARDY; /*!< (@ 0x00000100) Temperature measurement complete, data ready */
__IM uint32_t RESERVED2[31];
__IOM uint32_t PUBLISH_DATARDY; /*!< (@ 0x00000180) Publish configuration for event DATARDY */
__IM uint32_t RESERVED3[96];
__IOM uint32_t INTENSET; /*!< (@ 0x00000304) Enable interrupt */
__IOM uint32_t INTENCLR; /*!< (@ 0x00000308) Disable interrupt */
__IM uint32_t RESERVED4[127];
__IM int32_t TEMP; /*!< (@ 0x00000508) Temperature in degC (0.25deg steps) */
__IM uint32_t RESERVED5[5];
__IOM uint32_t A0; /*!< (@ 0x00000520) Slope of first piecewise linear function */
__IOM uint32_t A1; /*!< (@ 0x00000524) Slope of second piecewise linear function */
__IOM uint32_t A2; /*!< (@ 0x00000528) Slope of third piecewise linear function */
__IOM uint32_t A3; /*!< (@ 0x0000052C) Slope of fourth piecewise linear function */
__IOM uint32_t A4; /*!< (@ 0x00000530) Slope of fifth piecewise linear function */
__IOM uint32_t A5; /*!< (@ 0x00000534) Slope of sixth piecewise linear function */
__IM uint32_t RESERVED6[2];
__IOM uint32_t B0; /*!< (@ 0x00000540) y-intercept of first piecewise linear function */
__IOM uint32_t B1; /*!< (@ 0x00000544) y-intercept of second piecewise linear function */
__IOM uint32_t B2; /*!< (@ 0x00000548) y-intercept of third piecewise linear function */
__IOM uint32_t B3; /*!< (@ 0x0000054C) y-intercept of fourth piecewise linear function */
__IOM uint32_t B4; /*!< (@ 0x00000550) y-intercept of fifth piecewise linear function */
__IOM uint32_t B5; /*!< (@ 0x00000554) y-intercept of sixth piecewise linear function */
__IM uint32_t RESERVED7[2];
__IOM uint32_t T0; /*!< (@ 0x00000560) Endpoint of first piecewise linear function */
__IOM uint32_t T1; /*!< (@ 0x00000564) Endpoint of second piecewise linear function */
__IOM uint32_t T2; /*!< (@ 0x00000568) Endpoint of third piecewise linear function */
__IOM uint32_t T3; /*!< (@ 0x0000056C) Endpoint of fourth piecewise linear function */
__IOM uint32_t T4; /*!< (@ 0x00000570) Endpoint of fifth piecewise linear function */
} NRF_TEMP_Type; /*!< Size = 1396 (0x574) */
/* Peripheral: TEMP */
/* Description: Temperature Sensor */
/* Register: TEMP_TASKS_START */
/* Description: Start temperature measurement */
/* Bit 0 : Start temperature measurement */
#define TEMP_TASKS_START_TASKS_START_Pos (0UL) /*!< Position of TASKS_START field. */
#define TEMP_TASKS_START_TASKS_START_Msk (0x1UL << TEMP_TASKS_START_TASKS_START_Pos) /*!< Bit mask of TASKS_START field. */
#define TEMP_TASKS_START_TASKS_START_Trigger (1UL) /*!< Trigger task */
/* Register: TEMP_TASKS_STOP */
/* Description: Stop temperature measurement */
/* Bit 0 : Stop temperature measurement */
#define TEMP_TASKS_STOP_TASKS_STOP_Pos (0UL) /*!< Position of TASKS_STOP field. */
#define TEMP_TASKS_STOP_TASKS_STOP_Msk (0x1UL << TEMP_TASKS_STOP_TASKS_STOP_Pos) /*!< Bit mask of TASKS_STOP field. */
#define TEMP_TASKS_STOP_TASKS_STOP_Trigger (1UL) /*!< Trigger task */
/* Register: TEMP_SUBSCRIBE_START */
/* Description: Subscribe configuration for task START */
/* Bit 31 : */
#define TEMP_SUBSCRIBE_START_EN_Pos (31UL) /*!< Position of EN field. */
#define TEMP_SUBSCRIBE_START_EN_Msk (0x1UL << TEMP_SUBSCRIBE_START_EN_Pos) /*!< Bit mask of EN field. */
#define TEMP_SUBSCRIBE_START_EN_Disabled (0UL) /*!< Disable subscription */
#define TEMP_SUBSCRIBE_START_EN_Enabled (1UL) /*!< Enable subscription */
/* Bits 7..0 : DPPI channel that task START will subscribe to */
#define TEMP_SUBSCRIBE_START_CHIDX_Pos (0UL) /*!< Position of CHIDX field. */
#define TEMP_SUBSCRIBE_START_CHIDX_Msk (0xFFUL << TEMP_SUBSCRIBE_START_CHIDX_Pos) /*!< Bit mask of CHIDX field. */
/* Register: TEMP_SUBSCRIBE_STOP */
/* Description: Subscribe configuration for task STOP */
/* Bit 31 : */
#define TEMP_SUBSCRIBE_STOP_EN_Pos (31UL) /*!< Position of EN field. */
#define TEMP_SUBSCRIBE_STOP_EN_Msk (0x1UL << TEMP_SUBSCRIBE_STOP_EN_Pos) /*!< Bit mask of EN field. */
#define TEMP_SUBSCRIBE_STOP_EN_Disabled (0UL) /*!< Disable subscription */
#define TEMP_SUBSCRIBE_STOP_EN_Enabled (1UL) /*!< Enable subscription */
/* Bits 7..0 : DPPI channel that task STOP will subscribe to */
#define TEMP_SUBSCRIBE_STOP_CHIDX_Pos (0UL) /*!< Position of CHIDX field. */
#define TEMP_SUBSCRIBE_STOP_CHIDX_Msk (0xFFUL << TEMP_SUBSCRIBE_STOP_CHIDX_Pos) /*!< Bit mask of CHIDX field. */
/* Register: TEMP_EVENTS_DATARDY */
/* Description: Temperature measurement complete, data ready */
/* Bit 0 : Temperature measurement complete, data ready */
#define TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Pos (0UL) /*!< Position of EVENTS_DATARDY field. */
#define TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Msk (0x1UL << TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Pos) /*!< Bit mask of EVENTS_DATARDY field. */
#define TEMP_EVENTS_DATARDY_EVENTS_DATARDY_NotGenerated (0UL) /*!< Event not generated */
#define TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Generated (1UL) /*!< Event generated */
/* Register: TEMP_PUBLISH_DATARDY */
/* Description: Publish configuration for event DATARDY */
/* Bit 31 : */
#define TEMP_PUBLISH_DATARDY_EN_Pos (31UL) /*!< Position of EN field. */
#define TEMP_PUBLISH_DATARDY_EN_Msk (0x1UL << TEMP_PUBLISH_DATARDY_EN_Pos) /*!< Bit mask of EN field. */
#define TEMP_PUBLISH_DATARDY_EN_Disabled (0UL) /*!< Disable publishing */
#define TEMP_PUBLISH_DATARDY_EN_Enabled (1UL) /*!< Enable publishing */
/* Bits 7..0 : DPPI channel that event DATARDY will publish to. */
#define TEMP_PUBLISH_DATARDY_CHIDX_Pos (0UL) /*!< Position of CHIDX field. */
#define TEMP_PUBLISH_DATARDY_CHIDX_Msk (0xFFUL << TEMP_PUBLISH_DATARDY_CHIDX_Pos) /*!< Bit mask of CHIDX field. */
/* Register: TEMP_INTENSET */
/* Description: Enable interrupt */
/* Bit 0 : Write '1' to enable interrupt for event DATARDY */
#define TEMP_INTENSET_DATARDY_Pos (0UL) /*!< Position of DATARDY field. */
#define TEMP_INTENSET_DATARDY_Msk (0x1UL << TEMP_INTENSET_DATARDY_Pos) /*!< Bit mask of DATARDY field. */
#define TEMP_INTENSET_DATARDY_Disabled (0UL) /*!< Read: Disabled */
#define TEMP_INTENSET_DATARDY_Enabled (1UL) /*!< Read: Enabled */
#define TEMP_INTENSET_DATARDY_Set (1UL) /*!< Enable */
/* Register: TEMP_INTENCLR */
/* Description: Disable interrupt */
/* Bit 0 : Write '1' to disable interrupt for event DATARDY */
#define TEMP_INTENCLR_DATARDY_Pos (0UL) /*!< Position of DATARDY field. */
#define TEMP_INTENCLR_DATARDY_Msk (0x1UL << TEMP_INTENCLR_DATARDY_Pos) /*!< Bit mask of DATARDY field. */
#define TEMP_INTENCLR_DATARDY_Disabled (0UL) /*!< Read: Disabled */
#define TEMP_INTENCLR_DATARDY_Enabled (1UL) /*!< Read: Enabled */
#define TEMP_INTENCLR_DATARDY_Clear (1UL) /*!< Disable */
/* Register: TEMP_TEMP */
/* Description: Temperature in degC (0.25deg steps) */
/* Bits 31..0 : Temperature in degC (0.25deg steps) */
#define TEMP_TEMP_TEMP_Pos (0UL) /*!< Position of TEMP field. */
#define TEMP_TEMP_TEMP_Msk (0xFFFFFFFFUL << TEMP_TEMP_TEMP_Pos) /*!< Bit mask of TEMP field. */
/* Register: TEMP_A0 */
/* Description: Slope of first piecewise linear function */
/* Bits 11..0 : Slope of first piecewise linear function */
#define TEMP_A0_A0_Pos (0UL) /*!< Position of A0 field. */
#define TEMP_A0_A0_Msk (0xFFFUL << TEMP_A0_A0_Pos) /*!< Bit mask of A0 field. */
/* Register: TEMP_A1 */
/* Description: Slope of second piecewise linear function */
/* Bits 11..0 : Slope of second piecewise linear function */
#define TEMP_A1_A1_Pos (0UL) /*!< Position of A1 field. */
#define TEMP_A1_A1_Msk (0xFFFUL << TEMP_A1_A1_Pos) /*!< Bit mask of A1 field. */
/* Register: TEMP_A2 */
/* Description: Slope of third piecewise linear function */
/* Bits 11..0 : Slope of third piecewise linear function */
#define TEMP_A2_A2_Pos (0UL) /*!< Position of A2 field. */
#define TEMP_A2_A2_Msk (0xFFFUL << TEMP_A2_A2_Pos) /*!< Bit mask of A2 field. */
/* Register: TEMP_A3 */
/* Description: Slope of fourth piecewise linear function */
/* Bits 11..0 : Slope of fourth piecewise linear function */
#define TEMP_A3_A3_Pos (0UL) /*!< Position of A3 field. */
#define TEMP_A3_A3_Msk (0xFFFUL << TEMP_A3_A3_Pos) /*!< Bit mask of A3 field. */
/* Register: TEMP_A4 */
/* Description: Slope of fifth piecewise linear function */
/* Bits 11..0 : Slope of fifth piecewise linear function */
#define TEMP_A4_A4_Pos (0UL) /*!< Position of A4 field. */
#define TEMP_A4_A4_Msk (0xFFFUL << TEMP_A4_A4_Pos) /*!< Bit mask of A4 field. */
/* Register: TEMP_A5 */
/* Description: Slope of sixth piecewise linear function */
/* Bits 11..0 : Slope of sixth piecewise linear function */
#define TEMP_A5_A5_Pos (0UL) /*!< Position of A5 field. */
#define TEMP_A5_A5_Msk (0xFFFUL << TEMP_A5_A5_Pos) /*!< Bit mask of A5 field. */
/* Register: TEMP_B0 */
/* Description: y-intercept of first piecewise linear function */
/* Bits 11..0 : y-intercept of first piecewise linear function */
#define TEMP_B0_B0_Pos (0UL) /*!< Position of B0 field. */
#define TEMP_B0_B0_Msk (0xFFFUL << TEMP_B0_B0_Pos) /*!< Bit mask of B0 field. */
/* Register: TEMP_B1 */
/* Description: y-intercept of second piecewise linear function */
/* Bits 11..0 : y-intercept of second piecewise linear function */
#define TEMP_B1_B1_Pos (0UL) /*!< Position of B1 field. */
#define TEMP_B1_B1_Msk (0xFFFUL << TEMP_B1_B1_Pos) /*!< Bit mask of B1 field. */
/* Register: TEMP_B2 */
/* Description: y-intercept of third piecewise linear function */
/* Bits 11..0 : y-intercept of third piecewise linear function */
#define TEMP_B2_B2_Pos (0UL) /*!< Position of B2 field. */
#define TEMP_B2_B2_Msk (0xFFFUL << TEMP_B2_B2_Pos) /*!< Bit mask of B2 field. */
/* Register: TEMP_B3 */
/* Description: y-intercept of fourth piecewise linear function */
/* Bits 11..0 : y-intercept of fourth piecewise linear function */
#define TEMP_B3_B3_Pos (0UL) /*!< Position of B3 field. */
#define TEMP_B3_B3_Msk (0xFFFUL << TEMP_B3_B3_Pos) /*!< Bit mask of B3 field. */
/* Register: TEMP_B4 */
/* Description: y-intercept of fifth piecewise linear function */
/* Bits 11..0 : y-intercept of fifth piecewise linear function */
#define TEMP_B4_B4_Pos (0UL) /*!< Position of B4 field. */
#define TEMP_B4_B4_Msk (0xFFFUL << TEMP_B4_B4_Pos) /*!< Bit mask of B4 field. */
/* Register: TEMP_B5 */
/* Description: y-intercept of sixth piecewise linear function */
/* Bits 11..0 : y-intercept of sixth piecewise linear function */
#define TEMP_B5_B5_Pos (0UL) /*!< Position of B5 field. */
#define TEMP_B5_B5_Msk (0xFFFUL << TEMP_B5_B5_Pos) /*!< Bit mask of B5 field. */
/* Register: TEMP_T0 */
/* Description: Endpoint of first piecewise linear function */
/* Bits 7..0 : Endpoint of first piecewise linear function */
#define TEMP_T0_T0_Pos (0UL) /*!< Position of T0 field. */
#define TEMP_T0_T0_Msk (0xFFUL << TEMP_T0_T0_Pos) /*!< Bit mask of T0 field. */
/* Register: TEMP_T1 */
/* Description: Endpoint of second piecewise linear function */
/* Bits 7..0 : Endpoint of second piecewise linear function */
#define TEMP_T1_T1_Pos (0UL) /*!< Position of T1 field. */
#define TEMP_T1_T1_Msk (0xFFUL << TEMP_T1_T1_Pos) /*!< Bit mask of T1 field. */
/* Register: TEMP_T2 */
/* Description: Endpoint of third piecewise linear function */
/* Bits 7..0 : Endpoint of third piecewise linear function */
#define TEMP_T2_T2_Pos (0UL) /*!< Position of T2 field. */
#define TEMP_T2_T2_Msk (0xFFUL << TEMP_T2_T2_Pos) /*!< Bit mask of T2 field. */
/* Register: TEMP_T3 */
/* Description: Endpoint of fourth piecewise linear function */
/* Bits 7..0 : Endpoint of fourth piecewise linear function */
#define TEMP_T3_T3_Pos (0UL) /*!< Position of T3 field. */
#define TEMP_T3_T3_Msk (0xFFUL << TEMP_T3_T3_Pos) /*!< Bit mask of T3 field. */
/* Register: TEMP_T4 */
/* Description: Endpoint of fifth piecewise linear function */
/* Bits 7..0 : Endpoint of fifth piecewise linear function */
#define TEMP_T4_T4_Pos (0UL) /*!< Position of T4 field. */
#define TEMP_T4_T4_Msk (0xFFUL << TEMP_T4_T4_Pos) /*!< Bit mask of T4 field. */
/* =========================================================================================================================== */
/* ================ TIMER ================ */

View File

@ -1,158 +0,0 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* TEMP - Temperature sensor
* https://infocenter.nordicsemi.com/topic/ps_nrf52833/temp.html?cp=4_1_0_5_25
*
* A very simple and rough model
*
* Notes:
* * At this point the device is always at 25 C
* * The measurement result will just be 25 +- 0.25 C
* * There is no per device variability
* * There is no modeling of possible calibration errors or inaccuracies due to no non-linearities compensation
*/
#include "NHW_common_types.h"
#include "NHW_config.h"
#include "NRF_TEMP.h"
#include <string.h>
#include <stdbool.h>
#include "nsi_hw_scheduler.h"
#include "NHW_peri_types.h"
#include "NRF_PPI.h"
#include "irq_ctrl.h"
#include "bs_rand_main.h"
#include "nsi_tasks.h"
#include "nsi_hws_models_if.h"
NRF_TEMP_Type NRF_TEMP_regs;
/* Mapping of peripheral instance to {int controller instance, int number} */
static struct nhw_irq_mapping nhw_temp_irq_map[NHW_TEMP_TOTAL_INST] = NHW_TEMP_INT_MAP;
static bs_time_t Timer_TEMP = TIME_NEVER; //Time when the next temperature measurement will be ready
static bool TEMP_hw_started = false;
static bool TEMP_INTEN = false; //interrupt enable
#define T_TEMP 36 /* microseconds */
#define TEMP_FBITS 2 /* fractional bits */
static double temperature = 25.0; /* Actual temperature the device is at */
/**
* Initialize the TEMP model
*/
static void nrf_temp_init(void) {
memset(&NRF_TEMP_regs, 0, sizeof(NRF_TEMP_regs));
NRF_TEMP_regs.A0 = 0x00000326;
NRF_TEMP_regs.A1 = 0x00000348;
NRF_TEMP_regs.A2 = 0x000003AA;
NRF_TEMP_regs.A3 = 0x0000040E;
NRF_TEMP_regs.A4 = 0x000004BD;
NRF_TEMP_regs.A5 = 0x000005A3;
NRF_TEMP_regs.B0 = 0x00003FEF;
NRF_TEMP_regs.B1 = 0x00003FBE;
NRF_TEMP_regs.B2 = 0x00003FBE;
NRF_TEMP_regs.B3 = 0x00000012;
NRF_TEMP_regs.B4 = 0x00000124;
NRF_TEMP_regs.B5 = 0x0000027C;
NRF_TEMP_regs.T0 = 0x000000E2;
NRF_TEMP_regs.T1 = 0x00000000;
NRF_TEMP_regs.T2 = 0x00000019;
NRF_TEMP_regs.T3 = 0x0000003C;
NRF_TEMP_regs.T4 = 0x00000050;
TEMP_hw_started = false;
TEMP_INTEN = false;
Timer_TEMP = TIME_NEVER;
}
NSI_TASK(nrf_temp_init, HW_INIT, 100);
/**
* TASK_START triggered handler
*/
void nrf_temp_task_start(void) {
if (TEMP_hw_started) {
return;
}
TEMP_hw_started = true;
Timer_TEMP = nsi_hws_get_time() + T_TEMP;
nsi_hws_find_next_event();
}
/**
* TASK_STOP triggered handler
*/
void nrf_temp_task_stop(void) {
TEMP_hw_started = false;
Timer_TEMP = TIME_NEVER;
nsi_hws_find_next_event();
}
void nrf_temp_regw_sideeffects_TASK_START(void) {
NRF_TEMP_regs.TASKS_START &= 1;
if ( NRF_TEMP_regs.TASKS_START ) {
NRF_TEMP_regs.TASKS_START = 0;
nrf_temp_task_start();
}
}
void nrf_temp_regw_sideeffects_TASK_STOP(void) {
NRF_TEMP_regs.TASKS_STOP &= 1;
if ( NRF_TEMP_regs.TASKS_STOP ) {
NRF_TEMP_regs.TASKS_STOP = 0;
nrf_temp_task_stop();
}
}
void nrf_temp_regw_sideeffects_INTENSET(void) {
NRF_TEMP_regs.INTENSET &= 1;
if ( NRF_TEMP_regs.INTENSET ) {
TEMP_INTEN = true;
}
}
void nrf_temp_regw_sideeffects_INTENCLEAR(void) {
NRF_TEMP_regs.INTENCLR &= 1;
if ( NRF_TEMP_regs.INTENCLR ) {
TEMP_INTEN = false;
NRF_TEMP_regs.INTENSET = 0;
NRF_TEMP_regs.INTENCLR = 0;
}
}
/**
* Time has come when the temperature measurement is ready
*/
static void nrf_temp_timer_triggered(void) {
NRF_TEMP_regs.TEMP = temperature*(1 << TEMP_FBITS) + bs_random_uniformRi(-1,1);
TEMP_hw_started = false;
Timer_TEMP = TIME_NEVER;
nsi_hws_find_next_event();
NRF_TEMP_regs.EVENTS_DATARDY = 1;
nrf_ppi_event(TEMP_EVENTS_DATARDY);
int inst = 0;
if ( TEMP_INTEN ){
hw_irq_ctrl_set_irq(nhw_temp_irq_map[inst].cntl_inst,
nhw_temp_irq_map[inst].int_nbr);
}
}
NSI_HW_EVENT(Timer_TEMP, nrf_temp_timer_triggered, 50);

View File

@ -1,24 +0,0 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _NRF_HW_MODEL_TEMP_H
#define _NRF_HW_MODEL_TEMP_H
#ifdef __cplusplus
extern "C"{
#endif
void nrf_temp_regw_sideeffects_TASK_START(void);
void nrf_temp_regw_sideeffects_TASK_STOP(void);
void nrf_temp_regw_sideeffects_INTENSET(void);
void nrf_temp_regw_sideeffects_INTENCLEAR(void);
void nrf_temp_task_start(void);
void nrf_temp_task_stop(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -7,18 +7,16 @@
*/
#include "hal/nrf_temp.h"
#include "bs_tracing.h"
#include "NRF_TEMP.h"
#include "NHW_TEMP.h"
void nrf_temp_task_trigger(NRF_TEMP_Type * p_reg, nrf_temp_task_t temp_task)
{
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)temp_task)) = 0x1UL;
if ( temp_task == NRF_TEMP_TASK_START ) {
NRF_TEMP_regs.TASKS_START = 1;
nrf_temp_regw_sideeffects_TASK_START();
nhw_TEMP_regw_sideeffects_TASKS_START();
} else if ( temp_task == NRF_TEMP_TASK_STOP ) {
NRF_TEMP_regs.TASKS_STOP = 1;
nrf_temp_regw_sideeffects_TASK_STOP();
nhw_TEMP_regw_sideeffects_TASKS_STOP();
} else {
bs_trace_error_line_time("Not supported task started in %s\n", __func__);
}
@ -27,11 +25,50 @@ void nrf_temp_task_trigger(NRF_TEMP_Type * p_reg, nrf_temp_task_t temp_task)
void nrf_temp_int_enable(NRF_TEMP_Type * p_reg, uint32_t mask)
{
NRF_TEMP_regs.INTENSET = mask;
nrf_temp_regw_sideeffects_INTENSET();
nhw_TEMP_regw_sideeffects_INTENSET();
}
void nrf_temp_int_disable(NRF_TEMP_Type * p_reg, uint32_t mask)
{
NRF_TEMP_regs.INTENCLR = mask;
nrf_temp_regw_sideeffects_INTENCLEAR();
nhw_TEMP_regw_sideeffects_INTENCLEAR();
}
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)) = 0x0UL;
nhw_TEMP_regw_sideeffects_EVENTS_all(0);
}
#if defined(DPPI_PRESENT)
static void nrf_temp_subscribe_common(NRF_TEMP_Type * p_reg,
nrf_temp_task_t task)
{
if (task == NRF_TEMP_TASK_START) {
nhw_TEMP_regw_sideeffects_SUBSCRIBE_START(0);
} else if ( task == NRF_TEMP_TASK_STOP ) {
nhw_TEMP_regw_sideeffects_SUBSCRIBE_STOP(0);
} else {
bs_trace_error_line_time("Attempted to subscribe to an not-supported task in the nrf_temp (%i)\n",
task);
}
}
void nrf_temp_subscribe_set(NRF_TEMP_Type * p_reg,
nrf_temp_task_t task,
uint8_t channel)
{
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
nrf_temp_subscribe_common(p_reg, task);
}
void nrf_temp_subscribe_clear(NRF_TEMP_Type * p_reg,
nrf_temp_task_t task)
{
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
nrf_temp_subscribe_common(p_reg, task);
}
#endif /* defined(DPPI_PRESENT) */

View File

@ -143,8 +143,9 @@ extern NRF_CCM_Type NRF_CCM_regs;
extern NRF_DPPIC_Type NRF_DPPIC_regs[];
#undef NRF_DPPIC_NS_BASE
#define NRF_DPPIC_NS_BASE (&NRF_DPPIC_regs[NHW_DPPI_NET_0])
extern NRF_TEMP_Type NRF_TEMP_regs;
#undef NRF_TEMP_NS_BASE
#define NRF_TEMP_NS_BASE NULL
#define NRF_TEMP_NS_BASE (&NRF_TEMP_regs)
extern NRF_RTC_Type NRF_RTC_regs[];
#undef NRF_RTC0_NS_BASE
#define NRF_RTC0_NS_BASE (&NRF_RTC_regs[NHW_RTC_NET0])