BLE5.2 1.0
开发文档说明
xc_drv_aotimer.c
浏览该文件的文档.
1
25/*-----------------------------------------------------------------------------------
26 INCLUDE HEADE FILES
27 ------------------------------------------------------------------------------------*/
28#include "xc_drv_aotimer.h"
29
30/*------------------------------------------------------------------------------------
31 Local Variables
32 -------------------------------------------------------------------------------------*/
33static bool aotimer_rst_flag = false;
34
35/*------------------------------------------------------------------------------------
36 Func Prototype
37 -------------------------------------------------------------------------------------*/
40
41/*------------------------------------------------------------------------------------
42 Functions
43 -------------------------------------------------------------------------------------*/
44
45
46
57void xc_aotimer_init(uint8_t reg_idx, AOTimer_InitCfg_t *init_cfg)
58{
59 if (aotimer_rst_flag == false) {
60 cprao_aon_clken_grctl__timer_ao_pclk_en__setf(ENABLE);
61 aotimer_rst_flag = true;
62 }
63
64 //The clocks for ao timer0 and ao timer1 need to be turned on at the same time.
65 if (AOTIMER0_IDX == reg_idx) {
66 cprao_aon_clken_grctl__timer0_ao_pclk_en__setf(ENABLE);
67 cprao_aon_clken_grctl__timer1_ao_pclk_en__setf(ENABLE);
68 } else if (AOTIMER1_IDX == reg_idx) {
69 cprao_aon_clken_grctl__timer0_ao_pclk_en__setf(ENABLE);
70 cprao_aon_clken_grctl__timer1_ao_pclk_en__setf(ENABLE);
71 }
72 cpr_lp_ctl__timer_sysclk_sel__setf(ENABLE);
73
74 aotimer_tcr__tes__setf(reg_idx, DISABLE);
75 aotimer_tcr__tms__setf(reg_idx, (uint8_t)init_cfg->aotimer_mode);
76 (void)aotimer_tic__tic__getf(reg_idx);
77}
78
79
80
81
92static uint32_t xc_aotimer_us_to_ticks(uint32_t us)
93{
94 uint32_t ticks = AOTIMER_TICK_CAL(us);
95
96 if (ticks < AOTIMER_MIN_TLC_VAL)
97 ticks = AOTIMER_MIN_TLC_VAL;
98
99 return ticks;
100}
101
102
103
104
115void xc_aotimer_set_value(uint8_t reg_idx, uint32_t us)
116{
117 uint32_t ticks = xc_aotimer_us_to_ticks(us);
118
119 aotimer_tcr__tes__setf(reg_idx, AOTIMER_TCR_TES_DISABLE);
120
121 aotimer_tlc_set(reg_idx, ticks);
122}
123
124
125
135void xc_aotimer_start(uint8_t reg_idx)
136{
137 NVIC_EnableIRQ( (IRQn_Type)(TIMER_AO0_IRQn+reg_idx) );
138 aotimer_tcr__tim__setf(reg_idx, 0);
139 aotimer_tcr__tes__setf(reg_idx, ENABLE);
140 // Wait for timer enable
141 while(aotimer_tcr__tes__getf(reg_idx) != ENABLE)
142 {
143 __nop();
144 }
145}
146
156void xc_aotimer_stop(uint8_t reg_idx)
157{
158 aotimer_tcr__tes__setf(reg_idx, DISABLE);
159}
160
171{
172 cprao_aon_reg1__timer_ao_sleep_clksw__setf(0);
173 (void)aotimer_tic__tic__getf(AOTIMER0_IDX);
174 if (aotimer_n_callback[0] != NULL)
175 aotimer_n_callback[0](NULL);
176}
177
188{
189 cprao_aon_reg1__timer_ao_sleep_clksw__setf(0);
190 (void)aotimer_tic__tic__getf(AOTIMER1_IDX);
191 if (aotimer_n_callback[1] != NULL)
192 aotimer_n_callback[1](NULL);
193}
194
204__WEAK void aotimer0_callback(void *context)
205{ /* AOTimer0 中断回调处理事件 */
206}
207
217__WEAK void aotimer1_callback(void *context)
218{ /* AOTimer1 中断回调处理事件 */
219}
AOTimer_ModeTypeDef aotimer_mode
void xc_aotimer_start(uint8_t reg_idx)
xc_aotimer_start
aotimer_handler_callback aotimer_n_callback[2]
void xc_aotimer_init(uint8_t reg_idx, AOTimer_InitCfg_t *init_cfg)
xc_aotimer_init
__WEAK void aotimer1_callback(void *context)
aotimer1_callback
static uint32_t xc_aotimer_us_to_ticks(uint32_t us)
xc_aotimer_us_to_ticks
void AOTIMER1_Handler(void)
AOTIMER1_Handler
void xc_aotimer_set_value(uint8_t reg_idx, uint32_t us)
xc_aotimer_set_value
void AOTIMER0_Handler(void)
AOTIMER0_Handler
void xc_aotimer_stop(uint8_t reg_idx)
xc_aotimer_stop
__WEAK void aotimer0_callback(void *context)
aotimer0_callback
static bool aotimer_rst_flag
The header of xc_drv_aotimer.c
void(* aotimer_handler_callback)(void *context)