1 /*****************************************************************************
2  * Copyright (c) 2019, Nations Technologies Inc.
3  *
4  * All rights reserved.
5  * ****************************************************************************
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the disclaimer below.
12  *
13  * Nations' name may not be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
19  * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  * ****************************************************************************/
27 
28 /**
29  * @file Eif_timer.c
30  * @author Nations
31  * @version v1.0.0
32  *
33  * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
34  */
35 #include "Eif_timer.h"
36 #include "bsp_timer.h"
37 #include "ke_event.h"
38 //#include "Eif_iom.h"
39 
40 
41 /*************************************
42 *函数名:eif_timer_isr
43 *功能:设置一个定时器事件
44 *参数:void
45 *
46 *返回值:void
47 *备注:
48 **************************************/
eif_timer_isr(void)49 void eif_timer_isr(void)
50 {
51     ke_event_set(KE_EVENT_KE_TIMER);
52 }
53 
54 /*************************************
55 *函数名:eif_timer_init
56 *功能:定时器初始化,配置自动重装值和分频系数
57 *参数:void
58 *
59 *返回值:void
60 *备注:
61 **************************************/
eif_timer_init(void)62 void eif_timer_init(void)
63 {
64     TIM3_config(9999,35);//36分频,1MHz计数,10ms定时中断
65 }
66 
67 /*************************************
68 *函数名:eif_set_timeout
69 *功能:设置超时时间,10ms计时基数
70 *参数:to,超时时长
71 *
72 *返回值:void
73 *备注:
74 **************************************/
eif_set_timeout(uint32_t to)75 void eif_set_timeout(uint32_t to)
76 {
77     TIM3_set_timeout(to);
78 }
79 
80 /*************************************
81 *函数名:eif_get_time
82 *功能:获取超时剩余时间,单位ms
83 *参数:void
84 *
85 *返回值:void
86 *备注:
87 **************************************/
eif_get_time(void)88 uint32_t eif_get_time(void)
89 {
90     return (TIM3_get_time());
91 }
92 
93 /*************************************
94 *函数名:eif_enable_timer
95 *功能:启动或关闭定时器
96 *参数:enable,1:启动; 0:关闭
97 *
98 *返回值:void
99 *备注:
100 **************************************/
eif_enable_timer(bool enable)101 void eif_enable_timer(bool enable)
102 {
103     TIM3_IRQ_enable(enable);
104 }
105 
106