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

/************************************************************************
 * function   : atimer_slave_pro
 * Description: atimer_slave_pro atimer处理回调函数
 * input : none
 * return: none
 ************************************************************************/
void atimer_slave_pro(void)
{
	static uint16_t times = 0;
	if(atimer_get_status(ATIM_STATUS_TIF)||atimer_get_status(ATIM_STATUS_UIF))
	{
		printfS("times = %d \r\n", times);
		times ++;
		if(times > 65530)
		{
			times = 0;
		}	
	}
}


/************************************************************************
 * function   : atimer_slave_test
 * Description: 从机模式
 * input : none
 * return: none
 ************************************************************************/
void atimer_slave_test(void)
{
	printfS("start atimer slave test! \r\n");
	
	gpio_init(GPIOF, PIN0, 7);		//PF0 ATIM_CH1
	gpio_init(GPIOG, PIN0, 12);		//PG0 ATIM_ETR(外部事件触发的外部时钟计数模式)
	atimer_module_enable();			//使能时钟并复位定时器0模块	
	atimer_slave_init(48000, 2000, ATIM_RESET, ATIM_CHANNEL1);	
	atimer_counter(ATIM_ENABLE);		//计数器使能(如果使用ATIM_TRIGGER触发模式，计时器需要关闭，即入口参数为ATIM_DISABLE)
	atimer_irq(ATIM_TIE, ATIMER_IRQn, ATIM_ENABLE, atimer_slave_pro);//允许触发事件中断,开启中断
	
	while(1)
	{
		printfS("atimer count value : %d \r\n", atimer_get_cnt());
		delay_ms(50);	
	}	
}






