|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
PDM-IF (digital MEMS microphone) peripheral-block model for ra8_emulator. More...
#include <stdint.h>#include <stdio.h>#include "board_console.h"#include "board_periph_block.h"#include "emu_host_io_internal.h"Go to the source code of this file.
Data Structures | |
| struct | pdm_channel_t |
| One modelled PDM channel: run/enable gates + synthetic-tone state. More... | |
Enumerations | |
| enum | pdm_map_t : uint64_t { k_pdm_base = 0x40256000UL , k_pdm_span = 0x400UL , k_pdm_words = 0x400UL / 4UL , k_pdm_ch_count = 3UL , k_pdm_ch0_off = 0x100UL , k_pdm_ch_stride = 0x100UL , k_pdm_off_cstrtr = 0x00UL , k_pdm_off_cstptr = 0x04UL , k_pdm_off_csr = 0x10UL , k_pdm_ch_pddrcr = 0xE0UL , k_pdm_ch_pddrr = 0xE8UL , k_pdm_ch_pddsr = 0xECUL } |
| PDM-IF register-window geometry (ra8_pdm_regs.h). More... | |
| enum | pdm_field_t : uint32_t { k_pdm_pddrcr_datre = 0x1U , k_pdm_pddsr_num = 0x000000FFU , k_pdm_pddrr_mask20 = 0x000FFFFFU , k_pdm_fifo_depth = 32U } |
| PDM-IF register field masks / bits (ra8_pdm_regs.h). More... | |
| enum | pdm_tone_t : uint32_t { k_pdm_tone_period = 64U , k_pdm_tone_qmask = 63U , k_pdm_tone_half = 32U } |
| Synthetic-tone shape constants (deterministic, integer-only). More... | |
| enum | pdm_amp_t : int32_t { k_pdm_tone_amp = 20000 , k_pdm_tone_step = 1250 } |
| Synthetic-tone amplitude / slope (20-bit signed, well below +-524288). More... | |
| enum | pdm_dither_t : uint32_t { k_pdm_lcg_mul = 1664525U , k_pdm_lcg_add = 1013904223U , k_pdm_lcg_shift = 16U , k_pdm_dither_mask = 0x3FFU , k_pdm_dither_half = 512U } |
| Per-channel pseudo-random dither (window-to-window variety). More... | |
| enum | pdm_console_t : uint32_t { k_pdm_console_line_cap = 48U , k_pdm_console_every = 512U } |
| Console anti-flood cadence for the PDM (I2S/audio) tab. More... | |
Functions | |
| static RA8_INTERNAL bool | internal_pdm_live (uint32_t ch) |
True when channel ch is both started and read-enabled. | |
| static RA8_INTERNAL uint32_t | internal_pdm_next_sample (uint32_t ch) |
| Next 20-bit two's-complement PCM sample for a live channel. | |
| static RA8_INTERNAL void | internal_pdm_console_maybe (uint32_t ch) |
| Push an anti-flood "PDMn samples=.." line to the I2S/audio tab. | |
| static RA8_INTERNAL bool | internal_pdm_channel_at (uint64_t off, uint32_t *ch, uint64_t *ch_off) |
| Compute the channel index + in-bank offset for an in-window address. | |
| static RA8_INTERNAL uint32_t | internal_pdm_read_csr (void) |
| PDCSR: one run bit per currently-started channel. | |
| static RA8_INTERNAL uint64_t | internal_pdm_read (uc_engine *uc, uint64_t addr, unsigned size) |
| MMIO read inside the PDM window. | |
| static RA8_INTERNAL void | internal_pdm_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value) |
| MMIO write inside the PDM window: latch, then update run/enable gates. | |
| static RA8_INTERNAL void | internal_pdm_reset (void) |
| Clear all PDM channel + shadow state to power-on. | |
| static RA8_INTERNAL void | internal_pdm_report (void) |
| Print one line per PDM channel the firmware captured from. | |
| static RA8_INTERNAL void | internal_board_periph_pdm_register (void) |
| Self-register the PDM-IF block before main runs (decentralized). | |
Variables | |
| static pdm_channel_t | s_pdm [k_pdm_ch_count] |
| static uint32_t | s_pdm_reg [k_pdm_words] |
| Reflect-on-read shadow. | |
| static const board_periph_block_t | s_k_pdm_block |
| This block's descriptor (static lifetime; the core keeps the pointer). | |
PDM-IF (digital MEMS microphone) peripheral-block model for ra8_emulator.
Models the single RA8D2 PDM-IF block at 0x4025_6000 (ra8_pdm_regs.h / ra8_pdm.c, the real HUM Ch 49 PDM-IF). The firmware read path (ra8_pdm_read) polls a channel's data-status register PDDSR.NUM for the FIFO fill count, then drains that many 20-bit signed PCM samples out of the data-read register PDDRR. The stop path (ra8_pdm_stop) polls the common channel-status register PDCSR until the channel's run bit clears.
This block turns that register set into a synthetic-audio source. A channel only produces samples once it has been BOTH started (a PDCSTRTR bit for it) AND had its data read enabled (PDDRCR.DATRE) – the honest-model rule from issue #218: an unconfigured / unstarted read yields zero samples (PDDSR.NUM reads 0, PDDRR reads 0), never a faked pass. Once live, PDDSR reports a full FIFO and each PDDRR read yields the next sample of a deterministic low-amplitude triangle tone plus a small pseudo-random dither, so the tone is a genuine non-degenerate signal (non-trivial RMS / peak / span) and drifts window-to-window – exactly what pdm_mic_demo's plausibility check needs to report active=Y on a real signal rather than on the sparse fallback's degenerate 0/-1 toggle.
The value path is synthetic (ra8_emulator has no analog microphone); this is a run-headless enabler, not a claim about a physical mic. Self-registers its descriptor with the board_periph core from a file-scope constructor – see board_periph_block.h.
Definition in file board_periph_pdm.c.
| enum pdm_amp_t : int32_t |
Synthetic-tone amplitude / slope (20-bit signed, well below +-524288).
| Enumerator | |
|---|---|
| k_pdm_tone_amp | Triangle peak amplitude (+-). |
| k_pdm_tone_step | Per-sample slope = 2*amp / (period/2). |
Definition at line 74 of file board_periph_pdm.c.
| enum pdm_console_t : uint32_t |
Console anti-flood cadence for the PDM (I2S/audio) tab.
| Enumerator | |
|---|---|
| k_pdm_console_line_cap | Max chars in a "PDM.. samples=.." line. |
| k_pdm_console_every | Push one line per N samples per channel. |
Definition at line 89 of file board_periph_pdm.c.
| enum pdm_dither_t : uint32_t |
Per-channel pseudo-random dither (window-to-window variety).
Definition at line 80 of file board_periph_pdm.c.
| enum pdm_field_t : uint32_t |
PDM-IF register field masks / bits (ra8_pdm_regs.h).
Definition at line 59 of file board_periph_pdm.c.
| enum pdm_map_t : uint64_t |
PDM-IF register-window geometry (ra8_pdm_regs.h).
Definition at line 43 of file board_periph_pdm.c.
| enum pdm_tone_t : uint32_t |
Synthetic-tone shape constants (deterministic, integer-only).
| Enumerator | |
|---|---|
| k_pdm_tone_period | Samples per triangle cycle (power of two). |
| k_pdm_tone_qmask | period-1: phase wrap mask. |
| k_pdm_tone_half | period/2: rising-then-falling split point. |
Definition at line 67 of file board_periph_pdm.c.
|
static |
Self-register the PDM-IF block before main runs (decentralized).
Definition at line 366 of file board_periph_pdm.c.
References board_periph_register_block(), RA8_INTERNAL, and s_k_pdm_block.
|
static |
Compute the channel index + in-bank offset for an in-window address.
Compute the channel index + in-bank offset for an in-window address; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
| [in] | off | Register or byte offset addressed by the operation. |
| [in,out] | ch | Selected channel identifier. |
| [in,out] | ch_off | Ch off state or storage updated in place by the operation. |
| true | The PDM channel at condition holds or completed successfully; false otherwise. |
Definition at line 190 of file board_periph_pdm.c.
References k_pdm_ch0_off, k_pdm_ch_count, k_pdm_ch_stride, and RA8_INTERNAL.
Referenced by internal_pdm_read(), and internal_pdm_write().
|
static |
Push an anti-flood "PDMn samples=.." line to the I2S/audio tab.
Push an anti-flood "pdmn samples=.." line to the i2s/audio tab; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
| [in] | ch | Selected channel identifier. |
Definition at line 166 of file board_periph_pdm.c.
References board_console_push(), k_board_console_ch_i2s, k_pdm_console_every, k_pdm_console_line_cap, RA8_INTERNAL, and s_pdm.
Referenced by internal_pdm_read().
|
static |
True when channel ch is both started and read-enabled.
True when channel ch is both started and read-enabled; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
| [in] | ch | Selected channel identifier. |
| true | The PDM live condition holds or completed successfully; false otherwise. |
Definition at line 117 of file board_periph_pdm.c.
References k_pdm_ch_count, RA8_INTERNAL, and s_pdm.
Referenced by internal_pdm_read().
|
static |
Next 20-bit two's-complement PCM sample for a live channel.
Next 20-bit two's-complement pcm sample for a live channel; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
| [in] | ch | Selected channel identifier. |
| value | The operation-specific PDM next sample value. |
Definition at line 136 of file board_periph_pdm.c.
References k_pdm_dither_half, k_pdm_dither_mask, k_pdm_lcg_add, k_pdm_lcg_mul, k_pdm_lcg_shift, k_pdm_pddrr_mask20, k_pdm_tone_amp, k_pdm_tone_half, k_pdm_tone_qmask, k_pdm_tone_step, pdm_channel_t::lcg, pdm_channel_t::phase, RA8_INTERNAL, s_pdm, and pdm_channel_t::samples.
Referenced by internal_pdm_read().
|
static |
MMIO read inside the PDM window.
MMIO read inside the pdm window; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| value | The operation-specific PDM read value. |
Definition at line 235 of file board_periph_pdm.c.
References internal_pdm_channel_at(), internal_pdm_console_maybe(), internal_pdm_live(), internal_pdm_next_sample(), internal_pdm_read_csr(), k_pdm_base, k_pdm_ch_pddrr, k_pdm_ch_pddsr, k_pdm_fifo_depth, k_pdm_off_csr, k_pdm_pddsr_num, k_pdm_span, RA8_INTERNAL, and s_pdm_reg.
|
static |
PDCSR: one run bit per currently-started channel.
Pdcsr: one run bit per currently-started channel; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
| value | The operation-specific PDM read csr value. |
Definition at line 211 of file board_periph_pdm.c.
References k_pdm_ch_count, RA8_INTERNAL, and s_pdm.
Referenced by internal_pdm_read().
|
static |
Print one line per PDM channel the firmware captured from.
Print one line per pdm channel the firmware captured from; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
Definition at line 338 of file board_periph_pdm.c.
References k_pdm_ch_count, priv_emu_io_errf(), RA8_INTERNAL, and s_pdm.
|
static |
Clear all PDM channel + shadow state to power-on.
Clear all pdm channel + shadow state to power-on; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
Definition at line 320 of file board_periph_pdm.c.
References k_pdm_ch_count, k_pdm_words, RA8_INTERNAL, s_pdm, and s_pdm_reg.
|
static |
MMIO write inside the PDM window: latch, then update run/enable gates.
MMIO write inside the pdm window: latch, then update run/enable gates; this step is contained within the board periph PDM model and uses bounded caller or module-owned storage.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| [in] | value | Register or payload value involved in the operation. |
Definition at line 279 of file board_periph_pdm.c.
References internal_pdm_channel_at(), k_pdm_base, k_pdm_ch_count, k_pdm_ch_pddrcr, k_pdm_off_cstptr, k_pdm_off_cstrtr, k_pdm_pddrcr_datre, k_pdm_span, s_pdm, and s_pdm_reg.
|
static |
This block's descriptor (static lifetime; the core keeps the pointer).
Definition at line 353 of file board_periph_pdm.c.
Referenced by internal_board_periph_pdm_register().
|
static |
Definition at line 103 of file board_periph_pdm.c.
Referenced by internal_pdm_console_maybe(), internal_pdm_live(), internal_pdm_next_sample(), internal_pdm_read_csr(), internal_pdm_report(), internal_pdm_reset(), and internal_pdm_write().
|
static |
Reflect-on-read shadow.
Definition at line 104 of file board_periph_pdm.c.
Referenced by internal_pdm_read(), internal_pdm_reset(), and internal_pdm_write().