36static const char*
s_tag =
"ADC";
41 "temperature CNVCS code drift between ra8_adc.h and ra8_adc_b_regs.h");
43 "internal-Vref CNVCS code drift between ra8_adc.h and ra8_adc_b_regs.h");
55typedef enum : uint8_t {
67typedef enum : int32_t {
86typedef enum : int32_t {
109 uint32_t* out_diagval)
221 if (reg ==
nullptr) {
224 const uint32_t cnvcs =
226 const uint32_t sgsel =
228 const uint32_t ainmd =
232 *reg = (cnvcs | sgsel | ainmd);
253 if (reg ==
nullptr) {
256 const uint32_t adprc_field =
258 const uint32_t sign_field =
262 *reg = (cleared | adprc_field | sign_field);
286 if (adstr ==
nullptr) {
358 uint32_t diagval = 0U;
372 const int32_t actual = (int32_t)(int16_t)data;
377 *out_pass = (!err_flag) && in_band;
409 if (exd ==
nullptr) {
Cross-TU constants shared by the ADC_B driver split.
@ k_ra8_adc_busy_wait_limit
ADSR.ADACT busy-poll budget.
static int32_t internal_selfdiag_expected(ra8_adc_selfdiag_mode_t mode)
Ideal signed self-diagnosis result for a mode.
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.
static bool internal_is_supported_ext_chan(ra8_adc_internal_chan_t chan)
Test whether a channel is a supported internal/extended source.
static void internal_program_ext_channel(uint8_t vch, uint8_t physical_ch, uint8_t group, bool differential)
Program a dedicated ADCHCR slot for an extended-analog channel.
ra8_adc_diag_slot_t
Dedicated virtual-channel / scan-group used for diagnostic reads.
@ k_ra8_adc_diag_group
Dedicated scan group for diagnostic reads.
@ k_ra8_adc_diag_vchan
Dedicated ADCHCR slot for diagnostic reads.
ra8_err_t ra8_adc_self_diagnose(ra8_adc_selfdiag_mode_t mode, uint16_t *out_code, bool *out_pass)
Run an ADC_B built-in self-diagnosis pass on A/D unit 0.
static ra8_err_t internal_start_and_wait(uint8_t group)
Start a scan group and bounded-poll ADSR.ADACT0 to completion.
static ra8_err_t internal_selfdiag_run(uint32_t diagval)
Arm the self-diagnosis channel, run one scan, and disarm DIAGVAL.
ra8_adc_selfdiag_expect_t
Ideal 16-bit signed self-diagnosis result per mode.
@ k_ra8_adc_selfdiag_expect_mode1
0x0000.
@ k_ra8_adc_selfdiag_expect_mode3
0x7FFF.
@ k_ra8_adc_selfdiag_expect_mode2
0x8000.
static bool internal_selfdiag_in_band(int32_t diff)
Test whether a signed deviation is inside the tolerance band.
static bool internal_diagval_for_mode(ra8_adc_selfdiag_mode_t mode, uint32_t *out_diagval)
Translate a public self-diagnosis mode into the DIAGVAL code.
ra8_adc_selfdiag_tol_t
Allowed absolute deviation from the ideal self-diagnosis result.
@ k_ra8_adc_selfdiag_tol_lsb
+/- LSB tolerance about the ideal.
static void internal_set_data_format(uint8_t vch, uint8_t adprc, uint8_t signsel)
Force the ADPRC data-format and SIGNSEL sign-format on a slot.
Full-featured ADC_B driver.
ra8_adc_internal_chan_t
Internal / extended-analog channels readable through the HAL.
@ k_ra8_adc_chan_temperature
On-chip die-temperature sensor.
@ k_ra8_adc_chan_int_ref_volt
Internal reference voltage.
ra8_adc_selfdiag_mode_t
ADC_B built-in self-diagnosis modes (HUM Ch 53.3.11 p 3411-3414).
@ k_ra8_adc_selfdiag_mode_3
Positive full-scale.
@ k_ra8_adc_selfdiag_mode_2
Negative full-scale.
@ k_ra8_adc_selfdiag_mode_1
Zero-differential reference.
ADC16H (16-bit SAR) register layout for the Renesas RA8D2 / RA8P1.
@ k_ra8_adc_b_chan_int_ref_volt
Internal reference voltage.
@ k_ra8_adc_b_chan_selfdiag_adc0
Self-diagnosis A/D unit 0.
@ k_ra8_adc_b_chan_temperature
On-chip temperature sensor.
@ k_ra8_adexdr_mask_data
DATA[15:0] conversion result.
@ k_ra8_adexdr_mask_err
ERR conversion-error flag.
@ k_ra8_addopcrc_adprc_12bit
12-bit data.
@ k_ra8_addopcrc_adprc_16bit
16-bit data.
static volatile uint32_t * ra8_adc_b_addopcrc(uint8_t ch)
Pointer to the per-virtual-channel ADDOPCRC[n] register.
@ k_ra8_adchcr_mask_cnvcs
[14:8]
@ k_ra8_adchcr_mask_ainmd
[15]
@ k_ra8_adchcr_mask_sgsel
[4:0]
@ k_ra8_adsgdcr_mask_diagval
DIAGVAL[2:0].
@ k_ra8_adchcr_bit_sgsel
Scan group selection.
@ k_ra8_adchcr_bit_ainmd
Analog input mode (single/diff).
@ k_ra8_adchcr_bit_cnvcs
Physical channel selection.
@ k_ra8_adsgdcr_bit_diagval
Self-diagnosis mode select [2:0].
@ k_ra8_adsgdcr_diag_mode3
Mode 3: positive FS (0x7FFF).
@ k_ra8_adsgdcr_diag_mode2
Mode 2: negative FS (0x8000).
@ k_ra8_adsgdcr_diag_mode1
Mode 1: zero differential (0x0000).
@ k_ra8_addopcrc_mask_signsel
SIGNSEL.
@ k_ra8_addopcrc_mask_adprc
ADPRC[1:0].
static volatile uint32_t * ra8_adc_b_adstr(uint8_t group)
Pointer to the per-scan-group ADSTR[n] register.
static uint8_t ra8_adc_b_adexdr_index_for_chan(uint8_t cnvcs)
Map a CNVCS extended-channel code to its ADEXDR index.
@ k_ra8_adstr_mask_adst
RA8 adstr mask adst.
static volatile uint32_t * ra8_adc_b_adchcr(uint8_t ch)
Pointer to the per-virtual-channel ADCHCR register.
@ k_ra8_adsr_mask_adact0
RA8 adsr mask adact0.
@ k_ra8_addopcrc_signsel_unsigned
Unsigned data format.
@ k_ra8_addopcrc_signsel_signed
Signed data format.
@ k_ra8_adc_b_ext_chan_base
ADEXDR index n = CNVCS - this.
@ k_ra8_addopcrc_bit_signsel
Signed/unsigned select [20].
@ k_ra8_addopcrc_bit_adprc
Data-format select [17:16].
static volatile uint32_t * ra8_adc_b_adexdr(uint8_t n)
Pointer to the ADEXDR[n] extended-analog result register.
static volatile uint32_t * ra8_adc_b_adsgdcr(uint8_t group)
Pointer to the per-scan-group ADSGDCR[n] register (self-diagnosis).
static volatile uint32_t * ra8_adc_b_adsger(void)
Pointer to the 32-bit ADSGER register (scan-group enable).
static volatile uint32_t * ra8_adc_b_adsr(void)
Pointer to the 32-bit ADSR register (status).
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_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ 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.
Lightweight Logging Interface for ra8-firmware.