/*******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized. This
* software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
* Copyright 2025 Renesas Electronics Corporation All rights reserved.
*******************************************************************************/

/*******************************************************************************
 * DESCRIPTION   : ECM initialize function
 ******************************************************************************/
/******************************************************************************
 * @file          ecm_enable_v4h.c
 * - Version      : 0.01
 * @brief         ECM setting.
 * .
 *****************************************************************************/
/******************************************************************************
 * History : DD.MM.YYYY Version  Description
 *         : 29.01.2025 0.01     First Release
 *****************************************************************************/

#include <stdint.h>
#include "ecm_enable_v4h.h"

#if (ECM_ERROR_ENABLE == 1)
#include "log.h"
#endif /* ECM_ERROR_ENABLE == 1 */
#if ((ECM_ERROR_ENABLE == 1) || (ECM_ENABLE == 1))
#include "ecc_enable_v4h.h"
#include "mem_io.h"
#endif /* (ECM_ERROR_ENABLE == 1) || (ECM_ENABLE == 1) */

#if (ECM_ERROR_ENABLE == 1)
#define TYPE1_ECM_REG_MAX       (13U)
#define TYPE2_ECM_REG_MAX       (22U)
#define TYPE3_ECM_CTLREG_MAX    (1U)
#define TYPE3_ECM_TGTREG_MAX    (2U)

typedef struct{
    uint32_t phys_addr; /* Physical address of ECM registers. */
    uint32_t value;     /* Setting value of ECM registers. */
} ECM_ERROR_TABLE;
#endif /* ECM_ERROR_ENABLE == 1 */

#if ((ECM_ERROR_ENABLE == 1) || (ECM_ENABLE == 1))
void ecm_unlock(void)
{
    mem_write32(ECMWPCNTR, 0xACCE0001U);
}

void ecm_write(uint32_t adr, uint32_t val)
{
    mem_write32(ECMWACNTR, ((0xACCEU << 16U) | (adr & 0xffffU)));
    mem_write32(adr, val);
}

void ecm_lock(void)
{
    mem_write32(ECMWPCNTR, 0xACCE0000U);
}
#endif /* (ECM_ERROR_ENABLE == 1) || (ECM_ENABLE == 1) */

#if (ECM_ERROR_ENABLE == 1)
void ecm_init_setting(void)
{
    uint32_t reg;
    uint32_t loop;

    const ECM_ERROR_TABLE ecmerrctlr_type1_tbl[TYPE1_ECM_REG_MAX] = {
    [0]   =     {0xFD850000U, 0x00381000U},    /* ECMERRCTLR0 */
    [1]   =     {0xFD850004U, 0xA400C000U},    /* ECMERRCTLR1 */
        /* Skip ECMERRCTLR2 setting */
        /* Skip ECMERRCTLR3 setting */
        /* Skip ECMERRCTLR4 setting */
        /* Skip ECMERRCTLR5 setting */
    [2]   =     {0xFD850018U, 0xCC000000U},    /* ECMERRCTLR6 */
    [3]   =     {0xFD85001CU, 0x0C000000U},    /* ECMERRCTLR7 */
        /* Skip ECMERRCTLR8 setting */
        /* Skip ECMERRCTLR9 setting */
        /* Skip ECMERRCTLR10 setting */
        /* Skip ECMERRCTLR11 setting */
        /* Skip ECMERRCTLR12 setting */
        /* Skip ECMERRCTLR13 setting */
        /* Skip ECMERRCTLR14 setting */
        /* Skip ECMERRCTLR15 setting */
        /* Skip ECMERRCTLR16 setting */
    [4]   =     {0xFD850044U, 0x2D000000U},    /* ECMERRCTLR17 */
    [5]   =     {0xFD850048U, 0x0EC0003FU},    /* ECMERRCTLR18 */
    [6]   =     {0xFD85004CU, 0x00FFFF08U},    /* ECMERRCTLR19 */
    [7]   =     {0xFD850050U, 0x0000001EU},    /* ECMERRCTLR20 */
    [8]   =     {0xFD850054U, 0x9F800000U},    /* ECMERRCTLR21 */
        /* Skip ECMERRCTLR22 setting */
        /* Skip ECMERRCTLR23 setting */
        /* Skip ECMERRCTLR24 setting */
        /* Skip ECMERRCTLR25 setting */
        /* Skip ECMERRCTLR26 setting */
        /* Skip ECMERRCTLR27 setting */
        /* Skip ECMERRCTLR28 setting */
        /* Skip ECMERRCTLR29 setting */
        /* Skip ECMERRCTLR30 setting */
        /* Skip ECMERRCTLR31 setting */
        /* Skip ECMERRCTLR32 setting */
        /* Skip ECMERRCTLR33 setting */
        /* Skip ECMERRCTLR34 setting */
    [9]   =     {0xFD85008CU, 0x300003C0U},    /* ECMERRCTLR35 */
        /* Skip ECMERRCTLR36 setting */
        /* Skip ECMERRCTLR37 setting */
    [10]  =     {0xFD850098U, 0x33300054U},    /* ECMERRCTLR38 */
        /* Skip ECMERRCTLR39 setting */
        /* Skip ECMERRCTLR40 setting */
    [11]  =     {0xFD8500A4U, 0x01000880U},    /* ECMERRCTLR41 */
    [12]  =     {0xFD8500A8U, 0x00040020U},    /* ECMERRCTLR42 */
    };

    const ECM_ERROR_TABLE ecmerrtgtr_type1_tbl[TYPE1_ECM_REG_MAX] = {
    [0]   =     {0xFD850200U, 0x00381000U},    /* ECMERRTGTR0 */
    [1]   =     {0xFD850204U, 0xA400C000U},    /* ECMERRTGTR1 */
        /* Skip ECMERRTGTR2 setting */
        /* Skip ECMERRTGTR3 setting */
        /* Skip ECMERRTGTR4 setting */
        /* Skip ECMERRTGTR5 setting */
    [2]   =     {0xFD850218U, 0xCC000000U},    /* ECMERRTGTR6 */
    [3]   =     {0xFD85021CU, 0x0C000000U},    /* ECMERRTGTR7 */
        /* Skip ECMERRTGTR8 setting */
        /* Skip ECMERRTGTR9 setting */
        /* Skip ECMERRTGTR10 setting */
        /* Skip ECMERRTGTR11 setting */
        /* Skip ECMERRTGTR12 setting */
        /* Skip ECMERRTGTR13 setting */
        /* Skip ECMERRTGTR14 setting */
        /* Skip ECMERRTGTR15 setting */
        /* Skip ECMERRTGTR16 setting */
    [4]   =     {0xFD850244U, 0x2D000000U},    /* ECMERRTGTR17 */
    [5]   =     {0xFD850248U, 0x0EC0003FU},    /* ECMERRTGTR18 */
    [6]   =     {0xFD85024CU, 0x00FFFF08U},    /* ECMERRTGTR19 */
    [7]   =     {0xFD850250U, 0x0000001EU},    /* ECMERRTGTR20 */
    [8]   =     {0xFD850254U, 0x9F800000U},    /* ECMERRTGTR21 */
        /* Skip ECMERRTGTR22 setting */
        /* Skip ECMERRTGTR23 setting */
        /* Skip ECMERRTGTR24 setting */
        /* Skip ECMERRTGTR25 setting */
        /* Skip ECMERRTGTR26 setting */
        /* Skip ECMERRTGTR27 setting */
        /* Skip ECMERRTGTR28 setting */
        /* Skip ECMERRTGTR29 setting */
        /* Skip ECMERRTGTR30 setting */
        /* Skip ECMERRTGTR31 setting */
        /* Skip ECMERRTGTR32 setting */
        /* Skip ECMERRTGTR33 setting */
        /* Skip ECMERRTGTR34 setting */
    [9]   =     {0xFD85028CU, 0x300003C0U},    /* ECMERRTGTR35 */
        /* Skip ECMERRTGTR36 setting */
        /* Skip ECMERRTGTR37 setting */
    [10]  =     {0xFD850298U, 0x33300054U},    /* ECMERRTGTR38 */
        /* Skip ECMERRTGTR39 setting */
        /* Skip ECMERRTGTR40 setting */
    [11]  =     {0xFD8502A4U, 0x01000880U},    /* ECMERRTGTR41 */
    [12]  =     {0xFD8502A8U, 0x00040020U},    /* ECMERRTGTR42 */
    };

    const ECM_ERROR_TABLE ecmerrctlr_type2_tbl[TYPE2_ECM_REG_MAX] = {
    [0]   =     {0xFD850000U, 0x4000000FU},    /* ECMERRCTLR0 */
    [1]   =     {0xFD850004U, 0x1C004000U},    /* ECMERRCTLR1 */
    [2]   =     {0xFD850008U, 0xFFFFFFFFU},    /* ECMERRCTLR2 */
    [3]   =     {0xFD85000CU, 0xFFFFFFFFU},    /* ECMERRCTLR3 */
    [4]   =     {0xFD850010U, 0xFFFFFFFFU},    /* ECMERRCTLR4 */
    [5]   =     {0xFD850014U, 0xC1FFFFFFU},    /* ECMERRCTLR5 */
    [6]   =     {0xFD850018U, 0x15000A80U},    /* ECMERRCTLR6 */
    [7]   =     {0xFD85001CU, 0x00803481U},    /* ECMERRCTLR7 */
        /* Skip ECMERRCTLR8 setting */
        /* Skip ECMERRCTLR9 setting */
        /* Skip ECMERRCTLR10 setting */
        /* Skip ECMERRCTLR11 setting */
        /* Skip ECMERRCTLR12 setting */
        /* Skip ECMERRCTLR13 setting */
        /* Skip ECMERRCTLR14 setting */
        /* Skip ECMERRCTLR15 setting */
    [8]   =     {0xFD850040U, 0x00003E9FU},    /* ECMERRCTLR16 */
    [9]   =     {0xFD850044U, 0x00938060U},    /* ECMERRCTLR17 */
    [10]  =     {0xFD850048U, 0x003C1FC0U},    /* ECMERRCTLR18 */
    [11]  =     {0xFD85004CU, 0xFF0000F0U},    /* ECMERRCTLR19 */
    [12]  =     {0xFD850050U, 0x02222220U},    /* ECMERRCTLR20 */
    [13]  =     {0xFD850054U, 0x0061BE0FU},    /* ECMERRCTLR21 */
        /* Skip ECMERRCTLR22 setting */
        /* Skip ECMERRCTLR23 setting */
        /* Skip ECMERRCTLR24 setting */
        /* Skip ECMERRCTLR25 setting */
        /* Skip ECMERRCTLR26 setting */
        /* Skip ECMERRCTLR27 setting */
        /* Skip ECMERRCTLR28 setting */
        /* Skip ECMERRCTLR29 setting */
        /* Skip ECMERRCTLR30 setting */
        /* Skip ECMERRCTLR31 setting */
    [14]  =     {0xFD850080U, 0x03E9043BU},    /* ECMERRCTLR32 */
    [15]  =     {0xFD850084U, 0x03E9043BU},    /* ECMERRCTLR33 */
        /* Skip ECMERRCTLR34 setting */
    [16]  =     {0xFD85008CU, 0xC3F00C00U},    /* ECMERRCTLR35 */
    [17]  =     {0xFD850090U, 0xFFFFFFFFU},    /* ECMERRCTLR36 */
        /* Skip ECMERRCTLR37 setting */
    [18]  =     {0xFD850098U, 0x00000002U},    /* ECMERRCTLR38 */
        /* Skip ECMERRCTLR39 setting */
    [19]  =     {0xFD8500A0U, 0x000067FEU},    /* ECMERRCTLR40 */
    [20]  =     {0xFD8500A4U, 0x20010000U},    /* ECMERRCTLR41 */
    [21]  =     {0xFD8500A8U, 0x00800400U},    /* ECMERRCTLR42 */
    };

    const ECM_ERROR_TABLE ecmerrtgtr_type2_tbl[TYPE2_ECM_REG_MAX] = {
    [0]   =     {0xFD850200U, 0x4000000FU},    /* ECMERRTGTR0 */
    [1]   =     {0xFD850204U, 0x1C004000U},    /* ECMERRTGTR1 */
    [2]   =     {0xFD850208U, 0xFFFFFFFFU},    /* ECMERRTGTR2 */
    [3]   =     {0xFD85020CU, 0xFFFFFFFFU},    /* ECMERRTGTR3 */
    [4]   =     {0xFD850210U, 0xFFFFFFFFU},    /* ECMERRTGTR4 */
    [5]   =     {0xFD850214U, 0xC1FFFFFFU},    /* ECMERRTGTR5 */
    [6]   =     {0xFD850218U, 0x15000A80U},    /* ECMERRTGTR6 */
    [7]   =     {0xFD85021CU, 0x00803481U},    /* ECMERRTGTR7 */
        /* Skip ECMERRTGTR8 setting */
        /* Skip ECMERRTGTR9 setting */
        /* Skip ECMERRTGTR10 setting */
        /* Skip ECMERRTGTR11 setting */
        /* Skip ECMERRTGTR12 setting */
        /* Skip ECMERRTGTR13 setting */
        /* Skip ECMERRTGTR14 setting */
        /* Skip ECMERRTGTR15 setting */
    [8]   =     {0xFD850240U, 0x00003E9FU},    /* ECMERRTGTR16 */
    [9]   =     {0xFD850244U, 0x00938060U},    /* ECMERRTGTR17 */
    [10]  =     {0xFD850248U, 0x003C1FC0U},    /* ECMERRTGTR18 */
    [11]  =     {0xFD85024CU, 0xFF0000F0U},    /* ECMERRTGTR19 */
    [12]  =     {0xFD850250U, 0x02222220U},    /* ECMERRTGTR20 */
    [13]  =     {0xFD850254U, 0x0061BE0FU},    /* ECMERRTGTR21 */
        /* Skip ECMERRTGTR22 setting */
        /* Skip ECMERRTGTR23 setting */
        /* Skip ECMERRTGTR24 setting */
        /* Skip ECMERRTGTR25 setting */
        /* Skip ECMERRTGTR26 setting */
        /* Skip ECMERRTGTR27 setting */
        /* Skip ECMERRTGTR28 setting */
        /* Skip ECMERRTGTR29 setting */
        /* Skip ECMERRTGTR30 setting */
        /* Skip ECMERRTGTR31 setting */
    [14]  =     {0xFD850280U, 0x03E9043BU},    /* ECMERRTGTR32 */
    [15]  =     {0xFD850284U, 0x03E9043BU},    /* ECMERRTGTR33 */
        /* Skip ECMERRTGTR34 setting */
    [16]  =     {0xFD85028CU, 0xC3F00C00U},    /* ECMERRTGTR35 */
    [17]  =     {0xFD850290U, 0xFFFFFFFFU},    /* ECMERRTGTR36 */
        /* Skip ECMERRTGTR37 setting */
    [18]  =     {0xFD850298U, 0x00000002U},    /* ECMERRTGTR38 */
        /* Skip ECMERRTGTR39 setting */
    [19]  =     {0xFD8502A0U, 0x000067FEU},    /* ECMERRTGTR40 */
    [20]  =     {0xFD8502A4U, 0x20010000U},    /* ECMERRTGTR41 */
    [21]  =     {0xFD8502A8U, 0x00800400U},    /* ECMERRTGTR42 */
    };

    const ECM_ERROR_TABLE ecmerrctlr_type3_tbl[TYPE3_ECM_CTLREG_MAX] = {
        /* Skip ECMERRCTLR0 setting */
        /* Skip ECMERRCTLR1 setting */
        /* Skip ECMERRCTLR2 setting */
        /* Skip ECMERRCTLR3 setting */
        /* Skip ECMERRCTLR4 setting */
        /* Skip ECMERRCTLR5 setting */
        /* Skip ECMERRCTLR6 setting */
        /* Skip ECMERRCTLR7 setting */
        /* Skip ECMERRCTLR8 setting */
        /* Skip ECMERRCTLR9 setting */
        /* Skip ECMERRCTLR10 setting */
        /* Skip ECMERRCTLR11 setting */
        /* Skip ECMERRCTLR12 setting */
        /* Skip ECMERRCTLR13 setting */
        /* Skip ECMERRCTLR14 setting */
        /* Skip ECMERRCTLR15 setting */
    [0]   =     {0xFD850040U, 0x3FFFC000U},    /* ECMERRCTLR16 */
        /* Skip ECMERRCTLR17 setting */
        /* Skip ECMERRCTLR18 setting */
        /* Skip ECMERRCTLR19 setting */
        /* Skip ECMERRCTLR20 setting */
        /* Skip ECMERRCTLR21 setting */
        /* Skip ECMERRCTLR22 setting */
        /* Skip ECMERRCTLR23 setting */
        /* Skip ECMERRCTLR24 setting */
        /* Skip ECMERRCTLR25 setting */
        /* Skip ECMERRCTLR26 setting */
        /* Skip ECMERRCTLR27 setting */
        /* Skip ECMERRCTLR28 setting */
        /* Skip ECMERRCTLR29 setting */
        /* Skip ECMERRCTLR30 setting */
        /* Skip ECMERRCTLR31 setting */
        /* Skip ECMERRCTLR32 setting */
        /* Skip ECMERRCTLR33 setting */
        /* Skip ECMERRCTLR34 setting */
        /* Skip ECMERRCTLR35 setting */
        /* Skip ECMERRCTLR36 setting */
        /* Skip ECMERRCTLR37 setting */
        /* Skip ECMERRCTLR38 setting */
        /* Skip ECMERRCTLR39 setting */
        /* Skip ECMERRCTLR40 setting */
        /* Skip ECMERRCTLR41 setting */
        /* Skip ECMERRCTLR42 setting */
    };

    const ECM_ERROR_TABLE ecmerrtgtr_type3_tbl[TYPE3_ECM_TGTREG_MAX] = {
    [0]   =     {0xFD850200U, 0x80000000U},    /* ECMERRTGTR0 */
        /* Skip ECMERRTGTR1 setting */
        /* Skip ECMERRTGTR2 setting */
        /* Skip ECMERRTGTR3 setting */
        /* Skip ECMERRTGTR4 setting */
        /* Skip ECMERRTGTR5 setting */
        /* Skip ECMERRTGTR6 setting */
        /* Skip ECMERRTGTR7 setting */
        /* Skip ECMERRTGTR8 setting */
        /* Skip ECMERRTGTR9 setting */
        /* Skip ECMERRTGTR10 setting */
        /* Skip ECMERRTGTR11 setting */
        /* Skip ECMERRTGTR12 setting */
        /* Skip ECMERRTGTR13 setting */
        /* Skip ECMERRTGTR14 setting */
        /* Skip ECMERRTGTR15 setting */
    [1]   =     {0xFD850240U, 0x3FFFC000U},    /* ECMERRTGTR16 */
        /* Skip ECMERRTGTR17 setting */
        /* Skip ECMERRTGTR18 setting */
        /* Skip ECMERRTGTR19 setting */
        /* Skip ECMERRTGTR20 setting */
        /* Skip ECMERRTGTR21 setting */
        /* Skip ECMERRTGTR22 setting */
        /* Skip ECMERRTGTR23 setting */
        /* Skip ECMERRTGTR24 setting */
        /* Skip ECMERRTGTR25 setting */
        /* Skip ECMERRTGTR26 setting */
        /* Skip ECMERRTGTR27 setting */
        /* Skip ECMERRTGTR28 setting */
        /* Skip ECMERRTGTR29 setting */
        /* Skip ECMERRTGTR30 setting */
        /* Skip ECMERRTGTR31 setting */
        /* Skip ECMERRTGTR32 setting */
        /* Skip ECMERRTGTR33 setting */
        /* Skip ECMERRTGTR34 setting */
        /* Skip ECMERRTGTR35 setting */
        /* Skip ECMERRTGTR36 setting */
        /* Skip ECMERRTGTR37 setting */
        /* Skip ECMERRTGTR38 setting */
        /* Skip ECMERRTGTR39 setting */
        /* Skip ECMERRTGTR40 setting */
        /* Skip ECMERRTGTR41 setting */
        /* Skip ECMERRTGTR42 setting */
    };

    /* Unlock the write protect of ECM registers */
    ecm_unlock();

    NOTICE("ECMERRCTLR and ECMERRTGTR register initial setting.\n");
    /* For the initial setting flow for Type-1, please refer to the following
     * section in the "SAN(Safety Application Note)."
     * Section 4.1.2.5  : (1)
     * Section 4.1.4.5  : (1)
     * Section 4.12.1.5 : (1)
     * Section 4.13.1.5 : (1)
     * Section 4.14.5   : (1)
     * Section 4.16.5   : (1)
     * Section 4.18.5   : (1)
     * Section 4.2.7.5  : (1)
     * Section 4.2.9.5  : (1)
     * Section 4.23.5   : (1)
     * Section 4.3.11.5 : (1)
     * Section 4.3.12.5 : (1)
     * Section 4.3.14.5 : (1)
     * Section 4.3.19.5 : (1)
     * Section 4.3.21.5 : (1)
     * Section 4.4.14.5 : (1)
     * Section 4.4.16.5 : (3)
     * Section 4.4.18.5 : (1)
     * Section 4.4.20.5 : (1)
     * Section 4.4.3.5  : (1)
     * Section 4.4.4.5  : (1)
     * Section 4.4.6.5  : (1)
     * Section 4.4.7.5  : (1)
     * Section 4.4.9.5  : (1)
     * Section 4.5.1.5  : (1)
     * Section 4.7.1.5  : (1)
     * Section 4.7.10.5 : (1)
     * Section 4.7.3.5  : (1)
     * Section 4.7.4.5  : (1)
     * Section 4.7.7.5  : (1)
     * Section 4.7.8.5  : (1)
     * Section 5.6.5    : (1)
     * Section 5.8.1.5  : (1)
     */
    for (loop = 0U; loop < TYPE1_ECM_REG_MAX; loop++)
    {
        reg  = mem_read32(ecmerrctlr_type1_tbl[loop].phys_addr);
        reg |= (ecmerrctlr_type1_tbl[loop].value);
        ecm_write(ecmerrctlr_type1_tbl[loop].phys_addr, reg);

        INFO("[Type-1]ECMERRCTLR[\t%d]\t(0x%08x) =\t0x%08x \tsetting value = 0x%08x\n",
            loop,
            ecmerrctlr_type1_tbl[loop].phys_addr,
            mem_read32(ecmerrctlr_type1_tbl[loop].phys_addr),
            ecmerrctlr_type1_tbl[loop].value);
    }

    for (loop = 0U; loop < TYPE1_ECM_REG_MAX; loop++)
    {
        reg  = mem_read32(ecmerrtgtr_type1_tbl[loop].phys_addr);
        reg &= ~(ecmerrtgtr_type1_tbl[loop].value);
        ecm_write(ecmerrtgtr_type1_tbl[loop].phys_addr, reg);

        INFO("[Type-1]ECMERRTGTR[\t%d]\t(0x%08x) =\t0x%08x \tsetting value = 0x%08x\n",
            loop,
            ecmerrtgtr_type1_tbl[loop].phys_addr,
            mem_read32(ecmerrtgtr_type1_tbl[loop].phys_addr),
            ecmerrtgtr_type1_tbl[loop].value);
    }

    /* For the initial setting flow for Type-2, please refer to the following
     * section in the "SAN(Safety Application Note)."
     * Section 4.1.1.5  : (1)
     * Section 4.12.2.5 : (1)
     * Section 4.12.3.5 : (1)
     * Section 4.15.5   : (1)
     * Section 4.16.5   : (1)
     * Section 4.2.1.5  : (1)
     * Section 4.2.10.5 : (1)
     * Section 4.2.12.5 : (1)
     * Section 4.2.2.5  : (1)
     * Section 4.2.4.5  : (1)
     * Section 4.2.8.5  : (1)
     * Section 4.3.1.5  : (1)
     * Section 4.3.10.5 : (1)
     * Section 4.3.11.5 : (1)
     * Section 4.3.12.5 : (1)
     * Section 4.3.13.5 : (1)
     * Section 4.3.15.5 : (1)
     * Section 4.3.16.5 : (1)
     * Section 4.3.2.5  : (1)
     * Section 4.3.5.5  : (1)
     * Section 4.3.7.5  : (1)
     * Section 4.3.8.5  : (1)
     * Section 4.4.10.5 : (1)
     * Section 4.4.12.5 : (8)
     * Section 4.4.13.5 : (1)
     * Section 4.4.15.5 : (1)
     * Section 4.4.2.5  : (1)
     * Section 4.5.3.5  : (1)
     * Section 4.6.5    : (1)
     * Section 4.7.2.5  : (1)
     * Section 5.11.5   : (1)
     * Section 5.12.5   : (1)
     * Section 5.13.5   : (1)
     * Section 5.4.5    : (1)
     * Section 5.8.2.5  : (1)
     */
    for (loop = 0U; loop < TYPE2_ECM_REG_MAX; loop++)
    {
        /* Initial Setting Type-2 for ECMERRCTLR registers */
        reg  = mem_read32(ecmerrctlr_type2_tbl[loop].phys_addr);
        reg |= (ecmerrctlr_type2_tbl[loop].value);
        ecm_write(ecmerrctlr_type2_tbl[loop].phys_addr, reg);

        INFO("[Type-2]ECMERRCTLR[\t%d]\t(0x%08x) =\t0x%08x \tsetting value = 0x%08x\n",
            loop,
            ecmerrctlr_type2_tbl[loop].phys_addr,
            mem_read32(ecmerrctlr_type2_tbl[loop].phys_addr),
            ecmerrctlr_type2_tbl[loop].value);
    }

    for (loop = 0U; loop < TYPE2_ECM_REG_MAX; loop++)
    {
        /* Initial Setting Type-2 for ECMERRTGTR registers */
        reg  = mem_read32(ecmerrtgtr_type2_tbl[loop].phys_addr);
        reg &= ~(ecmerrtgtr_type2_tbl[loop].value);
        ecm_write(ecmerrtgtr_type2_tbl[loop].phys_addr, reg);

        INFO("[Type-2]ECMERRTGTR[\t%d]\t(0x%08x) =\t0x%08x \tsetting value = 0x%08x\n",
            loop,
            ecmerrtgtr_type2_tbl[loop].phys_addr,
            mem_read32(ecmerrtgtr_type2_tbl[loop].phys_addr),
            ecmerrtgtr_type2_tbl[loop].value);
    }

    /* For the initial setting flow for Type-3, please refer to the following
     * section in the "SAN(Safety Application Note)."
     * Section 4.19.1.5 : (3)
     * Section 6.2.5    : (12)
     */
    for (loop = 0U; loop < TYPE3_ECM_CTLREG_MAX; loop++)
    {
        /* Initial Setting Type-3 for ECMERRCTLR registers */
        reg  = mem_read32(ecmerrctlr_type3_tbl[loop].phys_addr);
        reg |= (ecmerrctlr_type3_tbl[loop].value);
        ecm_write(ecmerrctlr_type3_tbl[loop].phys_addr, reg);

        INFO("[Type-3]ECMERRCTLR[\t%d]\t(0x%08x) =\t0x%08x \tsetting value = 0x%08x\n",
            loop,
            ecmerrctlr_type3_tbl[loop].phys_addr,
            mem_read32(ecmerrctlr_type3_tbl[loop].phys_addr),
            ecmerrctlr_type3_tbl[loop].value);
    }

    for (loop = 0U; loop < TYPE3_ECM_TGTREG_MAX; loop++)
    {
        /* Initial Setting Type-3 for ECMERRTGTR registers */
        reg  = mem_read32(ecmerrtgtr_type3_tbl[loop].phys_addr);
        reg &= ~(ecmerrtgtr_type3_tbl[loop].value);
        ecm_write(ecmerrtgtr_type3_tbl[loop].phys_addr, reg);

        INFO("[Type-3]ECMERRTGTR[\t%d]\t(0x%08x) =\t0x%08x \tsetting value = 0x%08x\n",
            loop,
            ecmerrtgtr_type3_tbl[loop].phys_addr,
            mem_read32(ecmerrtgtr_type3_tbl[loop].phys_addr),
            ecmerrtgtr_type3_tbl[loop].value);
    }

    /* Lock the ECM registers */
    ecm_lock();
}
/* End of function ecm_init_setting(void) */
#endif /* ECM_ERROR_ENABLE == 1 */

