#include "pit.h"
#include "lcd.h"
#include "function_drv.h"
#include "data.h"
#include "sys.h"
#include "rtp.h"
#include "wav_pit.h"
#include "wav_dac.h"
#include "pwm_drv.h"
#include "pit_drv.h"


//动态显示的定时器
void PIT1_Init(void)	
{
	NVIC_Init(1, 0, PIT1_IRQn, 2);
	
	PIT1->PCSR &= (~PCSR_EN);
	PIT1->PCSR = (5<<8)|PCSR_OVW|PCSR_PIE|PCSR_RLD|PCSR_PDBG; //75mhz/32  中断模式
	PIT1->PMR = 23437;//10ms	
	PIT1->PCSR |= PCSR_EN;
}

void PIT1_Init_1(void)	
{
	NVIC_Init(1, 0, PIT1_IRQn, 2);
	
	PIT1->PCSR = (5<<8)|PCSR_OVW|PCSR_RLD|PCSR_PDBG; //75mhz/32  中断模式
	
	PIT1->PCSR&=~PCSR_PIE;
	
	PIT1->PMR = 35156;//15ms
	PIT1->PCSR&=~PCSR_EN;	
}

/**********************SD卡************************/
extern u8 sd_flag;
extern const UINT16 gDutyBuf[16];

void PIT1_Init_SD(void)	
{
	NVIC_Init(1, 0, PIT1_IRQn, 2);
	
	PIT1->PCSR &= (~PCSR_EN);
	
	PIT1->PCSR = (9<<8)|PCSR_OVW|PCSR_PIE|PCSR_RLD|PCSR_PDBG; //60Mhz/512  中断模式
	
	PIT1->PMR = 1170*3;//1ms
	PIT1->PCSR |= PCSR_EN;	
}

/**************************************************/

void PIT1_IRQHandler(void)
{	
	static UINT16 i = 0;
	static UINT8 L_flag = 0; 
	
	UINT8 buf[2];

}

#if WAV_FLAG

//控制Wav播放的定时器
void PIT2_Init(UINT16 arr)
{
	NVIC_Init(2, 0, PIT2_IRQn, 2);
	
	PIT2->PCSR &= (~PCSR_EN);
	PIT2->PCSR = (0<<8)|PCSR_OVW|PCSR_PIE|PCSR_RLD|PCSR_PDBG; //75mhz/1  中断模式
	PIT2->PMR = arr-3;	
	
	PIT2->PCSR &=(~PCSR_EN);
}

void PIT2_IRQHandler(void)
{
	static UINT32 jj=0;
	static short i = 0;
	short temp = 0;
	
	PIT2->PCSR |=(1<<2);		// 4.clear PIF interrupt flag
//	PIT2->PCSR &=(~PCSR_EN);
	

}
#endif 

//禁止定时器14
void LT_UsartTimeDisable(void)
{
	PIT1->PCSR &=~PCSR_PIE;
	PIT1->PCSR &=~PCSR_EN;
}

//使能定时器14
void LT_UsartTimeEnable(void)
{
//	gRxfist = 0;
	PIT1->PCSR |=PCSR_PIE;
	PIT1->PCSR |=PCSR_EN;
}

//设置定时器14装载值
void LT_UsartTimeSetCounter(UINT32 Counter)
{
	PIT1->PMR = Counter;//
	PIT1->PCSR |=PCSR_PIF;
	LT_UsartTimeEnable();
}


