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

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();

    pet_sm_alloc();

	ucp_spinlock_init();

    int32_t core_id = get_core_id();

#ifdef PALLADIUM_TEST
    int flag = 1;
    debug_write((DBG_DDR_IDX_DRV_BASE+(core_id<<2)), flag);	// 0xB0
#endif

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

#ifdef PALLADIUM_TEST
    flag++;
    debug_write((DBG_DDR_IDX_DRV_BASE+(core_id<<2)), flag);
#endif

#ifdef TEST_ENABLE
	fh_test_init();
#endif

#ifdef PALLADIUM_TEST
	flag++;
	debug_write((DBG_DDR_IDX_DRV_BASE+(core_id<<2)), flag);
#endif


    return;
}

void ecs_rfm_spu1_msg_transfer_init(void)
{
    msg_transfer_mem_alloc();

    handshake_slave_with_master();

    msg_transfer_queue_init();

	phy_init();

    return;
}

