当前位置:网站首页>络达开发---自定义Timer的实现
络达开发---自定义Timer的实现
2022-08-11 01:15:00 【MicMind】
平台:AB1565M
SDK版本:V2.11.0
开发环境:windows10
络达SDK是在FreeRTOS的基础上进行构建的,因此我们可以使用该RTOS的机制来建设Timer任务。
需要在C文件中添加头文件:
#include "timers.h"Timer的句柄为:TimerHandle_t,用来定义一个Timer对像;
相关接口函数有:
TimerHandle_t xTimerCreate( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction );用来建议一个Timer对象,参数xTimerPeriodInTicks在SDK中的单位为ms;uxAutoReload的参数表示超时后是否需要重新计时,否则Timer只会被触发一次;pvTimerID值可以为0,pxCallbackFunction为Timer超时后执行的回调函数,用户通常在该回调函数中处理一些周期性的任务。
#define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )用来启动Timer;
#define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )该函数用来停止Timer的计数,但并不会销毁timer,因此被Stop后还可以重新start。参数xTimer为执行xTimerCreate时的返回值。xTicksToWait的值通常为0。
可以发现,Timer的Start和Stop均是调用的另一个函数:xTimerGenericCommand,
函数原型为:
BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;Timer创建时,会传递一个回调函数的参数,用于当Timer超时时来触发该回调函数,其原型为:
void notify_timer_callback(TimerHandle_t expiredTimer)参数expiredTimer为执行xTimerCreate函数的返回值,因此可以发现,该回调函数可以被多个不同的Timer同时使用,在回调函数中通过该expiredTimer可以来区分是哪个Timer超时,从而做出不同的处理。
下图为笔者创建的一个周期性的Timer,执行周期为1s,回调函数如下
uint16_t lgTxVal=0;
static void notify_timer_callback(TimerHandle_t expiredTimer)
{
lgTxVal++;
LOG_MSGID_I(GHP,"[BLE_GHP]in timer callback function, tx:%d\r\n", 1, lgTxVal);
//send notify
ble_ghp_write_data(g_ghp_cntx.conn_handle, &lgTxVal, 2);
}执行的结果如下图所示:

边栏推荐
- 20张图,全面掌握MVCC原理!
- ABP中的数据过滤器
- #yyds Dry Goods Inventory#[Yugong Series] August 2022 Go Teaching Course 008-Integer of Data Types
- HW-蓝队工作流程(1)
- 如何破坏Excel文件,让其显示文件已损坏方法
- 成功解决TypeError: can‘t multiply sequence by non-int of type ‘float‘
- [ASM] The relationship between the role of the bytecode operation ClassWriter COMPUTE_FRAMES and visitMaxs
- postgresql参数意义
- 二维数组实战项目--------《扫雷游戏》
- 关于编程本质那些事
猜你喜欢

Linux install redis database

简陋的nuxt3学习笔记

深度解析:什么是太爱速M抢单模式?

Two-dimensional array combat project -------- "Minesweeper Game"

J9数字论:DAO治理更像一种生态过程:治理原生于网络,不断演变

R language multiple linear regression, ARIMA analysis of the impact of different candidates in the United States on the economic GDP time series

MySQL indexes and transactions

Data Filters in ABP

Still using Xshell?You are out, recommend a more modern terminal connection tool, easy to use!

Apache Commons Configuration Remote Code Execution Vulnerability (CVE-2022-33980) Analysis & Reproduction
随机推荐
嵌入式软件打log的一些心得
【服务器数据恢复】raid5崩溃导致lvm信息和VXFS文件系统损坏的数据恢复案例
[Server data recovery] Data recovery case of lvm information and VXFS file system corruption caused by raid5 crash
@Autowired注入RedisCache报错空指针
Data Analysis Interview Manual "SQL"
SystemVerilog: 验证知识点点滴滴
Data Filters in ABP
二维数组实战项目--------《扫雷游戏》
22/8/9 Collection of Greedy Problems
Only lazy and hungry. You still don't understand the singleton pattern!
② 关系数据库标准语言SQL 数据定义(创建、修改基本表)、数据更新(增删改)
Elastic scaling of construction resources
Sigma开发注意细节
Difference Between Image Recognition and Semantic Segmentation
HW-常见攻击方式和漏洞原理(2)
BEVDepth: Acquisition of Reliable Depth for Multi-view 3D Object Detection 论文笔记
C#使用计时器
16. 最接近的三数之和
Apache Commons Configuration远程代码执行漏洞(CVE-2022-33980)分析&复现
SAP ABAP JSON 格式数据处理