timer.h
Go to the documentation of this file.
1 /********************************************************************************************************
2  * @file timer.h
3  *
4  * @brief This is the source file for TLSR8258
5  *
6  * @author Driver Group
7  * @date May 8, 2018
8  *
9  * @par Copyright (c) 2018, Telink Semiconductor (Shanghai) Co., Ltd.
10  * All rights reserved.
11  *
12  * The information contained herein is confidential property of Telink
13  * Semiconductor (Shanghai) Co., Ltd. and is available under the terms
14  * of Commercial License Agreement between Telink Semiconductor (Shanghai)
15  * Co., Ltd. and the licensee or the terms described here-in. This heading
16  * MUST NOT be removed from this file.
17  *
18  * Licensees are granted free, non-transferable use of the information in this
19  * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
20  * @par History:
21  * 1.initial release(DEC. 26 2018)
22  *
23  * @version A001
24  *
25  *******************************************************************************************************/
26 
27 #ifndef TIMER_H_
28 #define TIMER_H_
29 #include "compiler.h"
30 #include "register.h"
31 #include "analog.h"
32 #include "gpio.h"
33 
37 typedef enum{
38  TIMER0 =0,
39  TIMER1 =1,
40  TIMER2 =2,
42 
46 typedef enum{
52 
53 #define sys_tick_per_us 16
54 #define CLOCK_SYS_CLOCK_1250US (1250 * sys_tick_per_us)
55 
59 enum{
63 };
64 
71 static inline unsigned long clock_time(void)
72 {
73  return reg_system_tick;
74 }
75 
76 
77 
78 
85 extern void sleep_us(unsigned long us);
86 
87 #define ClockTime clock_time
88 #define WaitUs sleep_us
89 #define WaitMs(t) sleep_us((t)*1000)
90 #define sleep_ms(t) sleep_us((t)*1000)
91 
99 static inline unsigned int clock_time_exceed(unsigned int ref, unsigned int us)
100 {
101  return ((unsigned int)(clock_time() - ref) > us * 16);
102 }
103 
110 extern void timer0_gpio_init(GPIO_PinTypeDef pin, GPIO_PolTypeDef pol);
111 
118 extern void timer1_gpio_init(GPIO_PinTypeDef pin, GPIO_PolTypeDef pol);
119 
127 
135 extern void timer0_set_mode(TIMER_ModeTypeDef mode,unsigned int init_tick, unsigned int cap_tick);
136 
144 extern void timer1_set_mode(TIMER_ModeTypeDef mode,unsigned int init_tick, unsigned int cap_tick);
145 
153 extern void timer2_set_mode(TIMER_ModeTypeDef mode,unsigned int init_tick, unsigned int cap_tick);
154 
160 extern void timer_start(TIMER_TypeDef type);
161 
167 extern void timer_stop(TIMER_TypeDef type);
168 
169 
170 
171 #endif /* TIMER_H_ */
172  //end of GP10
static unsigned long clock_time(void)
This function performs to gets system timer0 address.
Definition: timer.h:71
void timer2_gpio_init(GPIO_PinTypeDef pin, GPIO_PolTypeDef pol)
initiate GPIO for gpio trigger and gpio width mode of timer2.
GPIO_PolTypeDef
Define rising/falling types.
Definition: gpio_8258.h:135
TIMER_ModeTypeDef
Mode of Timer.
Definition: timer.h:46
Definition: timer.h:50
Definition: timer.h:60
Definition: timer.h:47
void timer0_gpio_init(GPIO_PinTypeDef pin, GPIO_PolTypeDef pol)
initiate GPIO for gpio trigger and gpio width mode of timer0.
Definition: timer.h:61
Definition: timer.h:62
void timer_start(TIMER_TypeDef type)
the specifed timer start working.
static unsigned int clock_time_exceed(unsigned int ref, unsigned int us)
This function performs to calculation exceed us of the timer.
Definition: timer.h:99
Definition: timer.h:40
Definition: timer.h:39
void timer1_set_mode(TIMER_ModeTypeDef mode, unsigned int init_tick, unsigned int cap_tick)
set mode, initial tick and capture of timer1.
GPIO_PinTypeDef
Define GPIO types.
Definition: gpio_8258.h:38
#define reg_system_tick
Definition: register_8258.h:809
Definition: timer.h:49
void timer_stop(TIMER_TypeDef type)
the specifed timer stop working.
void timer2_set_mode(TIMER_ModeTypeDef mode, unsigned int init_tick, unsigned int cap_tick)
set mode, initial tick and capture of timer2.
TIMER_TypeDef
Type of Timer.
Definition: timer.h:37
void sleep_us(unsigned long us)
This function performs to set sleep us.
void timer0_set_mode(TIMER_ModeTypeDef mode, unsigned int init_tick, unsigned int cap_tick)
set mode, initial tick and capture of timer0.
Definition: timer.h:38
Definition: timer.h:48
void timer1_gpio_init(GPIO_PinTypeDef pin, GPIO_PolTypeDef pol)
initiate GPIO for gpio trigger and gpio width mode of timer1.