ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_tsn_regs.h File Reference

Temperature Sensor (TSN) register layout for the Renesas RA8D2. More...

#include <stdint.h>
#include "ra8_attributes.h"
Include dependency graph for ra8_tsn_regs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  r_tsn_ctrl_regs_t
 TSN control block register window. More...
struct  r_tsn_cal_regs_t
 TSN factory-calibration block (read-only on hardware). More...

Enumerations

enum  ra8_tsn_addr_t : uintptr_t {
  k_ra8_tsn_ctrl_base_addr = 0x40235000UL ,
  k_ra8_tsn_cal_base_addr = 0x02C1EDA0UL
}
enum  ra8_tscr_bit_t : uint8_t {
  k_ra8_tscr_bit_tsen = 4U ,
  k_ra8_tscr_bit_tsoe = 7U
}
 Bit positions in TSCR (Temperature Sensor Control Register). More...
enum  ra8_tscr_mask_t : uint8_t {
  k_ra8_tscr_mask_tsen = (uint8_t)(1U << 4U) ,
  k_ra8_tscr_mask_tsoe = (uint8_t)(1U << 7U) ,
  k_ra8_tscr_mask_all = (uint8_t)((1U << 4U) | (1U << 7U))
}
 Bit masks for TSCR (Temperature Sensor Control Register). More...
enum  ra8_tscdr_field_t : uint16_t { k_ra8_tscdr_data_mask = 0x0FFFU }
 Field widths for TSCDR / TSCDR2 calibration words. More...
enum  ra8_tsn_cal_t : int32_t {
  k_ra8_tsn_slope_uv_per_c = 4000 ,
  k_ra8_tsn_ref_temp_degc = 25
}
 Calibration constants for the degC conversion. More...
enum  ra8_tsn_adc_const_t : int32_t {
  k_ra8_tsn_adc_avcc_uv = 3300000 ,
  k_ra8_tsn_adc_full_scale = 4096 ,
  k_ra8_tsn_uv_per_mv = 1000
}
 ADC-side scaling constants used by the two-point conversion. More...

Functions

static volatile r_tsn_ctrl_regs_tra8_tsn (void)
 Get pointer to the TSN control block (HUM Ch 55.2.1 p 3498).
static volatile const r_tsn_cal_regs_tra8_tsn_cal (void)
 Get pointer to the factory-calibration block (TSCDR + TSCDR2).
static volatile const uint32_t * ra8_tsn_tscdr (void)
 Get pointer to the factory-programmed calibration word (TSCDR).

Detailed Description

Temperature Sensor (TSN) register layout for the Renesas RA8D2.

The RA8D2 temperature sensor has two halves:

  1. A control block at R_TSN_CTRL_BASE (0x40235000) which holds the enable and calibration-mode bits. The sensor output is routed through ADC_B channel "temperature sensor" – the actual raw code is read from ADC_B, not from here.
  2. A calibration block at R_TSN_CAL_BASE (0x02C1EDA0) which lives in the MRAM "trimming" area and holds factory- programmed reference values used to convert the raw ADC code into degrees Celsius.

Calibration maths

\[ T(degC) = \frac{(V_{raw} - V_{ref}) \times slope}{1000} + T_{ref} \]

where V_raw is the raw ADC sample (14-bit right-aligned), V_ref is TSCDR (reference code at T_ref degC), and slope is BSP_FEATURE_TSN_SLOPE = 4000 uV/degC for the RA8D2.

Register map

Block Offset Reg Width Purpose
TSN_CTRL 0x00 TSCR 8 Sensor control (TSEN)
TSN_CAL 0x00 TSCDR 32 Reference code @ T_ref
Note
TSCDR is a single-cell memory-mapped value, not a struct.

Definition in file ra8_tsn_regs.h.

Enumeration Type Documentation

◆ ra8_tscdr_field_t

enum ra8_tscdr_field_t : uint16_t

Field widths for TSCDR / TSCDR2 calibration words.

HUM Ch 55.2.2 "TSCDR : Temperature Sensor Calibration Data Register", p 3498-3499. Only the lower 12 bits are meaningful; reserved bits read 0. The same width applies to live conversion samples that the ADC produces for the temperature-sensor channel.

Enumerator
k_ra8_tscdr_data_mask 

12-bit data mask (HUM Ch 55.2.2 p 3498).

Definition at line 94 of file ra8_tsn_regs.h.

◆ ra8_tscr_bit_t

enum ra8_tscr_bit_t : uint8_t

Bit positions in TSCR (Temperature Sensor Control Register).

HUM Ch 55.2.1 "TSCR : Temperature Sensor Control Register", p 3498.

Enumerator
k_ra8_tscr_bit_tsen 

1 = sensor enabled, 0 = off.

k_ra8_tscr_bit_tsoe 

1 = output enabled to ADC_B.

Definition at line 63 of file ra8_tsn_regs.h.

◆ ra8_tscr_mask_t

enum ra8_tscr_mask_t : uint8_t

Bit masks for TSCR (Temperature Sensor Control Register).

Pre-shifted masks corresponding to the bit positions in ra8_tscr_bit_t. k_ra8_tscr_mask_all covers every documented bit so callers (and unit tests) can ignore any reserved bits the silicon happens to surface (HUM Ch 55.2.1 "TSCR" p 3498).

Enumerator
k_ra8_tscr_mask_tsen 

TSEN bit (sensor enable).

k_ra8_tscr_mask_tsoe 

TSOE bit (ADC output enable).

k_ra8_tscr_mask_all 

TSEN | TSOE.

Definition at line 78 of file ra8_tsn_regs.h.

◆ ra8_tsn_adc_const_t

enum ra8_tsn_adc_const_t : int32_t

ADC-side scaling constants used by the two-point conversion.

The two-point trim formula from HUM Ch 55.3.1 (p 3499-3500) needs three magic-free numbers:

  • k_ra8_tsn_adc_avcc_uv – AVCC0 / VREFH0 in microvolts. The EK-RA8D2 board ties both rails to a 3.3 V LDO (HUM Ch 69 "Electrical Characteristics" lists 3.3 V typical). Using microvolts keeps the divide in 64-bit integer math.
  • k_ra8_tsn_adc_full_scale – 12-bit ADC full-scale (4096). Matches the ADC-side resolution that the temperature-sensor channel produces (HUM Ch 53 "16-bit A/D Converter" the TSN channel runs in 12-bit mode and Ch 55.2.2 p 3498 confirms the calibration words are 12-bit too).
  • k_ra8_tsn_uv_per_mv – 1000 scale factor that promotes a degC value into milli-degC. Naming reflects the equivalent microvolt-per-millivolt ratio so the conversion math stays self-documenting.
Enumerator
k_ra8_tsn_adc_avcc_uv 

AVCC = 3.3 V expressed in uV.

k_ra8_tsn_adc_full_scale 

12-bit ADC full-scale.

k_ra8_tsn_uv_per_mv 

1000-x scale (degC -> mC).

Definition at line 200 of file ra8_tsn_regs.h.

◆ ra8_tsn_addr_t

enum ra8_tsn_addr_t : uintptr_t
Enumerator
k_ra8_tsn_ctrl_base_addr 

TSN control block.

k_ra8_tsn_cal_base_addr 

Factory calibration.

Definition at line 51 of file ra8_tsn_regs.h.

◆ ra8_tsn_cal_t

enum ra8_tsn_cal_t : int32_t

Calibration constants for the degC conversion.

From BSP_FEATURE_TSN_SLOPE (4000 uV/degC) and the reference temperature embedded in the RA8D2 HUM section "Temperature Sensor".

Enumerator
k_ra8_tsn_slope_uv_per_c 

Slope in microvolts per degC.

k_ra8_tsn_ref_temp_degc 

Reference temperature (degC).

Definition at line 173 of file ra8_tsn_regs.h.

Function Documentation

◆ ra8_tsn()

volatile r_tsn_ctrl_regs_t * ra8_tsn ( void )
inlinestatic

Get pointer to the TSN control block (HUM Ch 55.2.1 p 3498).

Definition at line 139 of file ra8_tsn_regs.h.

References k_ra8_tsn_ctrl_base_addr.

Referenced by ra8_tsn_clear_status(), ra8_tsn_deinit(), ra8_tsn_get_status(), and ra8_tsn_init().

◆ ra8_tsn_cal()

volatile const r_tsn_cal_regs_t * ra8_tsn_cal ( void )
inlinestatic

Get pointer to the factory-calibration block (TSCDR + TSCDR2).

HUM Ch 55.2.2 "TSCDR / TSCDR2", p 3498-3499. The block is read-only on hardware – callers must treat the pointer's targets as const even though the struct fields are plain volatile uint32_t so unit tests can poke them.

Definition at line 153 of file ra8_tsn_regs.h.

References k_ra8_tsn_cal_base_addr.

Referenced by ra8_tsn_convert_to_milli_c().

◆ ra8_tsn_tscdr()

volatile const uint32_t * ra8_tsn_tscdr ( void )
inlinestatic

Get pointer to the factory-programmed calibration word (TSCDR).

Definition at line 160 of file ra8_tsn_regs.h.

References k_ra8_tsn_cal_base_addr.