|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Cyclic Redundancy Check driver implementation. More...
#include "ra8_crc.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_crc_regs.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_mstp.h"Go to the source code of this file.
Enumerations | |
| enum | crc_shift_t : uint8_t { k_crc_shift_byte3 = 24U } |
| Byte-3 shift for little-endian word assembly. More... | |
| enum | ra8_crccr0_bit_t : uint8_t { k_ra8_crccr0_lms_shift = 6U , k_ra8_crccr0_dorclr_shift = 7U , k_ra8_crccr0_dorclr = 1U << 7U , k_ra8_crccr0_gps_mask = 0x07U } |
| Bit positions inside CRCCR0 (HUM Ch 48.2.1 p 3181). More... | |
| enum | ra8_crc_seed_t : uint32_t { k_ra8_crc_32bit_seed = 0xFFFFFFFFUL } |
| Standard init / xor-out value for IEEE-style 32-bit CRCs. More... | |
Functions | |
| static bool | internal_ra8_crc_is_32bit_poly (ra8_crc_poly_t poly) |
| Determine if a polynomial uses 32-bit data input. | |
| static void | internal_crc_feed_words (const uint8_t *data, uint32_t len) |
| Feed len bytes through the calculator as packed 32-bit words. | |
| static void | internal_crc_feed_bytes (const uint8_t *data, uint32_t len) |
| Feed len bytes through the calculator via the 8-bit alias. | |
| ra8_err_t | ra8_crc_init (ra8_crc_poly_t poly) |
| Configure the CRC block for a given polynomial. | |
| void | ra8_crc_reset (void) |
| Clear the running CRC state. | |
| ra8_err_t | ra8_crc_compute (const uint8_t *data, uint32_t len, uint32_t *out_crc) |
| Compute a CRC over a byte buffer. | |
| ra8_err_t | ra8_crc_deinit (void) |
| Tear down the CRC block (disable + MSTP release). | |
| ra8_err_t | ra8_crc_set_poly (ra8_crc_poly_t poly) |
| Change the CRC polynomial at runtime without a reset. | |
| ra8_err_t | ra8_crc_get_status (uint8_t *out_poly) |
| Read the current polynomial selection (CRCCR0.GPS). | |
| ra8_err_t | ra8_crc_enter_stop (void) |
| Put CRC into MSTP-gated stop. | |
| ra8_err_t | ra8_crc_exit_stop (void) |
| Exit MSTP-gated stop. | |
Variables | |
| static const char * | s_tag = "CRC" |
Cyclic Redundancy Check driver implementation.
Driver for the RA8D2 CRC block. The CRC unit accepts one of five hard-wired polynomials (CRC-8, CRC-16, CRC-CCITT, CRC-32 IEEE 802.3, CRC-32C Castagnoli) selected by CRCCR0.GPS[2:0], accumulates the running result in CRCDOR as data is written to CRCDIR/CRCDIR_BY, and can be reset between operations via the write-only CRCCR0.DORCLR bit.
Cross-verified against FSP r_crc.c (R_CRC_Open, R_CRC_Calculate, R_CRC_Close) at _reference/fsp/ra/fsp/src/ r_crc/r_crc.c. Like FSP, the driver pulses DORCLR during init to clear stale CRCDOR contents (crccr0 |= 1 << R_CRC_CRCCR0_DORCLR_Pos in R_CRC_Open) and uses byte-access CRCDIR_BY for 8/16/CCITT polynomials and 32-bit CRCDIR for 32-bit polynomials. Every register access carries a HUM Ch 48 citation (p 3180-3189).
Definition in file ra8_crc.c.
| enum crc_shift_t : uint8_t |
| enum ra8_crc_seed_t : uint32_t |
Standard init / xor-out value for IEEE-style 32-bit CRCs.
HUM Ch 48 documents the calculator core but not the init / xor-out convention – those are part of the CRC variant spec rather than the hardware. IEEE 802.3 / CRC-32 and Castagnoli / CRC-32C both use init = 0xFFFFFFFF and xor_out = 0xFFFFFFFF (per ITU-T V.42 / RFC 3385 respectively). The on-chip calculator starts CRCDOR at 0 by default, so the driver must pre-load CRCDOR with the init value before clocking data through, and XOR the read- back with the same constant on the way out.
| Enumerator | |
|---|---|
| k_ra8_crc_32bit_seed | IEEE-802.3 / Castagnoli init = xor-out. |
| enum ra8_crccr0_bit_t : uint8_t |
|
inlinestatic |
Feed len bytes through the calculator via the 8-bit alias.
HUM Ch 48.2.3 p 3182 – CRC-8 / CRC-16 / CRC-CCITT consume one byte per write through CRCDIR_BY at offset +0x04.
| [in] | data | Pointer to len bytes (non-NULL). |
| [in] | len | Byte count. |
Definition at line 149 of file ra8_crc.c.
References r_crc_regs_t::CRCDIR_BY, ra8_crc(), and RA8_INTERNAL.
Referenced by ra8_crc_compute().
|
inlinestatic |
Feed len bytes through the calculator as packed 32-bit words.
HUM Ch 48.2.3 p 3182 – for CRC-32 / CRC-32C the engine consumes 32-bit words. FSP's R_CRC_Calculate and the project's mirror loop pack four bytes little-endian into each CRCDIR write. Trailing bytes that don't form a full word are ignored (FSP behaviour and HUM Note 1 p 3180 "This function cannot divide data used in CRC calculations").
| [in] | data | Pointer to len bytes (non-NULL). |
| [in] | len | Byte count; the low two bits are ignored. |
Definition at line 118 of file ra8_crc.c.
References r_crc_regs_t::CRCDIR, k_crc_shift_byte3, ra8_crc(), and RA8_INTERNAL.
Referenced by ra8_crc_compute().
|
inlinestatic |
Determine if a polynomial uses 32-bit data input.
| [in] | poly | Polynomial selection. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
| k_ra8_ok | Success path. |
| k_ra8_err_invalid_arg | Caller violated a precondition. |
Definition at line 74 of file ra8_crc.c.
References k_ra8_crc_poly_32_ieee802_3, k_ra8_crc_poly_32c_rev, and RA8_INTERNAL.
Referenced by ra8_crc_compute().
|
nodiscard |
Compute a CRC over a byte buffer.
Feeds each byte of data into CRCDIR and reads the running result from CRCDOR at the end. The CRC unit is not reset between calls – the caller must write CRCCR1 to clear state via ra8_crc_reset() first.
| [in] | data | Pointer to bytes (not NULL). |
| [in] | len | Byte count. |
| [out] | out_crc | Receives the final result. |
Definition at line 190 of file ra8_crc.c.
References r_crc_regs_t::CRCCR0, r_crc_regs_t::CRCDOR, internal_crc_feed_bytes(), internal_crc_feed_words(), internal_ra8_crc_is_32bit_poly(), k_ra8_crc_32bit_seed, k_ra8_crccr0_gps_mask, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_crc(), and s_tag.
Referenced by crc_demo_one_iter(), and ra8_nsc_crc_compute().
|
nodiscard |
Tear down the CRC block (disable + MSTP release).
Definition at line 236 of file ra8_crc.c.
References r_crc_regs_t::CRCCR0, r_crc_regs_t::CRCCR1, k_ra8_mstp_crc, ra8_crc(), and ra8_mstp_disable().
|
nodiscard |
Put CRC into MSTP-gated stop.
Definition at line 264 of file ra8_crc.c.
References r_crc_regs_t::CRCCR0, k_ra8_mstp_crc, ra8_crc(), and ra8_mstp_disable().
|
nodiscard |
Exit MSTP-gated stop.
Definition at line 271 of file ra8_crc.c.
References k_ra8_mstp_crc, and ra8_mstp_enable().
|
nodiscard |
Read the current polynomial selection (CRCCR0.GPS).
Definition at line 256 of file ra8_crc.c.
References r_crc_regs_t::CRCCR0, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_crc(), and s_tag.
|
nodiscard |
Configure the CRC block for a given polynomial.
| [in] | poly | One of the k_ra8_crc_poly_* values. |
Definition at line 158 of file ra8_crc.c.
References r_crc_regs_t::CRCCR0, r_crc_regs_t::CRCCR1, k_ra8_crccr0_dorclr, k_ra8_mstp_crc, k_ra8_ok, ra8_crc(), ra8_log_info_val, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.
Referenced by crc_demo_setup_or_halt(), and ra8_nsc_crc_init().
| void ra8_crc_reset | ( | void | ) |
Clear the running CRC state.
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 180 of file ra8_crc.c.
References r_crc_regs_t::CRCCR0, k_ra8_crccr0_dorclr, and ra8_crc().
Referenced by crc_demo_one_iter().
|
nodiscard |
Change the CRC polynomial at runtime without a reset.
Definition at line 246 of file ra8_crc.c.
References r_crc_regs_t::CRCCR0, k_ra8_crccr0_dorclr, k_ra8_ok, and ra8_crc().