Niobe开发板OpenHarmony内核编程开发——定时器

本示例将演示如何在Niobe Wifi IoT开发板上使用cmsis 2.0 接口进行定时器开发

Timer API分析

osTimerNew()

    /// Create and Initialize a timer./// \param[in]     func          function pointer to callback function./// \param[in]     type          \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior./// \param[in]     argument      argument to the timer callback function./// \param[in]     attr          timer attributes; NULL: default values./// \return timer ID for reference by other functions or NULL in case of error.osTimerId_t osTimerNew	(osTimerFunc_t func,osTimerType_t type,void *argument,const osTimerAttr_t *attr)

描述:

函数osTimerNew创建一个一次性或周期性计时器,并将其与一个带参数的回调函数相关联。计时器在osTimerStart启动之前一直处于停止状态。可以在RTOS启动(调用 osKernelStart)之前安全地调用该函数,但不能在内核初始化 (调用 osKernelInitialize)之前调用该函数。

注意 :不能在中断服务调用该函数
参数:
|名字|描述|
|:–|:------|
| func | 函数指针指向回调函数. |
| type | 定时器类型,osTimerOnce表示单次定时器,ostimer周期表示周期性定时器. |
| argument |定时器回调函数的参数|
| attr |计时器属性|

osTimerStart()

  /// Start or restart a timer./// \param[in]     timer_id      timer ID obtained by \ref osTimerNew./// \param[in]     ticks         \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer./// \return status code that indicates the execution status of the function.osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks);

描述:

函数osTimerStart启动或重新启动指定参数timer_id的计时器。参数ticks指定计时器的计数值。

注意 :不能在中断服务调用该函数

参数:

名字描述
timer_id由osTimerNew获得的计时器ID.
ticks时间滴答计时器的值.

软件设计

软件设计

主要代码分析

在OS_Timer_example函数中,通过osTimerNew()函数创建了回调函数为OS_Timer1_Callback的定时器1,并通过osTimerStart()函数将该定时器设置为100个tick,因为hi3861默认10ms为一个tick,所以100个tick正好为1S钟,1S计时到后会触发OS_Timer1_Callback()函数并打印日志。定时器2也同理为3S触发OS_Timer2_Callback()函数并打印日志.

  static void OS_Timer_example(void)
{osTimerId_t timerId1, timerId2;uint32_t delay;osStatus_t status;timer1Exec = 1U;/// Create and Initialize a timer./// \param[in]     func          function pointer to callback function./// \param[in]     type          \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior./// \param[in]     argument      argument to the timer callback function./// \param[in]     attr          timer attributes; NULL: default values./// \return timer ID for reference by other functions or NULL in case of error.timerId1 = osTimerNew((osTimerFunc_t)OS_Timer1_Callback, osTimerPeriodic, &timer1Exec, NULL);if (timerId1 != NULL){delay = 100U;/// Start or restart a timer./// \param[in]     timer_id      timer ID obtained by \ref osTimerNew./// \param[in]     ticks         \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer./// \return status code that indicates the execution status of the function.//osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks);status = osTimerStart(timerId1, delay);if (status != osOK){printf("Falied to start timer1!\n");}}timer2Exec = 100U;timerId2 = osTimerNew((osTimerFunc_t)OS_Timer2_Callback, osTimerPeriodic, &timer2Exec, NULL);if (timerId2 != NULL){delay = 300U;status = osTimerStart(timerId2, delay);if (status != osOK){printf("Falied to start timer2!\n");}}
}

编译调试

修改 BUILD.gn 文件

修改 applications\app路径下 BUILD.gn 文件,指定 os_timer_example 参与编译。

#"TW001_OS_helloworld:helloworld_example",
#"TW002_OS_thread:os_thread_example",
"TW003_OS_timer:os_timer_example",
#"TW004_OS_event:os_event_example",
#"TW005_OS_mutex:os_mutex_example",
#"TW006_OS_semp:os_semaphore_example",
#"TW007_OS_message:os_message_example",

运行结果

示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,OS_Timer1_Callback会1S打印一次数据,OS_Timer2_Callback会3S打印一次数据。

This is Niebo Timer1_Callback:1!
This is Niebo Timer1_Callback:1!
This is Niebo Timer1_Callback:1!
This is Niebo Timer2_Callback:100!
This is Niebo Timer1_Callback:1!
This is Niebo Timer1_Callback:1!
This is Niebo Timer1_Callback:1!
This is Niebo Timer2_Callback:100!

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ……

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ……

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ……

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/618363.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++11 设计模式2. 简单工厂模式

简单工厂(Simple Factory)模式 我们从实际例子出发,来看在什么情况下,应用简单工厂模式。 还是以一个游戏举例 //策划:亡灵类怪物,元素类怪物,机械类怪物:都有生命值&#xff0…

自动化测试Junit

1.什么是Junit JUint是Java编程语言的单元测试框架,用于编写和运行可重复的自动化测试。 JUnit 促进了“先测试后编码”TDD的理念,强调建立测试数据的一段代码,可以先测试,然后再应用。这个方法就好比“测试一点,编码一…

MAT工具详解

简介 Java自带的JVisualVm可以用来分析Java堆内存,可以用来排查内存泄漏和内存浪费的问题,但是功能不是特别强大, MAT(Memory Aanlysis Tool)是一款更优的工具。 MAT功能 功能组 全局信息 直方图 按照类的数量倒序…

互联网轻量级框架整合之MyBatis配置详解

MyBatis核心配置文件mybatis-config.xml里有诸多配置项&#xff0c;但常用的就无非就如下这么多 <?xml version"1.0" encoding"UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTDConfig3.0//EN" "https://mybati…

【力扣】125.验证回文串

刷题&#xff0c;过了真的好有成就感&#xff01;&#xff01;&#xff01; 题解&#xff1a; 根据题目要求&#xff0c;我们需要处理一下几个问题&#xff1a; 将大写字母转变成小写对原来的字符串进行处理&#xff0c;只要字母和数字考虑只有一个和字符串为空的情况 1、将…

整数在内存中的存储和内存操作函数

目录 整数在内存中的存储1. 整数在内存中的存储2. 大小端字节序和字节序判断2.1 什么是大小端?2.2 为什么有大小端 3. 练习3.1 请简述大端字节序和小端字节序的概念&#xff0c;设计⼀个小程序来判断当前机器的字节序。&#xff08;10分&#xff09;-百度笔试题3.2 练习23.3 练…

Harbor私有镜像仓库

Docker私有仓库Harbor ​ 前面学习了Docker及Dockerfile构建镜像&#xff0c;那么构建的镜像放在哪里才能被Docker容器快速获取到呢&#xff1f;我们知道&#xff0c;可以把镜像放入Docker Hub镜像仓库&#xff0c;但是Docker Hub是国外网站&#xff0c;一方面镜像放在Docker …

Python 读写T5557低频RFID,将T5557卡制做成ID、HID卡

本示例使用的发卡器&#xff1a; T5557 T5567 T5577低频RFID读写器 EM4100 HID卡复制器 酒店门卡-淘宝网 (taobao.com) from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget,QMessageBox,QCheckBox,QLineEdit from…

【LeetCode】回溯算法类题目详解

所有题目均来自于LeetCode&#xff0c;刷题代码使用的Python3版本 回溯算法 回溯算法是一种搜索的方法&#xff0c;在二叉树总结当中&#xff0c;经常使用到递归去解决相关的问题&#xff0c;在二叉树的所有路径问题中&#xff0c;我们就使用到了回溯算法来找到所有的路径。 …

策略为王股票软件源代码\StkUI\View\BaseView.cpp-------显示股票基本资料的视图-------程序代码都在里面了

CString strHeader info.GetStockCode(); strHeader " "; /修改 strHeader info.GetStockName(); strHeader "\r\n\r\n "; GetEditCtrl().SetWindowText( strHeader ); GetEditCtrl().SetSel…

5.9 mybatis之callSettersOnNulls作用

文章目录 1. 当callSettersOnNullstrue时2. 当callSettersOnNullsfalse时 在mybatis的settings配置参数中有个callSettersOnNulls参数&#xff0c;官方解释为&#xff1a;指定当结果集中值为 null 的时候是否调用映射对象的 setter&#xff08;map 对象时为 put&#xff09;方法…

REINFORCE及进阶算法讲解笔记

REINFORCE 总结 估计VALUE-methods没有在理论上证明收敛&#xff0c;而policy-methods不需要估计value function。 本算法总结了过去的算法&#xff0c;将过去算法作为特例看待&#xff0c;证明了即使是结合函数估计和实际采样的value梯度都可以无偏估计&#xff0c;证明了某种…