33static const char*
s_tag =
"PDM";
53typedef enum : uint32_t {
187 const uint8_t channel = (uint8_t)(uintptr_t)ctx;
202 for (uint32_t i = 0U; i < count; ++i) {
284 const uint32_t n = (avail < max) ? avail : max;
285 for (uint32_t i = 0U; i < n; ++i) {
304 (
void*)(uintptr_t)ch,
349 if ((
ra8_pdm()->PDCSR & running) == 0U) {
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_RANGE_TAG(value, min, max, errcode, tag)
Tagged range check (adds a component tag to the log line).
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
ra8_elc_event_t
Partial list of ELC events (populate as drivers need them).
@ k_ra8_elc_event_pdm_dat0
PDM channel 0 data reception.
@ k_ra8_elc_event_pdm_dat1
PDM channel 1 data reception.
@ k_ra8_elc_event_pdm_dat2
PDM channel 2 data reception.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_exists
Item already exists – cannot create again.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ 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.
NVIC + ICU IELSR allocator.
ra8_err_t ra8_isr_register(ra8_elc_event_t event, ra8_isr_handler_t handler, void *ctx, uint8_t priority, uint16_t *out_slot)
Allocate an IELSR slot for an ELC event + handler.
ra8_err_t ra8_isr_unregister(ra8_elc_event_t event)
Release a previously-allocated IELSR slot.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
#define ra8_log_error(tag, message)
RA8 log error.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Module Stop Control (MSTP) register layout for the Renesas RA8D2.
@ k_ra8_mstp_pdmif
MSTPC24 PDM-IF.
ra8_err_t ra8_pdm_stop(uint8_t ch)
Stop a channel and wait for its filter to halt.
ra8_err_t ra8_pdm_init(void)
Release the PDM-IF module stop and reset its common bank.
ra8_err_t ra8_pdm_read_enable(uint8_t ch)
Clear status, enable data read and prime the receive FIFO.
static void internal_pdm_data_isr(void *ctx)
Drain one PDM FIFO threshold and dispatch its signed samples.
static pdm_stream_state_t s_streams[k_ra8_pdm_ch_count]
ra8_err_t ra8_pdm_configure(uint8_t ch, const ra8_pdm_channel_cfg_t *cfg)
Program a channel's mode, decimation and filter coefficients.
static const ra8_elc_event_t s_pdm_data_events[k_ra8_pdm_ch_count]
ra8_err_t ra8_pdm_stream_enable(uint8_t ch, ra8_pdm_data_callback_t callback, void *ctx, uint8_t priority)
Enable interrupt-driven FIFO delivery for one running channel.
static void internal_pdm_write_mode(volatile r_pdm_ch_regs_t *reg, const ra8_pdm_channel_cfg_t *cfg)
Write a channel's PDMDSR + PDSFCR mode/decimation words.
static int32_t internal_pdm_sign_extend20(uint32_t raw)
Sign-extend one 20-bit PDDRR sample to a full int32_t.
ra8_err_t ra8_pdm_stream_disable(uint8_t ch)
Disable interrupt-driven delivery for one channel.
ra8_err_t ra8_pdm_start(uint8_t ch)
Activate a configured channel's filter (start trigger).
ra8_err_t ra8_pdm_deinit(void)
Put the PDM-IF block back into module stop.
ra8_err_t ra8_pdm_read(uint8_t ch, int32_t *out, uint32_t max, uint32_t *out_count)
Drain up to max PCM samples from a channel's FIFO.
static void internal_pdm_write_coeffs(volatile r_pdm_ch_regs_t *reg, const ra8_pdm_channel_cfg_t *cfg)
Write a channel's high-pass, compensation and low-pass coefficients.
pdm_impl_const_t
Implementation-local bounds (HUM Ch 49 "Normal Processing Flow").
@ k_pdm_prime_discards
FIFO depth (32) minus 2 priming reads.
@ k_pdm_field_3bit
3-bit field mask (SFMD).
@ k_pdm_stop_poll_max
Bounded stop-poll retry budget.
Pulse Density Modulation Interface (PDM-IF) capture driver.
void(* ra8_pdm_data_callback_t)(void *ctx, const int32_t *samples, uint32_t count)
PDM FIFO data callback invoked from ICU interrupt context.
@ k_ra8_pdm_hpf_h_count
High-pass filter h(0..1) coefficients.
@ k_ra8_pdm_comp_h_count
Compensation filter h(0..10) coefficients.
@ k_ra8_pdm_lpf_h1_count
Low-pass (half-band) h1(0..19) coefficients.
@ k_ra8_pdm_ch_count
Number of channels (bound).
Pulse Density Modulation Interface (PDM-IF) register layout.
static volatile r_pdm_regs_t * ra8_pdm(void)
Get a pointer to the PDM-IF register block.
@ k_ra8_pdm_pdscr_clr_all
PDSCR clear-all write pattern.
@ k_ra8_pdm_pdstptr_stp
PDSTPTR[0] stop trigger.
@ k_ra8_pdm_pddrcr_datre
PDDRCR[0] data read enable.
@ k_ra8_pdm_pdsr_state
PDSR[0] channel running.
@ k_ra8_pdm_pdstrtr_strt
PDSTRTR[0] start trigger.
@ k_ra8_pdm_pdicr_idre
PDICR[2] data IRQ enable.
@ k_ra8_pdm_pdmdsr_hfis_pos
[9:8] High-pass input shift.
@ k_ra8_pdm_pdmdsr_dbis_pos
[31:28] Data buffer input shift.
@ k_ra8_pdm_pdmdsr_lfis_pos
[17:16] Low-pass input shift.
@ k_ra8_pdm_pdmdsr_sfmd_pos
[6:4] Sinc filter mode shift.
@ k_ra8_pdm_pdmdsr_inpsel
[0] Input data edge select.
@ k_ra8_pdm_pdmdsr_cfis_pos
[13:12] Compensation input shift.
@ k_ra8_pdm_pddrr_dat_mask
PDDRR[19:0] 20-bit PCM.
@ k_ra8_pdm_pddrr_sign_ext
High bits set on negatives.
@ k_ra8_pdm_pddrr_sign_bit
PDDRR[19] sign bit.
@ k_ra8_pdm_pddsr_num_mask
PDDSR[7:0] FIFO fill count.
static volatile r_pdm_ch_regs_t * ra8_pdm_ch(uint8_t ch)
Get a pointer to a PDM-IF channel register bank.
@ k_ra8_pdm_fifo_depth
PDDRR FIFO depth (samples).
@ k_ra8_pdm_pdsfcr_ckdiv_pos
[3:0] PDM_CLKn dividend ratio.
@ k_ra8_pdm_pdsfcr_sincrng_pos
[28:24] Sinc output valid range.
@ k_ra8_pdm_pdsfcr_sincdec_pos
[23:16] Sinc decimation ratio.
Per-channel interrupt callback binding.
void * ctx
Caller context.
ra8_pdm_data_callback_t callback
Caller callback.
Per-channel PDM-IF register bank (256 bytes, HUM Ch 49.2).
volatile uint32_t PDICR
+0x0C Interrupt Control.
volatile uint32_t PDDSR
+0xEC Data Status (FIFO fill count).
volatile uint32_t PDLFCH1R[k_ra8_pdm_lfch1_count]
+0x68 Low-pass filter coeff h1(0..19).
volatile uint32_t PDDBCR
+0xC0 Data Buffer Control.
volatile uint32_t PDDRCR
+0xE0 Data Read Control.
volatile uint32_t PDSFCR
+0x24 Sinc Filter Control.
volatile uint32_t PDDRR
+0xE8 Data Read (20-bit PCM out).
volatile uint32_t PDHFCHR[2]
+0x30 High-pass filter coeff h(0..1).
volatile uint32_t PDSCR
+0x18 Status Clear.
volatile uint32_t PDCFCHR[k_ra8_pdm_cfch_count]
+0x38 Comp filter coeff h(0..10).
volatile uint32_t PDHFCS0R
+0x28 High-pass filter coeff s(0).
volatile uint32_t PDLFCH010R
+0x64 Low-pass filter coeff h0(10).
volatile uint32_t PDHFCK1R
+0x2C High-pass filter coeff k(1).
volatile uint32_t PDMDSR
+0x20 Mode Setting.
Full PDM-IF register block: common bank + 3 channel banks.
volatile uint32_t PDCSTRTR
+0x00 Channel Software Start Trigger.
volatile uint32_t PDCDRCR
+0x24 Channel Data Read Control.
volatile uint32_t PDCICR
+0x0C Channel Interrupt Control.
volatile uint32_t PDCSTPTR
+0x04 Channel Software Stop Trigger.
One PDM channel's mode + filter configuration.
uint16_t lpf_h0
Low-pass filter coefficient h0.
uint16_t hpf_h[k_ra8_pdm_hpf_h_count]
High-pass filter h(0..1).
uint16_t comp_h[k_ra8_pdm_comp_h_count]
Compensation filter h(0..10).
uint16_t lpf_h1[k_ra8_pdm_lpf_h1_count]
Low-pass filter h1(0..19).
uint8_t hpf_shift
High-pass input shift (PDMDSR.HFIS[1:0]).
uint8_t rx_threshold
Data reception threshold code (PDDBCR.DATRITHR).
uint16_t hpf_k1
High-pass filter coefficient k(1).
uint8_t sinc_order
Sinc filter order 1..4 (PDMDSR.SFMD).
uint8_t data_shift
Data-buffer input shift (PDMDSR.DBIS[3:0]).
uint8_t clock_div
PDM_CLKn divider code (PDSFCR.CKDIV[3:0]).
uint8_t lpf_shift
Low-pass input shift (PDMDSR.LFIS[1:0]).
uint8_t cf_shift
Compensation input shift (PDMDSR.CFIS[1:0]).
uint8_t sinc_dec
Sinc decimation ratio - 1 (PDSFCR.SINCDEC[7:0]).
uint8_t sinc_range
Sinc output clip range (PDSFCR.SINCRNG[4:0]).
uint8_t edge
0: rise-edge ch n; 1: fall-edge ch n-1 (INPSEL).
uint16_t hpf_s0
High-pass filter coefficient s(0).