"""Component for the Link ECC interface in LPDDR5 architectures."""

# Copyright (c) 2025 Linus Held. All rights reserved.

from ...core import Base, BasicEvent, CoverageBlock, PipelineBlock
from ...interfaces import FaultType


class LinkEcc(Base):
    """Component for the Link ECC interface.

    This block models the transmission errors on the interface (Source) and
    the corresponding Error Correction Code (Coverage) that mitigates these errors.
    """

    def __init__(self, name: str):
        """Initializes the LinkEcc component.

        Args:
            name (str): The descriptive name of the component.
        """
        self.sbe_if_source_rate = 5.050

        self.sbe_if_dc_residual = 1.0
        self.sbe_if_dc_latent = 1.0

        super().__init__(name)

    def configure_blocks(self):
        """Configures the root block as a sequential pipeline.

        Using a PipelineBlock ensures that the faults generated by the BasicEvent (Source)
        are immediately processed by the CoverageBlock (ECC).
        """
        self.root_block = PipelineBlock(
            self.name,
            [
                BasicEvent(FaultType.SBE, self.sbe_if_source_rate, is_spfm=True),
                CoverageBlock(
                    FaultType.SBE,
                    self.sbe_if_dc_residual,
                    dc_rate_latent_cL=self.sbe_if_dc_latent,
                    is_spfm=True,
                ),
            ],
        )
