
/*******************************************************************************
 * the includes
 ******************************************************************************/
#include "extern.h"
#include <string.h>
#include "drivers/reset/reset_drv.h"
#include "mcu.h"

/*******************************************************************************
 * the defines
 ******************************************************************************/
#define ASW_HEAD_MASK         (0xAABBCCDDul)


/*******************************************************************************
 * the typedefs
 ******************************************************************************/
typedef struct
{
    uint8_t HWVersion[4];
    uint8_t BLVersion[8];
    uint8_t bootBuildTime[12];
    uint8_t bootBuildDate[16];
    uint8_t ECUName[8];
    uint8_t Reverse[16];
} Bootloade_CfgInfoType;//64 byte

typedef struct
{
    uint32_t sAswHeader;
    uint8_t appBuildTime[12];
    uint8_t appBuildDate[16];
    uint8_t appSW_VERSION[16];
    uint8_t reverse[16];
} app_CfgInfoType;//64 byte

/*******************************************************************************
 * the globals
 ******************************************************************************/

extern McuType mcu;

/*******************************************************************************
 * the constants
 ******************************************************************************/
#pragma location = ".asw_header"
__root const app_CfgInfoType app_info = {
    .sAswHeader = ASW_HEAD_MASK,//0x00010400
    .appBuildTime = __TIME__,//0x00010404
    .appBuildDate = __DATE__,//0x00010410
    .appSW_VERSION = "SW0101_20250204",
};


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

void getSW_VERSION(unsigned char *pdata)
{
    memcpy(pdata, &(app_info.appSW_VERSION), sizeof(app_info.appSW_VERSION));
}

void getHW_VERSION(unsigned char *pdata)
{
    Bootloade_CfgInfoType * PBootInfo;
    PBootInfo = (Bootloade_CfgInfoType *)0x00000C0;
    memcpy(pdata, &(PBootInfo->HWVersion), sizeof(PBootInfo->HWVersion));
    //memcpy(pdata, HW_VERSION, );
}

void getBuildTime(unsigned char *pdata)
{
    memcpy(pdata, &(app_info.appBuildDate), 12);
    memcpy(pdata + 12,  &(app_info.appBuildTime), 8);
    pdata[11] = ' ';
}

void getBL_VERSION(unsigned char *pdata)
{
    Bootloade_CfgInfoType * PBootInfo;
    PBootInfo = (Bootloade_CfgInfoType *)0x00000C0;
    memcpy(pdata, &(PBootInfo->BLVersion), sizeof(PBootInfo->BLVersion));
}

void getEcuName(unsigned char *pdata)
{
    Bootloade_CfgInfoType * PBootInfo;
    PBootInfo = (Bootloade_CfgInfoType *)0x00000C0;
    memcpy(pdata, &(PBootInfo->ECUName), sizeof(PBootInfo->ECUName));
}

void extHardwareReset(void)
{
    //SBC_Write_RegField(SBC_M_S_CTRL, SBC_M_S_CTRL_MODE_Msk, SBC_M_S_CTRL_MODE_Pos, SBC_MODE_RESET, NULL);
    ResetDrv_SoftwareResetModule(&mcu.resetDrv,RESETDRV_SWRESET_SYS);
}
void extSortwareReset(void)
{
    ResetDrv_SoftwareResetModule(&mcu.resetDrv,RESETDRV_SWRESET_SYS);
}