Nordic52840SDK学习之定时器
Nordic 52840 SDK学习之定时器
今天开始学习52840SDK,特在此处记录学习内容,防止以后忘记,或许可以给以后的初学者提供一些帮助。如有错误,请发邮件至843036544@qq.com,我看到会及时改正。
当前只是初学该sdk,内容可能比较简单,不喜勿喷。
简介:定时器部分,主要是写了一些测试代码(在源sdk中添加了一些测试接口),用来学习定时器的使用。
步骤:
1)包含头文件app_timer.h
2)定义Timer id和interval
其中id用来区分不同功能的定时器,interval表示定时器的间隔(即每隔多长时间进入定时器中断函数)
3)Timer初始化(该初始化在原始sdk中已经调用)
4)创建一个定时器Timer
ret_code_t app_timer_create(app_timer_id_t const * p_timer_id,
app_timer_mode_t mode,
app_timer_timeout_handler_t timeout_handler);
p_timer_id: 定时器id
mode:APP_TIMER_MODE_SINGLE_SHOT(只进入一次);APP_TIMER_MODE_REPEATED(重复进入)
timeout_handler:定时器中断处理函数
5)启动定时器
ret_code_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context)
timeout_ticks: 定时器启动后多长时间进入定时器处理函数
p_context: 如果有参数需要传入定时器处理函数,可通过该参数传入
6)停止定时器
ret_code_t app_timer_stop(app_timer_id_t timer_id);
7)定时器其他函数
ret_code_t app_timer_stop_all(void);
uint32_t app_timer_cnt_get(void);
void app_timer_pause(void);
void app_timer_resume(void);
uint8_t app_timer_op_queue_utilization_get(void);
uint32_t app_timer_cnt_diff_compute(uint32_t ticks_to, uint32_t ticks_from);
其中,我只测试了pause函数,该函数会将所有timer都暂停。 具官方文档介绍,该函数用于debug。
This function can be used for debugging purposes to ensure that application is halted when entering a breakpoint.
其他函数后续使用的时候在继续添加使用方法。
下面是我的测试代码:
#include "app_timer.h" APP_TIMER_DEF( ipl_app_timer_id );
#define IPL_TIME_INTERVAL APP_TIMER_TICKS( 1000 ) //每隔1000ms进入一次 APP_TIMER_DEF( ipl_app_timer_id2 );
#define IPL_TIME_INTERVAL_2 APP_TIMER_TICKS( 500 ) //每隔500ms进入一次 void ipl_app_timerout_handle( void *p_context )
{
static int count = ;
count ++; NRF_LOG_INFO( "ipl app timer count=%d\n",count ); if( count== )
{
//app_timer_pause(); //此次调用该函数,会导致timer1和timer2都停止
app_timer_stop( ipl_app_timer_id );
}
} void ipl_app_timerout_handle2( void *p_context )
{
static int num = ;
num ++; NRF_LOG_INFO( "ipl app timer2 num=%d\n",num ); if( num== )
{
app_timer_start( ipl_app_timer_id, IPL_TIME_INTERVAL, NULL );
}
} /**@brief Function for ipl timer test init.
*/
ret_code_t ipl_app_timers_init( void )
{
ret_code_t err_code; err_code = app_timer_create( &ipl_app_timer_id, APP_TIMER_MODE_REPEATED, ipl_app_timerout_handle );
if( err_code != NRF_SUCCESS )
{
NRF_LOG_INFO( "Create timer error\n" );
return NRF_ERROR_NULL;
} app_timer_start( ipl_app_timer_id, IPL_TIME_INTERVAL, NULL );
return NRF_SUCCESS;
} ret_code_t ipl_app_timers2_init( void )
{
ret_code_t err_code; err_code = app_timer_create( &ipl_app_timer_id2, APP_TIMER_MODE_REPEATED, ipl_app_timerout_handle2 );
if( err_code != NRF_SUCCESS )
{
NRF_LOG_INFO( "Create timer error\n" );
return NRF_ERROR_NULL;
} app_timer_start( ipl_app_timer_id2, IPL_TIME_INTERVAL_2, NULL );
return NRF_SUCCESS;
} int main( void )
{
timers_init(); //初始化定时器
ipl_app_timers_init();
ipl_app_timers2_init(); ...... }
最新文章
- iOS 开发之路(WKWebView内嵌HTML5之图片上传) 五
- shell中的语法(1)
- 简单利用jQuery加tomcat,让前端开发不再依赖于后端的接口
- Erlang进程间消息接收超时设定
- 护眼色的RGB值
- opc 方面研究
- ASP防注入
- mysql5.7.14安装与配置
- hdoj 1028 Ignatius and the Princess III(区间dp)
- 【C++ 中文手册】即将完成
- P4610 [COCI2011-2012#7] KAMPANJA
- 【博客开篇】服务器配置:Windows2008R2+PHP5.6+SQLServer2008(X64)
- selenium模拟登陆淘宝
- 斜率DP个人理解
- 021 RDD的依赖关系,以及造成的stage的划分
- 显式提交/隐式提交 //ajax方式的隐式提交
- Android activity之间数据传递和共享的方式之Application
- UVa 1610 聚会游戏
- 常用算法 (JS实现)
- django 建立一个简单的应用
热门文章
- Linux切换用户时报错/.bash_profile: Permission denied,命令行(终端提示符)出现-bash-4.2$
- 在Ubuntu 18.04中安装Wine QQ、微信、TIM
- 如何获取论文的 idea
- Spring JPA实现增删改查
- Python JSON的基本使用
- layer弹窗插件留言提交
- Day01_企业权限管理(SSM整合)
- VulnHub靶场学习_HA: Natraj
- 从零写一个Asp.net core手脚架(模型验证)
- 安卓APP开发的初步了解