#include "ape_ecpri_timer.h"
#include "ucp_drv_common.h"
#include "ucp_ecpri.h"
#include "ucp_param.h"
#include "mtimer_com.h"
#include "ape_cnt.h"
#include "ucp_utility.h"
#include "ucp_printf.h"
#include "phy_para.h"
#include "stc_timer.h"
#include "smartos.h"
#include "ucp_mtimer.h"
#include "ape_mtimer.h"

extern void osp_timer_call_task();

extern stPhyScsPara* phyPara;
extern stSfnPara gCellSfnPara[2];
extern stStcTimerPara gStcTimerPara;

void set_ecpri_timer_ape_int(void)
{
	int32_t apeId = get_core_id();
	// tx slot
	uint32_t intNum = APC_ECPRI_SUB_INTR2;
	int32_t ret = smart_irq_request(intNum, isr_ecpri_ape_slot_offset);
	if (0 != ret)
	{
		UCP_PRINT_ERROR("attach int num: 0x%x error. errno = 0x%x. \r\n", intNum, ret);
		debug_write(DBG_DDR_ERR_IDX(apeId, 32), ret);
	}
}

int32_t clr_ecpri_timer_ape_int(void)
{
	int32_t apeId = get_core_id();
	// tx slot
	uint32_t intNum = APC_ECPRI_SUB_INTR2;
	int32_t ret = smart_irq_free(intNum);
	if (0 != ret)
	{
		UCP_PRINT_ERROR("detach int num: 0x%x error. errno = 0x%x. \r\n", intNum, ret);
		// debug write
		debug_write(DBG_DDR_ERR_IDX(apeId, 0), ret);
		return -1;
	}

	return 0;
}

void isr_ecpri_ape_slot_offset(void)
{
	mtimer_ape_slot_callback(MTIMER_ECPRI_ID);
}

