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

ADC16H (16-bit SAR) peripheral-block model for the board emulator. More...

#include <stdint.h>
#include <stdio.h>
#include "board_console.h"
#include "board_periph_block.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_periph_adc.c:

Go to the source code of this file.

Enumerations

enum  adc_console_t : uint32_t { k_adc_console_line_cap = 48U }
 Console-tap line buffer capacity for an ADC conversion summary. More...
enum  adc_map_t : uint64_t {
  k_adc_base = 0x40338000UL ,
  k_adc_span = 0x2224UL ,
  k_adc_off_adsger = 0x0048UL ,
  k_adc_off_adintcr = 0x005CUL ,
  k_adc_off_adsgdcr0 = 0x0200UL ,
  k_adc_off_adchcr0 = 0x0600UL ,
  k_adc_off_addopcrc0 = 0x060CUL ,
  k_adc_off_adtrgenr = 0x0C08UL ,
  k_adc_off_adstr0 = 0x0C20UL ,
  k_adc_off_adstopr = 0x0C60UL ,
  k_adc_off_adsr = 0x0C80UL ,
  k_adc_off_addr0 = 0x2000UL ,
  k_adc_off_adexdr0 = 0x2180UL ,
  k_adc_chcr_stride = 0x10UL ,
  k_adc_addr_stride = 0x04UL ,
  k_adc_str_stride = 0x04UL ,
  k_adc_sgdcr_stride = 0x04UL ,
  k_adc_exdr_stride = 0x04UL
}
 ADC_B block geometry (ra8_adc_b_regs.h, FSP R_ADC_B0_Type). More...
enum  adc_dim_t : uint32_t {
  k_adc_max_channels = 24U ,
  k_adc_result_regs = 23U ,
  k_adc_ext_regs = 23U ,
  k_adc_scan_groups = 9U ,
  k_adc_reg_words = 0x2224U / 4U
}
 ADC_B array dimensions (mirror ra8_adc_b_limits_t). More...
enum  adc_field_t : uint32_t {
  k_adc_adst_mask = 0x00000001UL ,
  k_adc_adact0_mask = 0x00000001UL ,
  k_adc_addr_data = 0x0000FFFFUL ,
  k_adc_chcr_sgsel = 0x0000001FUL ,
  k_adc_chcr_cnvcs_m = 0x00007F00UL ,
  k_adc_chcr_cnvcs_s = 8U ,
  k_adc_sgdcr_diagval = 0x00000007UL ,
  k_adc_opcrc_adprc_m = 0x00030000UL ,
  k_adc_opcrc_adprc_s = 16U
}
 ADC_B field shifts / masks the model consults. More...
enum  adc_adprc_t : uint32_t {
  k_adc_adprc_16bit = 0x0U ,
  k_adc_adprc_14bit = 0x1U ,
  k_adc_adprc_12bit = 0x2U ,
  k_adc_adprc_10bit = 0x3U
}
 ADDOPCRCn.ADPRC[1:0] data-format codes (HUM Ch 53.2.3.4 p 3339). More...
enum  adc_midscale_t : uint16_t {
  k_adc_mid_16bit = 0x8000U ,
  k_adc_mid_14bit = 0x2000U ,
  k_adc_mid_12bit = 0x0800U ,
  k_adc_mid_10bit = 0x0200U
}
 Resolution-appropriate mid-scale (half-full-scale) result codes. More...
enum  adc_ext_chan_t : uint32_t {
  k_adc_ext_chan_base = 0x60U ,
  k_adc_chan_selfdiag = 0x60U ,
  k_adc_chan_temp = 0x64U ,
  k_adc_chan_int_vref = 0x65U
}
 Extended-analog (internal) channel CNVCS codes (ra8_adc_b_regs.h). More...
enum  adc_selfdiag_t : uint32_t {
  k_adc_diagval_mode1 = 0x4U ,
  k_adc_diagval_mode2 = 0x5U ,
  k_adc_diagval_mode3 = 0x6U ,
  k_adc_selfdiag_zero = 0x0000U ,
  k_adc_selfdiag_negfs = 0x8000U ,
  k_adc_selfdiag_posfs = 0x7FFFU
}
 ADSGDCRn.DIAGVAL self-diagnosis mode codes + ideal 16-bit results. More...
enum  adc_sample_t : uint16_t {
  k_adc_sample_code = 2048U ,
  k_adc_temp_code = 1800U
}
 Plausible conversion result reported on every scan. More...
enum  adc_elc_event_t : uint16_t { k_event_adc0_scan_end = 0x09CU }
 ADC_B scan-complete (ADI) ELC event the model raises on a scan start. More...

Functions

static RA8_INTERNAL uint32_t internal_adc_word (uint64_t off)
 Word index into the backing store for an in-window offset.
static RA8_INTERNAL uint32_t internal_adc_chcr (uint32_t ch)
 Read an ADCHCRn slot's raw config word from the backing store.
static RA8_INTERNAL void internal_adc_set_result (uint32_t ch, uint16_t code)
 Store a freshly converted code into ADDR[ch] (DATA[15:0], ERR clear).
static RA8_INTERNAL void internal_adc_set_ext_result (uint32_t idx, uint16_t code)
 Store an extended-analog result into ADEXDR[idx] (DATA[15:0], ERR clear).
static RA8_INTERNAL uint32_t internal_adc_diagval (uint32_t group)
 Read ADSGDCR[group].DIAGVAL[2:0] (self-diagnosis mode) from the store.
static RA8_INTERNAL uint16_t internal_adc_selfdiag_ideal (uint32_t diagval)
 Ideal 16-bit self-diagnosis code for the armed DIAGVAL mode.
static RA8_INTERNAL uint16_t internal_adc_ext_value (uint32_t phys, uint32_t group)
 Synthetic ADEXDR code for an extended-analog channel (phys >= base).
static RA8_INTERNAL uint32_t internal_adc_adprc (uint32_t slot)
 Read ADDOPCRC[slot].ADPRC[1:0] data-format code from the store.
static RA8_INTERNAL uint16_t internal_adc_midscale_for_adprc (uint32_t adprc)
 Resolution-appropriate mid-scale result code for an ADPRC format.
static RA8_INTERNAL void internal_adc_convert_group (uint32_t group)
 Populate result registers for every channel enrolled in group.
static RA8_INTERNAL uint64_t internal_adc_read (uc_engine *uc, uint64_t addr, unsigned size)
 MMIO read: ADSR holds ADACT0 idle; everything else reads back.
static RA8_INTERNAL void internal_adc_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
 MMIO write: ADSTR kicks a scan; other registers latch the value.
static RA8_INTERNAL void internal_adc_reset (void)
 Clear all ADC_B register state and observability counters.
static RA8_INTERNAL void internal_adc_report (void)
 Print the ADC_B scan count + last reported result code.
static RA8_INTERNAL void internal_board_periph_adc_register (void)
 Self-register the ADC_B block before main runs (decentralized).

Variables

static uint32_t s_adc_reg [k_adc_reg_words]
 Backing store for the whole ADC_B window (word-addressed).
static uint32_t s_adc_scans
 Conversions kicked via ADSTR.
static uint16_t s_adc_last_code
 Last result code written to an ADDR.
static const board_periph_block_t s_k_adc_block
 This block's descriptor (static lifetime; the core keeps the pointer).

Detailed Description

ADC16H (16-bit SAR) peripheral-block model for the board emulator.

Models the RA8 ADC16H converter (ra8_adc_b_regs.h / adc.c) at base 0x40338000 so a software-triggered conversion produces real result data instead of the sparse fallback's all-ones junk. The driver's single-channel polling read (ra8_adc_read_channel) drives the block as:

  1. Programme an ADCHCRn slot (CNVCS = physical channel, SGSEL = scan group) plus that slot's ADDOPCRCn.ADPRC data-format (conversion resolution).
  2. Kick the scan by writing ADSTR[group].ADST = 1.
  3. Poll ADSR.ADACT0 until it reads 0 (unit idle), then read ADDR[ch].

On the ADSTR write this model walks the configured ADCHCRn slots, populates the matching ADDR[ch] result register with a resolution-appropriate mid-scale (half-full-scale) code – read from the slot's ADDOPCRCn.ADPRC field so a 16-bit conversion reports 0x8000 while a 12-bit one reports 0x0800 (HUM Ch 53.2.3.4 p 3339) – leaves ADSR.ADACT0 clear (the conversion is modelled as instantaneous, so the firmware's idle poll completes on its first read), and raises the group's scan-complete (ADI) event through the core's ICU -> NVIC path. Control registers read back what was written so the driver's "configure then verify" sequence sees a coherent block.

Internal / extended-analog channels (CNVCS >= k_adc_ext_chan_base: the self-diagnosis source 0x60, the temperature sensor 0x64, the internal Vref 0x65) report through ADEXDR[CNVCS - base], NOT the ordinary ADDR[] slot (HUM Ch 53.2.13.2 p 3391). For those slots the model populates ADEXDR instead: the self-diagnosis result is the IDEAL value for the armed ADSGDCRn.DIAGVAL mode (0x0000 / 0x8000 / 0x7FFF – a healthy SAR, so ra8_adc_self_diagnose's band check passes; a stuck-SAR fault cannot be injected here and stays a silicon-only test), the temperature channel returns k_adc_temp_code, and every other extended source returns the mid-scale code. This lets adc_diag_tsn_demo run its self-test + die-temperature path headless (paired with the TSN factory-calibration seed ra8_emulator writes at 0x02C1EDA0).

Self-registers its descriptor with the board_periph core from a file-scope constructor; the core keeps no central block list – see board_periph_block.h.

Since
0.1.0

Definition in file board_periph_adc.c.

Enumeration Type Documentation

◆ adc_adprc_t

enum adc_adprc_t : uint32_t

ADDOPCRCn.ADPRC[1:0] data-format codes (HUM Ch 53.2.3.4 p 3339).

Selects the conversion resolution / result width per virtual channel: 0b00 -> 16-bit, 0b01 -> 14-bit, 0b10 -> 12-bit, 0b11 -> 10-bit. The model uses this to pick a resolution-appropriate mid-scale (adc_midscale_t) result code for a converted channel.

Enumerator
k_adc_adprc_16bit 

ADPRC 0b00: 16-bit result.

k_adc_adprc_14bit 

ADPRC 0b01: 14-bit result.

k_adc_adprc_12bit 

ADPRC 0b10: 12-bit result.

k_adc_adprc_10bit 

ADPRC 0b11: 10-bit result.

Definition at line 111 of file board_periph_adc.c.

◆ adc_console_t

enum adc_console_t : uint32_t

Console-tap line buffer capacity for an ADC conversion summary.

Enumerator
k_adc_console_line_cap 

Max chars in an "ADC grp=.. .." line.

Definition at line 54 of file board_periph_adc.c.

◆ adc_dim_t

enum adc_dim_t : uint32_t

ADC_B array dimensions (mirror ra8_adc_b_limits_t).

Enumerator
k_adc_max_channels 

ADCHCR0..23 virtual-channel config slots.

k_adc_result_regs 

ADDR[0..22] result slots.

k_adc_ext_regs 

ADEXDR[0..22] extended-analog slots.

k_adc_scan_groups 

ADSGER / ADTRGENR / ADSTR width [8:0].

k_adc_reg_words 

Backing-store word count.

Definition at line 81 of file board_periph_adc.c.

◆ adc_elc_event_t

enum adc_elc_event_t : uint16_t

ADC_B scan-complete (ADI) ELC event the model raises on a scan start.

RA8D2 ELC event signal table (HUM Ch 19): the ADC0 scan-end / conversion-end group interrupt (ADI0) is 0x09C. A firmware that routes scan-complete through ra8_isr_register writes the same number into an IELSR slot, so the ICU model can match the raised event to that slot. The polling demo does not arm it, but raising it keeps an interrupt-driven scan path observable.

Enumerator
k_event_adc0_scan_end 

ADC0 ADI scan-complete event.

Definition at line 191 of file board_periph_adc.c.

◆ adc_ext_chan_t

enum adc_ext_chan_t : uint32_t

Extended-analog (internal) channel CNVCS codes (ra8_adc_b_regs.h).

CNVCS values at or above k_adc_ext_chan_base do not sample an external pin; they route an on-chip source whose result is read back from ADEXDR[CNVCS - base], NOT the ordinary ADDR[] slot (HUM Ch 53.2.13.2 p 3391). The model populates ADEXDR for these so ra8_adc_self_diagnose / ra8_adc_read_internal_channel see real data instead of an all-zero result.

Enumerator
k_adc_ext_chan_base 

ADEXDR index origin (n = CNVCS - base).

k_adc_chan_selfdiag 

Self-diagnosis A/D unit 0.

k_adc_chan_temp 

On-chip temperature sensor.

k_adc_chan_int_vref 

Internal reference voltage.

Definition at line 144 of file board_periph_adc.c.

◆ adc_field_t

enum adc_field_t : uint32_t

ADC_B field shifts / masks the model consults.

Enumerator
k_adc_adst_mask 

ADSTR[n].ADST start bit.

k_adc_adact0_mask 

ADSR.ADACT0 unit-0 busy flag.

k_adc_addr_data 

ADDR[n] DATA[15:0] field.

k_adc_chcr_sgsel 

ADCHCRn.SGSEL[4:0] scan group.

k_adc_chcr_cnvcs_m 

ADCHCRn.CNVCS[14:8] phys channel.

k_adc_chcr_cnvcs_s 

ADCHCRn.CNVCS shift.

k_adc_sgdcr_diagval 

ADSGDCRn.DIAGVAL[2:0] mode.

k_adc_opcrc_adprc_m 

ADDOPCRCn.ADPRC[17:16] format.

k_adc_opcrc_adprc_s 

ADDOPCRCn.ADPRC shift.

Definition at line 90 of file board_periph_adc.c.

◆ adc_map_t

enum adc_map_t : uint64_t

ADC_B block geometry (ra8_adc_b_regs.h, FSP R_ADC_B0_Type).

Enumerator
k_adc_base 

ADC_B register-window base.

k_adc_span 

Full FSP R_ADC_B0_Type window size.

k_adc_off_adsger 

ADSGER scan-group enable.

k_adc_off_adintcr 

ADINTCR per-group scan-end IE.

k_adc_off_adsgdcr0 

ADSGDCR[0] scan-group self-diag ctrl.

k_adc_off_adchcr0 

ADCHCR[0] per-channel config.

k_adc_off_addopcrc0 

ADDOPCRC[0] per-channel ADPRC format.

k_adc_off_adtrgenr 

ADTRGENR per-group HW-trigger enable.

k_adc_off_adstr0 

ADSTR[0] per-group SW start.

k_adc_off_adstopr 

ADSTOPR force-stop.

k_adc_off_adsr 

ADSR conversion status (RO).

k_adc_off_addr0 

ADDR[0] conversion results.

k_adc_off_adexdr0 

ADEXDR[0] extended-analog results.

k_adc_chcr_stride 

ADCHCRn occupies 16 bytes per slot.

k_adc_addr_stride 

ADDR[n] is 4 bytes per slot.

k_adc_str_stride 

ADSTR[n] is 4 bytes per slot.

k_adc_sgdcr_stride 

ADSGDCRn is 4 bytes per slot.

k_adc_exdr_stride 

ADEXDRn is 4 bytes per slot.

Definition at line 59 of file board_periph_adc.c.

◆ adc_midscale_t

enum adc_midscale_t : uint16_t

Resolution-appropriate mid-scale (half-full-scale) result codes.

A "mid-scale" analog input converts to half of the full-scale code, whose magnitude tracks the ADPRC data-format width. The model reports these so a 16-bit conversion looks 16-bit (0x8000) and a 12-bit one looks 12-bit (0x0800), instead of always the old fixed 12-bit half-scale.

Enumerator
k_adc_mid_16bit 

16-bit half-scale.

k_adc_mid_14bit 

14-bit half-scale.

k_adc_mid_12bit 

12-bit half-scale.

k_adc_mid_10bit 

10-bit half-scale.

Definition at line 127 of file board_periph_adc.c.

◆ adc_sample_t

enum adc_sample_t : uint16_t

Plausible conversion result reported on every scan.

Enumerator
k_adc_sample_code 

12-bit half-scale (~VREFH/2) mid-scale.

k_adc_temp_code 

12-bit temperature-sensor code (~26 degC).

Definition at line 172 of file board_periph_adc.c.

◆ adc_selfdiag_t

enum adc_selfdiag_t : uint32_t

ADSGDCRn.DIAGVAL self-diagnosis mode codes + ideal 16-bit results.

HUM Table 53.19 (p 3412): mode 1 (DIAGVAL 0x4) drives 0x0000, mode 2 (0x5) negative full-scale 0x8000, mode 3 (0x6) positive full-scale 0x7FFF. This model returns the IDEAL per mode: it represents a healthy SAR + reference (which is the only faithful behaviour when there is no analog core to fault), so ra8_adc_self_diagnose's +/-256-LSB band check passes. The fault path (a stuck SAR) cannot be injected here and is a silicon-only test.

Enumerator
k_adc_diagval_mode1 

DIAGVAL mode 1: zero.

k_adc_diagval_mode2 

DIAGVAL mode 2: negative full-scale.

k_adc_diagval_mode3 

DIAGVAL mode 3: positive full-scale.

k_adc_selfdiag_zero 

Mode-1 ideal 0x0000.

k_adc_selfdiag_negfs 

Mode-2 ideal 0x8000 (-32768).

k_adc_selfdiag_posfs 

Mode-3 ideal 0x7FFF (+32767).

Definition at line 162 of file board_periph_adc.c.

Function Documentation

◆ internal_adc_adprc()

RA8_INTERNAL uint32_t internal_adc_adprc ( uint32_t slot)
static

Read ADDOPCRC[slot].ADPRC[1:0] data-format code from the store.

Read addopcrc[slot].adprc[1:0] data-format code from the store; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]slotSlot input used by the operation.
Returns
The ADC adprc result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC adprc value.
Precondition
Arguments satisfy the ranges documented for ADC adprc.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 356 of file board_periph_adc.c.

References internal_adc_word(), k_adc_chcr_stride, k_adc_off_addopcrc0, k_adc_opcrc_adprc_m, k_adc_opcrc_adprc_s, RA8_INTERNAL, and s_adc_reg.

Referenced by internal_adc_convert_group().

◆ internal_adc_chcr()

RA8_INTERNAL uint32_t internal_adc_chcr ( uint32_t ch)
static

Read an ADCHCRn slot's raw config word from the backing store.

Read an adchcrn slot's raw config word from the backing store; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]chSelected channel identifier.
Returns
The ADC chcr result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC chcr value.
Precondition
Arguments satisfy the ranges documented for ADC chcr.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 235 of file board_periph_adc.c.

References internal_adc_word(), k_adc_chcr_stride, k_adc_off_adchcr0, RA8_INTERNAL, and s_adc_reg.

Referenced by internal_adc_convert_group().

◆ internal_adc_convert_group()

RA8_INTERNAL void internal_adc_convert_group ( uint32_t group)
static

Populate result registers for every channel enrolled in group.

Walks the 24 ADCHCRn slots; any slot whose SGSEL matches the started group is a virtual channel that converts. A normal (external-pin) channel reports to its own virtual-channel result register ADDR[slot] – the same index the driver reads back (driver convention virtual_ch == physical_ch) – filled with a resolution-scaled mid-scale sample taken from the slot's ADDOPCRCn.ADPRC data-format. A slot with no ADDR register (the top diagnostic slot) produces no ordinary result; an internal / extended-analog channel reports through ADEXDR instead.

Parameters
[in]groupPeripheral channel or scan-group identifier.
Precondition
Arguments satisfy the ranges documented for ADC convert group.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 407 of file board_periph_adc.c.

References board_console_push(), internal_adc_adprc(), internal_adc_chcr(), internal_adc_ext_value(), internal_adc_midscale_for_adprc(), internal_adc_set_ext_result(), internal_adc_set_result(), k_adc_chcr_cnvcs_m, k_adc_chcr_cnvcs_s, k_adc_chcr_sgsel, k_adc_console_line_cap, k_adc_ext_chan_base, k_adc_max_channels, k_adc_result_regs, k_board_console_ch_adc, and RA8_INTERNAL.

Referenced by internal_adc_write().

◆ internal_adc_diagval()

RA8_INTERNAL uint32_t internal_adc_diagval ( uint32_t group)
static

Read ADSGDCR[group].DIAGVAL[2:0] (self-diagnosis mode) from the store.

Read adsgdcr[group].diagval[2:0] (self-diagnosis mode) from the store; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]groupPeripheral channel or scan-group identifier.
Returns
The ADC diagval result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC diagval value.
Precondition
Arguments satisfy the ranges documented for ADC diagval.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 292 of file board_periph_adc.c.

References internal_adc_word(), k_adc_off_adsgdcr0, k_adc_sgdcr_diagval, k_adc_sgdcr_stride, RA8_INTERNAL, and s_adc_reg.

Referenced by internal_adc_ext_value().

◆ internal_adc_ext_value()

RA8_INTERNAL uint16_t internal_adc_ext_value ( uint32_t phys,
uint32_t group )
static

Synthetic ADEXDR code for an extended-analog channel (phys >= base).

Synthetic adexdr code for an extended-analog channel (phys >= base); this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]physPhys input used by the operation.
[in]groupPeripheral channel or scan-group identifier.
Returns
The ADC ext value result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC ext value value.
Precondition
Arguments satisfy the ranges documented for ADC ext value.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 334 of file board_periph_adc.c.

References internal_adc_diagval(), internal_adc_selfdiag_ideal(), k_adc_chan_selfdiag, k_adc_chan_temp, k_adc_sample_code, k_adc_temp_code, and RA8_INTERNAL.

Referenced by internal_adc_convert_group().

◆ internal_adc_midscale_for_adprc()

RA8_INTERNAL uint16_t internal_adc_midscale_for_adprc ( uint32_t adprc)
static

Resolution-appropriate mid-scale result code for an ADPRC format.

Resolution-appropriate mid-scale result code for an adprc format; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]adprcAdprc input used by the operation.
Returns
The ADC midscale for adprc result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC midscale for adprc value.
Precondition
Arguments satisfy the ranges documented for ADC midscale for adprc.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 375 of file board_periph_adc.c.

References k_adc_adprc_10bit, k_adc_adprc_14bit, k_adc_adprc_16bit, k_adc_mid_10bit, k_adc_mid_12bit, k_adc_mid_14bit, k_adc_mid_16bit, and RA8_INTERNAL.

Referenced by internal_adc_convert_group().

◆ internal_adc_read()

RA8_INTERNAL uint64_t internal_adc_read ( uc_engine * uc,
uint64_t addr,
unsigned size )
static

MMIO read: ADSR holds ADACT0 idle; everything else reads back.

MMIO read: adsr holds adact0 idle; everything else reads back; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
Returns
The ADC read result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC read value.
Precondition
Arguments satisfy the ranges documented for ADC read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 461 of file board_periph_adc.c.

References internal_adc_word(), k_adc_adact0_mask, k_adc_base, k_adc_off_adsr, k_adc_span, RA8_INTERNAL, and s_adc_reg.

◆ internal_adc_report()

RA8_INTERNAL void internal_adc_report ( void )
static

Print the ADC_B scan count + last reported result code.

Print the adc_b scan count + last reported result code; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for ADC report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 540 of file board_periph_adc.c.

References priv_emu_io_errf(), RA8_INTERNAL, s_adc_last_code, and s_adc_scans.

◆ internal_adc_reset()

RA8_INTERNAL void internal_adc_reset ( void )
static

Clear all ADC_B register state and observability counters.

Clear all adc_b register state and observability counters; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for ADC reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 523 of file board_periph_adc.c.

References k_adc_reg_words, RA8_INTERNAL, s_adc_last_code, s_adc_reg, and s_adc_scans.

◆ internal_adc_selfdiag_ideal()

RA8_INTERNAL uint16_t internal_adc_selfdiag_ideal ( uint32_t diagval)
static

Ideal 16-bit self-diagnosis code for the armed DIAGVAL mode.

Ideal 16-bit self-diagnosis code for the armed diagval mode; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]diagvalDiagval input used by the operation.
Returns
The ADC selfdiag ideal result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC selfdiag ideal value.
Precondition
Arguments satisfy the ranges documented for ADC selfdiag ideal.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 310 of file board_periph_adc.c.

References k_adc_diagval_mode2, k_adc_diagval_mode3, k_adc_selfdiag_negfs, k_adc_selfdiag_posfs, k_adc_selfdiag_zero, and RA8_INTERNAL.

Referenced by internal_adc_ext_value().

◆ internal_adc_set_ext_result()

RA8_INTERNAL void internal_adc_set_ext_result ( uint32_t idx,
uint16_t code )
static

Store an extended-analog result into ADEXDR[idx] (DATA[15:0], ERR clear).

Store an extended-analog result into adexdr[idx] (data[15:0], err clear); this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]idxBounded index of the selected entry.
[in]codeInstruction, status, or command code decoded by the operation.
Precondition
Arguments satisfy the ranges documented for ADC set ext result.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 271 of file board_periph_adc.c.

References internal_adc_word(), k_adc_addr_data, k_adc_exdr_stride, k_adc_ext_regs, k_adc_off_adexdr0, RA8_INTERNAL, s_adc_last_code, and s_adc_reg.

Referenced by internal_adc_convert_group().

◆ internal_adc_set_result()

RA8_INTERNAL void internal_adc_set_result ( uint32_t ch,
uint16_t code )
static

Store a freshly converted code into ADDR[ch] (DATA[15:0], ERR clear).

Store a freshly converted code into addr[ch] (data[15:0], err clear); this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]chSelected channel identifier.
[in]codeInstruction, status, or command code decoded by the operation.
Precondition
Arguments satisfy the ranges documented for ADC set result.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 251 of file board_periph_adc.c.

References internal_adc_word(), k_adc_addr_data, k_adc_addr_stride, k_adc_off_addr0, k_adc_result_regs, RA8_INTERNAL, s_adc_last_code, and s_adc_reg.

Referenced by internal_adc_convert_group().

◆ internal_adc_word()

RA8_INTERNAL uint32_t internal_adc_word ( uint64_t off)
static

Word index into the backing store for an in-window offset.

Word index into the backing store for an in-window offset; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in]offRegister or byte offset addressed by the operation.
Returns
The ADC word result produced by the board periph ADC model.
Return values
valueThe operation-specific ADC word value.
Precondition
Arguments satisfy the ranges documented for ADC word.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 219 of file board_periph_adc.c.

References RA8_INTERNAL.

Referenced by internal_adc_adprc(), internal_adc_chcr(), internal_adc_diagval(), internal_adc_read(), internal_adc_set_ext_result(), internal_adc_set_result(), and internal_adc_write().

◆ internal_adc_write()

RA8_INTERNAL void internal_adc_write ( uc_engine * uc,
uint64_t addr,
unsigned size,
uint64_t value )
static

MMIO write: ADSTR kicks a scan; other registers latch the value.

MMIO write: adstr kicks a scan; other registers latch the value; this step is contained within the board periph ADC model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for ADC write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ADC model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 490 of file board_periph_adc.c.

References board_periph_icu_raise_event(), board_periph_trace(), internal_adc_convert_group(), internal_adc_word(), k_adc_adst_mask, k_adc_base, k_adc_off_adstr0, k_adc_scan_groups, k_adc_span, k_adc_str_stride, k_event_adc0_scan_end, priv_emu_io_errf(), s_adc_last_code, s_adc_reg, and s_adc_scans.

◆ internal_board_periph_adc_register()

RA8_INTERNAL void internal_board_periph_adc_register ( void )
static

Self-register the ADC_B block before main runs (decentralized).

Definition at line 565 of file board_periph_adc.c.

References board_periph_register_block(), RA8_INTERNAL, and s_k_adc_block.

Variable Documentation

◆ s_adc_last_code

uint16_t s_adc_last_code
static

Last result code written to an ADDR.

Definition at line 206 of file board_periph_adc.c.

Referenced by internal_adc_report(), internal_adc_reset(), internal_adc_set_ext_result(), internal_adc_set_result(), and internal_adc_write().

◆ s_adc_reg

uint32_t s_adc_reg[k_adc_reg_words]
static

Backing store for the whole ADC_B window (word-addressed).

Most ADC_B registers are plain read-back control words, so a flat word array answers them; the model only adds behaviour for ADSTR (scan start), ADSR (busy flag held idle) and ADDR (populated result). A scan-result counter feeds the end-of-run report line.

Definition at line 204 of file board_periph_adc.c.

Referenced by internal_adc_adprc(), internal_adc_chcr(), internal_adc_diagval(), internal_adc_read(), internal_adc_reset(), internal_adc_set_ext_result(), internal_adc_set_result(), and internal_adc_write().

◆ s_adc_scans

uint32_t s_adc_scans
static

Conversions kicked via ADSTR.

Definition at line 205 of file board_periph_adc.c.

Referenced by internal_adc_report(), internal_adc_reset(), and internal_adc_write().

◆ s_k_adc_block

const board_periph_block_t s_k_adc_block
static
Initial value:
= {
.base = (uint64_t)k_adc_base,
.span = (uint64_t)k_adc_span,
.order = (uint32_t)k_block_order_i2c,
.tick = nullptr,
.name = "ADC_B",
}
@ k_adc_span
Full FSP R_ADC_B0_Type window size.
@ k_adc_base
ADC_B register-window base.
static RA8_INTERNAL void internal_adc_reset(void)
Clear all ADC_B register state and observability counters.
static RA8_INTERNAL uint64_t internal_adc_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read: ADSR holds ADACT0 idle; everything else reads back.
static RA8_INTERNAL void internal_adc_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write: ADSTR kicks a scan; other registers latch the value.
static RA8_INTERNAL void internal_adc_report(void)
Print the ADC_B scan count + last reported result code.
@ k_block_order_i2c
I3C/I2C + GT911 (no tick today).
-proof

This block's descriptor (static lifetime; the core keeps the pointer).

Definition at line 552 of file board_periph_adc.c.

Referenced by internal_board_periph_adc_register().