// +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;
}

int32_t ecs_rfm_dm_alloc(void)
{
    EcsRfmDmLocalMgt_t* pEcsDmLocalMgt = get_ecs_rfm_dm_local_mgt();
	if (NULL == pEcsDmLocalMgt)
	{
		return -1;
	}
    MEM_SECTION_INFO* pMemSection = GetRfmDm1Section();
	if (NULL == pMemSection)
	{
		return -1;
	}

    pEcsDmLocalMgt->pCpriPara = (stCpriPara*)memSectionAlloc(pMemSection, sizeof(stCpriPara), MEM_ALIGNED_4BYTES, "pCpriPara");
	if (NULL == pEcsDmLocalMgt->pCpriPara)
	{
		return -1;
	}
	pEcsDmLocalMgt->pCpriDelay = (stCpriDelayMeasure*)memSectionAlloc(pMemSection, sizeof(stCpriDelayMeasure), MEM_ALIGNED_4BYTES, "pCpriDelay");
	if (NULL == pEcsDmLocalMgt->pCpriDelay)
	{
		return -1;
	}
	//stGpioOnBoard* pGpioInfo = (stGpioOnBoard*)0x0A4D7400;
	pEcsDmLocalMgt->pGpioInfo = (stGpioOnBoard*)memSectionAlloc(pMemSection, sizeof(stGpioOnBoard), MEM_ALIGNED_4BYTES, "pGpioInfo"); // (stGpioOnBoard*)0x0A4D7400;
	if (NULL == pEcsDmLocalMgt->pGpioInfo)
	{
		return -1;
	}

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

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

    return 0;
}

