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

#if 0
#include "ucp_printf.h"
#include "mem_sections.h"
#include "ucp_utility.h"
#include "ecs_sm_mgt.h"

EcsSmLocalMgt_t gEcsSmLocalMgt;
ALWAYS_INLINE EcsSmLocalMgt_t* get_ecs_sm_local_mgt(void)
{
    return (EcsSmLocalMgt_t *)&gEcsSmLocalMgt;
}

void ecs_sm_init(void)
{
    MEM_SECTION_INFO* pMemSection = GetEcsSramSection();
    memset_ucp(pMemSection->baseAddr,0,pMemSection->maxSize);
    return;
}

void ecs_sm_alloc(void)
{
    UCP_PRINT_EMPTY("start allocating ecs share memory");
    uint32_t i,j;

    EcsSmLocalMgt_t* pEcsSmLocalMgt = get_ecs_sm_local_mgt();
    MEM_SECTION_INFO* pMemSection = GetEcsSramSection();

    pEcsSmLocalMgt->pHandshake = (UcpHandshake_t *)memSectionAlloc(pMemSection, sizeof(UcpHandshake_t), MEM_ALIGNED_4BYTES, "pHandshake");
    pEcsSmLocalMgt->pSyncInfo = (SyncInfo_t *)memSectionAlloc(pMemSection, sizeof(SyncInfo_t), MEM_ALIGNED_4BYTES, "pSyncInfo");
    pEcsSmLocalMgt->pBufIdxBase = (uint16_t *)memSectionAlloc(pMemSection, MAX_INSTANCE_NUM*UCP4008_TRAFFIC_MAX_NUM*MAX_M_BUFFER_NUM*sizeof(uint16_t), MEM_ALIGNED_4BYTES, "pBufIdxBase");

    for (i = 0; i < MAX_INSTANCE_NUM; i++) {
        for (j = 0; j < UCP4008_TRAFFIC_MAX_NUM; j++) {
            pEcsSmLocalMgt->pQueueCfg[i][j] = (MsgQueueCfg_t *)memSectionAlloc(pMemSection, sizeof(MsgQueueCfg_t), MEM_ALIGNED_4BYTES, "pQueueCfg");
        }
    }

    for (i = 0; i < MAX_INSTANCE_NUM; i++) {
        for (j = 0; j < UCP4008_TRAFFIC_MAX_NUM; j++) {
            pEcsSmLocalMgt->pDlQueue[i][j] = (MsgQueueCommonInfo_t *)memSectionAlloc(pMemSection, sizeof(MsgQueueCommonInfo_t), MEM_ALIGNED_64BYTES, "pDlQueue");
            pEcsSmLocalMgt->pUlQueue[i][j] = (MsgQueueCommonInfo_t *)memSectionAlloc(pMemSection, sizeof(MsgQueueCommonInfo_t), MEM_ALIGNED_64BYTES, "pUlQueue");
        }
    }

    pEcsSmLocalMgt->pLogCommonInfo = (SpuLogCommonInfo_t *)memSectionAlloc(pMemSection, sizeof(SpuLogCommonInfo_t), MEM_ALIGNED_4BYTES, "pLogCommonInfo");

    return;
}
#endif

