|
xt-sdk 文档 v1.0.3
xt-sdk 嵌入式 SDK API 参考
|
XTINY HAL 硬件定时器模块接口 更多...
宏定义 | |
| #define | XT_HAL_TIMER_INVALID_ID (0xFFFF) |
| #define | XT_HAL_TIMER_ACTIVE_BITS_S (0) |
| #define | XT_HAL_TIMER_ACTIVE_BITS_W (1) |
| #define | XT_HAL_TIMER_AUTO_RELOAD_BITS_S (1) |
| #define | XT_HAL_TIMER_AUTO_RELOAD_BITS_W (1) |
| #define | XT_HAL_TIMER_DIR_BITS_S (2) |
| #define | XT_HAL_TIMER_DIR_BITS_W (2) |
| #define | XT_HAL_TIMER_START (0x00 << XT_HAL_TIMER_ACTIVE_BITS_S) |
| #define | XT_HAL_TIMER_STOP (0x01 << XT_HAL_TIMER_ACTIVE_BITS_S) |
| #define | XT_HAL_TIMER_ONE_SHOT (0x00 << XT_HAL_TIMER_AUTO_RELOAD_BITS_S) |
| #define | XT_HAL_TIMER_PERIODIC (0x01 << XT_HAL_TIMER_AUTO_RELOAD_BITS_S) |
| #define | XT_HAL_TIMER_DIR_UP (0x00 << XT_HAL_TIMER_DIR_BITS_S) |
| #define | XT_HAL_TIMER_DIR_DOWN (0x01 << XT_HAL_TIMER_DIR_BITS_S) |
| #define | XT_HAL_TIMER_DEFAULT_MODE (XT_HAL_TIMER_PERIODIC | XT_HAL_TIMER_DIR_UP | XT_HAL_TIMER_START) |
类型定义 | |
| typedef void(* | xt_hal_timer_cb_t) (uint8_t timer_id, uint32_t event_id) |
| 定时器回调函数类型定义 | |
枚举 | |
| enum | xt_hal_timer_event_id { XT_HAL_TIMER_EVENT_TIMEOUT = 0x00 } |
| 定时器事件 ID 枚举 更多... | |
函数 | |
| xt_err_t | xt_hal_timer_setup (uint8_t timer_id, uint32_t mode, uint32_t tick_freq_hz, uint32_t tick_num, xt_hal_timer_cb_t cb) |
| 初始化定时器 | |
| xt_err_t | xt_hal_timer_close (uint8_t timer_id) |
| 关闭定时器 | |
| xt_err_t | xt_hal_timer_start (uint8_t timer_id) |
| 启动定时器 | |
| xt_err_t | xt_hal_timer_stop (uint8_t timer_id) |
| 停止定时器 | |
| uint32_t | xt_hal_timer_get_clk_src_freq (uint8_t timer_id) |
| 获取定时器时钟源频率 | |
| uint32_t | xt_hal_timer_get_prescaler (uint8_t timer_id) |
| 获取定时器实际分频值 | |
| uint32_t | xt_hal_timer_get_count (uint8_t timer_id) |
| 获取定时器当前计数值 | |
XTINY HAL 硬件定时器模块接口
| #define XT_HAL_TIMER_ACTIVE_BITS_S (0) |
在文件 xt_hal_timer.h 第 35 行定义.
| #define XT_HAL_TIMER_ACTIVE_BITS_W (1) |
在文件 xt_hal_timer.h 第 36 行定义.
| #define XT_HAL_TIMER_AUTO_RELOAD_BITS_S (1) |
在文件 xt_hal_timer.h 第 37 行定义.
| #define XT_HAL_TIMER_AUTO_RELOAD_BITS_W (1) |
在文件 xt_hal_timer.h 第 38 行定义.
| #define XT_HAL_TIMER_DEFAULT_MODE (XT_HAL_TIMER_PERIODIC | XT_HAL_TIMER_DIR_UP | XT_HAL_TIMER_START) |
默认模式:周期+向上+立即启动
在文件 xt_hal_timer.h 第 48 行定义.
| #define XT_HAL_TIMER_DIR_BITS_S (2) |
在文件 xt_hal_timer.h 第 39 行定义.
| #define XT_HAL_TIMER_DIR_BITS_W (2) |
在文件 xt_hal_timer.h 第 40 行定义.
| #define XT_HAL_TIMER_DIR_DOWN (0x01 << XT_HAL_TIMER_DIR_BITS_S) |
向下计数
在文件 xt_hal_timer.h 第 47 行定义.
| #define XT_HAL_TIMER_DIR_UP (0x00 << XT_HAL_TIMER_DIR_BITS_S) |
向上计数
在文件 xt_hal_timer.h 第 46 行定义.
| #define XT_HAL_TIMER_INVALID_ID (0xFFFF) |
在文件 xt_hal_timer.h 第 33 行定义.
| #define XT_HAL_TIMER_ONE_SHOT (0x00 << XT_HAL_TIMER_AUTO_RELOAD_BITS_S) |
单次触发模式
在文件 xt_hal_timer.h 第 44 行定义.
| #define XT_HAL_TIMER_PERIODIC (0x01 << XT_HAL_TIMER_AUTO_RELOAD_BITS_S) |
周期触发模式
在文件 xt_hal_timer.h 第 45 行定义.
| #define XT_HAL_TIMER_START (0x00 << XT_HAL_TIMER_ACTIVE_BITS_S) |
初始化后立即启动
在文件 xt_hal_timer.h 第 42 行定义.
| #define XT_HAL_TIMER_STOP (0x01 << XT_HAL_TIMER_ACTIVE_BITS_S) |
初始化后不启动
在文件 xt_hal_timer.h 第 43 行定义.
| typedef void(* xt_hal_timer_cb_t) (uint8_t timer_id, uint32_t event_id) |
| uint32_t xt_hal_timer_get_clk_src_freq | ( | uint8_t | timer_id | ) |
获取定时器时钟源频率
定时器实际频率 = xt_hal_timer_get_clk_src_freq(timer_id) / xt_hal_timer_get_prescaler(timer_id)
| timer_id | 定时器索引 |
| uint32_t xt_hal_timer_get_count | ( | uint8_t | timer_id | ) |
获取定时器当前计数值
| timer_id | 定时器索引 |
| uint32_t xt_hal_timer_get_prescaler | ( | uint8_t | timer_id | ) |
获取定时器实际分频值
返回结果 = psc + 1,参数错误时返回 0。
| timer_id | 定时器索引 |
| xt_err_t xt_hal_timer_setup | ( | uint8_t | timer_id, |
| uint32_t | mode, | ||
| uint32_t | tick_freq_hz, | ||
| uint32_t | tick_num, | ||
| xt_hal_timer_cb_t | cb ) |
初始化定时器
| timer_id | 定时器索引 |
| mode | 定时器模式,见 XT_HAL_TIMER_ONE_SHOT, XT_HAL_TIMER_PERIODIC 等 |
| tick_freq_hz | 定时器频率,单位 Hz, 内部从时钟源分频到最接近参数的频率。
|
| tick_num | 回调触发前定时器经历的 tick 数量
|
| cb | 定时器回调函数,见 xt_hal_timer_cb_t |