一、简介
DCB管理器:若没有延迟执行,可以不需要此服务
中断管理器:若没有回调函数处理,可以不需要此服务
时钟服务不包括PIN脚的复用初始化,需要用户确保引脚复用问题;
前序:ADI_TMR_ ,adi_tmr_
API返回值:ADI_TMR_RESULT_SUCCESS(0)表示成功,非零值都是失败
建议:现有debug模式版本的library,最终采用release版本
初始化服务:adi_tmr_Init()
不需要额外的内存
终止服务:adi_tmr_Terminate()
定时器IDs
在adi_tmr.h定义为u32类型,但不是简单的枚举类型,实质为complex类型。
二、基本定时器函数
适用范围:general-purpose timer,core timer,watchdog timer
adi_tmr_Open//open函数会是定时器配置恢复上电值,清除任何未决状态
adi_tmr_Close
adi_tmr_Reset()在open后调用,需要复位至上电默认值使用此函数。
三、通用定时器函数
adi_tmr_GPControl:用于配置通用定时器
adi_tmr_GPGroupEnable:用于使能或禁用单个或一组通用定时器
四、内核定时器函数
adi_tmr_CoreControl:用于配置内核定时器
五、看门狗定时函数
adi_tmr_WatchdogControl:用于配置看门狗定时器
六、外设定时器函数
适用范围:general-purpose timer,watchdog timer
adi_tmr_GetPeripheralID:用于识别外设ID对应的指定的定时器
七、回调函数
使用范围:general-purpose timer,core timer,watchdog timer
1.adi_tmr_InstallCallback:针对指定的定时器安装回调函数
1)回调函数类型为ADI_DCB_CALLBACK_FN
2)回调函数被传入3个参数:
ClientHandle – a value provided by the client when the callback is installed
ADI_TMR_EVENT_TIMER_EXPIRED – indicates a timer callback event
TimerID – the timer ID of the timer that generates the callback
3)当延迟调用函数未NULL,意味着没有延迟调用,而为立刻调用
4)单个回调函数可以被任意个定时器安装;(回调函数使用TimerID识别哪个产生)
5)注意一个定时器只能安装1个回调函数
6)此函数不会改变定时器的配置(例如方向)
2.adi_tmr_RemoveCallback:对指定定时器删除callback
1)此函数会禁止中断产生且从内部表里面删除callback
2)此函数正常不会需要
3)此函数不会改变定时器的配置
八、编码例子
ADI_TMR_RESULT Result; // return value
Result = adi_tmr_Init(NULL);
//完成上句,定时器服务可以使用,此函数不会改变定时器,只做内部数据结构的初始化
Result = adi_tmr_Open(ADI_TMR_GP_TIMER_0);
Result = adi_tmr_Open(ADI_TMR_GP_TIMER_1);
Result = adi_tmr_Open(ADI_TMR_CORE_TIMER);
Result = adi_tmr_Open(ADI_TMR_WDOG_TIMER);
//open函数会是定时器配置恢复上电值,清除任何未决状态
//Configuring a Timer
ADI_TMR_CORE_CMD_VALUE_PAIR CoreTable [] = {
{ADI_TMR_CORE_CMD_SET_COUNT, (void *)0x12345678 },
{ ADI_TMR_CORE_CMD_SET_PERIOD, (void *)0xabcdef },
{ ADI_TMR_CORE_CMD_SET_SCALE, (void *)0x10 },
{ ADI_TMR_CORE_CMD_SET_ACTIVE_MODE, (void *)TRUE },
{ ADI_TMR_CORE_CMD_END, NULL },
};
Result = adi_tmr_CoreControl(ADI_TMR_CORE_CMD_TABLE, CoreTable);
Result = adi_tmr_GPControl(ADI_TMR_GP_TIMER_0,
ADI_TMR_GP_CMD_SET_PERIOD, (void *)0x800000);
Result = adi_tmr_GPControl(ADI_TMR_GP_TIMER_0,
ADI_TMR_GP_CMD_SET_WIDTH, (void *)0x400000);
Result = adi_tmr_GPControl(ADI_TMR_GP_TIMER_0,
ADI_TMR_GP_CMD_SET_TIMER_MODE, (void *)0x1);
Result = adi_tmr_GPControl(ADI_TMR_GP_TIMER_1,
ADI_TMR_GP_CMD_SET_PERIOD, (void *)0x800000);
Result = adi_tmr_GPControl(ADI_TMR_GP_TIMER_1,
ADI_TMR_GP_CMD_SET_WIDTH, (void *)0x400000);
Result = adi_tmr_GPControl(ADI_TMR_GP_TIMER_1,
ADI_TMR_GP_CMD_SET_TIMER_MODE, (void *)0x1);
Result = adi_tmr_WatchdogControl
(ADI_TMR_WDOG_CMD_EVENT_SELECT, (void *)0x0);
Result = adi_tmr_WatchdogControl
(ADI_TMR_WDOG_CMD_SET_COUNT, (void *)0x12345678);
//Enabling Timers
Result = adi_tmr_WatchdogControl
(ADI_TMR_WDOG_CMD_ENABLE_TIMER, (void *)TRUE);
Result = adi_tmr_GPGroupEnable
(ADI_TMR_GP_TIMER_0 | ADI_TMR_GP_TIMER_1, TRUE);
//Disabling Timers
Result = adi_tmr_WatchdogControl
(ADI_TMR_WDOG_CMD_ENABLE_TIMER, (void *)FALSE);
Result = adi_tmr_GPGroupEnable
(ADI_TMR_GP_TIMER_0 | ADI_TMR_GP_TIMER_1, FALSE);
//Installing a Callback Function
...
Result = adi_tmr_InstallCallback
(ADI_TMR_GP_TIMER_0, TRUE, (void *)0x00000000, NULL, Callback);
Result = adi_tmr_InstallCallback
(ADI_TMR_GP_TIMER_1, TRUE, (void *)0x11111111, NULL, Callback);
Result = adi_tmr_InstallCallback
(ADI_TMR_CORE_TIMER, TRUE, (void *)0x22222222, NULL, Callback);
Result = adi_tmr_InstallCallback
(ADI_TMR_WDOG_TIMER, TRUE, (void *)0x33333333, NULL, Callback);
...
void Callback(void *ClientHandle, u32 Event, void *pArg) {
// Event = ADI_TMR_EVENT_TIMER_EXPIRED
switch ((u32)pArg) {
case ADI_TMR_GP_TIMER_0:
// do processing when gp timer 0 expires
// ClientHandle = 0x00000000
break;
case ADI_TMR_GP_TIMER_1:
// do processing when gp timer 1 expires
// ClientHandle = 0x11111111
break;
case ADI_TMR_CORE_TIMER:
// do processing when core timer expires
// ClientHandle = 0x22222222
break;
case ADI_TMR_WDOG_TIMER:
// do processing when watchdog timer expires
// ClientHandle = 0x33333333
break;
}
}
//Removing Callbacks
Result = adi_tmr_RemoveCallback(ADI_TMR_GP_TIMER_0);
Result = adi_tmr_RemoveCallback(ADI_TMR_GP_TIMER_1);
Result = adi_tmr_RemoveCallback(ADI_TMR_CORE_TIMER);
Result = adi_tmr_RemoveCallback(ADI_TMR_WDOG_TIMER);
//Termination
Result = adi_tmr_Terminate();
阅读(1031) | 评论(0) | 转发(0) |