/*
 * 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.
 */

/*! \brief a bootloader asw demo
 */

/*******************************************************************************
 * the includes
 ******************************************************************************/

#include <stdint.h>
#include "mcu.h"
#include "SEGGER_RTT.h"
#include "appTask.h"
#include "hwctrl.h"

/*******************************************************************************
 * the defines
 ******************************************************************************/
#define CAN_BUFF_MAX_NUM     (32)



/* Asw code head id to show asw is not empty */
#define ASW_HEAD_MASK         (0xAABBCCDDul)

#define ASW_VECTOR_START_ADDR 0xc000ul

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

typedef struct
{
    uint32_t sAswHeader;
    uint8_t appBuildTime[12];
    uint8_t appBuildDate[16];
} app_CfgInfoType;

/*******************************************************************************
 * the globals
 ******************************************************************************/
McuType                      mcu;

#pragma location = ".asw_header"
__root const app_CfgInfoType app_inif = {
    .sAswHeader = ASW_HEAD_MASK,//0x00010400
    .appBuildTime = __TIME__,//0x00010404
    .appBuildDate = __DATE__,//0x00010410
};



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




int main(void)
{
    
    IrqDrv_DisableGlobalInterrupt();

    /* Initialize all MCU drivers: flash drv included */
    Mcu_Init(&mcu);

    SEGGER_RTT_Init();

    hw_init(&mcu);

    appTaskInit(&mcu);

    IrqDrv_EnableGlobalInterrupt();
    SEGGER_RTT_printf(0,"-----init success-----\n");
    while(1)
    {
        appTask(&mcu);
    }
}


