/*******************************************************************************
 * Copyright (c) 2018-2021 Renesas Electronics Corporation. All rights reserved.
 *
 *     RENESAS ELECTRONICS CONFIDENTIAL AND PROPRIETARY
 *
 * This software is provided as reference/sample code under the license
 * agreement between Renesas Electronics Corporation and licensee (the
 * "License Agreement") and shall be treated as specified in the License
 * Agreement.
 * These instructions, statements, and software are the confidential
 * information of Renesas Electronics Corporation. They must be used and
 * modified solely for the purpose for which it was furnished by Renesas
 * Electronics Corporation. All or part of these instructions, statements and
 * software must not be reproduced nor disclosed to any third party in any
 * form, unless permitted by the License Agreement.
 *
 * THIS SOFTWARE IS PROVIDED BY RENESAS ELEOCTRONICS CORPORATION "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
 * SATISFACTORY QUALITY, ACCURACY, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED.
 * IN NO EVENT SHALL RENESAS ELECTRONICS CORPORATION BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 ******************************************************************************/

/*******************************************************************************
 * DESCRIPTION   : MFIS driver
 ******************************************************************************/
/******************************************************************************
 * @file          mfis.c
 * - Version      : 0.01
 * @brief         Initial setting process of MFIS.
 * .
 *****************************************************************************/
/******************************************************************************
 * History : DD.MM.YYYY Version  Description
 *         : 03.07.2020 0.01     First Release
 *****************************************************************************/
#include <stdint.h>     /* for uint32_t */
#include <mem_io.h>
#include <mfis_register.h>
#include <mfis.h>
#include <log.h>

#define MFIS_EXTRQHLDCNTR_TIMER_COUNT       (0x80000001U)

void mfis_init(void)
{
    uint32_t loop;
    const MFIS_SETTING_TABLE mfis_tbl[] = {
        /*  address             value        */
        {   MFIS_MFIERRCTLR0    ,   0xBFFBFB70U },
        {   MFIS_MFIERRCTLR1    ,   0x3607FFE8U },
        {   MFIS_MFIERRCTLR2    ,   0xFFFFFFFFU },
        {   MFIS_MFIERRCTLR3    ,   0x9FFFFFFFU },
        {   MFIS_MFIERRCTLR4    ,   0x13B9E8FFU },
        {   MFIS_MFIERRCTLR5    ,   0x00000000U },
        {   MFIS_MFIERRCTLR6    ,   0x00000000U },
        {   MFIS_MFIERRCTLR7    ,   0xFFFF6D7FU },
        {   MFIS_MFIERRCTLR8    ,   0x01FF0FFFU },
        {   MFIS_MFIERRCTLR9    ,   0xFF00175FU },
        {   MFIS_MFIERRCTLR10   ,   0x00000000U },
        {   MFIS_MFIERRCTLR11   ,   0x00000000U },
        {   MFIS_MFIERRCTLR12   ,   0x2550780FU },
        {   MFIS_MFIERRCTLR13   ,   0x00003F7FU },

        {   MFIS_MFIERRTGTR0    ,   0x8F080000U }, 
        {   MFIS_MFIERRTGTR1    ,   0x00000400U }, 
        {   MFIS_MFIERRTGTR2    ,   0x00000000U }, 
        {   MFIS_MFIERRTGTR3    ,   0x00000000U }, 
        {   MFIS_MFIERRTGTR4    ,   0x02000000U }, 
        {   MFIS_MFIERRTGTR5    ,   0x00000000U }, 
        {   MFIS_MFIERRTGTR6    ,   0x00000000U }, 
        {   MFIS_MFIERRTGTR7    ,   0x02AA002AU }, 
        {   MFIS_MFIERRTGTR8    ,   0x007F00A0U }, 
        {   MFIS_MFIERRTGTR9    ,   0xFD000000U }, 
        {   MFIS_MFIERRTGTR10   ,   0x00000000U },
        {   MFIS_MFIERRTGTR11   ,   0x00000000U },
        {   MFIS_MFIERRTGTR12   ,   0x00000000U },
        {   MFIS_MFIERRTGTR13   ,   0x00000000U }
    };

    /* removed write protection of MFIS */
    mem_write32(MFIS_MFISWPCNTR, (MFIS_PROT_CODEVALUE | MFISWPCNTR_WPD_BIT));

    /* sets the error detection enable / disable and    *
     * the output destination of the detected error     */
    for (loop = 0U; loop < (sizeof(mfis_tbl) / sizeof(mfis_tbl[0])); loop++)
    {
        mem_write32(mfis_tbl[loop].address, mfis_tbl[loop].value);
    }

    /* setting for controlling time that error request is holded */
    mem_write32(MFIS_MFIEXTRQMSKCNTR, MFIS_EXTRQHLDCNTR_TIMER_COUNT);
}
/* End of function mfis_init(void) */
