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

CRC calculator peripheral-block model for the board emulator. More...

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

Go to the source code of this file.

Data Structures

struct  crc_state_t
 CRC register state. More...

Enumerations

enum  crc_lit_t : uint32_t {
  k_u32_all = 0xFFFFFFFFU ,
  k_u16_mask = 0xFFFFU ,
  k_byte_mask = 0xFFU
}
 Bit-width masks for the CRC unit model. More...
enum  crc_map_t : uint64_t {
  k_crc_base = 0x40310000UL ,
  k_crc_span = 0x20UL ,
  k_crc_off_cr0 = 0x00UL ,
  k_crc_off_cr1 = 0x01UL ,
  k_crc_off_dir = 0x04UL ,
  k_crc_off_dor = 0x08UL
}
 CRC block geometry (ra8_crc_regs.h). More...
enum  crc_cr0_field_t : uint32_t {
  k_crc_gps_mask = 0x07U ,
  k_crc_dorclr = 0x80U
}
 CRCCR0 fields (ra8_crc_regs.h). More...
enum  crc_gps_t : uint32_t {
  k_crc_gps_8 = 1U ,
  k_crc_gps_16 = 2U ,
  k_crc_gps_ccitt = 3U ,
  k_crc_gps_32 = 4U ,
  k_crc_gps_32c = 5U
}
 GPS polynomial encodings (CRCCR0.GPS). More...
enum  crc_poly_refl_t : uint32_t {
  k_crc_poly_16_refl = 0x0000A001U ,
  k_crc_poly_32_refl = 0xEDB88320U ,
  k_crc_poly_32c_refl = 0x82F63B78U
}
 Reflected (LSB-first) polynomials for the reflected GPS modes. More...
enum  crc_poly_fwd_t : uint32_t {
  k_crc_poly_8_fwd = 0x00000007U ,
  k_crc_poly_ccitt_fwd = 0x00001021U
}
 MSB-first polynomials for the non-reflected GPS modes. More...
enum  crc_order_t : uint32_t { k_crc_block_order = 140U }
 Per-tick order slot for the CRC block (relative order only). More...

Functions

static RA8_INTERNAL uint32_t internal_crc_step_reflected (uint32_t crc, uint8_t byte, uint32_t poly)
 Fold one byte into a reflected (LSB-first) CRC of any width.
static RA8_INTERNAL uint32_t internal_crc_step_forward (uint32_t crc, uint8_t byte, uint32_t poly, uint32_t width)
 Fold one byte into an MSB-first CRC of width bits.
static RA8_INTERNAL void internal_crc_fold_byte (uint8_t byte)
 Fold one input byte into CRCDOR using the CRCCR0.GPS polynomial.
static RA8_INTERNAL void internal_crc_reset (void)
 Reset the CRC unit to power-on state.
static RA8_INTERNAL uint64_t internal_crc_read (uc_engine *uc, uint64_t addr, unsigned size)
 MMIO read inside the CRC window.
static RA8_INTERNAL void internal_crc_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
 MMIO write inside the CRC window.
static RA8_INTERNAL void internal_crc_report (void)
 End-of-run CRC section: last result + bytes folded.
static RA8_INTERNAL void internal_crc_block_register (void)
 Register the CRC block before main (host constructor).

Variables

static crc_state_t s_crc
static const board_periph_block_t s_k_crc_block
 CRC block descriptor (self-registered with the core).

Detailed Description

CRC calculator peripheral-block model for the board emulator.

Models the RA8D2 CRC unit (ra8_crc_regs.h, ra8_crc.c) at 0x40310000 so crc_demo's hardware CRC matches its software reference (it printed "crc: hw=00000000 ... match=N" against the sparse fallback, which returned a constant 0). The unit is a single running-remainder register CRCDOR fed one byte at a time through CRCDIR; this model reproduces that:

  • CRCDIR (+0x04, write): each byte of the written value is folded into CRCDOR with the polynomial CRCCR0.GPS selects. A 32-bit access (CRC-32 / CRC-32C) folds four bytes LSB-first – the order ra8_crc's word feed produces – and an 8-bit access (CRC-8 / 16 / CCITT) folds one byte.
  • CRCDOR (+0x08, read/write): the running remainder. Writable so the driver can pre-seed it (CRC-32 / 32C seed 0xFFFFFFFF and XOR the readback in software; the hardware applies neither). CRCCR0.DORCLR clears it.
  • CRCCR0 (+0x00): GPS[2:0] polynomial select, LMS bit-order, DORCLR.

Reflection follows the RA8D2 polynomial definitions: CRC-32 / CRC-32C and the reflected CRC-16 fold LSB-first; CRC-8 and CRC-CCITT fold MSB-first. Only the CRC-32 path is exercised by an in-tree example (crc_demo, where it now reads match=Y); the others use their standard parameters.

Since
0.1.0

Definition in file board_periph_crc.c.

Enumeration Type Documentation

◆ crc_cr0_field_t

enum crc_cr0_field_t : uint32_t

CRCCR0 fields (ra8_crc_regs.h).

Enumerator
k_crc_gps_mask 

GPS[2:0] polynomial select.

k_crc_dorclr 

DORCLR: clear CRCDOR (bit 7).

Definition at line 55 of file board_periph_crc.c.

◆ crc_gps_t

enum crc_gps_t : uint32_t

GPS polynomial encodings (CRCCR0.GPS).

Enumerator
k_crc_gps_8 

CRC-8 (X^8+X^2+X+1).

k_crc_gps_16 

CRC-16 (X^16+X^15+X^2+1).

k_crc_gps_ccitt 

CRC-CCITT (X^16+X^12+X^5+1).

k_crc_gps_32 

CRC-32 (IEEE 802.3).

k_crc_gps_32c 

CRC-32C (Castagnoli).

Definition at line 61 of file board_periph_crc.c.

◆ crc_lit_t

enum crc_lit_t : uint32_t

Bit-width masks for the CRC unit model.

Enumerator
k_u32_all 

32-bit all-ones.

k_u16_mask 

16-bit mask.

k_byte_mask 

8-bit mask.

Definition at line 38 of file board_periph_crc.c.

◆ crc_map_t

enum crc_map_t : uint64_t

CRC block geometry (ra8_crc_regs.h).

Enumerator
k_crc_base 

CRC base (HUM Ch 48).

k_crc_span 

Register window.

k_crc_off_cr0 

CRCCR0 (GPS/LMS/DORCLR), 8b.

k_crc_off_cr1 

CRCCR1 (snoop), 8b.

k_crc_off_dir 

CRCDIR / CRCDIR_BY data in.

k_crc_off_dor 

CRCDOR result (32b).

Definition at line 45 of file board_periph_crc.c.

◆ crc_order_t

enum crc_order_t : uint32_t

Per-tick order slot for the CRC block (relative order only).

Enumerator
k_crc_block_order 

After the existing blocks; report order.

Definition at line 83 of file board_periph_crc.c.

◆ crc_poly_fwd_t

enum crc_poly_fwd_t : uint32_t

MSB-first polynomials for the non-reflected GPS modes.

Enumerator
k_crc_poly_8_fwd 

CRC-8 X^8+X^2+X+1.

k_crc_poly_ccitt_fwd 

CRC-CCITT.

Definition at line 77 of file board_periph_crc.c.

◆ crc_poly_refl_t

enum crc_poly_refl_t : uint32_t

Reflected (LSB-first) polynomials for the reflected GPS modes.

Enumerator
k_crc_poly_16_refl 

Reflected 0x8005.

k_crc_poly_32_refl 

Reflected 0x04C11DB7.

k_crc_poly_32c_refl 

Reflected 0x1EDC6F41.

Definition at line 70 of file board_periph_crc.c.

Function Documentation

◆ internal_crc_block_register()

RA8_INTERNAL void internal_crc_block_register ( void )
static

Register the CRC block before main (host constructor).

Definition at line 318 of file board_periph_crc.c.

References board_periph_register_block(), RA8_INTERNAL, and s_k_crc_block.

◆ internal_crc_fold_byte()

RA8_INTERNAL void internal_crc_fold_byte ( uint8_t byte)
static

Fold one input byte into CRCDOR using the CRCCR0.GPS polynomial.

Fold one input byte into crcdor using the crccr0.gps polynomial; this step is contained within the board periph CRC model and uses bounded caller or module-owned storage.

Parameters
[in]byteOne data byte received from or sent to the emulated interface.
Precondition
Arguments satisfy the ranges documented for CRC fold byte.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph CRC 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 158 of file board_periph_crc.c.

References internal_crc_step_forward(), internal_crc_step_reflected(), k_crc_gps_16, k_crc_gps_32, k_crc_gps_32c, k_crc_gps_8, k_crc_gps_ccitt, k_crc_gps_mask, k_crc_poly_16_refl, k_crc_poly_32_refl, k_crc_poly_32c_refl, k_crc_poly_8_fwd, k_crc_poly_ccitt_fwd, RA8_INTERNAL, and s_crc.

Referenced by internal_crc_write().

◆ internal_crc_read()

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

MMIO read inside the CRC window.

MMIO read inside the crc window; this step is contained within the board periph CRC 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 CRC read result produced by the board periph CRC model.
Return values
valueThe operation-specific CRC read value.
Precondition
Arguments satisfy the ranges documented for CRC read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph CRC 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 211 of file board_periph_crc.c.

References k_crc_base, k_crc_off_cr0, k_crc_off_cr1, k_crc_off_dor, RA8_INTERNAL, and s_crc.

◆ internal_crc_report()

RA8_INTERNAL void internal_crc_report ( void )
static

End-of-run CRC section: last result + bytes folded.

End-of-run crc section: last result + bytes folded; this step is contained within the board periph CRC model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for CRC report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph CRC 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 293 of file board_periph_crc.c.

References k_crc_gps_mask, priv_emu_io_errf(), RA8_INTERNAL, and s_crc.

◆ internal_crc_reset()

RA8_INTERNAL void internal_crc_reset ( void )
static

Reset the CRC unit to power-on state.

Reset the crc unit to power-on state; this step is contained within the board periph CRC model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for CRC reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph CRC 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 190 of file board_periph_crc.c.

References RA8_INTERNAL, and s_crc.

◆ internal_crc_step_forward()

RA8_INTERNAL uint32_t internal_crc_step_forward ( uint32_t crc,
uint8_t byte,
uint32_t poly,
uint32_t width )
static

Fold one byte into an MSB-first CRC of width bits.

Fold one byte into an msb-first crc of width bits; this step is contained within the board periph CRC model and uses bounded caller or module-owned storage.

Parameters
[in]crcCrc input used by the operation.
[in]byteOne data byte received from or sent to the emulated interface.
[in]polyPoly input used by the operation.
[in]widthWidth of the affected region in pixels.
Returns
The CRC step forward result produced by the board periph CRC model.
Return values
valueThe operation-specific CRC step forward value.
Precondition
Arguments satisfy the ranges documented for CRC step forward.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph CRC 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 134 of file board_periph_crc.c.

References k_u32_all.

Referenced by internal_crc_fold_byte().

◆ internal_crc_step_reflected()

RA8_INTERNAL uint32_t internal_crc_step_reflected ( uint32_t crc,
uint8_t byte,
uint32_t poly )
static

Fold one byte into a reflected (LSB-first) CRC of any width.

Fold one byte into a reflected (lsb-first) crc of any width; this step is contained within the board periph CRC model and uses bounded caller or module-owned storage.

Parameters
[in]crcCrc input used by the operation.
[in]byteOne data byte received from or sent to the emulated interface.
[in]polyPoly input used by the operation.
Returns
The CRC step reflected result produced by the board periph CRC model.
Return values
valueThe operation-specific CRC step reflected value.
Precondition
Arguments satisfy the ranges documented for CRC step reflected.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph CRC 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 110 of file board_periph_crc.c.

References RA8_INTERNAL.

Referenced by internal_crc_fold_byte().

◆ internal_crc_write()

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

MMIO write inside the CRC window.

MMIO write inside the crc window; this step is contained within the board periph CRC 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 CRC write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph CRC 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 243 of file board_periph_crc.c.

References internal_crc_fold_byte(), k_byte_mask, k_crc_base, k_crc_dorclr, k_crc_off_cr0, k_crc_off_cr1, k_crc_off_dir, k_crc_off_dor, k_u16_mask, and s_crc.

Variable Documentation

◆ s_crc

◆ s_k_crc_block

const board_periph_block_t s_k_crc_block
static
Initial value:
= {
.base = (uint32_t)k_crc_base,
.span = (uint32_t)k_crc_span,
.order = (uint32_t)k_crc_block_order,
.tick = nullptr,
.name = "CRC",
}
static RA8_INTERNAL void internal_crc_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write inside the CRC window.
@ k_crc_base
CRC base (HUM Ch 48).
@ k_crc_span
Register window.
static RA8_INTERNAL void internal_crc_report(void)
End-of-run CRC section: last result + bytes folded.
static RA8_INTERNAL void internal_crc_reset(void)
Reset the CRC unit to power-on state.
static RA8_INTERNAL uint64_t internal_crc_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read inside the CRC window.
@ k_crc_block_order
After the existing blocks; report order.
-proof

CRC block descriptor (self-registered with the core).

Definition at line 305 of file board_periph_crc.c.

Referenced by internal_crc_block_register().