/*
 * Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
 * All rights reserved.
 *
 * Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
 * exclusively with CVA's microcontroller products. This file can be freely
 * distributed within development tools that are supporting such microcontroller
 * products.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
 * CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
 * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 */

/*******************************************************************************
 * the includes
 ******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "fee_cfg.h"
#include "fee_extra.h"
#include "fee_jobs.h"
#include "fee_sector.h"
#include "fee_internal.h"
#include "mcu.h"

/*******************************************************************************
 * the defines
 ******************************************************************************/


/*******************************************************************************
 * the typedefs
 ******************************************************************************/

/*******************************************************************************
 * the globals
 ******************************************************************************/
const Fee_BlockConfigType Fee_BlockCfg[FEE_BLOCK_NUM] =
{
        {
                FEE_BLOCK_MOTORDATA_DATASET0,
                81,
        },
        {
                FEE_BLOCK_DIDDATA0_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA1_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA2_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA3_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA4_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA5_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA6_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA7_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA8_DATASET0,
                21,
        },
        {
                FEE_BLOCK_DIDDATA9_DATASET0,
                21,
        },
};

Fee_BlockInfoType Fee_BlockInfo[FEE_BLOCK_NUM];

const Fee_BlockType Fee_Block[FEE_BLOCK_NUM] =
{
    {
        &Fee_BlockCfg[0],
        &Fee_BlockInfo[0]
    },
    {
        &Fee_BlockCfg[1],
        &Fee_BlockInfo[1]
    },
    {
        &Fee_BlockCfg[2],
        &Fee_BlockInfo[2]
    },
    {
        &Fee_BlockCfg[3],
        &Fee_BlockInfo[3]
    },
    {
        &Fee_BlockCfg[4],
        &Fee_BlockInfo[4]
    },
    {
        &Fee_BlockCfg[5],
        &Fee_BlockInfo[5]
    },
    {
        &Fee_BlockCfg[6],
        &Fee_BlockInfo[6]
    },
    {
        &Fee_BlockCfg[7],
        &Fee_BlockInfo[7]
    },
    {
        &Fee_BlockCfg[8],
        &Fee_BlockInfo[8]
    },
    {
        &Fee_BlockCfg[9],
        &Fee_BlockInfo[9]
    },
    {
        &Fee_BlockCfg[10],
        &Fee_BlockInfo[10]
    },
};

Fee_SectorInfoType  Fee_SectorInfo[FEE_SECTOR_NUM];

const Fee_SectorConfigType Fee_SectorCfg[FEE_SECTOR_NUM] = 
{
    {
        (void *)0x10010000,
        (void *)0x10010800,
        2,
        &Fee_SectorInfo[0]
    },
    {
        (void *)0x10010800,
        (void *)0x10011000,
        2,
        &Fee_SectorInfo[1]
    },
};

const Fee_SectorType Fee_Sector =
{
    FEE_SECTOR_NUM,
    &Fee_SectorCfg[0],
    FEE_BLOCK_NUM,
    &Fee_Block[0],
};

const Fee_MethodType Fee_FlsMethod =
{
    Fee_InternalWriteCheck,
    Fee_InternalReadCheckData,
    Fee_InternalEarseCheckPhrase,
    Fee_InternalIsWriteable,
    Fee_InternalCalcCrc8
};

Fee_JobControlBlockType Fee_sysJob =
{
    FEE_JOB_UNLOCK,
    0x0000,
    0x0000,
    FEE_JOB_OP_UNDEFINE,
    NULL,
    NULL,
};

Fee_JobControlBlockType Fee_userJob =
{
    FEE_JOB_UNLOCK,
    0x0000,
    0x0000,
    FEE_JOB_OP_UNDEFINE,
    NULL,
    NULL,
};

Fee_JobsType Fee_JobCfg =
{
    false,
    &Fee_userJob,
    &Fee_sysJob
};

Fee_JobControlBlockType Fee_JobControlBlock =
{
    FEE_JOB_UNLOCK,
    0,
    0,
    FEE_JOB_OP_UNDEFINE,
    NULL,
    NULL
};

Fee_GcRuntimeType Fee_GcRuntime =
{
    FEE_GC_INIT,
    FEE_GC_COPY_WRITE_MARK,
    NULL,
    0,
    NULL,
    NULL,
    NULL,
    FEE_GC_STATE_NO_ERROR
};

Fee_RunTimeType Fee_Runtime =
{
    FEE_MAIN_FUN_FSM_ERROR,
    FEE_INITIALIZATION_ERROR,
    &Fee_JobCfg,
    NULL,
    &Fee_JobControlBlock,
    &Fee_GcRuntime,
    FEE_JOB_RESULT_OK
};

uint8_t Fee_RuntimeCache[FEE_BUFF_SIZE];

const FeeType fee =
{
        &Fee_Sector,
        &Fee_FlsMethod,
        &Fee_Runtime,
        (void *)&Fee_RuntimeCache[0],
};

/*******************************************************************************
 * the functions
 ******************************************************************************/


