/***********************************************************************
 * Copyright (c)  2017 - 2022, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : atim_singlepulse.c
 * Description : atim_singlepulse source file
 * Author(s)   : Hackett
 * version     : V1.0
 * Modify date : 2022-07-10
 ***********************************************************************/
#include  "atim_singlepulse.h"
#include  "uart0.h"
#include  "uart1.h"
#include  "uart2.h"
#include  "atimer.h"
#include  "gpio.h"


/************************************************************************
 * function   : atimer_singlepulse_pro
 * Description: atimer_singlepulse_pro atimer处理回调函数
 * input : none
 * return: none
 ************************************************************************/
void atimer_singlepulse_pro(void)
{
	static uint16_t times = 0;

	if(atimer_get_status(ATIM_STATUS_UIF))
	{	
		printfS("times = %d \r\n", times);
		times ++;
		if(times > 65530)
		{
			times = 0;
		}
	}	
}


/************************************************************************
 * function   : atimer_singlepulse_test
 * Description: 单脉冲输出
 * input : none
 * return: none
 ************************************************************************/
void atimer_singlepulse_test(void)
{
	printfS("start atimer singlepulse test! \r\n");
	
	gpio_init(GPIOF, PIN0, 7);		//PF0 ATIM_CH1
	gpio_init(GPIOF, PIN2, 10);		//PF2 ATIM_CH2	触发输入
	atimer_module_enable();			//使能时钟并复位定时器0模块	
	atimer_singlepulse_init(48000, 2, ATIM_CHANNEL1, ATIM_CHANNEL2);	
	atimer_counter(ATIM_ENABLE);	//计数器使能
	atimer_irq(ATIM_UIE, ATIMER_IRQn, ATIM_ENABLE, atimer_singlepulse_pro);//允许更新事件中断,开启中断
	
	atimer_set_compare(ATIM_CHANNEL1, (48000 / 2));//通道3的输出比较值
	
}

