|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Interrupt-driven onboard PDM microphone recorder for camera servers. More...
#include <stdint.h>#include <string.h>#include "c6_camera_server.h"#include "ra8_attributes.h"#include "ra8_audio.h"#include "ra8_audio_source_pdm.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_err.h"#include "ra8_register_guard.h"Go to the source code of this file.
Data Structures | |
| struct | c6_cam_audio_bank_t |
| Writer position and timing metadata for one SDRAM audio bank. More... | |
Enumerations | |
| enum | c6_cam_audio_cfg_t : uint32_t { k_c6_cam_audio_rate_hz = 16000U , k_c6_cam_audio_frame_samples = 256U , k_c6_cam_audio_ring_samples = 16000U , k_c6_cam_audio_settle_ms = 300U , k_c6_cam_audio_discard = 1024U , k_c6_cam_audio_poll_attempts = 500000U , k_c6_cam_audio_irq_priority = 5U , k_c6_cam_audio_bank_count = 2U , k_c6_cam_audio_gain = 16U , k_c6_cam_wav_header_bytes = 44U , k_c6_cam_wav_sample_bytes = 2U , k_c6_cam_wav_capacity , k_c6_cam_byte_mask = 0xFFU , k_c6_cam_shift_24 = 24U , k_c6_cam_ms_per_second = 1000U , k_c6_cam_wav_riff_overhead = 36U , k_c6_cam_wav_audio_format_off = 20U , k_c6_cam_wav_channels_off = 22U , k_c6_cam_wav_byte_rate_off = 28U , k_c6_cam_wav_bits_off = 34U , k_c6_cam_wav_data_size_off = 40U } |
| Audio capture, storage, and WAV constants. More... | |
Functions | |
| static void | internal_c6_cam_audio_put_u16 (uint8_t *out, uint16_t value) |
| Write one little-endian 16-bit scalar. | |
| static void | internal_c6_cam_audio_put_u32 (uint8_t *out, uint32_t value) |
| Write one little-endian 32-bit scalar. | |
| static int16_t | internal_c6_cam_audio_s16 (int32_t sample) |
| Convert signed 20-bit PDM PCM to saturated signed 16-bit PCM. | |
| static void | internal_c6_cam_audio_on_frame (void *ctx, const ra8_audio_frame_t *frame) |
| Append one complete audio frame to the active SDRAM ring. | |
| static void | internal_c6_cam_audio_write_header (uint32_t samples) |
| Serialize the canonical mono PCM-S16LE WAV header. | |
| ra8_err_t | c6_cam_audio_start (void) |
| Start continuous MIC1 capture into the SDRAM audio ring. | |
| ra8_err_t | c6_cam_audio_snapshot_wav (const uint8_t **out_wav, uint32_t *out_bytes, uint32_t *out_timestamp_ms) |
| Snapshot the rolling microphone ring as mono PCM-S16LE WAV. | |
Variables | |
| static ra8_audio_source_t | s_audio_source |
| Fixed audio source objects and interrupt assembly scratch. | |
| static ra8_audio_source_pdm_state_t | s_audio_state |
| static int32_t | s_audio_frame [k_c6_cam_audio_frame_samples] |
| static int32_t | s_audio_ring [k_c6_cam_audio_bank_count][k_c6_cam_audio_ring_samples] |
| Ping-pong PCM rings and generated WAV live in external SDRAM. | |
| static uint8_t | s_audio_wav [k_c6_cam_wav_capacity] |
| static volatile uint8_t | s_audio_active_bank |
| Active ISR bank and per-bank metadata guarded during handoff. | |
| static c6_cam_audio_bank_t | s_audio_banks [k_c6_cam_audio_bank_count] |
| static const uint8_t | s_wav_tag_riff [] = {'R', 'I', 'F', 'F'} |
| The three fixed-width chunk tags of a canonical PCM WAV header. | |
| static const uint8_t | s_wav_tag_wavefmt [] = {'W', 'A', 'V', 'E', 'f', 'm', 't', ' '} |
| static const uint8_t | s_wav_tag_data [] = {'d', 'a', 't', 'a'} |
Interrupt-driven onboard PDM microphone recorder for camera servers.
The PDM-IF hardware continuously decimates MIC1 into 20-bit PCM. The generic ra8_audio PDM backend assembles fixed frames in interrupt context, then this module appends them to a caller-owned one-second SDRAM bank. HTTP requests atomically hand capture to the other SDRAM bank and expose the stable bank as PCM-S16LE WAV without stopping the PDM source, camera capture, or allocating memory.
Definition in file c6_cam_audio.c.
| enum c6_cam_audio_cfg_t : uint32_t |
Audio capture, storage, and WAV constants.
Definition at line 32 of file c6_cam_audio.c.
|
nodiscard |
Snapshot the rolling microphone ring as mono PCM-S16LE WAV.
Definition at line 273 of file c6_cam_audio.c.
References internal_c6_cam_audio_put_u16(), internal_c6_cam_audio_s16(), internal_c6_cam_audio_write_header(), k_c6_cam_audio_ring_samples, k_c6_cam_wav_header_bytes, k_c6_cam_wav_sample_bytes, k_ra8_err_no_data, k_ra8_err_null_ptr, k_ra8_ok, ra8_register_guard_enter(), ra8_register_guard_exit(), s_audio_active_bank, s_audio_banks, s_audio_ring, and s_audio_wav.
Referenced by internal_c6_cam_http_audio().
|
nodiscard |
Start continuous MIC1 capture into the SDRAM audio ring.
Definition at line 229 of file c6_cam_audio.c.
References ra8_board_pdm_mic_config_t::channel, internal_c6_cam_audio_on_frame(), k_c6_cam_audio_discard, k_c6_cam_audio_frame_samples, k_c6_cam_audio_irq_priority, k_c6_cam_audio_poll_attempts, k_c6_cam_audio_rate_hz, k_c6_cam_audio_settle_ms, k_ra8_board_pdm_mic1, k_ra8_err_invalid_state, k_ra8_ok, ra8_board_pdm_mic_config_t::pdm, ra8_audio_source_pdm_init(), ra8_audio_source_stop(), ra8_audio_source_stream_start(), ra8_board_pdm_mic_get_config(), ra8_board_pdm_mic_route(), s_audio_frame, s_audio_source, s_audio_state, ra8_board_pdm_mic_config_t::sample_rate_hz, and ra8_board_pdm_mic_config_t::valid_bits.
Referenced by internal_c6_cam_prepare_media().
|
static |
Append one complete audio frame to the active SDRAM ring.
Writes interrupt-delivered PCM into the selected bank and updates bounded metadata.
| [in,out] | ctx | Unused callback context. |
| [in] | frame | Borrowed PCM-S32LE audio frame. |
Definition at line 170 of file c6_cam_audio.c.
References ra8_audio_frame_t::data, ra8_audio_frame_t::format, k_c6_cam_audio_rate_hz, k_c6_cam_audio_ring_samples, k_c6_cam_ms_per_second, k_ra8_audio_format_pcm_s32le, c6_cam_audio_bank_t::oldest_timestamp_ms, RA8_INTERNAL, s_audio_active_bank, s_audio_banks, s_audio_ring, c6_cam_audio_bank_t::sample_count, ra8_audio_frame_t::sample_count, ra8_audio_frame_t::timestamp_ms, and c6_cam_audio_bank_t::write_index.
Referenced by c6_cam_audio_start().
|
static |
Write one little-endian 16-bit scalar.
Splits the value into two wire-order WAV bytes.
| [out] | out | Destination for two bytes. |
| [in] | value | Scalar to serialize. |
Definition at line 105 of file c6_cam_audio.c.
References k_c6_cam_byte_mask, and RA8_INTERNAL.
Referenced by c6_cam_audio_snapshot_wav(), and internal_c6_cam_audio_write_header().
|
static |
Write one little-endian 32-bit scalar.
Splits the value into four wire-order WAV bytes.
| [out] | out | Destination for four bytes. |
| [in] | value | Scalar to serialize. |
Definition at line 123 of file c6_cam_audio.c.
References k_c6_cam_byte_mask, k_c6_cam_shift_24, and RA8_INTERNAL.
Referenced by internal_c6_cam_audio_write_header().
|
static |
Convert signed 20-bit PDM PCM to saturated signed 16-bit PCM.
Applies fixed application gain, removes four low-significance bits, then saturates to the WAV range.
| [in] | sample | Signed sample supplied by the PDM backend. |
| INT16_MAX | The scaled input exceeded positive 16-bit range. |
| INT16_MIN | The scaled input exceeded negative 16-bit range. |
Definition at line 146 of file c6_cam_audio.c.
References k_c6_cam_audio_gain, and RA8_INTERNAL.
Referenced by c6_cam_audio_snapshot_wav().
|
static |
Serialize the canonical mono PCM-S16LE WAV header.
Writes RIFF, format, rate, alignment, and data-size fields into static storage.
| [in] | samples | Number of mono samples following the header. |
Definition at line 210 of file c6_cam_audio.c.
References internal_c6_cam_audio_put_u16(), internal_c6_cam_audio_put_u32(), k_c6_cam_audio_rate_hz, k_c6_cam_wav_audio_format_off, k_c6_cam_wav_bits_off, k_c6_cam_wav_byte_rate_off, k_c6_cam_wav_channels_off, k_c6_cam_wav_data_size_off, k_c6_cam_wav_riff_overhead, k_c6_cam_wav_sample_bytes, memcpy(), RA8_INTERNAL, s_audio_wav, s_wav_tag_data, s_wav_tag_riff, and s_wav_tag_wavefmt.
Referenced by c6_cam_audio_snapshot_wav().
|
static |
Active ISR bank and per-bank metadata guarded during handoff.
Definition at line 77 of file c6_cam_audio.c.
Referenced by c6_cam_audio_snapshot_wav(), and internal_c6_cam_audio_on_frame().
|
static |
Definition at line 78 of file c6_cam_audio.c.
Referenced by c6_cam_audio_snapshot_wav(), and internal_c6_cam_audio_on_frame().
|
static |
Definition at line 68 of file c6_cam_audio.c.
Referenced by c6_cam_audio_start().
|
static |
Ping-pong PCM rings and generated WAV live in external SDRAM.
Definition at line 73 of file c6_cam_audio.c.
Referenced by c6_cam_audio_snapshot_wav(), and internal_c6_cam_audio_on_frame().
|
static |
Fixed audio source objects and interrupt assembly scratch.
Definition at line 66 of file c6_cam_audio.c.
Referenced by c6_cam_audio_start().
|
static |
Definition at line 67 of file c6_cam_audio.c.
Referenced by c6_cam_audio_start().
|
static |
Definition at line 74 of file c6_cam_audio.c.
Referenced by c6_cam_audio_snapshot_wav(), and internal_c6_cam_audio_write_header().
|
static |
Definition at line 91 of file c6_cam_audio.c.
Referenced by internal_c6_cam_audio_write_header().
|
static |
The three fixed-width chunk tags of a canonical PCM WAV header.
Byte arrays rather than C strings, because that is what the file format is: each tag is followed immediately by a binary length or format field, so the header carries no terminator after any of them and copying one would corrupt the field that follows.
Definition at line 89 of file c6_cam_audio.c.
Referenced by internal_c6_cam_audio_write_header().
|
static |
Definition at line 90 of file c6_cam_audio.c.
Referenced by internal_c6_cam_audio_write_header().