WXK
2025-01-21 8f1a91a8ec98e430cfe4357bda099d495917198e
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
77
/**
 *******************************************************************************
 * @file     app_timer.h
 * @create   2023-08-01    
 * @author   Panchip BLE GROUP
 * @note
 * Copyright (c) Shanghai Panchip Microelectronics Co.,Ltd.
 *
 *******************************************************************************
 */
#ifndef APP_TIMER_H_
#define APP_TIMER_H_
 
#include <stdint.h>
#include <stdbool.h>
#include "os/queue.h"
#include "soc_api.h"
 
/*! ms to ticks */
#define APP_TIMER_MS_TO_TICKS(ms)       ((uint32_t)((ms)*(uint64_t)soc_32k_clock_freq_get() / 1000))
 
/*! Invalid value used to indicate that timer is idle. */
#define APP_TIMER_IDLE_VAL                 0xFFFFFFFFFFFFFFFFULL
 
/*! Check if timer is idle */
#define APP_TIMER_IS_IDLE(timer)         (timer->endVal == APP_TIMER_IDLE_VAL)
 
/*! Minimum value of the timeout_ticks parameter of app_timer_start(). */
#define APP_TIMER_MIN_TIMEOUT_TICKS     10
 
/*! Capacity of timer requests FIFO item number.  */
#define APP_TIMER_REQ_FIFO_ITEM_NUM     10
 
enum{
    APP_TIMER_OK,
    APP_TIMER_NO_MEM,
};
 
/**@brief timer timeout call-back. */
typedef void (*app_timer_timeout_handler_t)(void *ctxt);
 
/**
 * @brief app_timer control block
 */
struct app_timer_s{
    SLIST_ENTRY(app_timer_s)    next;
    uint64_t                    endVal;
    uint32_t                    reloadPeriod;
    app_timer_timeout_handler_t handler;
    void                         *ctxt;
};
typedef struct app_timer_s app_timer_t;
 
/**@brief Timer modes. */
typedef enum{
    APP_TIMER_MODE_SINGLE_SHOT,                 /**< The timer will expire only once. */
    APP_TIMER_MODE_REPEATED                     /**< The timer will restart each time it expires. */
}app_timer_mode_t;
 
int app_timer_init(void);
 
int app_timer_create(app_timer_t *ptimer, app_timer_mode_t mode, app_timer_timeout_handler_t timeout_handler);
 
int app_timer_start(app_timer_t *ptimer, uint32_t timeout_ticks, void *ctxt);
 
int app_timer_stop(app_timer_t *ptimer);
 
int app_timer_stop_all(void);
 
 
#define APP_TIMER_TEST_EN 0
#if APP_TIMER_TEST_EN
void app_timer_test(void);
#endif
 
 
#endif /* APP_TIMER_H_ */