Repository navigation
Expand file tree
/
Copy pathmulti_timer.h
More file actions
executable file
·76 lines (64 loc) · 2.04 KB
/
Copy pathmulti_timer.h
File metadata and controls
executable file
·76 lines (64 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (c) 2016 Zibin Zheng <znbin@qq.com>
* All rights reserved
*/
#ifndef _MULTI_TIMER_H_
#define _MULTI_TIMER_H_
#include <stdint.h>
#include <stddef.h>
/*
It means 1 tick for 1ms.
Your can configurate for your tick time such as 5ms/10ms and so on.
*/
#define CFG_TIMER_1_TICK_N_MS 1
typedef struct Timer {
uint32_t cur_ticks; /* Record current timer start tick */
uint32_t cur_expired_time; /* Record current timer expired time */
uint32_t timeout; /* Delay (xx ms) time to start tiemr */
uint32_t repeat; /* Timer interval expired time (xx ms) */
void * arg; /* Input argument for timeout_cb function */
void (*timeout_cb)(void *arg); /* Timer expired callback function */
struct Timer* next; /* Pointer to next timer */
} Timer;
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initializes the timer struct handle.
* @param handle: the timer handle strcut.
* @param timeout_cb: timeout callback.
* @param timeout: delay to start the timer.
* @param repeat: repeat interval time.
* @param arg: the input argument for timeout_cb fucntion.
* @retval None
*/
void timer_init(struct Timer* handle, void(*timeout_cb)(void *arg), \
uint32_t timeout, uint32_t repeat, void *arg);
/**
* @brief Start the timer work, add the handle into work list.
* @param btn: target handle strcut.
* @retval 0: succeed. -1: already exist.
*/
int timer_start(struct Timer* handle);
/**
* @brief Stop the timer work, remove the handle off work list.
* @param handle: target handle strcut.
* @retval 0: succeed. -1: timer not exist.
*/
int timer_stop(struct Timer* handle);
/**
* @brief background ticks, timer repeat invoking interval nms.
* @param None.
* @retval None.
*/
void timer_ticks(void);
/**
* @brief main loop.
* @param None.
* @retval None
*/
void timer_loop(void);
#ifdef __cplusplus
}
#endif
#endif