API GUIDE / TCU / LL
G32S10 TCU LL 接口
LL 层接口:当前SDK中LL层使用的TCU寄存器宏集中在 tcu_regs.h,前缀为 TCU_。
1. LL 与基础辅助接口规范
1.1 LL层实现边界
当前LL实现文件为
code/include/drivers/g32s10/tcu/ll_tcu.h,寄存器映射和寄存器位定义文件为code/include/drivers/g32s10/tcu/tcu_regs.h。所有公开
ll_tcu_*接口均为static inline,首参数统一为tcu_regs_t *tcux或const tcu_regs_t *tcux。LL层不做参数合法性判断,不返回状态码;调用者必须保证
tcux、channel_id、channel_mask、位域枚举值等参数合法。写寄存器、置位、清位类接口返回
void;读寄存器、读状态、读数据类接口返回uint32_t。channel_id范围统一为07;channel_mask使用TCU_CHANNEL_FLAG(channel)组合,有效bit范围为bit0bit7。status_rd/status_set/status_clr只提供LL接口,当前HAL和example不主动使用这组三个寄存器。GPIO1仅适用于正交编码模式;普通捕获模式只使用GPIO0输入。
1.2 LL层公开宏
当前SDK中LL层使用的TCU寄存器宏集中在 tcu_regs.h,前缀为 TCU_。
| 宏 | 用途 | 说明 |
|---|---|---|
TCU_MASK_ALL | 全bit掩码 | 需要对寄存器全部bit进行清除、屏蔽或关闭时使用,替代 0xFFFFFFFFUL 魔法数字。 |
TCU_CHANNEL_COUNT / TCU_CHANNEL_MAX | 通道数量和最大通道号 | 当前TCU通道范围为0~7。 |
TCU_CHANNEL_FLAG(channel) | 通道bit生成 | channel 范围为0~7,用于 cnt_enable、clock_enable、status_set 等通道mask参数。 |
TCU_CHANNEL_FLAG_ALL | 全通道mask | bit0~bit7有效。 |
TCU_CHANNEL_VALUE_MASK / TCU_COUNTER_MAX | 计数值掩码和最大值 | FULL、HALF、COUNT、CAPTURE、STORE等16bit计数值使用。 |
TCU_FLAG_FULL(channel) | FULL事件flag | channel 范围为07,对应 ir/ie bit0bit7。 |
TCU_FLAG_CAPTURE(channel) | CAPTURE事件flag | channel 范围为07,对应 ir/ie bit8bit15。 |
TCU_FLAG_HALF(channel) | HALF事件flag | channel 范围为07,对应 ir/ie bit16bit23。 |
TCU_FLAG_FULL_MASK_ALL / TCU_FLAG_CAPTURE_MASK_ALL / TCU_FLAG_HALF_MASK_ALL | 事件分组mask | 用于FULL、CAPTURE、HALF事件分组处理。 |
TCU_FLAG_CHANNEL_EVENT_MASK | 通道事件总mask | bit0~bit23有效,覆盖FULL、CAPTURE、HALF三类通道事件。 |
TCU_EDGE_NONE / TCU_EDGE_POSITIVE / TCU_EDGE_NEGATIVE / TCU_EDGE_BOTH | 边沿选择 | 写入时钟、GPIO0、GPIO1、store边沿字段。 |
TCU_CONTROL_* | CONTROL寄存器位域 | 用于通道CONTROL寄存器的输入使能、边沿、门控、方向、计数模式和store配置。 |
TCU_COUNT_MODE_* | 计数模式 | 写入CONTROL寄存器 COUNT_MODE 字段。 |
TCU_GATE_SEL_* | 门控源选择 | 写入CONTROL寄存器 GATE_SEL 字段。 |
TCU_DIRECTION_SEL_* | 方向源选择 | 写入CONTROL寄存器 DIRECTION_SEL 字段。 |
TCU_PRESCALER_TPRE_MASK | TPRE字段掩码 | prescaler寄存器低16bit有效。 |
TCU_PRESCALER_DIV_NONE | 不分频编码 | 实际分频为1时TPRE字段为0。 |
TCU_CAPTURE_* | 捕获控制位域 | 用于capture寄存器的捕获次数和捕获源字段。 |
TCU_CAP_VALUE_HIGH() / TCU_CAP_VALUE_PERIOD() | 捕获值解包 | 从 cap_value 中分别提取高电平宽度和周期值。 |
TCU_FILTER_GPIO0_* / TCU_FILTER_GPIO1_* | 输入滤波字段 | 用于 filter_value 寄存器。 |
TCU_STORE_VALUE_CURRENT() / TCU_STORE_VALUE_PREVIOUS() | store值解包 | 从 store_value 中分别提取当前值和上一次值。 |
TCU_HALL_* | HALL状态字段 | HALL状态支持通道0~7。 |
TCU_SOFT_RST_TRIGGER / TCU_SOFT_RST_STATUS | 软复位触发和状态清除 | 向 soft_rst 写 0 触发软复位;向 soft_rst_st 写 1 清除完成状态。 |
TCU_REG_ADDR() / TCU_FIELD_VALUE() / TCU_WRITE_FIELD() | 寄存器辅助宏 | 用于寄存器地址计算、字段值生成和字段读改写。 |
1.3 基础辅助与寄存器访问
1.3.1 ll_tcu_is_instance
static inline bool ll_tcu_is_instance(const tcu_regs_t *tcux);
功能说明: 判断传入的TCU寄存器基地址是否为当前SDK支持的TCU实例。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | const tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
true | 条件成立 |
false | 条件不成立 |
补充说明:
参数约束:
tcux可为任意地址,接口只做地址比较。当前芯片TCU只有一个实例。
1.3.2 ll_tcu_reg_write
static inline void ll_tcu_reg_write(tcu_regs_t *tcux, uint32_t offset, uint32_t value);
功能说明: 按TCU基地址偏移写一个32位寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
offset | uint32_t | 输入 | 32位对齐的寄存器字节偏移 |
value | uint32_t | 输入 | 写入寄存器的32位值 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
tcux为TCU实例;offset为TCU寄存器空间内的32位对齐偏移。该接口主要用于调试、寄存器dump或少量未封装寄存器访问。
1.3.3 ll_tcu_reg_read
static inline uint32_t ll_tcu_reg_read(tcu_regs_t *tcux, uint32_t offset);
功能说明: 按TCU基地址偏移读一个32位寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
offset | uint32_t | 输入 | 32位对齐的寄存器字节偏移 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | 当前寄存器值 |
补充说明:
参数约束:
tcux为TCU实例;offset为TCU寄存器空间内的32位对齐偏移。
1.4 软复位
1.4.1 ll_tcu_soft_reset
static inline void ll_tcu_soft_reset(tcu_regs_t *tcux);
功能说明: 触发TCU模块软复位。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
tcux为TCU实例。该接口向
soft_rst写入TCU_SOFT_RST_TRIGGER(值为 0)触发软复位。
1.4.2 ll_tcu_soft_reset_status_get
static inline uint32_t ll_tcu_soft_reset_status_get(tcu_regs_t *tcux);
功能说明: 读取TCU软复位状态寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | soft_rst_st 当前值 |
补充说明:
参数约束:
tcux为TCU实例。
1.4.3 ll_tcu_soft_reset_status_clear
static inline void ll_tcu_soft_reset_status_clear(tcu_regs_t *tcux);
功能说明: 清除TCU软复位状态。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
tcux为TCU实例。该接口固定写入
TCU_SOFT_RST_STATUS清除soft_rst_st(0x270)状态位。
1.5 计数使能和通道时钟
1.5.1 ll_tcu_cnt_status_get
static inline uint32_t ll_tcu_cnt_status_get(tcu_regs_t *tcux);
功能说明: 读取TCU通道计数使能状态。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | cnt_status 当前值,bit0bit7对应通道07 |
补充说明:
参数约束:
tcux为TCU实例。
1.5.2 ll_tcu_cnt_enable
static inline void ll_tcu_cnt_enable(tcu_regs_t *tcux, uint32_t channel_mask);
功能说明: 使能指定TCU通道计数器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_mask | uint32_t | 输入 | 通道bitmask,使用 TCU_CHANNEL_FLAG(channel) 组合,channel范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_mask有效bit为bit0~bit7。该接口只控制计数使能,不负责通道时钟打开;启动通道时通常需要配合
ll_tcu_clock_enable()。
1.5.3 ll_tcu_cnt_disable
static inline void ll_tcu_cnt_disable(tcu_regs_t *tcux, uint32_t channel_mask);
功能说明: 关闭指定TCU通道计数器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_mask | uint32_t | 输入 | 通道bitmask,使用 TCU_CHANNEL_FLAG(channel) 组合,channel范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_mask有效bit为bit0~bit7。
1.5.4 ll_tcu_clock_status_get
static inline uint32_t ll_tcu_clock_status_get(tcu_regs_t *tcux);
功能说明: 读取TCU通道时钟状态。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | clock_status 当前值,bit0bit7对应通道07 |
补充说明:
参数约束:
tcux为TCU实例。
1.5.5 ll_tcu_clock_enable
static inline void ll_tcu_clock_enable(tcu_regs_t *tcux, uint32_t channel_mask);
功能说明: 使能指定TCU通道时钟。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_mask | uint32_t | 输入 | 通道bitmask,使用 TCU_CHANNEL_FLAG(channel) 组合,channel范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_mask有效bit为bit0~bit7。
1.5.6 ll_tcu_clock_disable
static inline void ll_tcu_clock_disable(tcu_regs_t *tcux, uint32_t channel_mask);
功能说明: 关闭指定TCU通道时钟。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_mask | uint32_t | 输入 | 通道bitmask,使用 TCU_CHANNEL_FLAG(channel) 组合,channel范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_mask有效bit为bit0~bit7。
1.6 中断和状态
1.6.1 ll_tcu_interrupt_status_get
static inline uint32_t ll_tcu_interrupt_status_get(tcu_regs_t *tcux);
功能说明: 读取TCU中断事件状态寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | ir 当前值 |
补充说明:
参数约束:
tcux为TCU实例。返回值包含FULL、CAPTURE、HALF事件状态,使用
TCU_FLAG_*宏解析。
1.6.2 ll_tcu_interrupt_status_set
static inline void ll_tcu_interrupt_status_set(tcu_regs_t *tcux, uint32_t interrupt_mask);
功能说明: 软件置位TCU中断事件状态。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
interrupt_mask | uint32_t | 输入 | 中断事件mask,使用 TCU_FLAG_FULL()、TCU_FLAG_CAPTURE()、TCU_FLAG_HALF() 组合 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
interrupt_mask有效范围为TCU_FLAG_CHANNEL_EVENT_MASK。
1.6.3 ll_tcu_interrupt_status_clear
static inline void ll_tcu_interrupt_status_clear(tcu_regs_t *tcux, uint32_t interrupt_mask);
功能说明: 清除TCU中断事件状态。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
interrupt_mask | uint32_t | 输入 | 中断事件mask,使用 TCU_FLAG_FULL()、TCU_FLAG_CAPTURE()、TCU_FLAG_HALF() 组合 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
interrupt_mask有效范围为TCU_FLAG_CHANNEL_EVENT_MASK。
1.6.4 ll_tcu_interrupt_mask_get
static inline uint32_t ll_tcu_interrupt_mask_get(tcu_regs_t *tcux);
功能说明: 读取TCU中断屏蔽寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | ie 当前值,bit为1表示对应事件被屏蔽 |
补充说明:
参数约束:
tcux为TCU实例。
1.6.5 ll_tcu_interrupt_enable
static inline void ll_tcu_interrupt_enable(tcu_regs_t *tcux, uint32_t interrupt_mask);
功能说明: 使能指定TCU中断事件源。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
interrupt_mask | uint32_t | 输入 | 中断事件mask,使用 TCU_FLAG_* 宏组合 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
interrupt_mask有效范围为TCU_FLAG_CHANNEL_EVENT_MASK。硬件语义为写
ie_clr清屏蔽位。
1.6.6 ll_tcu_interrupt_disable
static inline void ll_tcu_interrupt_disable(tcu_regs_t *tcux, uint32_t interrupt_mask);
功能说明: 屏蔽指定TCU中断事件源。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
interrupt_mask | uint32_t | 输入 | 中断事件mask,使用 TCU_FLAG_* 宏组合 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
interrupt_mask有效范围为TCU_FLAG_CHANNEL_EVENT_MASK。硬件语义为写
ie_set置屏蔽位。
1.6.7 ll_tcu_interrupt_pending_get
static inline uint32_t ll_tcu_interrupt_pending_get(tcu_regs_t *tcux);
功能说明: 读取TCU未屏蔽的pending事件。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | ir & ~ie 的结果 |
补充说明:
参数约束:
tcux为TCU实例。返回值只表示读取瞬间的软件计算结果;若硬件事件同时变化,调用者应按中断处理流程再次确认或清除事件。
1.6.8 ll_tcu_status_get
static inline uint32_t ll_tcu_status_get(tcu_regs_t *tcux);
功能说明: 读取TCU通道状态寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | status_rd 当前值 |
补充说明:
参数约束:
tcux为TCU实例。当前HAL和example不主动使用该状态寄存器。
1.6.9 ll_tcu_status_set
static inline void ll_tcu_status_set(tcu_regs_t *tcux, uint32_t channel_mask);
功能说明: 软件置位TCU通道状态。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_mask | uint32_t | 输入 | 通道bitmask,使用 TCU_CHANNEL_FLAG(channel) 组合,channel范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_mask有效bit为bit0~bit7。当前HAL和example不主动使用该状态寄存器。
1.6.10 ll_tcu_status_clear
static inline void ll_tcu_status_clear(tcu_regs_t *tcux, uint32_t channel_mask);
功能说明: 清除TCU通道状态。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_mask | uint32_t | 输入 | 通道bitmask,使用 TCU_CHANNEL_FLAG(channel) 组合,channel范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_mask有效bit为bit0~bit7。当前HAL和example不主动使用该状态寄存器。
1.7 通道基础寄存器
1.7.1 ll_tcu_full_set
static inline void ll_tcu_full_set(tcu_regs_t *tcux, uint8_t channel_id, uint32_t full_value);
功能说明: 配置指定TCU通道FULL比较值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
full_value | uint32_t | 输入 | FULL比较值,有效范围0~`TCU_COUNTER_MAX` |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7;full_value低16bit有效。FULL值可在TCU运行过程中重新写入,具体生效时序以硬件为准。
1.7.2 ll_tcu_full_get
static inline uint32_t ll_tcu_full_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道FULL比较值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | FULL寄存器当前值 |
补充说明:
参数约束:
channel_id范围0~7。
1.7.3 ll_tcu_half_set
static inline void ll_tcu_half_set(tcu_regs_t *tcux, uint8_t channel_id, uint32_t half_value);
功能说明: 配置指定TCU通道HALF比较值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
half_value | uint32_t | 输入 | HALF比较值,有效范围0~`TCU_COUNTER_MAX` |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7;half_value低16bit有效。HALF值可在TCU运行过程中重新写入,具体生效时序以硬件为准。
1.7.4 ll_tcu_half_get
static inline uint32_t ll_tcu_half_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道HALF比较值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | HALF寄存器当前值 |
补充说明:
参数约束:
channel_id范围0~7。
1.7.5 ll_tcu_count_set
static inline void ll_tcu_count_set(tcu_regs_t *tcux, uint8_t channel_id, uint32_t count_value);
功能说明: 写入指定TCU通道COUNT计数值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
count_value | uint32_t | 输入 | COUNT计数值,有效范围0~`TCU_COUNTER_MAX` |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7;count_value低16bit有效。COUNT值可在TCU运行过程中重新写入,具体生效时序以硬件为准。
1.7.6 ll_tcu_count_get
static inline uint32_t ll_tcu_count_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道COUNT计数值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | COUNT寄存器当前值 |
补充说明:
参数约束:
channel_id范围0~7。
1.7.7 ll_tcu_control_set
static inline void ll_tcu_control_set(tcu_regs_t *tcux, uint8_t channel_id, uint32_t control_value);
功能说明: 直接写入指定TCU通道CONTROL寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
control_value | uint32_t | 输入 | 已拼装的CONTROL寄存器值 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7;control_value由调用者按TCU_CONTROL_*宏拼装。通常优先使用独立位域接口配置CONTROL寄存器,直接写接口主要用于快速初始化或调试。
1.7.8 ll_tcu_control_get
static inline uint32_t ll_tcu_control_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道CONTROL寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | CONTROL寄存器当前值 |
补充说明:
参数约束:
channel_id范围0~7。
1.7.9 ll_tcu_prescaler_div_to_tpre
static inline uint32_t ll_tcu_prescaler_div_to_tpre(uint32_t div);
功能说明: 将实际分频系数转换为TCU prescaler寄存器TPRE字段值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
div | uint32_t | 输入 | 实际分频系数 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | TPRE字段值 |
补充说明:
TPRE为0表示不分频,即实际分频系数为1。
TPRE为n且n大于0时,实际分频系数为
(n + 1) * 2。硬件没有2分频配置;当
div <= 1时返回0。
1.7.10 ll_tcu_prescaler_tpre_to_div
static inline uint32_t ll_tcu_prescaler_tpre_to_div(uint32_t tpre);
功能说明: 将TCU prescaler寄存器TPRE字段值转换为实际分频系数。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tpre | uint32_t | 输入 | TPRE字段值 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | 实际分频系数 |
补充说明:
tpre为0时返回1,表示不分频。tpre大于0时返回(tpre + 1) * 2。
1.7.11 ll_tcu_prescaler_set
static inline void ll_tcu_prescaler_set(tcu_regs_t *tcux, uint8_t channel_id, uint32_t prescaler);
功能说明: 配置指定TCU通道prescaler寄存器TPRE字段。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
prescaler | uint32_t | 输入 | TPRE寄存器值,有效范围0~`TCU_PRESCALER_TPRE_MASK` |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7;prescaler低16bit有效。传入值是寄存器TPRE编码,不是实际分频系数;可使用
ll_tcu_prescaler_div_to_tpre()从实际分频系数换算。
1.7.12 ll_tcu_prescaler_get
static inline uint32_t ll_tcu_prescaler_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道prescaler寄存器TPRE字段。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | TPRE寄存器当前值 |
补充说明:
参数约束:
channel_id范围0~7。可使用
ll_tcu_prescaler_tpre_to_div()换算为实际分频系数。
1.8 通道CONTROL位域
1.8.1 ll_tcu_count_mode_set
static inline void ll_tcu_count_mode_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t count_mode);
功能说明: 配置指定TCU通道CONTROL寄存器的计数模式字段。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
count_mode | uint8_t | 输入 | 计数模式,使用 TCU_COUNT_MODE_* |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
count_mode写入COUNT_MODE位域。
1.8.2 ll_tcu_extal_enable
static inline void ll_tcu_extal_enable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 使能指定TCU通道EXTAL输入。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。EXTAL通常作为通道计数时钟输入使用。
1.8.3 ll_tcu_extal_disable
static inline void ll_tcu_extal_disable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 关闭指定TCU通道EXTAL输入。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。
1.8.4 ll_tcu_clock_edge_set
static inline void ll_tcu_clock_edge_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t edge);
功能说明: 配置指定TCU通道时钟输入边沿。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
edge | uint8_t | 输入 | 边沿选择,使用 TCU_EDGE_NONE、TCU_EDGE_POSITIVE、TCU_EDGE_NEGATIVE、TCU_EDGE_BOTH |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
edge写入CLK_EDGE位域。常见计时配置为EXTAL使能并选择上升沿计数。
1.8.5 ll_tcu_gpio0_enable
static inline void ll_tcu_gpio0_enable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 使能指定TCU通道GPIO0输入。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。普通捕获模式使用GPIO0作为捕获输入。
1.8.6 ll_tcu_gpio0_disable
static inline void ll_tcu_gpio0_disable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 关闭指定TCU通道GPIO0输入。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。
1.8.7 ll_tcu_gpio0_edge_set
static inline void ll_tcu_gpio0_edge_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t edge);
功能说明: 配置指定TCU通道GPIO0输入边沿。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
edge | uint8_t | 输入 | 边沿选择,使用 TCU_EDGE_* |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
edge写入GPIO0_EDGE位域。
1.8.8 ll_tcu_gpio1_enable
static inline void ll_tcu_gpio1_enable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 使能指定TCU通道GPIO1输入。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。GPIO1仅适用于正交编码模式。
1.8.9 ll_tcu_gpio1_disable
static inline void ll_tcu_gpio1_disable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 关闭指定TCU通道GPIO1输入。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。
1.8.10 ll_tcu_gpio1_edge_set
static inline void ll_tcu_gpio1_edge_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t edge);
功能说明: 配置指定TCU通道GPIO1输入边沿。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
edge | uint8_t | 输入 | 边沿选择,使用 TCU_EDGE_* |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
edge写入GPIO1_EDGE位域。GPIO1仅适用于正交编码模式。
1.8.11 ll_tcu_gate_select_set
static inline void ll_tcu_gate_select_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t gate_select);
功能说明: 配置指定TCU通道门控信号源。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
gate_select | uint8_t | 输入 | 门控源选择,使用 TCU_GATE_SEL_* |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
gate_select写入GATE_SEL位域。
1.8.12 ll_tcu_gate_polarity_set
static inline void ll_tcu_gate_polarity_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t polarity);
功能说明: 配置指定TCU通道门控极性。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
polarity | uint8_t | 输入 | 门控极性字段值,0或1 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
polarity写入GATE_POLARITY位域。
1.8.13 ll_tcu_direction_select_set
static inline void ll_tcu_direction_select_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t direction_select);
功能说明: 配置指定TCU通道方向信号源。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
direction_select | uint8_t | 输入 | 方向源选择,使用 TCU_DIRECTION_SEL_* |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
direction_select写入DIRECTION_SEL位域。正交编码模式使用
TCU_DIRECTION_SEL_QUADRATURE。
1.8.14 ll_tcu_direction_polarity_set
static inline void ll_tcu_direction_polarity_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t polarity);
功能说明: 配置指定TCU通道方向极性。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
polarity | uint8_t | 输入 | 方向极性字段值,0或1 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
polarity写入DIRECTION_POLARITY位域。
1.8.15 ll_tcu_store_enable
static inline void ll_tcu_store_enable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 使能指定TCU通道store功能。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。正交编码模式可通过store寄存器获取A/B相或Z相事件对应的计数值。
1.8.16 ll_tcu_store_disable
static inline void ll_tcu_store_disable(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 关闭指定TCU通道store功能。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
channel_id范围0~7。
1.8.17 ll_tcu_store_edge_set
static inline void ll_tcu_store_edge_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t edge);
功能说明: 配置指定TCU通道store触发边沿。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
edge | uint8_t | 输入 | 边沿选择,使用 TCU_EDGE_* |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
edge写入STORE_EDGE位域。
1.9 捕获控制和捕获值
1.9.1 ll_tcu_capture_num_set
static inline void ll_tcu_capture_num_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t capture_num);
功能说明: 配置指定TCU通道捕获次数。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 捕获通道号,范围0~7 |
capture_num | uint8_t | 输入 | 捕获次数字段值,范围0~0xFF |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
capture_num写入CAPTURE_NUM位域。HAL默认使用连续捕获;有限次数捕获由上层按需要配置。
1.9.2 ll_tcu_capture_num_get
static inline uint32_t ll_tcu_capture_num_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道捕获次数配置。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 捕获通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | CAPTURE_NUM 字段值 |
补充说明:
参数约束:
channel_id范围0~7。
1.9.3 ll_tcu_capture_source_set
static inline void ll_tcu_capture_source_set(tcu_regs_t *tcux, uint8_t channel_id, uint8_t source);
功能说明: 配置指定TCU通道捕获源。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 捕获通道号,范围0~7 |
source | uint8_t | 输入 | 捕获源,使用 TCU_CAPTURE_SEL_CLOCK、TCU_CAPTURE_SEL_GPIO0、TCU_CAPTURE_SEL_GPIO1 |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
source写入CAPTURE_SEL位域。普通捕获模式使用GPIO0;GPIO1仅适用于正交编码模式。
1.9.4 ll_tcu_capture_source_get
static inline uint32_t ll_tcu_capture_source_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道捕获源配置。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 捕获通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | CAPTURE_SEL 字段值 |
补充说明:
参数约束:
channel_id范围0~7。
1.9.5 ll_tcu_capture_high_get
static inline uint32_t ll_tcu_capture_high_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道捕获高电平宽度值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 捕获通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | cap_value 低16bit的高电平宽度值 |
补充说明:
参数约束:
channel_id范围0~7。接口内部使用宏解包,不向上层返回packed数据。
1.9.6 ll_tcu_capture_period_get
static inline uint32_t ll_tcu_capture_period_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道捕获周期值。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 捕获通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | cap_value 高16bit的周期值 |
补充说明:
参数约束:
channel_id范围0~7。接口内部使用宏解包,不向上层返回packed数据。
1.10 输入滤波
1.10.1 ll_tcu_filter_gpio0_set
static inline void ll_tcu_filter_gpio0_set(tcu_regs_t *tcux, uint8_t channel_id, uint16_t filter);
功能说明: 配置指定TCU通道GPIO0输入滤波计数。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
filter | uint16_t | 输入 | GPIO0滤波计数值,有效范围0~0x03FF |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
filter低10bit有效。普通捕获模式可使用GPIO0滤波。
1.10.2 ll_tcu_filter_gpio0_get
static inline uint32_t ll_tcu_filter_gpio0_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道GPIO0输入滤波计数。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | GPIO0滤波计数字段值 |
补充说明:
参数约束:
channel_id范围0~7。
1.10.3 ll_tcu_filter_gpio1_set
static inline void ll_tcu_filter_gpio1_set(tcu_regs_t *tcux, uint8_t channel_id, uint16_t filter);
功能说明: 配置指定TCU通道GPIO1输入滤波计数。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
filter | uint16_t | 输入 | GPIO1滤波计数值,有效范围0~0x03FF |
返回值表:
| 返回值 | 说明 |
|---|---|
| 无 | 接口不返回状态码 |
补充说明:
参数约束:
filter低10bit有效。GPIO1仅适用于正交编码模式。
1.10.4 ll_tcu_filter_gpio1_get
static inline uint32_t ll_tcu_filter_gpio1_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道GPIO1输入滤波计数。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | GPIO1滤波计数字段值 |
补充说明:
参数约束:
channel_id范围0~7。
1.11 Store值和HALL状态
1.11.1 ll_tcu_store_current_get
static inline uint32_t ll_tcu_store_current_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道store当前值字段。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | store_value 低16bit的当前值 |
补充说明:
参数约束:
channel_id范围0~7。正交编码模式可通过该接口读取A/B相事件对应的store值。
1.11.2 ll_tcu_store_previous_get
static inline uint32_t ll_tcu_store_previous_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道store历史值字段。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | store_value 高16bit的上一次值 |
补充说明:
参数约束:
channel_id范围0~7。正交编码模式可通过该接口读取Z相事件或历史store值。
1.11.3 ll_tcu_hall_state_get
static inline uint32_t ll_tcu_hall_state_get(tcu_regs_t *tcux);
功能说明: 读取TCU HALL状态寄存器。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | hall_state 当前值,低8bit有效 |
补充说明:
参数约束:
tcux为TCU实例。HALL状态支持通道0~7。
1.11.4 ll_tcu_hall_state_channel_get
static inline uint32_t ll_tcu_hall_state_channel_get(tcu_regs_t *tcux, uint8_t channel_id);
功能说明: 读取指定TCU通道的HALL状态位。
参数表:
| 参数 | 类型 | 方向 | 说明 |
|---|---|---|---|
tcux | tcu_regs_t * | 输入 | TCU寄存器基地址 |
channel_id | uint8_t | 输入 | 通道号,范围0~7 |
返回值表:
| 返回值 | 说明 |
|---|---|
uint32_t | 指定通道HALL状态,返回0或非0 |
补充说明:
参数约束:
channel_id范围0~7。HALL状态支持通道0~7,通道0同样可读取HALL状态。
2. 寄存器映射与位域约定
2.1 寄存器映射
当前SDK使用具名结构体声明,再通过typedef导出寄存器类型。TCU寄存器结构体位于:
code/include/drivers/g32s10/tcu/tcu_regs.h
关键寄存器分组如下:
| 偏移 | 成员 | 说明 |
|---|---|---|
0x010/0x014/0x018 | cnt_status/cnt_enable/cnt_disable | 通道计数器状态、使能、关闭。 |
0x01C/0x02C/0x03C | clock_status/clock_disable/clock_enable | 通道时钟状态、关闭、使能。 |
0x020/0x024/0x028 | ir/ir_set/ir_clr | 中断事件状态、软件置位、清除。 |
0x030/0x034/0x038 | ie/ie_set/ie_clr | 中断屏蔽状态、屏蔽、使能。 |
0x040-0x0BC | channel[8] | 每通道FULL/HALF/COUNT/CONTROL。 |
0x0C0-0x0DC | capture[8] | 捕获控制寄存器。 |
0x0E0-0x0FC | cap_value[8] | 捕获值寄存器。 |
0x120-0x13C | prescaler[8] | 通道分频寄存器。 |
0x140 | hall_state | HALL状态寄存器,低8 bit有效。 |
0x150/0x154/0x158 | status_rd/status_set/status_clr | 通道状态读、置位、清除;当前HAL和example不主动使用。 |
0x1A0-0x1BC | filter_value[8] | GPIO0/GPIO1输入滤波寄存器。 |
0x220-0x23C | store_value[8] | Store current/previous值寄存器。 |
0x260/0x270 | soft_rst/soft_rst_st | 软复位控制和状态。 |
2.2 寄存器和位域宏
| 宏类别 | 代表宏 | 使用说明 |
|---|---|---|
| 全bit掩码 | TCU_MASK_ALL | 全寄存器mask操作。 |
| 通道数量 | TCU_CHANNEL_COUNT / TCU_CHANNEL_MAX | 普通TCU通道0~7。 |
| 通道bit | TCU_CHANNEL_FLAG(channel) / TCU_CHANNEL_FLAG_ALL | cnt_*、clock_*、status_* 和启动/停止使用。 |
| 计数值掩码 | TCU_CHANNEL_VALUE_MASK / TCU_COUNTER_MAX | 普通通道计数有效值为16 bit。 |
| 中断flag | TCU_FLAG_FULL(channel) / TCU_FLAG_CAPTURE(channel) / TCU_FLAG_HALF(channel) | FULL、CAPTURE、HALF事件flag。 |
| 中断分组mask | TCU_FLAG_FULL_MASK_ALL / TCU_FLAG_CAPTURE_MASK_ALL / TCU_FLAG_HALF_MASK_ALL | ir/ie 中三类事件固定bit分组。 |
| 中断总mask | TCU_FLAG_CHANNEL_EVENT_MASK | 普通通道事件总mask。 |
| 边沿编码 | TCU_EDGE_NONE/POSITIVE/NEGATIVE/BOTH | 写入CONTROL中时钟、GPIO0、GPIO1和store边沿字段。 |
| 控制位域 | TCU_CONTROL_* | channel[n].control 的计数模式、边沿、门控、方向、GPIO、EXTAL和store字段。 |
| 分频位域 | TCU_PRESCALER_TPRE_MASK / TCU_PRESCALER_DIV_NONE | prescaler[n] 的TPRE字段和不分频编码。 |
| 捕获位域 | TCU_CAPTURE_* | capture[n] 的NUM和SEL字段。 |
| 捕获值解包 | TCU_CAP_VALUE_HIGH() / TCU_CAP_VALUE_PERIOD() | 解包 cap_value[n]。 |
| Store值解包 | TCU_STORE_VALUE_CURRENT() / TCU_STORE_VALUE_PREVIOUS() | 解包 store_value[n]。 |
| HALL状态 | TCU_HALL_STATE_MASK / TCU_HALL_STATE_CHANNEL(channel) | hall_state 低8 bit。 |
| 软复位 | TCU_SOFT_RST_TRIGGER / TCU_SOFT_RST_STATUS | 向 soft_rst 写 0 触发软复位;向 soft_rst_st 写 1 清除完成状态。 |
| MMIO辅助宏 | TCU_REG_ADDR / TCU_FIELD_VALUE / TCU_WRITE_FIELD | 配合 im_mmio_update_bits_32() 实现字段写入。 |
2.3 寄存器访问约束
结构体读写成员使用
__IO/__I/__O保留volatile语义。cnt_enable/cnt_disable、clock_enable/clock_disable、ir_set/ir_clr、ie_set/ie_clr、status_set/status_clr均为写动作寄存器,读值无业务含义。soft_rst写 0 触发软复位;soft_rst_st写 1 清除完成状态。store_flag/store_mask/store_filter_value当前在寄存器映射中隐藏为reserved,不向SDK用户开放。捕获和store数据读取接口直接拆分为16 bit字段语义,不向用户暴露packed包装数据。