当前位置:网站首页>Introduction to RT thread kernel (4) -- clock management
Introduction to RT thread kernel (4) -- clock management
2022-07-05 04:20:00 【Number and form】
Timer management
Hardware timer : The external crystal oscillator provides the chip input clock
Software timer : Provided by the operating system , The unit is the time length of the clock beat , The timing value must be an integral multiple of the clock beat . The clock beat of the system is 10ms, The time setting of the soft timer must be 20ms,30ms etc. .
Two timer mechanisms :
Single trigger timer : Execute timer event only once , Then the timer stops automatically
Cycle triggered timer : Periodically trigger timer events , The straightway user stops manually
HAED_TIMER Pattern ( The default mode )
The timer timeout function in this mode executes in the interrupt context , Can be initialized in / Use parameters when creating timers RT_TIMER_FLAG_HARD_TIMER To specify the .
SOFT_TIMER Pattern
Define by macro RT_USING_TIMER_SOFT To decide whether to enable the mode . When this mode is enabled , The system will create a timer Threads , then SOFT_TIMER The timer timeout function of mode will be in timer Execute in the context of thread . Can be initialized in / Use parameters when creating timers RT_TIMER_FLAG_SOFT_TIMER To specify the settings SOFT_TIMER Pattern .
Timer control block :
struct rt_timer
typedef struct rt_timer *rt_timer_t
Timer management mode :
Initialize the timer :
void rt_system_timer_init(void);
SOFT_TIMER initialization :
void rt_system_timer_thread_init(void);
Timer creation :
rt_timer_t rt_timer_create()
Timer deletion ( Free memory )
rt_err_t rt_timer_delete(rt_timer_t timer);
Timer initialization :
rt_timer_init()
Timer disengagement :( Don't free memory )
rt_err_t rt_timer_detach(rt_timer_t timer);
Start timer :
rt_err_t rt_timer_start(rt_timer_t timer);
Stop timer :
rt_err_t rt_timer_stop(rt_timer_t timer);
Control timer function interface :
You can view and modify the timer settings according to the parameters of the command type
rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void* arg);
Parameters :timer, Timer handle
cmd Commands for controlling timers , Currently, four commands are supported , Set the timing time , Check the timing , Set single trigger , Set cycle trigger
arg And cmd Corresponding control command parameters such as ,cmd When setting timeout for , You can pass the timeout parameter through arg To set
cmd command :
#define RT_TIMER_CTRL_SET_TIME 0x0 /* Set timer timeout /
#define RT_TIMER_CTRL_GET_TIME 0x1 / Get timer timeout /
#define RT_TIMER_CTRL_SET_ONESHOT 0x2 / Set the timer to a single timer /
#define RT_TIMER_CTRL_SET_PERIODIC 0x3 / Set the timer to periodic timer */
High precision delay
Use timer delay because each time the delay time is an integral multiple of the clock beat , If you need more accurate delay , You need to read the count of the hardware timer or directly use the hardware timer
stay Cortex-M In the series ,SysTick Has been RT-Thread Used as a OS Tick Use , It is configured to 1/RT_TICK_PER_SECOND The way to trigger an interrupt after seconds , The interrupt handler function uses Cortex-M3 default SysTick_Handler name . stay Cortex-M3 Of CMSIS(Cortex Microcontroller Software Interface Standard) It is stipulated in the specification that SystemCoreClock Represents the dominant frequency of the chip , So based on the SysTick as well as SystemCoreClock, We can use SysTick Obtain an accurate delay function , As shown in the following example ,Cortex-M3 Based on SysTick Precise delay ( The system is required to enable SysTick After use ):
边栏推荐
- 在线文本行固定长度填充工具
- Study notes 7
- What is test development? Why do so many companies hire test developers now?
- [thingsboard] how to replace the homepage logo
- Mixed compilation of C and CC
- 防护电路中的元器件
- 【thingsboard】替换首页logo的方法
- C language course setting: cinema ticket selling management system
- SPI read / write flash principle + complete code
- DFS and BFS concepts of trees and graphs
猜你喜欢

Common features of ES6

Laravel8 export excel file

在线文本行固定长度填充工具

Use threejs to create geometry and add materials, lights, shadows, animations, and axes

MacBook installation postgresql+postgis
![[phantom engine UE] realize the animation production of mapping tripod deployment](/img/89/351641c3da7e2acdbf389bc298b75e.png)
[phantom engine UE] realize the animation production of mapping tripod deployment
![[moteur illusoire UE] il ne faut que six étapes pour réaliser le déploiement du flux de pixels ue5 et éviter les détours! (4.26 et 4.27 principes similaires)](/img/eb/a93630aff7545c6c3b71dcc9f5aa61.png)
[moteur illusoire UE] il ne faut que six étapes pour réaliser le déploiement du flux de pixels ue5 et éviter les détours! (4.26 et 4.27 principes similaires)

SPI read / write flash principle + complete code

American 5g open ran suffered another major setback, and its attempt to counter China's 5g technology has failed

TPG x AIDU|AI领军人才招募计划进行中!
随机推荐
蛇形矩阵
Differences among 10 addressing modes
【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)
在线SQL转Excel(xls/xlsx)工具
Mixed compilation of C and CC
Threejs rendering obj+mtl model source code, 3D factory model
指针函数(基础)
Containerd series - what is containerd?
What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
Learning notes 8
Threejs realizes rain, snow, overcast, sunny, flame
Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
Clickpaas low code platform
Containerd series - detailed explanation of plugins
mxnet导入报各种libcudart*.so、 libcuda*.so找不到
PR video clip (project packaging)
BDF application - topology sequence
How does the applet solve the rendering layer network layer error?
电源管理总线 (PMBus)