#include "UDS_27Service_Internal.h"

uint32_t Ser27_SeedRandomNumber = 0x727u;

void Ser27_CreateRandomSeed(void)
{
    Ser27_SeedRandomNumber = Ser27_SeedRandomNumber * 1103515245ul+12345u;
}

void Ser27_ErrDelayTimerCtrlInit(void)
{
    /*调用读出函数*/
    Ser27_ReadCtrlInfoFromDFlash();
    Ser27_SeedRandomNumber = Ser27_FlowCtrlCnt.RandNum;
    if((Ser27_FlowCtrlCnt.LV11_ReqSeedCnt >= SER27_MAX_REQ_SEED_NUM) || ( Ser27_FlowCtrlCnt.LV1ReqSeedCnt >= SER27_MAX_REQ_SEED_NUM ) )
    {
        Ser27_EnDelayTimer();
    }  
}

void Ser27_EnDelayTimer(void)
{
    Ser27_FlowCtrl.LV1DelayCtrl = SER27_ERR_DELAY_TIMER_EN;
}

void Ser27_WriteCtrlInfoToDFlash(void)
{
    DFlash_WriteData(WriteSer27Addr, (uint32_t *)&Ser27_FlowCtrlCnt.Flag, sizeof(Ser27_FlowCtrlCnt) , WriteFDL);
}

void Ser27_ReadCtrlInfoFromDFlash(void)
{
    ReadDFlashData_fdl(WriteSer27Addr, (uint32_t *)&Ser27_FlowCtrlCnt.Flag, sizeof(Ser27_FlowCtrlCnt) , Ser27ToDFlashInfoInit);
}