/***********************************************************************
 * Copyright (c)  2017 - 2022, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : app.c
 * Description : app source file
 * Author(s)   : Dan
 * version     : V1.0
 * Modify date : 2022-08-04
 ***********************************************************************/
#include  "app.h"
#include  "config.h"
#include  "common.h"
#include  "uart0.h"
#include  "uart1.h"
#include  "uart2.h"
#include  "lptimer.h"
#include  "dma.h"


volatile uint8_t flag_ov_int = 0;
volatile uint8_t flag_trig_int = 0;
volatile uint8_t flag_comp_int = 0;
volatile uint32_t data[5];
volatile uint32_t data1;
volatile uint8_t dma_complete_flag = 0;


uint32_t g_data_buf[512];

#ifdef UART0_COMM
uint8_t uart0_rx_flag = 0;
uint8_t uart0_rx_buf[64];
uint8_t uart0_rx_count = 0;
#endif

#ifdef UART1_COMM
uint8_t uart1_rx_flag = 0;
uint8_t uart1_rx_buf[64];
uint8_t uart1_rx_count = 0;
#endif

#ifdef UART2_COMM
uint8_t uart2_rx_flag = 0;
uint8_t uart2_rx_buf[64];
uint8_t uart2_rx_count = 0;
#endif

#ifdef UART0_COMM
/************************************************************************
 * function   : uart0_rec_pro
 * Description: uart0 rec pro 串口接收处理回调函数
 * input : none
 * return: none
 ************************************************************************/
void uart0_rec_pro(void)
{
	uart0_rx_buf[uart0_rx_count] = uart0_recv_byte();
	uart0_rx_count++;
	uart0_rx_flag = 1;	
}
#endif

#ifdef UART1_COMM
/************************************************************************
 * function   : uart1_rec_pro
 * Description: uart1 rec pro 串口接收处理回调函数
 * input : none
 * return: none
 ************************************************************************/
void uart1_rec_pro(void)
{
	uart1_rx_buf[uart1_rx_count] = uart1_recv_byte();
	uart1_rx_count++;
	uart1_rx_flag = 1;	
}
#endif

#ifdef UART2_COMM
/************************************************************************
 * function   : uart1_rec_pro
 * description: uart1 rec pro 串口接收处理回调函数
 * input : none
 * return: none
 ************************************************************************/
void uart2_rec_pro(void)
{
	uart2_rx_buf[uart2_rx_count] = uart2_recv_byte();
	uart2_rx_count++;
	uart2_rx_flag = 1;	
}
#endif
/************************************************************************
 * function   : uart_init
 * description: uart_init 串口初始化
 * input 	  : none
 * return	  : none
 ************************************************************************/
void uart_init(void)
{
#ifdef  UART0_COMM     
	uart0_rx_flag = 0;
	uart0_init(PCLK, UART0_BAUD_RATE);
	uart0_irq_init(UART0_IRQ_ENABLE, uart0_rec_pro);
#endif

#ifdef  UART1_COMM	
	uart1_rx_flag = 0;	
	uart1_init(PCLK, UART1_BAUD_RATE);
	uart1_irq_init(UART1_IRQ_ENABLE, uart1_rec_pro);
#endif

#ifdef  UART2_COMM    
    uart2_rx_flag = 0;	
	uart2_init(PCLK, UART2_BAUD_RATE);
	uart2_irq_init(UART2_IRQ_ENABLE, uart2_rec_pro);
#endif
}

/*******************************************************************
* function		: lptimer_count_irq
* description	: 定时器中断处理函数
* input			: none
* return		: none
********************************************************************/
void lptimer_count_irq(void)
{
	static uint32_t time = 0;
	printfS("time=%d\r\n",time++);
}
/*******************************************************************
* function		: lptimer_trigger_irq
* description	: lptimer_trigger_irq
* input			: none
* return		: none
********************************************************************/
void lptimer_trigger_irq(void)
{
	
#ifdef LPTIMER0
	printfS("trigger cnt=%d\r\n",REG_LPTIM0_CNT1);
#elif defined LPTIMER1
	printfS("trigger cnt=%d\r\n",REG_LPTIM1_CNT2);
#elif defined LPTIMER2
	printfS("trigger cnt=%d\r\n",REG_LPTIM2_CNT1);
#elif defined LPTIMER3
	printfS("trigger cnt=%d\r\n",REG_LPTIM3_CNT2);
#endif
}

/*******************************************************************
* function		: lptimer_irq_timeout
* description	: 定时中断处理函数
* input			: none
* return		: none
********************************************************************/
void lptimer_timeout_irq(void)
{
	flag_ov_int = 1;
}
/*******************************************************************
* function		: dmac_tc_irq
* description	: dmac中断处理函数
* input			: none
* return		: none
********************************************************************/
void dmac_tc_irq(void)
{
	dma_complete_flag = 1;
}
/*******************************************************************
* function		: lptimer_count_load_test
* description	: lptimer_count_load_test
* input			: none
* return		: none
********************************************************************/
void lptimer_count_load_test(void)
{
#ifdef LPTIMER0																					//be defined in app.h
	lptimer0_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV32, 1500000); 	    //时钟源为48M,32分频，定时1s
	
	lptimer0_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM0_IER_UIE, lptimer_count_irq);      		//LPTimer0溢出中断初始化
	
	lptimer0_start();	                                                                        //LPTimer0启动计数
	
	printfS("lptimer0 count_load test start\r\n");                    
	
	while(1)
	{
		REG_LPTIM0_BUFFER1 = 0x00000000;
		REG_LPTIM0_LOAD1 =0x01;
		while(REG_LPTIM0_LOAD1);
		printfS("CNT=%x,BUFFER=%x\r\n",REG_LPTIM0_CNT1,REG_LPTIM0_BUFFER1);
		delay_ms(2000);
	}
#elif defined LPTIMER1																			//be defined in app.h
	lptimer1_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV32, 1500000); 	    //时钟源为48M,32分频，定时1s
	
	lptimer1_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM1_IER_UIE, lptimer_count_irq);				//LPTimer1溢出中断初始化
	
	lptimer1_start();																			//LPTimer1启动计数																
	
	printfS("lptimer1 count_load test start\r\n");     
	
	while(1)
	{
		REG_LPTIM1_BUFFER2 = 0x00000000;
		REG_LPTIM1_LOAD2 =0x01;
		while(REG_LPTIM1_LOAD2);
		printfS("CNT=%x,BUFFER=%x\r\n",REG_LPTIM1_CNT2,REG_LPTIM1_BUFFER2);
		delay_ms(2000);
	}	
#elif  defined LPTIMER2																			//be defined in app.h
	lptimer2_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV32, 1500000); 	    //时钟源为48M,32分频，定时1s
	
	lptimer2_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM2_IER_UIE, lptimer_count_irq);				//LPTimer2溢出中断初始化
	
	lptimer2_start();				                                                         	//LPTimer2启动计数
	
	printfS("lptimer2 count_load test start\r\n");     
	
	while(1)
	{
		REG_LPTIM2_BUFFER1 = 0x00000000;
		REG_LPTIM2_LOAD1 =0x01;
		while(REG_LPTIM2_LOAD1);
		printfS("CNT=%x,BUFFER=%x\r\n",REG_LPTIM2_CNT1,REG_LPTIM2_BUFFER1);
		delay_ms(2000);
	}
#elif  defined LPTIMER3																			//be defined in app.h
	lptimer3_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV32, 1500000); 	    //时钟源为48M,32分频，定时1s
	
	lptimer3_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM3_IER_UIE, lptimer_count_irq);				//LPTimer3溢出中断初始化
	
	lptimer3_start();		                                                                    //LPTimer3启动计数
	
	printfS("lptimer3 count_load test start\r\n");     
	
	while(1)
	{
		REG_LPTIM3_BUFFER2 = 0x00000000;
		REG_LPTIM3_LOAD2 =0x01;
		while(REG_LPTIM3_LOAD2);
		printfS("CNT=%x,BUFFER=%x\r\n",REG_LPTIM3_CNT2,REG_LPTIM3_BUFFER2);
		delay_ms(2000);
	}
#endif	
}

/*******************************************************************
* function		: lptimer_count_ms_test
* description	: lptimer_count_ms_test
* input			: none
* return		: none
********************************************************************/
void lptimer_count_ms_test(void)
{
#ifdef LPTIMER0                                                                                 //be defined in app.h
	lptimer0_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV128, 375000);		//时钟源为48M,128分频，定时1s
	
	lptimer0_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM0_IER_UIE, lptimer_count_irq);				//LPTimer0溢出中断初始化
	
	lptimer0_start();		                                                                    //LPTimer0启动计数	
                                                                        
	printfS("lptimer0 count_ms test start\r\n");   
	
#elif defined LPTIMER1                                                                          //be defined in app.h
	lptimer1_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1, 24000000); 		//时钟源为48M,1分频，定时500ms
	
	lptimer1_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM1_IER_UIE, lptimer_count_irq);				//LPTimer1溢出中断初始化
	
	lptimer1_start();																			//LPTimer1启动计数														

	printfS("lptimer1 count_ms test start\r\n");   
	
#elif defined LPTIMER2                                                                          //be defined in app.h
	lptimer2_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV32, 150000); 		//时钟源为48M,32分频，定时100ms
	
	lptimer2_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM2_IER_UIE, lptimer_count_irq);				//LPTimer2溢出中断初始化
	
	lptimer2_start();			                                                                //LPTimer2启动计数				
	
	printfS("lptimer2 count_ms test start\r\n");   
	
#elif defined LPTIMER3                                                                          //be defined in app.h
	lptimer3_count_init(VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV4,12000000); 		//时钟源为48M,4分频，定时1000ms
		 
	lptimer3_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM3_IER_UIE, lptimer_count_irq);				//LPTimer3溢出中断初始化
		 
	lptimer3_start();	                                                                        //LPTimer3启动计数
	
	printfS("lptimer3 count_ms test start\r\n");                                                                                     
#endif	
}

/*******************************************************************
* function		: lptimer_pwm_test
* description	: lptimer_pwm_test
* input			: none
* return		: none
********************************************************************/
void lptimer_pwm_test(void)
{
#ifdef LPTIMER0                                                                                     //be defined in app.h
	lptimer0_pwm_init(3000, 20000, VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);       	//时钟源为48M，输出占空比为15%的PWM，极性为高
	
	lptimer0_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM0_IER_CC1IE, NULL);
	lptimer0_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM0_IER_CC2IE, NULL);							//LPTimer0比较中断初始化
	
	lptimer0_start();																				//LPTimer0启动计数
		
	printfS("lptimer0 pwm test start\r\n");
	
#elif defined LPTIMER1	                                                                            //be defined in app.h
	lptimer1_pwm_init(4000, 16000, VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);		    //时钟源为48M，输出占空比为25%的PWM，极性为高
		
	lptimer1_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM1_IER_CC1IE, NULL);							//LPTimer1比较中断初始化
	lptimer1_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM1_IER_CC2IE, NULL);		
	
	lptimer1_start();				                                                          		//LPTimer1启动计数
																	
	printfS("lptimer1 pwm test start\r\n");
	
#elif defined LPTIMER2                                                                              //be defined in app.h
	lptimer2_pwm_init(4000, 10000, VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);	        //时钟源为48M，输出占空比为40%的PWM，极性为高
	
	lptimer2_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM2_IER_CC1IE, NULL);							//LPTimer2比较中断初始化
	lptimer2_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM2_IER_CC2IE, NULL);	
	
	lptimer2_start();																				//LPTimer2启动计数
	
	printfS("lptimer2 pwm test start\r\n");
	
#elif defined LPTIMER3 																				//be defined in app.h
	lptimer3_pwm_init(12000, 24000, VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);	    //时钟源为48M，输出占空比为50%的PWM，极性为高
		 
	lptimer3_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM3_IER_CC1IE, NULL);							//LPTimer3比较中断初始化
	lptimer3_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM3_IER_CC2IE, NULL);	 
	
	lptimer3_start();																				//LPTimer3启动计数
	 
	printfS("lptimer3 pwm test start\r\n");
	
#endif
	
}

/*******************************************************************
* function		: lptimer_trigger_test
* description	: lptimer_trigger_test
* input			: none
* return		: none
********************************************************************/
void lptimer_trigger_test(void)
{
#ifdef LPTIMER0																						//be defined in app.h
	lptimer0_trigger_init(VAL_LPTIM_CR2_CLKSEL_LSRC32K, VAL_LPTIM_CR2_DIVSEL_DIV1, 65535); 	        //时钟源为48M,不分频，定时1000ms，Trigger触发计数初始化
		
	lptimer0_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM0_IER_TIE, lptimer_trigger_irq);  			    //外部触发中断初始化
	
	lptimer0_start();	                                                                            //LPTimer0启动计数
	
	printfS("lptimer0 trigger test start!\r\n"); 
	
#elif defined LPTIMER1 																				//be defined in app.h
	lptimer1_trigger_init(VAL_LPTIM_CR2_CLKSEL_LSRC32K, VAL_LPTIM_CR2_DIVSEL_DIV1, 65535);		    //时钟源为48M,不分频，定时1000ms，Trigger触发计数初始化
	
	lptimer1_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM1_IER_TIE, lptimer_trigger_irq);			    //外部触发中断初始化
	
	lptimer1_start();																			    //LPTimer1启动计数

	printfS("lptimer1 trigger test start!\r\n"); 
	
#elif defined LPTIMER2                                                                              //be defined in app.h
	lptimer2_trigger_init(VAL_LPTIM_CR2_CLKSEL_LSRC32K, VAL_LPTIM_CR2_DIVSEL_DIV1, 65535);		    //时钟源为48M,不分频，定时1000ms，Trigger触发计数初始化
	
	lptimer2_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM2_IER_TIE, lptimer_trigger_irq);			    //外部触发中断初始化
	
	lptimer2_start();	                                                                            //LPTimer2启动计数
            
	printfS("lptimer2 trigger test start!\r\n"); 
	
#elif defined LPTIMER3																				//be defined in app.h
	lptimer3_trigger_init(VAL_LPTIM_CR2_CLKSEL_LSRC32K, VAL_LPTIM_CR2_DIVSEL_DIV1, 65535);	        //时钟源为48M,不分频，定时1000ms，Trigger触发计数初始化
	
	lptimer3_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM3_IER_TIE, lptimer_trigger_irq);			    //外部触发中断初始化
	
	lptimer3_start();						                                                        //LPTimer3启动计数
	
	printfS("lptimer3 trigger test start!\r\n"); 	
#endif
	
	while(1)
	{
		
	}
}

/*******************************************************************
* function		: lptimer_extcount_test
* description	: lptimer_extcount_test
* input			: none
* return		: none
********************************************************************/
void lptimer_extcount_test(void)
{
#ifdef LPTIMER0																						//be defined in app.h
	lptimer0_extcount_init(VAL_LPTIM_CR2_CLKSEL_LPTIN, VAL_LPTIM_CR2_DIVSEL_DIV1,0xffffffff);	    //时钟源为低速时钟32K，不分频，外部异步计数初始化
	
	lptimer0_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM0_IER_UIE, NULL);  							//溢出中断初始化
	
	lptimer0_start();	                                                                            //LPTimer0启动计数

	printfS("lptimer0 extcount test start\r\n");
	
#elif defined LPTIMER1																				//be defined in app.h
	lptimer1_extcount_init(VAL_LPTIM_CR2_CLKSEL_LPTIN, VAL_LPTIM_CR2_DIVSEL_DIV1, 0xffffffff);      //时钟源为低速时钟32K，不分频，外部异步计数初始化
	
	lptimer1_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM1_IER_UIE, NULL);							    //溢出中断初始化
	
	lptimer1_start();																				//LPTimer1启动计数
	
	printfS("lptimer1 extcount test start\r\n");	
	
#elif defined LPTIMER2																				//be defined in app.h
	lptimer2_extcount_init(VAL_LPTIM_CR2_CLKSEL_LPTIN, VAL_LPTIM_CR2_DIVSEL_DIV1, 0xffffffff);	    //时钟源为低速时钟32K，不分频，外部异步计数初始化
		 
	lptimer2_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM2_IER_UIE, NULL);							    //溢出中断初始化
		 
	lptimer2_start();	                                                                            //LPTimer2启动计数

	printfS("lptimer2 extcount test start\r\n");
	
#elif defined LPTIMER3																				//be defined in app.h
	lptimer3_extcount_init(VAL_LPTIM_CR2_CLKSEL_LPTIN, VAL_LPTIM_CR2_DIVSEL_DIV1, 0xffffffff);	    //时钟源为低速时钟32K，不分频，外部异步计数初始化
	
	lptimer3_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM3_IER_UIE, NULL);							    //溢出中断初始化
	
	lptimer3_start();																				//LPTimer3启动计数

	printfS("lptimer3 extcount test start\r\n");
	
#endif
	

	while(1)
	{
#ifdef LPTIMER0																					
		printfS("trigger cnt=%d\r\n",REG_LPTIM0_CNT1);
		delay_ms(500);
#elif defined LPTIMER1
		printfS("trigger cnt=%d\r\n",REG_LPTIM1_CNT2);
		delay_ms(500);
#elif defined LPTIMER2
		printfS("trigger cnt=%d\r\n",REG_LPTIM2_CNT1);
		delay_ms(500);
#elif defined LPTIMER3
		printfS("trigger cnt=%d\r\n",REG_LPTIM3_CNT2);
		delay_ms(500);
#endif
	}
}

/*******************************************************************
* function		: lptimer_time_out_test
* description	: lptimer_time_out_test
* input			: none
* return		: none
********************************************************************/
void lptimer_time_out_test(void)
{
#ifdef LPTIMER0																						//be defined in app.h
	lptimer0_time_out_init(VAL_LPTIM_CR2_CLKSEL_LSRC32K, VAL_LPTIM_CR2_DIVSEL_DIV1,65535);	        //Timeout模式初始化，第一次脉冲来时开始计数，若计数到目标值前没有脉冲到来，则触发溢出超时中断
	
	lptimer0_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM0_IER_UIE, lptimer_timeout_irq);  				//溢出中断初始化
	
	lptimer0_start();																				//LPTimer0启动计数
	
	printfS("lptimer0 time_out test start\r\n");
	
#elif defined LPTIMER1																				//be defined in app.h
	lptimer1_time_out_init(VAL_LPTIM_CR2_CLKSEL_LSRC32K, VAL_LPTIM_CR2_DIVSEL_DIV1,65535);			//Timeout模式初始化，第一次脉冲来时开始计数，若计数到目标值前没有脉冲到来，则触发溢出超时中断
	
	lptimer1_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM1_IER_UIE, lptimer_timeout_irq);				//溢出中断初始化
	
	lptimer1_start();																				//LPTimer1启动计数																						 //LPTimer0启动计数
	
	printfS("lptimer1 time_out test start\r\n");
	
#elif defined LPTIMER2																				//be defined in app.h
	lptimer2_time_out_init(VAL_LPTIM_CR2_CLKSEL_LPTIN, VAL_LPTIM_CR2_DIVSEL_DIV1,65535);			//Timeout模式初始化，第一次脉冲来时开始计数，若计数到目标值前没有脉冲到来，则触发溢出超时中断
	
	lptimer2_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM2_IER_UIE, lptimer_timeout_irq);				//溢出中断初始化
	
	lptimer2_start();	                                                                        	//LPTimer2启动计数

	printfS("lptimer2 time_out test start\r\n");	
	
#elif defined LPTIMER3																				//be defined in app.h
	lptimer3_time_out_init(VAL_LPTIM_CR2_CLKSEL_LPTIN, VAL_LPTIM_CR2_DIVSEL_DIV1,65535);			//Timeout模式初始化，第一次脉冲来时开始计数，若计数到目标值前没有脉冲到来，则触发溢出超时中断
	
	lptimer3_irq_init(VAL_LPTIM_IRQ_ENABLE, VAL_LPTIM3_IER_UIE, lptimer_timeout_irq);				//溢出中断初始化
	
	lptimer3_start();		                                                                        //LPTimer3启动计数	
	
	printfS("lptimer3 time_out test start\r\n");	
	
#endif

	while(!flag_ov_int)
	{
#ifdef LPTIMER0
		printfS("trigger cnt=%d\r\n",REG_LPTIM0_CNT1);
#elif defined LPTIMER1
		printfS("trigger cnt=%d\r\n",REG_LPTIM1_CNT2);
#elif defined LPTIMER2
		printfS("trigger cnt=%d\r\n",REG_LPTIM2_CNT1);
#elif defined LPTIMER3
		printfS("trigger cnt=%d\r\n",REG_LPTIM3_CNT2);
#endif
	}
	printfS("lptimer count time out\r\n");
}
/*******************************************************************
* function		: lptimer_capture_test
* description	: lptimer_capture_test
* input			: none
* return		: none
********************************************************************/
void lptimer_capture_test(void)
{
	volatile uint32_t dma_data[8];
	
#ifdef LPTIMER0																				   				//be defined in app.h
	printfS("lptimer0 capture test start\r\n");				
					
	lptimer0_capture_init(0xffffffff,VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);  				//lptimer0 输入捕获初始化
				
	dma_init(DMA_Channel_1,DMA_TR_WIDTH_32,DMA_PERIP_TO_MEM);								   				//初始化dma
	dma_irq_init(DMA_Channel_1,DMA_IRQ_ENABLE,dmac_tc_irq);				
	dma_source_config(DMA_Channel_1,DMA_SRC_PER_LPTIMER0_RX1,DMA_SINC_NOC);				
	dma_destination_config(DMA_Channel_1,DMA_SRC_PER_MEMORY,DMA_DINC_INC);				
	dma_controler_enable();				
					
	lptimer0_start();			                                                               				//LPTimer0启动计数
					
	dma_irq_transfer(DMA_Channel_1,((uint32_t)&REG_LPTIM0_CCR1),((uint32_t)&dma_data),8);      				//配置源地址、目的地址、dma通道、block大小、开始dma中断传输
					
#elif defined LPTIMER1																						//be defined in app.h	
	printfS("lptimer1 capture test start\r\n");				
					
	lptimer1_capture_init(0xffffffff,VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);  				//lptimer1 输入捕获初始化
																											
	dma_init(DMA_Channel_2,DMA_TR_WIDTH_32,DMA_PERIP_TO_MEM);                                  				//初始化dma
	dma_irq_init(DMA_Channel_2,DMA_IRQ_ENABLE,dmac_tc_irq);				
	dma_source_config(DMA_Channel_2,DMA_SRC_PER_LPTIMER1_RX2,DMA_SINC_NOC);				
	dma_destination_config(DMA_Channel_2,DMA_SRC_PER_MEMORY,DMA_DINC_INC);				
	dma_controler_enable();				
				
	lptimer1_start();																		   				//LPTimer1启动计数																		
					
	dma_irq_transfer(DMA_Channel_2,((uint32_t)&REG_LPTIM1_CCR4),((uint32_t)&dma_data),8);      				//配置源地址、目的地址、dma通道、block大小、开始dma中断传输
					
#elif defined LPTIMER2																						//be defined in app.h			
	printfS("lptimer2 capture test start\r\n");				
					
	lptimer2_capture_init(0xffffffff,VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);  				//lptimer2 输入捕获初始化
					
	dma_init(DMA_Channel_3,DMA_TR_WIDTH_32,DMA_PERIP_TO_MEM);                                  				//初始化dma
	dma_irq_init(DMA_Channel_3,DMA_IRQ_ENABLE,dmac_tc_irq);				
	dma_source_config(DMA_Channel_3,DMA_SRC_PER_LPTIMER2_RX1,DMA_SINC_NOC);				
	dma_destination_config(DMA_Channel_3,DMA_SRC_PER_MEMORY,DMA_DINC_INC);				
	dma_controler_enable();				
					
	lptimer2_start();																		   				//LPTimer2启动计数
					
	dma_irq_transfer(DMA_Channel_3,((uint32_t)&REG_LPTIM2_CCR1),((uint32_t)&dma_data),8);      				//配置源地址、目的地址、dma通道、block大小、开始dma中断传输
					
#elif defined LPTIMER3																						//be defined in app.h		
	printfS("lptimer3 capture test start\r\n");				
					
	lptimer3_capture_init(0xffffffff,VAL_LPTIM_CR2_CLKSEL_LPTCLK, VAL_LPTIM_CR2_DIVSEL_DIV1);  				//lptimer3 输入捕获初始化
					
	dma_init(DMA_Channel_4,DMA_TR_WIDTH_32,DMA_PERIP_TO_MEM);                   			   				//初始化dma
	dma_irq_init(DMA_Channel_4,DMA_IRQ_ENABLE,dmac_tc_irq);				
	dma_source_config(DMA_Channel_4,DMA_SRC_PER_LPTIMER3_RX2,DMA_SINC_NOC);				
	dma_destination_config(DMA_Channel_4,DMA_SRC_PER_MEMORY,DMA_DINC_INC);				
	dma_controler_enable();				
					
	lptimer3_start();	                                                                       				//LPTimer3启动计数
					
	dma_irq_transfer(DMA_Channel_4,((uint32_t)&REG_LPTIM3_CCR4),((uint32_t)&dma_data),8);	   				//配置源地址、目的地址、dma通道、block大小、开始dma中断传输
	
#endif
	
	
	while(1)
	{
		if(dma_complete_flag == 1)
		{
			for(int i=0;i<8;i++)
			{
				printfS("CCR捕获的值为：%#x\r\n",dma_data[i]);
			}
			dma_complete_flag =0;
		}
	}
}

/*******************************************************************
* function		: lptimer0_test
* description	: lptimer0_test
* input			: none
* return		: none
********************************************************************/
void lptimer_test(void)
{
	printfS("System run at %dHz\r\n", SystemCoreClock);

//	lptimer_count_load_test();					//count_load模式
	
	lptimer_count_ms_test();					//计数模式
	
//	lptimer_pwm_test();							//PWM test 

//	lptimer_capture_test();						//输入捕获
	
//	lptimer_trigger_test();						//外部脉冲触发计数 
	
//	lptimer_extcount_test();					//外部异步脉冲计数
	
//	lptimer_time_out_test();					//Timeout test

}
/*******************************************************************
* function		: soc_test
* description	: soc_test
* input			: none
* return		: none
********************************************************************/
void soc_test(void)
{
	lptimer_test(); 
}
