// +FHDR------------------------------------------------------------
//                 Copyright (c) 2022 SmartLogic.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : ecs_rfm_spu1.c
// Author        : xianfeng.du
// Created On    : 2022-06-25
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

#include "typedef.h"
#include "rfm1_drv.h"
#include "ucp_handshake.h"
//#include "cpri_timer.h"
#include "ucp_utility.h"
#include "ucp_printf.h"
#include "phy_para.h"
#include "pet_sm_mgt.h"
#include "ecs_rfm_dm_mgt.h"
#include "msg_transfer_mem.h"

#ifdef TEST_ENABLE
#include "fh_test.h"
#endif

void phy_init(void);

uint32_t get_core_mask_by_phy(void);

ALWAYS_INLINE int32_t get_core_id(void)
{
    return ECS_RFM_SPU1_CORE_ID;
}

void ecs_rfm_spu1_drv_init(void)
{
    ecs_rfm_dm_alloc();
    ecs_rfm1_dm_init();

    pet_sm_alloc();

    ucp_spinlock_init();

    ecs_rfm1_drv_init();
    UCP_PRINT_EMPTY("ECS: rfm drv init finished.\r\n");

    return;
}

void ecs_rfm_spu1_msg_transfer_init(void)
{
    msg_transfer_mem_alloc();

    int32_t core_id = get_host_core_id();
    handshake_request_from_host(core_id);
    //handshake_with_host();

    msg_transfer_queue_init();//initialized local queuecfg from common queuecfg

    uint32_t u32_core_mask = get_core_mask_by_phy();
    debug_write(DBG_DDR_COMMON_IDX(core_id, 3), u32_core_mask);
    handshake_master_with_slave(u32_core_mask);

    handshake_response_to_host(core_id);

    phy_init();//phy application function:msg_transfer_cfg

    return;
}

