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

Data Operation Circuit (DOC) driver implementation. More...

#include "ra8_doc.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_doc_regs.h"
#include "ra8_err.h"
#include "ra8_log.h"
#include "ra8_mstp.h"
Include dependency graph for ra8_doc.c:

Go to the source code of this file.

Functions

static void internal_ra8_doc_set_mode_16 (ra8_docr_oms_t mode)
 Write mode into DOCR.OMS[1:0], clearing DOBW for 16-bit ops.
static uint16_t internal_ra8_doc_run_16 (uint16_t seed, uint16_t operand)
 Run the 16-bit DOC operation sequence and return the result.
ra8_err_t ra8_doc_init (void)
 Reset the DOC control register to its reset state.
ra8_err_t ra8_doc_add16 (uint16_t a, uint16_t b, uint16_t *out_sum)
 Perform a 16-bit hardware add.
ra8_err_t ra8_doc_sub16 (uint16_t a, uint16_t b, uint16_t *out_diff)
 Perform a 16-bit hardware subtract.
ra8_err_t ra8_doc_set_window (uint16_t lower, uint16_t upper, ra8_doc_window_polarity_t polarity)
 Implementation of ra8_doc_set_window() – programs DOCR/DODSR0/DODSR1.
ra8_err_t ra8_doc_window_compare (uint16_t value, bool *out_flag)
 Implementation of ra8_doc_window_compare() – writes DODIR, reads DOPCF.

Variables

static const char * s_tag = "DOC"

Detailed Description

Data Operation Circuit (DOC) driver implementation.

Thin wrapper that drives the DOC_B block through its add / sub / compare modes. Register writes go through the accessor from ra8_doc_regs.h, which returns a pointer to host RAM in RA8_OFF_TARGET and a real hardware address on target.

Per HUM Ch 57.2 p 3521 the DODSR0 register holds the running accumulator AND the operand reference; DODIR is the data input register. The hardware updates DODSR0 in place: writing DODIR triggers the operation, so the sequence is:

  1. Programme DOCR with the desired mode (and DOBW=0 for 16-bit).
  2. Write the seed to DODSR0.
  3. Write the operand to DODIR – triggers the operation.
  4. Read DODSR0 to obtain the result.

Definition in file ra8_doc.c.

Function Documentation

◆ internal_ra8_doc_run_16()

uint16_t internal_ra8_doc_run_16 ( uint16_t seed,
uint16_t operand )
inlinestatic

Run the 16-bit DOC operation sequence and return the result.

Per HUM Ch 57.2.4 / 57.2.5 p 3521 the operation is triggered by writing DODIR. Writes happen at 16-bit width because DOCR.DOBW=0 (set by internal_ra8_doc_set_mode_16). The DODSR0 readback is the silicon operation engine's result. The RAM-backed host register file has no operation engine, so on the unit-test build the readback is simply the seed value: host tests assert the register trace (DOCR / DODSR0 / DODIR) instead of the arithmetic, which the doc_demo HIL app proves on silicon.

Parameters
[in]seedInitial DODSR0 value (operand A).
[in]operandDODIR value (operand B).
Returns
16-bit DODSR0 readback.
Return values
0..UINT16_MAXThe DODSR0 value after the DODIR trigger write.
Precondition
Driver state has been initialized by ra8_doc_init.
DOCR.OMS has been programmed for the desired operation.
Postcondition
DODSR0 holds the operation result.
DOCR is unchanged by this helper.
Note
Not thread-safe; caller must serialize.
Since
0.1.0

Definition at line 87 of file ra8_doc.c.

References r_doc_regs_t::DODIR, r_doc_regs_t::DODSR0, ra8_doc(), and RA8_INTERNAL.

Referenced by ra8_doc_add16(), and ra8_doc_sub16().

◆ internal_ra8_doc_set_mode_16()

void internal_ra8_doc_set_mode_16 ( ra8_docr_oms_t mode)
inlinestatic

Write mode into DOCR.OMS[1:0], clearing DOBW for 16-bit ops.

Programmes the operation-mode select bits and forces DOBW=0 (16-bit operand width per HUM Ch 57.2.1 p 3519). DCSEL is left at 0 since the 16-bit add / subtract APIs don't use compare-mode detection.

Parameters
[in]modeOperation mode to programme.
Precondition
Driver state has been initialized by ra8_doc_init.
Caller has validated all pointer parameters.
Postcondition
DOCR.OMS holds mode; DOCR.DOBW=0; DOCR.DCSEL=0.
No global state is modified on the error path.
Note
Thread safety: see the header declaration.
Since
0.1.0

Definition at line 54 of file ra8_doc.c.

References r_doc_regs_t::DOCR, ra8_doc(), and RA8_INTERNAL.

Referenced by ra8_doc_add16(), and ra8_doc_sub16().

◆ ra8_doc_add16()

ra8_err_t ra8_doc_add16 ( uint16_t a,
uint16_t b,
uint16_t * out_sum )
nodiscard

Perform a 16-bit hardware add.

Parameters
[in]aFirst operand.
[in]bSecond operand.
[out]out_sumReceives a + b (wraps mod 2^16).
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 127 of file ra8_doc.c.

References internal_ra8_doc_run_16(), internal_ra8_doc_set_mode_16(), k_ra8_doc_mode_add, k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_hw_sum().

◆ ra8_doc_init()

ra8_err_t ra8_doc_init ( void )
nodiscard

Reset the DOC control register to its reset state.

Clears DOCR, DODIR, and DODSR0. Leaves the block disabled until the first operation.

Returns
k_ra8_ok on success.
Since
0.1.0

Definition at line 103 of file ra8_doc.c.

References r_doc_regs_t::DOCR, r_doc_regs_t::DODIR, r_doc_regs_t::DODSR0, r_doc_regs_t::DODSR1, r_doc_regs_t::DOSCR, k_ra8_doc_mask_dopcfcl, k_ra8_mstp_doc, k_ra8_ok, ra8_doc(), ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.

Referenced by internal_setup_or_halt().

◆ ra8_doc_set_window()

ra8_err_t ra8_doc_set_window ( uint16_t lower,
uint16_t upper,
ra8_doc_window_polarity_t polarity )
nodiscard

◆ ra8_doc_sub16()

ra8_err_t ra8_doc_sub16 ( uint16_t a,
uint16_t b,
uint16_t * out_diff )
nodiscard

Perform a 16-bit hardware subtract.

Parameters
[in]aMinuend.
[in]bSubtrahend.
[out]out_diffReceives a - b (wraps mod 2^16).
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 136 of file ra8_doc.c.

References internal_ra8_doc_run_16(), internal_ra8_doc_set_mode_16(), k_ra8_doc_mode_subtract, k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_doc_window_compare()

ra8_err_t ra8_doc_window_compare ( uint16_t value,
bool * out_flag )
nodiscard

Implementation of ra8_doc_window_compare() – writes DODIR, reads DOPCF.

Trigger a 16-bit window comparison and return the DOPCF flag.

Definition at line 193 of file ra8_doc.c.

References r_doc_regs_t::DOCR, r_doc_regs_t::DODIR, r_doc_regs_t::DOSCR, r_doc_regs_t::DOSR, k_ra8_doc_mask_dopcf, k_ra8_doc_mask_dopcfcl, k_ra8_doc_mask_oms, k_ra8_err_invalid_state, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_doc(), ra8_log_error, and s_tag.

Variable Documentation

◆ s_tag

const char* s_tag = "DOC"
static

Definition at line 36 of file ra8_doc.c.