#include "inter_vector.h"
#include "ucp_printf.h"
#include "rfm0_drv.h"
#include "spu_hw_queue.h"

#include "phy_para.h"
#include "rfm0_mtimer.h"
#include "ape_csu.h"
#include "hwque.h"
#include "ucp_printf.h"
#include "ucp_utility.h"
#include "ctc_intr.h"
#include "spu_log.h"
#include "app_interface.h"

/*****************************************************/
void ecs_rfm0_drv_init(void)
{
    int32_t apeId = get_core_id();
#ifdef PALLADIUM_TEST
    int32_t flag = 1;
    debug_write((DBG_DDR_IDX_DRV_BASE+(apeId<<2)), flag);	// 0xA0
#endif

    int32_t ret = 0;
#if 1
    ret = smart_irq_debug_init(DBG_DDR_IRQ_ADDR_BASE+apeId*DBG_DDR_IRQ_LEN, DBG_DDR_IRQ_LEN);
    if (0 != ret)
    {
        debug_write(DBG_DDR_ERR_IDX(apeId, 11), ret);
    }
#endif
    ret = smart_irq_init(apeId);
    if (0 != ret)
    {
        debug_write(DBG_DDR_ERR_IDX(apeId, 14), ret);
    }
    UCP_PRINT_EMPTY("smart inter init. \r\n");
#ifdef PALLADIUM_TEST
    flag++;
    debug_write((DBG_DDR_IDX_DRV_BASE+(apeId<<2)), flag);	// 0xA0
#endif

    ape_csu_init();
    UCP_PRINT_EMPTY("ape csu init. \r\n");
#ifdef PALLADIUM_TEST
    flag++;
    debug_write((DBG_DDR_IDX_DRV_BASE+(apeId<<2)), flag);	// 0xA0
#endif

    sfn_para_init();
    UCP_PRINT_EMPTY("sfn para init.\r\n");
#ifdef PALLADIUM_TEST
    flag++;
    debug_write((DBG_DDR_IDX_DRV_BASE+(apeId<<2)), flag);	// 0xA0
#endif

#if 0
	ctc_cal_intr_init();
	UCP_PRINT_EMPTY("ctc cal intr init.\r\n");
#ifdef PALLADIUM_TEST
    flag++;
    debug_write((DBG_DDR_IDX_DRV_BASE+(apeId<<2)), flag);	// 0xA0
#endif

    rfm0_mtimer_int_init();
    UCP_PRINT_EMPTY("set mtimer rfm0 int.\r\n");
#ifdef PALLADIUM_TEST
    flag++;
    debug_write((DBG_DDR_IDX_DRV_BASE+(apeId<<2)), flag);	// 0xA0
#endif
#endif
    //ecs_hw_que_init(apeId);
    //ecs_hw_que_init_withirq(apeId, apeId);
    //ecs_msg_que_init(apeId);
    //ecs_hw_que_init_noirq(apeId, ECS_RFM_SPU0_HW_QUEUE);
    spu_log_init(LOG_ERROR);
    UCP_PRINT_EMPTY("[rfm0_drv_init]: OK \r\n");
#ifdef PALLADIUM_TEST
    flag++;
    debug_write((DBG_DDR_IDX_DRV_BASE+(apeId<<2)), flag);	// 0xA0
#endif
}

