drivers/timer/ftimer_tacho
.
├── ftacho.c --> 转速计功能实现
├── ftimer_tacho_g.c --> 相关配置和全局变量
├── ftimer_tacho_hw.h --> 寄存器操作
├── ftimer_tacho_intr.c --> 中断相关处理
├── ftimer_tacho.h --> 用户接口
└── ftimer.c --> 定时器功能实现
以下部分将指导您完成ftimer_tacho驱动的软件配置:
ftimer_tacho控制数据
typedef struct
{
FTimerTachoConfig config; /* Current active configs */
boolean isready; /* Device is initialized and ready */
FTimerEventHandler evt_handlers[FMAX_TIMER_TACHO_EVENT];/* event handler for interrupt */
}FTimerTachoCtrl;
ftimer_tacho配置数据
typedef struct
{
u32 id; /* id of timer tacho */
char name[12]; /* instance name */
u32 irq_priority; /* intr priority */
u32 work_mode; /* timer/tacho/capture mode */
/* for timer function */
u32 timer_mode; /* free-run/restart */
u32 timer_bits; /* 32/64 bits */
u32 cmp_type; /* once/cycle cmp */
boolean clear_cnt; /* clear timer counts */
boolean force_load; /* start count from start val */
/* for tacho function */
u32 edge_mode; /* rising/falling/double */
u32 jitter_level; /* jitter level */
u32 plus_num; /* plus_num of period to calculate rpm */
u32 captue_cnt; /* in capture mode, when cnt reach this val, intr asserted */
}FTimerTachoConfig;
ftimer_tacho工作模式
typedef enum
{
/*TimerTacho mode */
FTIMER_WORK_MODE_TIMER = 0,
FTIMER_WORK_MODE_TACHO,
FTIMER_WORK_MODE_CAPTURE
}FTimerTachoModeType;
timer计数模式
typedef enum
{
/*Timer count mode*/
FTIMER_FREE_RUN = 0,
FTIMER_RESTART
}FTimerCntModeType;
ftimer_tacho中断事件类型
typedef enum
{
FTACHO_EVENT_OVER = 0, /*tacho超速事件*/
FTACHO_EVENT_UNDER, /*tacho低速事件*/
FTIMER_EVENT_ROLL_OVER, /*计数器翻转事件*/
FTIMER_EVENT_ONCE_CMP, /*单次定时输出事件*/
FTIMER_EVENT_CYC_CMP, /*重复定时输出事件*/
FTACHO_EVENT_CAPTURE, /*tacho输入捕获事件*/
FMAX_TIMER_TACHO_EVENT
}FTimerTachoEventType;
tacho输入模式选择
typedef enum
{
FTACHO_FALLING_EDGE = 0,
FTACHO_RISING_EDGE,
FTACHO_DOUBLE_EDGE
}FTachoEdgeType;
tacho消抖级数选择
typedef enum
{
FTACHO_JITTER_LEVEL0 = 0,
FTACHO_JITTER_LEVEL1,
FTACHO_JITTER_LEVEL2,
FTACHO_JITTER_LEVEL3,
}FTachoJitterLevelType;
将控制器复位
FError FTimerSoftwareReset(FTimerTachoCtrl *instance_p);
Note:
Input:
Return:
设置中断
void FTimerSetInterruptMask(FTimerTachoCtrl *instance_p,
FTimerTachoEventType intrType,
boolean enable);
Note:
Input:
Return:
启动timer_tacho
FError FTimerStart(FTimerTachoCtrl *instance_p);
Note:
Input:
Return:
停止timer外设
FError FTimerStop(FTimerTachoCtrl *instance_p);
Note:
Input:
Return:
timer 与 tacho-capture两种模式的切换
FError FTimerSwithMode(FTimerTachoCtrl *instance_p, FTimerTachoConfig *new_config_p);
Note:
Input:
Return:
注册中断事件处理回调函数
void FTimerRegisterEvtCallback(FTimerTachoCtrl *instance_p,
FTimerTachoEventType evt,
FTimerEventHandler callback);
Note:
Input:
Return:
打印寄存器信息
FError FTimeSettingDump(const FTimerTachoCtrl *instance_p);
Note:
Input:
Return:
TimerTacho中断处理函数
void FTimerTachoIntrHandler(s32 vector, void *param);
Note:
Input:
Return:
根据工作模式和状态设置相应的中断
void FTimerTachoSetIntr(FTimerTachoCtrl *instance_p);
Note:
Input:
Return:
TimerTacho驱动实例的初始化
FError FTimerInit(FTimerTachoCtrl *instance_p, const FTimerTachoConfig *config_p);
Note:
Input:
Return:
Timer驱动实例去使能,清零实例数据
void FTimerDeInit(FTimerTachoCtrl *instance_p);
Note:
Input:
Return:
完成Tacho驱动实例的初始化
FError FTachoInit(FTimerTachoCtrl *instance_p, const FTimerTachoConfig *config_p);
Note:
Input:
Return:
获取风扇的转速值
FError FTachoGetFanRPM(FTimerTachoCtrl *instance_p,u32 *rpm);
Note:
Input:
Return:
Tacho驱动实例去使能,清零实例数据
void FTachoDeInit(FTimerTachoCtrl *instance_p);
Note:
Input:
Return: