57typedef enum : uint32_t {
68typedef enum : int32_t {
74typedef enum : uint32_t {
79typedef enum : uint32_t {
135typedef enum : uint32_t {
173 __asm__
volatile(
"wfi");
200 bool neg = value < 0;
207 tmp[n++] = (uint8_t)
'0';
215 tmp[n++] = (uint8_t)
'-';
217 for (uint32_t i = 0U; i < n; ++i) {
218 out[i] = tmp[n - 1U - i];
260 return (uint32_t)(root >> 1);
396 .pdm = board_cfg.
pdm,
448 for (uint32_t i = 0U; i < n; ++i) {
449 const int32_t s = buf[i];
451 lo = (s < lo) ? s : lo;
452 hi = (s > hi) ? s : hi;
454 const int32_t mean = (int32_t)(sum / (int64_t)n);
458 for (uint32_t i = 0U; i < n; ++i) {
459 const int32_t d = buf[i] - mean;
460 const int32_t mag = (d < 0) ? -d : d;
461 peak = (mag > peak) ? mag : peak;
462 sumsq += (uint64_t)((int64_t)d * (int64_t)d);
495 const int32_t span = m->
max - m->
min;
524 static const uint8_t k_l_rms[] =
"pdm: rms=";
525 static const uint8_t k_l_peak[] =
" peak=";
526 static const uint8_t k_l_mean[] =
" mean=";
527 static const uint8_t k_l_span[] =
" span=";
528 static const uint8_t k_l_vary[] =
" vary=";
529 static const uint8_t k_l_act[] =
" active=";
530 static const uint8_t k_l_y[] =
"Y\r\n";
531 static const uint8_t k_l_n[] =
"N\r\n";
538 pdm_demo_tx(k_l_act, (uint32_t)(
sizeof(k_l_act) - 1U));
540 pdm_demo_tx(k_l_y, (uint32_t)(
sizeof(k_l_y) - 1U));
542 pdm_demo_tx(k_l_n, (uint32_t)(
sizeof(k_l_n) - 1U));
618 int32_t rms_lo = INT32_MAX;
620 uint32_t active_windows = 0U;
622 const int32_t vary = (rms_hi > rms_lo) ? (rms_hi - rms_lo) : 0;
626 rms_lo = (m.
rms < rms_lo) ? m.
rms : rms_lo;
627 rms_hi = (m.
rms > rms_hi) ? m.
rms : rms_hi;
630 if (active_windows == 0U) {
636 __asm__
volatile(
"wfi");
void main(void)
Secure fallback main entry point.
pdm_demo_magic_t
Result magic marker ('PDM1').
@ k_pdm_demo_magic
Pdm demo magic.
static uint32_t pdm_demo_isqrt(uint64_t value)
Integer square root of a 64-bit value (floor).
pdm_demo_threshold_t
Plausibility thresholds (20-bit signed full scale = +-524288).
@ k_pdm_demo_min_span
Min peak-to-peak to be non-degenerate.
@ k_pdm_demo_rms_floor
Min AC RMS to count as live audio.
static ra8_audio_source_pdm_state_t s_pdm_demo_source_state
Caller-owned PDM backend state.
static const uint8_t k_pdm_demo_banner_inactive[]
static void pdm_demo_io_or_halt(void)
Route P812/P502 to the PDM function and open the console.
pdm_isqrt_const_t
Integer-sqrt bit-window constants (64-bit radicand).
@ k_pdm_isqrt_top2
Shift to the top 2 bits of a 64-bit word.
@ k_pdm_isqrt_steps
32 two-bit steps span a 64-bit radicand.
static const uint8_t k_pdm_demo_banner_fail[]
static ra8_audio_source_t s_pdm_demo_source
Generic caller-owned audio source handle.
volatile pdm_mic_result_t g_pdm_mic_result
J-Link-probable capture result (read at &g_pdm_mic_result).
static void pdm_demo_clocks_or_halt(void)
Bring CGC + MSTP + SysTick up; halts on any failure.
static void pdm_demo_analyze(const int32_t *buf, uint32_t n, pdm_metrics_t *m)
Compute min/max/mean/peak/RMS for a captured window.
static void pdm_demo_tx(const uint8_t *bytes, uint32_t len)
Emit a byte run over the SCI8 console.
static void pdm_demo_pdm_or_halt(void)
Bind the on-board MIC1 through the reusable PDM audio source.
static const uint8_t k_pdm_demo_banner_pass[]
pdm_demo_const_t
App-wide tunables.
@ k_pdm_demo_settle_ms
Mic wake-up + filter settle delay.
@ k_pdm_demo_window
PCM samples per analysis window.
@ k_pdm_demo_report_win
Windows swept for the verdict banner.
@ k_pdm_demo_discard
Transient samples discarded up front.
@ k_pdm_demo_decimal
Radix for integer-to-ASCII.
@ k_pdm_demo_poll_max
Bounded capture poll retries (dead-mic).
@ k_pdm_demo_baud
SCI8 console baud.
static void pdm_demo_publish(const pdm_metrics_t *m, int32_t vary, bool active)
Print a per-window detail line and latch g_pdm_mic_result.
static bool pdm_demo_run_window(int32_t vary, pdm_metrics_t *out_m)
Capture one window, analyse it and publish it.
static bool pdm_demo_is_active(const pdm_metrics_t *m)
Decide whether a window carries plausible live audio.
static void pdm_demo_panic_halt(void)
Park forever after a fatal error.
static const uint8_t k_pdm_demo_banner_nodat[]
pdm_demo_str_cap_t
Sizing for the decimal serialiser buffer ("-2147483648" + NUL).
@ k_pdm_demo_int_str_cap
Pdm demo int str cap.
static const uint8_t k_pdm_demo_banner_init[]
static uint32_t pdm_demo_i32_to_dec(int32_t value, uint8_t *out)
Convert a signed 32-bit int into a decimal ASCII string.
static void pdm_demo_emit_kv(const uint8_t *label, uint32_t label_len, int32_t value)
Emit "<label><value>" with a decimal integer.
static int32_t s_pdm_demo_buf[k_pdm_demo_window]
Static capture buffer (kept off the stack).
Transport-neutral, caller-owned audio capture facade.
ra8_err_t ra8_audio_source_capture(ra8_audio_source_t *source, const ra8_audio_buffer_t *buffer, ra8_audio_frame_t *out_frame)
Capture one fixed-size PCM frame into caller-owned storage.
RA8 PDM-IF backend for the transport-neutral audio facade.
ra8_err_t ra8_audio_source_pdm_init(ra8_audio_source_t *source, ra8_audio_source_pdm_state_t *state, const ra8_audio_source_pdm_cfg_t *cfg)
Configure, start, settle, and bind one PDM audio source.
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_pdm_mic_get_config(ra8_board_pdm_mic_t microphone, ra8_board_pdm_mic_config_t *out_config)
Return the validated SPH0690 filter policy for one board microphone.
@ k_ra8_board_pdm_mic1
Rising-edge MIC1 (SELECT tied low).
ra8_err_t ra8_board_pdm_mic_route(void)
Route P812/P502 to PDMCLK2/PDMDAT2.
ra8_err_t ra8_board_clocks_init(ra8_board_clock_rates_t *out_rates)
Initialize the standard EK-RA8D2 clock tree and return its rates.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Statistics for one captured PCM window.
int32_t min
Minimum sample.
int32_t peak
Peak |sample - mean| (AC peak).
int32_t mean
DC mean (near 0 after the HPF).
uint32_t n
Samples analysed.
int32_t max
Maximum sample.
int32_t rms
AC RMS about the mean.
Debugger-probable capture result.
volatile uint32_t magic
0x50444D31 ('PDM1') once a window is done.
volatile uint32_t timestamp_ms
Latest frame capture-start timestamp.
volatile int32_t peak
Latest window AC peak.
volatile uint32_t active
1 = plausible live audio, 0 = degenerate.
volatile int32_t mean
Latest window DC mean.
volatile uint32_t samples
Samples in the latest window.
volatile uint32_t windows
Windows captured so far.
volatile int32_t vary
RMS spread across the report sweep.
volatile int32_t rms
Latest window AC RMS.
volatile int32_t span
Latest window max-min.
Caller-owned writable byte buffer.
Immutable view of one interleaved PCM frame.
uint32_t sample_count
Sample frames per channel.
uint32_t timestamp_ms
Capture-start monotonic milliseconds.
Complete PDM source initialization and capture policy.
Caller-owned mutable state for one PDM source backend.
Caller-owned handle binding an audio source backend and its state.
Clock rates published by the standard EK-RA8D2 bring-up.
uint32_t cpuclk0_hz
Main Cortex-M85 clock rate in hertz.
Board-owned PDM mechanism configuration for one microphone.
uint8_t channel
PDM-IF channel selector.
uint32_t sample_rate_hz
Decimated PCM sample rate.
ra8_pdm_channel_cfg_t pdm
SPH0690 filter coefficients.
uint8_t valid_bits
Significant PCM bits.