// +FHDR------------------------------------------------------------
//                 Copyright (c) 2020 PicocomTech.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : ecs_rfm_dm_mgt.c
// Author        : xianfeng.du
// Created On    : 2022-06-27
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

#include "ucp_printf.h"
#include "mem_sections.h"
#include "ecs_rfm_dm_mgt.h"

EcsRfmDmLocalMgt_t gEcsRfmDmLocalMgt;
EcsRfmDmLocalMgt_t* get_ecs_rfm_dm_local_mgt(void)
{
    return (EcsRfmDmLocalMgt_t *)&gEcsRfmDmLocalMgt;
}

void ecs_rfm_dm_alloc(void)
{
    //int32_t core_id = get_core_id();
    //UCP_PRINT_LOG("ecs_rfm_spu[%d] start allocating dm.",core_id);

    EcsRfmDmLocalMgt_t* pEcsDmLocalMgt = get_ecs_rfm_dm_local_mgt();
    MEM_SECTION_INFO* pMemSection = GetRfmDm1Section();

#ifdef DISTRIBUTED_BS
    pEcsDmLocalMgt->pCpriPara = (stCpriPara*)memSectionAlloc(pMemSection, sizeof(stCpriPara), MEM_ALIGNED_4BYTES, "pCpriPara");
    pEcsDmLocalMgt->pCpriDelay = (stCpriDelayMeasure*)memSectionAlloc(pMemSection, sizeof(stCpriDelayMeasure), MEM_ALIGNED_4BYTES, "pCpriDelay");
#endif
#ifdef INTEGRATED_BS
	//pEcsDmLocalMgt->pJesdGpioInfo = (stGpioJesd*)memSectionAlloc();
#endif
	//stGpioOnBoard* pGpioInfo = (stGpioOnBoard*)0x0A4D7400;
	pEcsDmLocalMgt->pGpioInfo = (stGpioOnBoard*)memSectionAlloc(pMemSection, sizeof(stGpioOnBoard), MEM_ALIGNED_4BYTES, "pGpioInfo"); // (stGpioOnBoard*)0x0A4D7400;

    pEcsDmLocalMgt->pAlarmStatus = (stFhAlarmStat*)memSectionAlloc(pMemSection, sizeof(stFhAlarmStat), MEM_ALIGNED_4BYTES, "pAlarmStatus");
    pEcsDmLocalMgt->pOamMsgPtr  = (stOamMsgTransferHeader*)memSectionAlloc(pMemSection, sizeof(stOamMsgTransferHeader), MEM_ALIGNED_4BYTES, "pOamMsg");
    pEcsDmLocalMgt->pOamBaseDelaySetRspPtr  =  (stCpriSetLinkDelay*)memSectionAlloc(pMemSection, sizeof(stCpriSetLinkDelay), MEM_ALIGNED_4BYTES, "pOamBaseDelaySetRsp");
    pEcsDmLocalMgt->pOamBaseDelayQryRspPtr  = (stCpriGetLinkDelay*)memSectionAlloc(pMemSection, sizeof(stCpriGetLinkDelay), MEM_ALIGNED_4BYTES, "pOamBaseDelayQryRsp");
    pEcsDmLocalMgt->pOamFiberDelayQryRspPtr = (stCpriGetRndDelay*)memSectionAlloc(pMemSection, sizeof(stCpriGetRndDelay), MEM_ALIGNED_4BYTES, "OamFiberDelayQryRsp");

    for (int i = 0; i < MTIMER_MAX_NUM; i++)
	{
		pEcsDmLocalMgt->pMtimerPara[i] = (stMtimerPara*)memSectionAlloc(pMemSection, sizeof(stMtimerPara), MEM_ALIGNED_4BYTES, "pMtimerPara[i]");
	}

    return;
}

