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

DAC_B (12-bit D/A) peripheral-block model for the board emulator. More...

#include <stdint.h>
#include <stdio.h>
#include "board_console.h"
#include "board_periph_block.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_periph_dac.c:

Go to the source code of this file.

Data Structures

struct  dac_inst_t
 One DAC_B instance: register backing store + write observability. More...

Enumerations

enum  dac_console_t : uint32_t {
  k_dac_console_line_cap = 48U ,
  k_dac_console_every = 256U
}
 Console-tap sizing for DAC output summaries. More...
enum  dac_map_t : uint64_t {
  k_dac_base = 0x40233000UL ,
  k_dac_stride = 0x100UL ,
  k_dac_count = 2UL ,
  k_dac_span = 0x200UL ,
  k_dac_inst_words = 0x100UL / 4UL ,
  k_dac_off_dadr = 0x00UL ,
  k_dac_off_dacr0 = 0x04UL ,
  k_dac_off_dacr1 = 0x08UL ,
  k_dac_off_dacr2 = 0x0CUL
}
 DAC_B block geometry (ra8_dac_b_regs.h, FSP R_DAC_B0_Type). More...
enum  dac_field_t : uint32_t {
  k_dac_dadr_mask = 0x00000FFFUL ,
  k_dac_dacen_mask = 0x00000001UL
}
 DAC_B field masks. More...

Functions

static RA8_INTERNAL uint32_t internal_dac_word (uint64_t inst_off)
 Word index into an instance's backing store for an in-instance offset.
static RA8_INTERNAL uint64_t internal_dac_read (uc_engine *uc, uint64_t addr, unsigned size)
 MMIO read inside the DAC window: read back the latched register.
static RA8_INTERNAL void internal_dac_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
 MMIO write inside the DAC window: latch the value; track DADR.
static RA8_INTERNAL void internal_dac_reset (void)
 Clear both DAC_B instances' registers and observability state.
static RA8_INTERNAL void internal_dac_report (void)
 Print one line per DAC_B instance that the firmware drove.
static RA8_INTERNAL void internal_board_periph_dac_register (void)
 Self-register the DAC_B block before main runs (decentralized).

Variables

static dac_inst_t s_dac [k_dac_count]
static const board_periph_block_t s_k_dac_block
 This block's descriptor (static lifetime; the core keeps the pointer).

Detailed Description

DAC_B (12-bit D/A) peripheral-block model for the board emulator.

Models the two RA8D2 DAC_B instances (ra8_dac_b_regs.h / ra8_dac_b.c): DAC_B0 at 0x40233000 and DAC_B1 at 0x40233100 (stride 0x100). Each instance drives one 12-bit channel through a {DADR, DACR0, DACR1, DACR2} register set.

The DAC has no conversion-result readback on silicon – ra8_dac_b_write is a single 16-bit store to DADR – so this block simply accepts every register write and reads each back as written. That read-back is what matters for the driver: ra8_dac_b_init_configured / _set_output_enable do a read-modify-write of DACR0 (DACEN / DAOUTDIS), and ra8_dac_b_get_status reads DACR0.DACEN, so the control state must survive. The model additionally tracks each channel's last and peak DADR code (and a write count) purely for the end-of-run report, so a ramp/triangle demo's output sweep is observable headlessly even though there is no hardware read path.

Self-registers its descriptor with the board_periph core from a file-scope constructor; the core keeps no central block list – see board_periph_block.h.

Since
0.1.0

Definition in file board_periph_dac.c.

Enumeration Type Documentation

◆ dac_console_t

enum dac_console_t : uint32_t

Console-tap sizing for DAC output summaries.

Enumerator
k_dac_console_line_cap 

Max chars in a "DAC.. code=.." line.

k_dac_console_every 

Push 1 line per N updates (anti-flood).

Definition at line 36 of file board_periph_dac.c.

◆ dac_field_t

enum dac_field_t : uint32_t

DAC_B field masks.

Enumerator
k_dac_dadr_mask 

12-bit DADR data field.

k_dac_dacen_mask 

DACR0.DACEN channel-enable bit.

Definition at line 55 of file board_periph_dac.c.

◆ dac_map_t

enum dac_map_t : uint64_t

DAC_B block geometry (ra8_dac_b_regs.h, FSP R_DAC_B0_Type).

Enumerator
k_dac_base 

DAC_B0 base.

k_dac_stride 

Bytes between DAC_B0 and DAC_B1.

k_dac_count 

DAC_B0 / DAC_B1.

k_dac_span 

Both instances (2 x 0x100 stride).

k_dac_inst_words 

Backing words per instance.

k_dac_off_dadr 

DADR 12-bit data (16-bit reg).

k_dac_off_dacr0 

DACR0 control (DACEN/DAE/DAOUTDIS).

k_dac_off_dacr1 

DACR1 control (DPSEL).

k_dac_off_dacr2 

DACR2 control (OFSSEL).

Definition at line 42 of file board_periph_dac.c.

Function Documentation

◆ internal_board_periph_dac_register()

RA8_INTERNAL void internal_board_periph_dac_register ( void )
static

Self-register the DAC_B block before main runs (decentralized).

Definition at line 227 of file board_periph_dac.c.

References board_periph_register_block(), RA8_INTERNAL, and s_k_dac_block.

◆ internal_dac_read()

RA8_INTERNAL uint64_t internal_dac_read ( uc_engine * uc,
uint64_t addr,
unsigned size )
static

MMIO read inside the DAC window: read back the latched register.

MMIO read inside the dac window: read back the latched register; this step is contained within the board periph dac model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
Returns
The dac read result produced by the board periph dac model.
Return values
valueThe operation-specific dac read value.
Precondition
Arguments satisfy the ranges documented for dac read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph dac model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 99 of file board_periph_dac.c.

References internal_dac_word(), k_dac_base, k_dac_count, k_dac_stride, RA8_INTERNAL, and s_dac.

◆ internal_dac_report()

RA8_INTERNAL void internal_dac_report ( void )
static

Print one line per DAC_B instance that the firmware drove.

Print one line per dac_b instance that the firmware drove; this step is contained within the board periph dac model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for dac report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph dac model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 195 of file board_periph_dac.c.

References internal_dac_word(), k_dac_count, k_dac_dacen_mask, k_dac_off_dacr0, priv_emu_io_errf(), RA8_INTERNAL, and s_dac.

◆ internal_dac_reset()

RA8_INTERNAL void internal_dac_reset ( void )
static

Clear both DAC_B instances' registers and observability state.

Clear both dac_b instances' registers and observability state; this step is contained within the board periph dac model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for dac reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph dac model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 180 of file board_periph_dac.c.

References k_dac_count, RA8_INTERNAL, and s_dac.

◆ internal_dac_word()

RA8_INTERNAL uint32_t internal_dac_word ( uint64_t inst_off)
static

Word index into an instance's backing store for an in-instance offset.

Word index into an instance's backing store for an in-instance offset; this step is contained within the board periph dac model and uses bounded caller or module-owned storage.

Parameters
[in]inst_offInst off input used by the operation.
Returns
The dac word result produced by the board periph dac model.
Return values
valueThe operation-specific dac word value.
Precondition
Arguments satisfy the ranges documented for dac word.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph dac model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 81 of file board_periph_dac.c.

References RA8_INTERNAL.

Referenced by internal_dac_read(), internal_dac_report(), and internal_dac_write().

◆ internal_dac_write()

RA8_INTERNAL void internal_dac_write ( uc_engine * uc,
uint64_t addr,
unsigned size,
uint64_t value )
static

MMIO write inside the DAC window: latch the value; track DADR.

MMIO write inside the dac window: latch the value; track dadr; this step is contained within the board periph dac model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for dac write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph dac model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 128 of file board_periph_dac.c.

References board_console_push(), board_periph_trace(), internal_dac_word(), k_board_console_ch_dac, k_dac_base, k_dac_console_every, k_dac_console_line_cap, k_dac_count, k_dac_dadr_mask, k_dac_off_dadr, k_dac_stride, priv_emu_io_errf(), and s_dac.

Variable Documentation

◆ s_dac

◆ s_k_dac_block

const board_periph_block_t s_k_dac_block
static
Initial value:
= {
.base = (uint64_t)k_dac_base,
.span = (uint64_t)k_dac_span,
.order = (uint32_t)k_block_order_i2c,
.tick = nullptr,
.name = "DAC_B",
}
@ k_block_order_i2c
I3C/I2C + GT911 (no tick today).
static RA8_INTERNAL void internal_dac_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write inside the DAC window: latch the value; track DADR.
static RA8_INTERNAL void internal_dac_reset(void)
Clear both DAC_B instances' registers and observability state.
static RA8_INTERNAL uint64_t internal_dac_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read inside the DAC window: read back the latched register.
@ k_dac_span
Both instances (2 x 0x100 stride).
@ k_dac_base
DAC_B0 base.
static RA8_INTERNAL void internal_dac_report(void)
Print one line per DAC_B instance that the firmware drove.
-proof

This block's descriptor (static lifetime; the core keeps the pointer).

Definition at line 214 of file board_periph_dac.c.

Referenced by internal_board_periph_dac_register().