31static const char*
s_tag =
"TSN";
45typedef enum : uint16_t {
103 for (uint16_t u = 0U; u < usec; ++u) {
131 bool high_ok =
false;
140 if (!high_ok || !low_ok) {
226 if (cal_hi == cal_lo) {
236 const int64_t v1_uv = (avcc_uv * (int64_t)cal_hi) / full_scale;
237 const int64_t v2_uv = (avcc_uv * (int64_t)cal_lo) / full_scale;
238 const int64_t vs_uv = (avcc_uv * (int64_t)raw_code) / full_scale;
241 const int64_t v_delta_uv = v1_uv - v2_uv;
242 const int64_t numerator_uv = (vs_uv - v1_uv) * (t1_milli_c - t2_milli_c);
243 const int64_t result_milli = (numerator_uv / v_delta_uv) + t1_milli_c;
245 *out_milli_c = (int32_t)result_milli;
259 uint16_t adc_raw = 0U;
Full-featured ADC_B driver.
ra8_err_t ra8_adc_read_internal_channel(ra8_adc_internal_chan_t chan, uint16_t *out_raw)
Blocking single conversion of an internal / extended-analog channel.
@ k_ra8_adc_chan_temperature
On-chip die-temperature sensor.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Shared CPU-intrinsic seam for the HAL drivers (host/target split).
static void ra8_hw_nop(void)
No-operation used to pad a calibrated busy-wait.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
@ k_ra8_mstp_tsn
MSTPD22 Temperature.
ra8_err_t ra8_tsn_convert_to_milli_c(uint16_t raw_code, int32_t *out_milli_c)
Convert a raw 12-bit TSN code to milli-degrees-Celsius.
ra8_err_t ra8_tsn_init(const ra8_tsn_config_t *cfg)
Power on the TSN block and enable its ADC output path.
static ra8_err_t internal_validate_cfg(const ra8_tsn_config_t *cfg)
Validate the high/low reference temperatures in a config.
static void internal_busy_wait_us(uint16_t usec)
Coarse software busy-wait used during init.
ra8_err_t ra8_tsn_exit_stop(void)
Clear MSTPD22 to re-power the TSN block.
ra8_err_t ra8_tsn_get_status(uint8_t *out_tscr)
Read TSCR (TSEN + TSOE bits).
static int16_t s_ra8_tsn_high_ref_degc
Cached high-side calibration temperature.
ra8_tsn_internal_t
Driver-internal magic values.
@ k_ra8_tsn_min_stab_us
tTSTBL spec floor.
@ k_ra8_tsn_busy_loops_per_us
Conservative spin count.
ra8_err_t ra8_tsn_read_die_temp_milli_c(int32_t *out_milli_c)
Read the die temperature end-to-end through the HAL.
ra8_err_t ra8_tsn_clear_status(void)
Clear TSCR (drive both TSEN and TSOE low).
ra8_err_t ra8_tsn_read_raw(uint16_t raw, uint16_t *out_code)
Pass through a raw ADC sample of the TSN channel.
static bool s_ra8_tsn_initialized
Tracks whether ra8_tsn_init has run successfully.
ra8_err_t ra8_tsn_enter_stop(void)
Re-assert MSTPD22 to clock-gate the TSN block.
static int16_t s_ra8_tsn_low_ref_degc
Cached low-side calibration temperature (always -40).
ra8_err_t ra8_tsn_deinit(void)
Tear down the TSN block.
On-chip Temperature Sensor (TSN) driver.
@ k_ra8_tsn_cal_temp_high_125
125 degC Tj_max parts.
@ k_ra8_tsn_cal_temp_low_n40
Always -40 degC on RA8D2.
@ k_ra8_tsn_cal_temp_high_105
95 / 105 degC parts.
Temperature Sensor (TSN) register layout for the Renesas RA8D2.
@ k_ra8_tscdr_data_mask
12-bit data mask (HUM Ch 55.2.2 p 3498).
@ k_ra8_tscr_mask_tsoe
TSOE bit (ADC output enable).
@ k_ra8_tscr_mask_all
TSEN | TSOE.
@ k_ra8_tscr_mask_tsen
TSEN bit (sensor enable).
@ k_ra8_tsn_uv_per_mv
1000-x scale (degC -> mC).
@ k_ra8_tsn_adc_avcc_uv
AVCC = 3.3 V expressed in uV.
@ k_ra8_tsn_adc_full_scale
12-bit ADC full-scale.
static volatile r_tsn_ctrl_regs_t * ra8_tsn(void)
Get pointer to the TSN control block (HUM Ch 55.2.1 p 3498).
static volatile const r_tsn_cal_regs_t * ra8_tsn_cal(void)
Get pointer to the factory-calibration block (TSCDR + TSCDR2).
TSN factory-calibration block (read-only on hardware).
volatile uint32_t TSCDR2
+0x04 Calibration code at low ref temperature.
volatile uint32_t TSCDR
+0x00 Calibration code at high ref temperature.
TSN control block register window.
volatile uint8_t TSCR
+0x00 Temperature Sensor Control Register.
Configuration descriptor for ra8_tsn_init.
uint16_t stab_us
tTSTBL in microseconds.
ra8_tsn_cal_temp_t low_ref_degc
Always -40 degC on RA8D2.
ra8_tsn_cal_temp_t high_ref_degc
105 or 125 degC.