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

Serial Sound Interface Enhanced (SSIE / I2S audio) driver. More...

#include <stdint.h>
#include "ra8_err.h"
Include dependency graph for ra8_ssie.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_ssie_cfg_t
 Configuration descriptor for ra8_ssie_init. More...
struct  ra8_ssie_status_t
 Snapshot of FIFO levels + error flags returned by ra8_ssie_get_status. More...
struct  ra8_ssie_dma_cfg_t
 DMA pump descriptor for ra8_ssie_attach_dma. More...

Typedefs

typedef void(* ra8_ssie_event_fn_t) (void *ctx, uint8_t channel, uint8_t events, uint32_t ssisr)
 SSIE event callback fired by ra8_ssie_dispatch.

Enumerations

enum  ra8_ssie_role_t : uint8_t {
  k_ra8_ssie_role_peripheral = 0U ,
  k_ra8_ssie_role_controller = 1U
}
 Controller / peripheral selection (drives SSICR.MST). More...
enum  ra8_ssie_format_t : uint8_t {
  k_ra8_ssie_format_i2s = 0U ,
  k_ra8_ssie_format_left_just = 1U ,
  k_ra8_ssie_format_right_just = 2U ,
  k_ra8_ssie_format_monaural = 3U ,
  k_ra8_ssie_format_tdm_4 = 4U ,
  k_ra8_ssie_format_tdm_6 = 5U ,
  k_ra8_ssie_format_tdm_8 = 6U ,
  k_ra8_ssie_format_tdm = 4U
}
 Audio frame format (drives SSIOFR.OMOD[1:0] and SSICR.FRM). More...
enum  ra8_ssie_data_word_t : uint8_t {
  k_ra8_ssie_dwl_8 = 0U ,
  k_ra8_ssie_dwl_16 = 1U ,
  k_ra8_ssie_dwl_18 = 2U ,
  k_ra8_ssie_dwl_20 = 3U ,
  k_ra8_ssie_dwl_22 = 4U ,
  k_ra8_ssie_dwl_24 = 5U ,
  k_ra8_ssie_dwl_32 = 6U
}
 Data word length (drives SSICR.DWL[2:0]). More...
enum  ra8_ssie_system_word_t : uint8_t {
  k_ra8_ssie_swl_8 = 0U ,
  k_ra8_ssie_swl_16 = 1U ,
  k_ra8_ssie_swl_24 = 2U ,
  k_ra8_ssie_swl_32 = 3U ,
  k_ra8_ssie_swl_48 = 4U ,
  k_ra8_ssie_swl_64 = 5U ,
  k_ra8_ssie_swl_128 = 6U ,
  k_ra8_ssie_swl_256 = 7U
}
 System word length (drives SSICR.SWL[2:0]). More...
enum  ra8_ssie_bclk_div_t : uint8_t {
  k_ra8_ssie_bclk_div_1 = 0x0U ,
  k_ra8_ssie_bclk_div_2 = 0x1U ,
  k_ra8_ssie_bclk_div_4 = 0x2U ,
  k_ra8_ssie_bclk_div_8 = 0x3U ,
  k_ra8_ssie_bclk_div_16 = 0x4U ,
  k_ra8_ssie_bclk_div_32 = 0x5U ,
  k_ra8_ssie_bclk_div_64 = 0x6U ,
  k_ra8_ssie_bclk_div_128 = 0x7U ,
  k_ra8_ssie_bclk_div_6 = 0x8U ,
  k_ra8_ssie_bclk_div_12 = 0x9U ,
  k_ra8_ssie_bclk_div_24 = 0xAU ,
  k_ra8_ssie_bclk_div_48 = 0xBU ,
  k_ra8_ssie_bclk_div_96 = 0xCU
}
 Bit-clock divider (drives SSICR.CKDV[3:0]). More...
enum  ra8_ssie_dir_t : uint8_t {
  k_ra8_ssie_dir_rx = 1U ,
  k_ra8_ssie_dir_tx = 2U ,
  k_ra8_ssie_dir_tx_rx = 3U
}
 Communication direction selector for ra8_ssie_start. More...
enum  ra8_ssie_event_t : uint8_t {
  k_ra8_ssie_evt_none = 0x00U ,
  k_ra8_ssie_evt_idle = 0x01U ,
  k_ra8_ssie_evt_tx_empty = 0x02U ,
  k_ra8_ssie_evt_rx_full = 0x04U ,
  k_ra8_ssie_evt_tx_under = 0x08U ,
  k_ra8_ssie_evt_tx_over = 0x10U ,
  k_ra8_ssie_evt_rx_under = 0x20U ,
  k_ra8_ssie_evt_rx_over = 0x40U ,
  k_ra8_ssie_evt_error = 0x78U
}
 Decoded SSIE callback event bit-flags. More...

Functions

ra8_err_t ra8_ssie_init (uint8_t channel, const ra8_ssie_cfg_t *cfg)
 Initialise an SSIE channel for I2S / TDM / monaural transfer.
ra8_err_t ra8_ssie_deinit (uint8_t channel)
 Tear down an SSIE channel and gate its clock.
ra8_err_t ra8_ssie_start (uint8_t channel, ra8_ssie_dir_t dir)
 Enable transmission, reception, or full duplex.
ra8_err_t ra8_ssie_stop (uint8_t channel)
 Disable transmission and reception.
ra8_err_t ra8_ssie_start_recovery (uint8_t channel)
 Force the channel back into a known idle state.
ra8_err_t ra8_ssie_mute (uint8_t channel, bool enable)
 Enable or disable mute on the next frame boundary.
ra8_err_t ra8_ssie_set_thresholds (uint8_t channel, uint8_t tx_threshold, uint8_t rx_threshold)
 Update the FIFO trigger watermarks at runtime.
ra8_err_t ra8_ssie_set_fifo_threshold (uint8_t channel, uint8_t tx_threshold, uint8_t rx_threshold)
 Programme SSITDMR / SSIRDMR FIFO thresholds in one call.
ra8_err_t ra8_ssie_attach_dma_pair (uint8_t channel, uint8_t tx_dma_channel, uint8_t rx_dma_channel)
 Pair an SSIE channel's TX + RX FIFOs to DMAC channels.
ra8_err_t ra8_ssie_send_iso (uint8_t channel, const uint32_t *buffer, uint16_t samples)
 Block-mode isochronous send.
ra8_err_t ra8_ssie_recv_iso (uint8_t channel, uint32_t *buffer, uint16_t max_samples, uint16_t *out_got)
 Block-mode isochronous receive.
ra8_err_t ra8_ssie_write_sample (uint8_t channel, uint32_t sample)
 Push one 32-bit sample into the transmit FIFO.
ra8_err_t ra8_ssie_read_sample (uint8_t channel, uint32_t *out)
 Pop one 32-bit sample from the receive FIFO.
ra8_err_t ra8_ssie_write_buffer (uint8_t channel, const uint32_t *buffer, uint16_t samples, uint16_t *out_written)
 Drain a host buffer into the TX FIFO until either runs out.
ra8_err_t ra8_ssie_read_buffer (uint8_t channel, uint32_t *buffer, uint16_t samples, uint16_t *out_read)
 Empty the RX FIFO into a host buffer until either runs out.
ra8_err_t ra8_ssie_attach_dma (uint8_t channel, const ra8_ssie_dma_cfg_t *dma)
 Attach DMAC channels to the SSIE TX and/or RX FIFOs.
ra8_err_t ra8_ssie_detach_dma (uint8_t channel)
 Tear down DMAC channels attached to the SSIE FIFOs.
ra8_err_t ra8_ssie_get_status (uint8_t channel, ra8_ssie_status_t *out)
 Snapshot SSISR + SSIFSR into a status struct.
ra8_err_t ra8_ssie_clear_status (uint8_t channel, uint32_t mask)
 Clear sticky error flags in SSISR.
ra8_err_t ra8_ssie_attach_handler (ra8_ssie_event_fn_t fn, void *ctx)
 Attach a shared event callback for both SSIE channels.
void ra8_ssie_dispatch (uint8_t channel)
 ISR helper: fire the registered event handler.
ra8_err_t ra8_ssie_set_irq_enable (uint8_t channel, uint32_t mask, bool enable)
 Update the IRQ enable mask without rewriting SSICR fully.
ra8_err_t ra8_ssie_enter_stop (uint8_t channel)
 Gate the channel's MSTP bit (preserve register state).
ra8_err_t ra8_ssie_exit_stop (uint8_t channel)
 Re-ungate the channel's MSTP bit.

Detailed Description

Serial Sound Interface Enhanced (SSIE / I2S audio) driver.

Tag
[Ring 3 / HAL] {World: NS}

Full-coverage RA8D2 SSIE driver. Each chip has two SSIE channels: SSIE0 is full-duplex (SSITXD0 + SSIRXD0) and SSIE1 is half-duplex (shared SSIDATA1 line). Both channels share the same register map and are addressed by channel = 0|1.

Coverage of HUM Ch 46 "Serial Sound Interface Enhanced (SSIE)" pages 3051-3121:

  • Lifecycle: ra8_ssie_init / ra8_ssie_deinit follow the procedure in HUM Ch 46.6.1 "Initial Settings" p 3097.
  • All four formats: I2S, TDM (4/6/8 ch), Monaural, Right/Left justified through SDTA/PDTA polarity selectors.
  • All eight system word lengths (8/16/24/32/48/64/128/256 b) and all seven legal data word lengths (8/16/18/20/22/24/32 b).
  • All thirteen controller-mode bit clock dividers (CKDV 0x0..0xC).
  • Controller + peripheral mode with audio clock source selection (CKS).
  • Mute control with frame-boundary effect (HUM Ch 46.5.4 p 3107).
  • Polarity controls (BCKP, LRCKP, SPDP) and DEL short/long frame.
  • LRCONT (LR-clock continuation) and BCKASTP (idle BCK auto-stop) for power-friendly controller operation.
  • Byte swap (BSW) and AUDIO_MCK enable (AUCKE).
  • FIFO threshold programming via SSISCR (TDES, RDFS).
  • Single-sample read/write + buffered TX/RX through the FIFO.
  • Full IRQ surface: TX-empty (TXI / TIE+TDE), RX-full (RXI / RIE+RDF), idle (IIRQ), and four error sources (TUIRQ, TOIRQ, RUIRQ, ROIRQ).
  • DMA pump: TX + RX channels via ra8_dmac with FIFO half-full watermarks driving the request signals.
  • Power transition (MSTPC7/MSTPC8 enter/exit).
  • Error recovery (start_recovery) and IRQ dispatch with W1C flag clearing.

Every register access in the matching .c carries a HUM Ch 46 citation. FSP r_ssi.c was used as reference for the SSICR / SSIFCR / SSISCR shift macros and the start/stop sequences only – no code copied.

State Machine

Definition in file ra8_ssie.h.

Typedef Documentation

◆ ra8_ssie_event_fn_t

typedef void(* ra8_ssie_event_fn_t) (void *ctx, uint8_t channel, uint8_t events, uint32_t ssisr)

SSIE event callback fired by ra8_ssie_dispatch.

Parameters
[in]ctxCaller context registered via ra8_ssie_attach_handler.
[in]channelChannel that fired (0 or 1).
[in]eventsDecoded ra8_ssie_event_t bitmap.
[in]ssisrSnapshot of SSISR at IRQ entry.

Definition at line 305 of file ra8_ssie.h.

Enumeration Type Documentation

◆ ra8_ssie_bclk_div_t

enum ra8_ssie_bclk_div_t : uint8_t

Bit-clock divider (drives SSICR.CKDV[3:0]).

Controller-mode only. Divides AUDIO_MCK to produce SSIBCKn. See HUM Ch 46.2.1 CKDV table, p 3056. Encodings 0xD..0xF are "setting prohibited" and intentionally not exposed.

Enumerator
k_ra8_ssie_bclk_div_1 

AUDIO_MCK / 1.

k_ra8_ssie_bclk_div_2 

AUDIO_MCK / 2.

k_ra8_ssie_bclk_div_4 

AUDIO_MCK / 4.

k_ra8_ssie_bclk_div_8 

AUDIO_MCK / 8.

k_ra8_ssie_bclk_div_16 

AUDIO_MCK / 16.

k_ra8_ssie_bclk_div_32 

AUDIO_MCK / 32.

k_ra8_ssie_bclk_div_64 

AUDIO_MCK / 64.

k_ra8_ssie_bclk_div_128 

AUDIO_MCK / 128.

k_ra8_ssie_bclk_div_6 

AUDIO_MCK / 6.

k_ra8_ssie_bclk_div_12 

AUDIO_MCK / 12.

k_ra8_ssie_bclk_div_24 

AUDIO_MCK / 24.

k_ra8_ssie_bclk_div_48 

AUDIO_MCK / 48.

k_ra8_ssie_bclk_div_96 

AUDIO_MCK / 96.

Definition at line 189 of file ra8_ssie.h.

◆ ra8_ssie_data_word_t

enum ra8_ssie_data_word_t : uint8_t

Data word length (drives SSICR.DWL[2:0]).

"Number of significant bits per channel" (HUM Ch 46.2.1 DWL, p 3057). The encoding 111b is "setting prohibited" and not exposed.

Enumerator
k_ra8_ssie_dwl_8 

8-bit data word.

k_ra8_ssie_dwl_16 

16-bit data word.

k_ra8_ssie_dwl_18 

18-bit data word.

k_ra8_ssie_dwl_20 

20-bit data word.

k_ra8_ssie_dwl_22 

22-bit data word.

k_ra8_ssie_dwl_24 

24-bit data word.

k_ra8_ssie_dwl_32 

32-bit data word.

Definition at line 151 of file ra8_ssie.h.

◆ ra8_ssie_dir_t

enum ra8_ssie_dir_t : uint8_t

Communication direction selector for ra8_ssie_start.

Enumerator
k_ra8_ssie_dir_rx 

Reception only (REN).

k_ra8_ssie_dir_tx 

Transmission only (TEN).

k_ra8_ssie_dir_tx_rx 

Full duplex (TEN | REN).

Definition at line 209 of file ra8_ssie.h.

◆ ra8_ssie_event_t

enum ra8_ssie_event_t : uint8_t

Decoded SSIE callback event bit-flags.

Event bits delivered to the registered callback via ra8_ssie_dispatch. Multiple bits may be set on a single dispatch. Maps to SSISR / SSIFSR flags via internal_decode_event in ra8_ssie.c.

Enumerator
k_ra8_ssie_evt_none 

No bits set.

k_ra8_ssie_evt_idle 

IIRQ asserted.

k_ra8_ssie_evt_tx_empty 

TDE asserted (TIE on).

k_ra8_ssie_evt_rx_full 

RDF asserted (RIE on).

k_ra8_ssie_evt_tx_under 

TUIRQ.

k_ra8_ssie_evt_tx_over 

TOIRQ.

k_ra8_ssie_evt_rx_under 

RUIRQ.

k_ra8_ssie_evt_rx_over 

ROIRQ.

k_ra8_ssie_evt_error 

Aggregate error mask.

Definition at line 225 of file ra8_ssie.h.

◆ ra8_ssie_format_t

enum ra8_ssie_format_t : uint8_t

Audio frame format (drives SSIOFR.OMOD[1:0] and SSICR.FRM).

The omod value goes straight to SSIOFR.OMOD[1:0] (HUM Ch 46.2.7 "OMOD" bits, p 3091). The driver maps the format_t enum to the exact OMOD encoding from the chapter table:

Enum OMOD FRM Words/frame
k_ra8_ssie_format_i2s 00b 00b 2 (L,R)
k_ra8_ssie_format_left_just 00b 00b 2, SDTA=0
k_ra8_ssie_format_right_just 00b 00b 2, PDTA=1
k_ra8_ssie_format_monaural 10b 00b 1
k_ra8_ssie_format_tdm_4 01b 01b 4
k_ra8_ssie_format_tdm_6 01b 10b 6
k_ra8_ssie_format_tdm_8 01b 11b 8
Enumerator
k_ra8_ssie_format_i2s 

I2S, 2 channels per frame.

k_ra8_ssie_format_left_just 

Left-justified, 2 channels.

k_ra8_ssie_format_right_just 

Right-justified, 2 channels.

k_ra8_ssie_format_monaural 

Monaural single-channel.

k_ra8_ssie_format_tdm_4 

TDM 4-slot.

k_ra8_ssie_format_tdm_6 

TDM 6-slot.

k_ra8_ssie_format_tdm_8 

TDM 8-slot.

k_ra8_ssie_format_tdm 

Backwards alias kept for unit tests that index OMOD directly.

Same encoding as k_ra8_ssie_format_tdm_4 (OMOD=01b, FRM=01b).

Definition at line 127 of file ra8_ssie.h.

◆ ra8_ssie_role_t

enum ra8_ssie_role_t : uint8_t

Controller / peripheral selection (drives SSICR.MST).

See HUM Ch 46.2.1 "MST" bit, p 3057.

Enumerator
k_ra8_ssie_role_peripheral 

Bit clock + LR clock are inputs.

k_ra8_ssie_role_controller 

Bit clock + LR clock are outputs.

Definition at line 103 of file ra8_ssie.h.

◆ ra8_ssie_system_word_t

enum ra8_ssie_system_word_t : uint8_t

System word length (drives SSICR.SWL[2:0]).

"Number of bits per channel" including padding (HUM Ch 46.2.1 SWL, p 3057). Must be at least the data word length.

Enumerator
k_ra8_ssie_swl_8 

8-bit system word.

k_ra8_ssie_swl_16 

16-bit system word.

k_ra8_ssie_swl_24 

24-bit system word.

k_ra8_ssie_swl_32 

32-bit system word.

k_ra8_ssie_swl_48 

48-bit system word.

k_ra8_ssie_swl_64 

64-bit system word.

k_ra8_ssie_swl_128 

128-bit system word.

k_ra8_ssie_swl_256 

256-bit system word.

Definition at line 169 of file ra8_ssie.h.

Function Documentation

◆ ra8_ssie_attach_dma()

ra8_err_t ra8_ssie_attach_dma ( uint8_t channel,
const ra8_ssie_dma_cfg_t * dma )
nodiscard

Attach DMAC channels to the SSIE TX and/or RX FIFOs.

Programmes a TX DMAC channel (source = caller buffer, dest = SSIFTDR, no dest increment) and an RX DMAC channel (source = SSIFRDR, dest = caller buffer, no source increment) per HUM Ch 46.4.1 "Operation in DMAC Transfer" p 3104. After this call the SSIE TIE/RIE bits are still required to advance the DMA (the FIFO watermark is the request signal).

Setting a channel ID >= 8 (the DMAC has only 8 channels) skips that direction.

Parameters
[in]channelChannel index (0 = SSIE0, 1 = SSIE1).
[in]dmaNon-NULL DMA configuration.
Returns
ra8_err_t error code.
Return values
k_ra8_okDMA channels programmed.
k_ra8_err_null_ptrdma was NULL.
k_ra8_err_invalid_argChannel out of range or DMA samples = 0.
Precondition
Channel previously initialized.
DMA channels not currently in use.
Postcondition
DMAC sources/destinations and counts loaded.
SSIE FIFO watermarks unchanged.
Note
Thread safety: not thread-safe.
See also
ra8_ssie_detach_dma
Since
0.1.0

Definition at line 224 of file ra8_ssie_stream.c.

References g_ssie_runtime, internal_attach_dma_dirs(), internal_validate_dma_cfg(), k_ra8_err_invalid_arg, k_ra8_ok, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_ssie_attach_dma_pair()

ra8_err_t ra8_ssie_attach_dma_pair ( uint8_t channel,
uint8_t tx_dma_channel,
uint8_t rx_dma_channel )
nodiscard

Pair an SSIE channel's TX + RX FIFOs to DMAC channels.

Thin variant of ra8_ssie_attach_dma that takes only the DMAC channel ids (no buffers / counts). Useful for callers who programme the DMAC descriptors themselves and only need the SSIE side to record which DMAC channels to free during ra8_ssie_detach_dma. Pass >= 8 to skip a direction.

Parameters
[in]channelSSIE channel index 0..1.
[in]tx_dma_channelDMAC channel id pumping TX (or >= 8).
[in]rx_dma_channelDMAC channel id pumping RX (or >= 8).
Returns
ra8_err_t error code.
Return values
k_ra8_okChannel binding recorded.
k_ra8_err_invalid_argChannel out of range OR both DMA ids >= 8.
Precondition
Channel previously initialized.
At least one of tx_dma_channel / rx_dma_channel < 8.
Postcondition
Internal DMA bookkeeping records the TX / RX DMAC ids.
No DMAC start was issued (compare ra8_ssie_attach_dma).
Note
Thread safety: not thread-safe.
See also
ra8_ssie_attach_dma
ra8_ssie_detach_dma
Since
0.1.0

Definition at line 264 of file ra8_ssie_stream.c.

References ra8_ssie_runtime_t::dma_attached, g_ssie_runtime, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_channel_count, k_ra8_ssie_dma_ch_unused, k_ra8_ssie_dma_max_ch, ra8_ssie_runtime_t::rx_dma_channel, and ra8_ssie_runtime_t::tx_dma_channel.

◆ ra8_ssie_attach_handler()

ra8_err_t ra8_ssie_attach_handler ( ra8_ssie_event_fn_t fn,
void * ctx )
nodiscard

Attach a shared event callback for both SSIE channels.

Parameters
[in]fnCallback invoked from ra8_ssie_dispatch.
[in]ctxOpaque context forwarded to the callback.
Returns
ra8_err_t error code.
Return values
k_ra8_okAlways succeeds (handler may be nullptr to detach).
Precondition
None.
Storage for the function pointer pair is process-global.
Postcondition
Subsequent ra8_ssie_dispatch calls invoke fn.
Previous handler is replaced.
Note
Thread safety: not thread-safe (writes two static pointers).
Since
0.1.0

Definition at line 915 of file ra8_ssie.c.

References k_ra8_ok, s_ssie_ctx, and s_ssie_fn.

◆ ra8_ssie_clear_status()

ra8_err_t ra8_ssie_clear_status ( uint8_t channel,
uint32_t mask )
nodiscard

Clear sticky error flags in SSISR.

Performs a write-1-to-clear on the bits in mask that overlap SSISR.{ROIRQ, RUIRQ, TOIRQ, TUIRQ}. Other bits are ignored. See HUM Ch 46.2.2, p 3066-3071 for the per-flag clear protocol.

Parameters
[in]channelChannel index.
[in]maskBitmask of flags to clear (use k_ra8_ssie_mask_err_all to clear them all).
Returns
ra8_err_t error code.
Return values
k_ra8_okMask written.
k_ra8_err_invalid_argchannel out of range.
Precondition
Channel initialized.
Caller already read SSISR (W1C requires "read 1 then write 0").
Postcondition
Flags in mask are cleared.
Other SSISR bits unchanged.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 884 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_err_all, priv_ra8_ssie_internal_regs(), and r_ssie_regs_t::SSISR.

◆ ra8_ssie_deinit()

ra8_err_t ra8_ssie_deinit ( uint8_t channel)
nodiscard

Tear down an SSIE channel and gate its clock.

Parameters
[in]channelChannel index.
Returns
ra8_err_t error code.
Precondition
IRQs masked or single-threaded.
ra8_ssie_init previously succeeded for channel.
Postcondition
SSICR.TEN = 0 and SSICR.REN = 0.
MSTP bit set (peripheral gated).
Note
Thread safety: not thread-safe.
See also
ra8_ssie_init
Since
0.1.0

Definition at line 638 of file ra8_ssie.c.

References g_ssie_runtime, k_ra8_err_invalid_arg, k_ra8_ssie_mask_aucke, k_ra8_ssie_mask_ren_ten, priv_ra8_ssie_internal_regs(), ra8_mstp_disable(), ra8_ssie_detach_dma(), s_ssie_mstp_table, r_ssie_regs_t::SSICR, and r_ssie_regs_t::SSIFCR.

Referenced by main().

◆ ra8_ssie_detach_dma()

ra8_err_t ra8_ssie_detach_dma ( uint8_t channel)
nodiscard

Tear down DMAC channels attached to the SSIE FIFOs.

Parameters
[in]channelChannel index.
Returns
ra8_err_t error code.
Return values
k_ra8_okAll attached DMA channels stopped.
k_ra8_err_invalid_argChannel out of range.
Precondition
ra8_ssie_attach_dma previously succeeded for channel.
TIE/RIE bits in SSIFCR cleared by caller before call.
Postcondition
Both DMAC channels stopped.
Internal DMA bookkeeping cleared.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 246 of file ra8_ssie_stream.c.

References ra8_ssie_runtime_t::dma_attached, g_ssie_runtime, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_channel_count, k_ra8_ssie_dma_ch_unused, k_ra8_ssie_dma_max_ch, ra8_dmac_stop(), ra8_ssie_runtime_t::rx_dma_channel, and ra8_ssie_runtime_t::tx_dma_channel.

Referenced by ra8_ssie_deinit().

◆ ra8_ssie_dispatch()

void ra8_ssie_dispatch ( uint8_t channel)

ISR helper: fire the registered event handler.

Snapshots SSISR for channel (HUM Ch 51 "Serial Sound Interface Enhanced (SSIE)", p 2731), then invokes the attached event handler. Out-of-range channel indices and unattached slots are silently dropped so spurious IRQs are harmless.

Parameters
[in]channelChannel that fired.
Precondition
Channel index in range (out-of-range silently dropped).
A handler was attached via ra8_ssie_attach_handler.
Postcondition
The registered handler ran with the SSISR snapshot.
No SSISR flags are auto-cleared (caller's responsibility).
Note
Thread safety: callable from IRQ context.
Since
0.1.0

Definition at line 923 of file ra8_ssie.c.

References internal_decode_event(), priv_ra8_ssie_internal_regs(), s_ssie_ctx, s_ssie_fn, r_ssie_regs_t::SSIFSR, and r_ssie_regs_t::SSISR.

◆ ra8_ssie_enter_stop()

ra8_err_t ra8_ssie_enter_stop ( uint8_t channel)
nodiscard

Gate the channel's MSTP bit (preserve register state).

Parameters
[in]channelChannel index.
Returns
ra8_err_t error code.
Precondition
Channel was initialized.
IRQs masked.
Postcondition
MSTP bit set, peripheral clock removed.
SSICR / SSIOFR contents persist (registers retain values).
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 949 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ssie_channel_count, ra8_mstp_disable(), and s_ssie_mstp_table.

◆ ra8_ssie_exit_stop()

ra8_err_t ra8_ssie_exit_stop ( uint8_t channel)
nodiscard

Re-ungate the channel's MSTP bit.

Parameters
[in]channelChannel index.
Returns
ra8_err_t error code.
Precondition
Channel was previously gated via ra8_ssie_enter_stop.
IRQs masked.
Postcondition
MSTP bit cleared, peripheral clock restored.
No SSICR / SSIOFR fields reprogrammed by this call.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 957 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ssie_channel_count, ra8_mstp_enable(), and s_ssie_mstp_table.

◆ ra8_ssie_get_status()

ra8_err_t ra8_ssie_get_status ( uint8_t channel,
ra8_ssie_status_t * out )
nodiscard

Snapshot SSISR + SSIFSR into a status struct.

Parameters
[in]channelChannel index.
[out]outNon-NULL status struct.
Returns
ra8_err_t error code.
Return values
k_ra8_okSnapshot taken.
k_ra8_err_null_ptrout was nullptr.
k_ra8_err_invalid_argchannel out of range.
Precondition
Channel previously initialized, out non-NULL.
IRQs may be enabled (read-only).
Postcondition
*out reflects a coherent SSISR/SSIFSR snapshot.
No registers are modified.
Note
Thread safety: safe to call from IRQ context.
Since
0.1.0

Definition at line 860 of file ra8_ssie.c.

References ra8_ssie_status_t::error, ra8_ssie_status_t::events, ra8_ssie_status_t::idle, internal_decode_event(), k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_err_all, k_ra8_ssie_mask_iirq, k_ra8_ssie_mask_rdc, k_ra8_ssie_mask_rdf, k_ra8_ssie_mask_tdc, k_ra8_ssie_mask_tde, k_ra8_ssie_shift_rdc, k_ra8_ssie_shift_tdc, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, ra8_ssie_status_t::rx_count, ra8_ssie_status_t::rx_full, s_tag, r_ssie_regs_t::SSIFSR, ra8_ssie_status_t::ssifsr, r_ssie_regs_t::SSISR, ra8_ssie_status_t::ssisr, ra8_ssie_status_t::tx_count, and ra8_ssie_status_t::tx_empty.

◆ ra8_ssie_init()

ra8_err_t ra8_ssie_init ( uint8_t channel,
const ra8_ssie_cfg_t * cfg )
nodiscard

Initialise an SSIE channel for I2S / TDM / monaural transfer.

Algorithm (HUM Ch 46.6.1 "Initial Settings", p 3097):

  1. Ungate MSTPC8 (SSIE0) or MSTPC7 (SSIE1) via ra8_mstp.
  2. Software-reset the channel (SSIFCR.SSIRST = 1, then 0).
  3. Programme SSICR with role / clock divider / word lengths + polarity (BCKP, LRCKP, SPDP) and DEL (short/long frame).
  4. Programme SSIOFR with the audio format (OMOD), LRCONT and BCKASTP.
  5. Programme SSISCR with the FIFO watermarks.
  6. Programme SSIFCR with AUCKE + BSW.
  7. Leave TEN / REN / interrupts cleared so the caller can prime the FIFOs and call ra8_ssie_start.
Parameters
[in]channelChannel index (0 = SSIE0, 1 = SSIE1).
[in]cfgNon-NULL configuration descriptor.
Returns
ra8_err_t error code.
Return values
k_ra8_okChannel initialized.
k_ra8_err_null_ptrcfg was nullptr.
k_ra8_err_invalid_argchannel out of range.
k_ra8_err_hw_timeoutSSIRST did not self-clear within k_ra8_ssie_reset_poll_max reads.
Precondition
IRQs masked or single-threaded init context.
ra8_mstp_init() has run.
Postcondition
SSICR holds the requested format with TEN/REN clear.
SSIE channel is ungated (MSTP bit cleared).
Note
Thread safety: not thread-safe.
See also
ra8_ssie_deinit
ra8_ssie_start
Since
0.1.0

Definition at line 610 of file ra8_ssie.c.

References g_ssie_runtime, internal_apply_init_regs(), internal_ssie_power_up(), internal_validate_init_cfg(), k_ra8_err_invalid_arg, k_ra8_ok, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, ra8_log_info_val, RA8_RETURN_ON_ERROR, and s_tag.

Referenced by internal_ssie_loop_run(), and ra8_board_audio_init().

◆ ra8_ssie_mute()

ra8_err_t ra8_ssie_mute ( uint8_t channel,
bool enable )
nodiscard

Enable or disable mute on the next frame boundary.

Toggles SSICR.MUEN per HUM Ch 46.2.1 (p 3056). Data is still written to the TX line but its bits are forced to zero.

Parameters
[in]channelChannel index.
[in]enabletrue to mute, false to un-mute.
Returns
ra8_err_t error code.
Return values
k_ra8_okMUEN updated.
k_ra8_err_invalid_argChannel out of range.
Precondition
Channel previously initialized.
IRQs masked.
Postcondition
SSICR.MUEN reflects enable.
No other SSICR field touched.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 740 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_muen, priv_ra8_ssie_internal_regs(), and r_ssie_regs_t::SSICR.

◆ ra8_ssie_read_buffer()

ra8_err_t ra8_ssie_read_buffer ( uint8_t channel,
uint32_t * buffer,
uint16_t samples,
uint16_t * out_read )
nodiscard

Empty the RX FIFO into a host buffer until either runs out.

Parameters
[in]channelChannel index.
[out]bufferDestination samples.
[in]samplesDestination-buffer length in samples.
[out]out_readReceives the number of samples consumed.
Returns
ra8_err_t error code.
Return values
k_ra8_okAt least zero samples consumed.
k_ra8_err_null_ptrbuffer or out_read was NULL.
k_ra8_err_invalid_argChannel out of range.
Precondition
Channel previously initialized.
buffer and out_read non-NULL.
Postcondition
*out_read <= samples.
SSIFSR.RDF cleared if any sample was read.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 829 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_rdc, k_ra8_ssie_mask_tde_clear, k_ra8_ssie_shift_rdc, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, s_tag, r_ssie_regs_t::SSIFRDR, and r_ssie_regs_t::SSIFSR.

◆ ra8_ssie_read_sample()

ra8_err_t ra8_ssie_read_sample ( uint8_t channel,
uint32_t * out )
nodiscard

Pop one 32-bit sample from the receive FIFO.

Parameters
[in]channelChannel index.
[out]outReceives the sample bits.
Returns
ra8_err_t error code.
Return values
k_ra8_okSample read.
k_ra8_err_null_ptrout was nullptr.
k_ra8_err_invalid_argchannel out of range.
Precondition
Channel previously initialized, out non-NULL.
Caller has confirmed RDF or non-zero RDC.
Postcondition
*out holds the dequeued sample.
SSIFRDR read pointer advanced by one stage.
Note
Thread safety: not thread-safe.
See also
ra8_ssie_write_sample
Since
0.1.0

Definition at line 782 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, s_tag, and r_ssie_regs_t::SSIFRDR.

◆ ra8_ssie_recv_iso()

ra8_err_t ra8_ssie_recv_iso ( uint8_t channel,
uint32_t * buffer,
uint16_t max_samples,
uint16_t * out_got )
nodiscard

Block-mode isochronous receive.

Drains up to max_samples.

Loops until either the destination buffer is full or the SSIE RX FIFO drains. Returns the actual sample count via out_got.

Parameters
[in]channelChannel index 0..1.
[out]bufferDestination buffer.
[in]max_samplesCapacity of buffer in 32-bit samples.
[out]out_gotReceives the number of samples consumed.
Returns
ra8_err_t error code.
Return values
k_ra8_okUp to max_samples words consumed.
k_ra8_err_null_ptrbuffer or out_got was NULL.
k_ra8_err_invalid_argChannel out of range.
Precondition
Channel previously initialized + started in RX mode.
buffer and out_got are non-NULL.
Postcondition
*out_got <= max_samples.
Receive FIFO drained to either empty or max_samples cap.
Note
Thread safety: not thread-safe.
See also
ra8_ssie_send_iso
Since
0.1.0

Definition at line 313 of file ra8_ssie_stream.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_rdc, k_ra8_ssie_mask_tde_clear, k_ra8_ssie_shift_rdc, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, s_tag, r_ssie_regs_t::SSIFRDR, and r_ssie_regs_t::SSIFSR.

◆ ra8_ssie_send_iso()

ra8_err_t ra8_ssie_send_iso ( uint8_t channel,
const uint32_t * buffer,
uint16_t samples )
nodiscard

Block-mode isochronous send.

Drains the buffer fully.

Loops until every requested sample has been pushed into SSIFTDR. Internally relies on the FIFO depth read-back to throttle, so the routine is bounded by samples * k_ra8_ssie_fifo_depth SSIFSR reads worst-case (HUM Ch 46.2.4 p 3083). The non-DMA path used by the iso pacing layer.

Parameters
[in]channelChannel index 0..1.
[in]bufferSource samples.
[in]samplesNumber of 32-bit samples to send.
Returns
ra8_err_t error code.
Return values
k_ra8_okAll samples queued.
k_ra8_err_null_ptrbuffer was NULL.
k_ra8_err_invalid_argChannel out of range.
Precondition
Channel previously initialized + started in TX mode.
buffer is non-NULL and points to samples words.
Postcondition
All samples words have been pushed into SSIFTDR.
Remaining FIFO occupancy is implementation-defined.
Note
Thread safety: not thread-safe.
See also
ra8_ssie_recv_iso
Since
0.1.0

Definition at line 285 of file ra8_ssie_stream.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_fifo_depth, k_ra8_ssie_mask_rdf_clear, k_ra8_ssie_mask_tdc, k_ra8_ssie_shift_tdc, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, s_tag, r_ssie_regs_t::SSIFSR, and r_ssie_regs_t::SSIFTDR.

◆ ra8_ssie_set_fifo_threshold()

ra8_err_t ra8_ssie_set_fifo_threshold ( uint8_t channel,
uint8_t tx_threshold,
uint8_t rx_threshold )
nodiscard

Programme SSITDMR / SSIRDMR FIFO thresholds in one call.

Convenience wrapper that drives ra8_ssie_set_thresholds with the exact pair of TX / RX FIFO watermarks the audio pipeline wants. The SSIE only carries SSISCR.TDES / SSISCR.RDFS (HUM Ch 46.2.8 p 3094) – the names SSITDMR / SSIRDMR are aliases the application layer uses for clarity.

Parameters
[in]channelChannel index (0 = SSIE0, 1 = SSIE1).
[in]tx_thresholdTDES[4:0]: TX-empty IRQ when TDC <= value.
[in]rx_thresholdRDFS[4:0]: RX-full IRQ when RDC > value.
Returns
ra8_err_t error code.
Return values
k_ra8_okThresholds programmed.
k_ra8_err_invalid_argChannel out of range or threshold > 0x1F.
Precondition
Channel previously initialized.
Channel currently idle.
Postcondition
SSISCR reflects the requested thresholds.
Other SSISCR fields are zero (reserved).
Note
Thread safety: not thread-safe.
See also
ra8_ssie_set_thresholds
Since
0.1.0

Definition at line 941 of file ra8_ssie.c.

References ra8_ssie_set_thresholds().

◆ ra8_ssie_set_irq_enable()

ra8_err_t ra8_ssie_set_irq_enable ( uint8_t channel,
uint32_t mask,
bool enable )
nodiscard

Update the IRQ enable mask without rewriting SSICR fully.

Performs read-modify-write on SSICR.{IIEN, ROIEN, RUIEN, TOIEN, TUIEN}. Pass k_ra8_ssie_mask_irq_all in mask to enable every IRQ source.

Parameters
[in]channelChannel index.
[in]maskMask of bits to set / clear.
[in]enabletrue to set bits, false to clear.
Returns
ra8_err_t error code.
Return values
k_ra8_okSSICR updated.
k_ra8_err_invalid_argChannel out of range.
Precondition
Channel initialized.
Caller has registered an event handler via ra8_ssie_attach_handler.
Postcondition
Requested bits set or cleared in SSICR.
Other SSICR fields untouched.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 897 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_irq_all, priv_ra8_ssie_internal_regs(), and r_ssie_regs_t::SSICR.

◆ ra8_ssie_set_thresholds()

ra8_err_t ra8_ssie_set_thresholds ( uint8_t channel,
uint8_t tx_threshold,
uint8_t rx_threshold )
nodiscard

Update the FIFO trigger watermarks at runtime.

Parameters
[in]channelChannel index.
[in]tx_thresholdTDES[4:0]: TX-empty IRQ when TDC <= value.
[in]rx_thresholdRDFS[4:0]: RX-full IRQ when RDC > value.
Returns
ra8_err_t error code.
Return values
k_ra8_okSSISCR updated.
k_ra8_err_invalid_argChannel out of range or threshold > 0x1F.
Precondition
Channel previously initialized.
Channel currently idle (SSISR.IIRQ = 1).
Postcondition
SSISCR.TDES = tx_threshold, SSISCR.RDFS = rx_threshold.
Other SSISCR bits zero (reserved).
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 757 of file ra8_ssie.c.

References internal_build_ssiscr(), k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_thresh_max, priv_ra8_ssie_internal_regs(), and r_ssie_regs_t::SSISCR.

Referenced by ra8_ssie_set_fifo_threshold().

◆ ra8_ssie_start()

ra8_err_t ra8_ssie_start ( uint8_t channel,
ra8_ssie_dir_t dir )
nodiscard

Enable transmission, reception, or full duplex.

Implements HUM Ch 46.6.2 "Transmission" (p 3098) and 46.6.3 "Reception" (p 3099). Resets both FIFOs (TFRST/RFRST), enables the matching interrupt mask in SSIFCR (TIE/RIE), enables the matching error masks in SSICR (TUIEN/ROIEN), then sets TEN/REN.

Parameters
[in]channelChannel index.
[in]dirk_ra8_ssie_dir_tx, ..._rx or ..._tx_rx.
Returns
ra8_err_t error code.
Return values
k_ra8_okDirection enabled.
k_ra8_err_invalid_argChannel or direction out of range.
k_ra8_err_busySSIE is not idle and direction would change (must call ra8_ssie_stop first).
Precondition
Channel previously initialized.
IRQs masked while modifying SSICR.
Postcondition
Requested REN/TEN bits asserted.
Matching IRQ enable bits asserted.
Note
Thread safety: not thread-safe.
See also
ra8_ssie_stop
Since
0.1.0

Definition at line 656 of file ra8_ssie.c.

References internal_apply_dir_irq_bits(), internal_pulse_fifo_reset(), k_ra8_err_busy, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_dir_rx, k_ra8_ssie_dir_tx, k_ra8_ssie_dir_tx_rx, k_ra8_ssie_mask_iirq, k_ra8_ssie_mask_ren_ten, priv_ra8_ssie_internal_regs(), RA8_RETURN_ON_ERROR, s_tag, r_ssie_regs_t::SSICR, r_ssie_regs_t::SSIFCR, and r_ssie_regs_t::SSISR.

Referenced by internal_ssie_loop_run().

◆ ra8_ssie_start_recovery()

ra8_err_t ra8_ssie_start_recovery ( uint8_t channel)
nodiscard

Force the channel back into a known idle state.

Issues a software reset (SSIFCR.SSIRST), waits for it to self-clear, then clears every error flag in SSISR. Used by the IRQ dispatcher when a TUIRQ/ROIRQ pair is observed.

Parameters
[in]channelChannel index.
Returns
ra8_err_t error code.
Return values
k_ra8_okChannel reset and flags cleared.
k_ra8_err_invalid_argChannel out of range.
k_ra8_err_hw_timeoutSSIRST did not self-clear in bound.
Precondition
Channel previously initialized.
Caller has consumed any pending RX data (FIFO is reset).
Postcondition
FIFOs are empty and all SSISR error flags cleared.
SSICR retains its mode bits (only TEN/REN are touched).
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 719 of file ra8_ssie.c.

References internal_wait_ssirst_clear(), k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_err_all, k_ra8_ssie_mask_ssirst, priv_ra8_ssie_internal_regs(), RA8_RETURN_ON_ERROR, s_tag, r_ssie_regs_t::SSIFCR, and r_ssie_regs_t::SSISR.

◆ ra8_ssie_stop()

ra8_err_t ra8_ssie_stop ( uint8_t channel)
nodiscard

Disable transmission and reception.

Implements HUM Ch 46.6.4 "Idle Operation" p 3100. Clears REN/TEN/error-IEN, leaves IIEN set so the caller is notified when SSIE finishes the in-flight frame.

Parameters
[in]channelChannel index.
Returns
ra8_err_t error code.
Return values
k_ra8_okStop requested; IIEN now armed.
k_ra8_err_invalid_argChannel out of range.
Precondition
Channel previously initialized.
IRQs masked while modifying SSICR.
Postcondition
REN/TEN/error-IEN bits cleared.
IIEN bit set so the next IIRQ fires the callback.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 697 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_mask_err_ien, k_ra8_ssie_mask_iien, k_ra8_ssie_mask_ren_ten, k_ra8_ssie_mask_rie_tie, priv_ra8_ssie_internal_regs(), r_ssie_regs_t::SSICR, and r_ssie_regs_t::SSIFCR.

Referenced by main().

◆ ra8_ssie_write_buffer()

ra8_err_t ra8_ssie_write_buffer ( uint8_t channel,
const uint32_t * buffer,
uint16_t samples,
uint16_t * out_written )
nodiscard

Drain a host buffer into the TX FIFO until either runs out.

Loops while samples > 0 and SSIFSR.TDC < depth. Returns the number of samples actually written via out_written.

Parameters
[in]channelChannel index.
[in]bufferSource samples.
[in]samplesSource-buffer length in samples.
[out]out_writtenReceives the number of samples written.
Returns
ra8_err_t error code.
Return values
k_ra8_okAt least zero samples written.
k_ra8_err_null_ptrbuffer or out_written was NULL.
k_ra8_err_invalid_argChannel out of range.
Precondition
Channel previously initialized.
buffer and out_written non-NULL.
Postcondition
*out_written <= samples.
SSIFSR.TDE cleared if any sample was written.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 794 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_fifo_depth, k_ra8_ssie_mask_rdf_clear, k_ra8_ssie_mask_tdc, k_ra8_ssie_shift_tdc, priv_ra8_ssie_internal_regs(), RA8_CHECK_NULL_PTR, s_tag, r_ssie_regs_t::SSIFSR, and r_ssie_regs_t::SSIFTDR.

Referenced by ra8_board_audio_play_sample_block().

◆ ra8_ssie_write_sample()

ra8_err_t ra8_ssie_write_sample ( uint8_t channel,
uint32_t sample )
nodiscard

Push one 32-bit sample into the transmit FIFO.

Performs a single 32-bit write to SSIFTDR (HUM Ch 46.2.5 p 3088). Samples wider than the configured DWL are truncated by the FIFO shift logic. Data alignment within the 32-bit word is governed by SSICR.PDTA / SSICR.SDTA.

Parameters
[in]channelChannel index (0 = SSIE0, 1 = SSIE1).
[in]sampleSample bits.
Returns
ra8_err_t error code.
Return values
k_ra8_okSample queued.
k_ra8_err_invalid_argchannel out of range.
Precondition
Channel was previously initialized.
Caller has (or accepts) FIFO space (TDE = 1).
Postcondition
One write to SSIFTDR has been issued.
No other registers are modified.
Note
Thread safety: not thread-safe.
See also
ra8_ssie_read_sample
Since
0.1.0

Definition at line 771 of file ra8_ssie.c.

References k_ra8_err_invalid_arg, k_ra8_ok, priv_ra8_ssie_internal_regs(), and r_ssie_regs_t::SSIFTDR.

Referenced by internal_ssie_loop_run().