#include "rfm1_gtimer2.h"
#include "dw_apb_timers.h"
#include "inter_vector.h"
#include "ucp_param.h"
#include "ucp_utility.h"
#include "ucp_drv_common.h"


extern void ddr_wr_callback();

int32_t rfm1_gtimer2_1_set_int()
{
	uint32_t intNum = 0;

	intNum = APC_TIMER20_INTR;
	int32_t ret = smart_irq_request(intNum, isr_rfm1_gtimer2_1);
	if (0 != ret)
	{
		return -1;
	}

	return 0;
}


uint32_t gRfm1Timer21IntCnt = 0;
//uint32_t gTimer21StcCntLast = 0;
void isr_rfm1_gtimer2_1(void)
{
	if (1 == (TIMER2_TIMER1INTSTAT&0x1)) // do_read_volatile(&TIMER2_TIMER1INTSTAT))
	{
		uint32_t tmrIntClr = TIMER2_TIMER1EOI; // do_read_volatile(&TIMER2_TIMER1EOI); // int clear
		tmrIntClr = 0;
		gRfm1Timer21IntCnt++;
		debug_write((DBG_DDR_IDX_DRV_BASE+64+7), gRfm1Timer21IntCnt); // 0x11c
		//debug_write((DBG_DDR_IDX_DRV_BASE+127), (GET_STC_CNT()-gTimer21StcCntLast)); // 0x1fc
		//gTimer21StcCntLast = GET_STC_CNT();

		ddr_wr_callback();
	}
}

uint32_t get_rfm1_gtimer2_1_intcnt()
{
	return gRfm1Timer21IntCnt;
}

void clear_rfm1_gtimer2_1_intcnt()
{
	gRfm1Timer21IntCnt = 0;
}

