当前位置:网站首页>Keyword interpretation and some APIs in RT thread
Keyword interpretation and some APIs in RT thread
2022-04-23 12:38:00 【Guistar~~】
Review the RTOS Well , This article is a complete reference RT_thread The official tutorial
1. Memory
-
Stack stack: Release is automatically allocated by the compiler such as int a
-
Pile up heap: Assigned and released by the programmer such as malloc function
-
Dynamic memory space :rt_system_heap_init(begin_addr,end_addr)
-
Dynamic memory application
char p;
p=(char)rt_malloc(10);
rt_free§; -
Memory reset : Requested memory block , Reset operation , Make sure there's nothing in it :
rt_memset(p,0,10); -
Memory leak solution :
malloc and free Matching use of
2. Threads
- Three parts : Thread code ( Entry function ), Thread control block , Thread stack
- Entry function :
void rtread_enter(viod *parameter)
{
} - Creation of dynamic threads :rt_rtread_create();
- Detailed parameters
rt_thread_t rt_thread_create(const char *name,
void (*entry)(void *parameter),
void *parameter, // Parameters
rt_uint_t stack_size,
rt_uint8_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick)
- Start thread :
rt_err_t rt_thread_startup(rt_thread_t thread)
3. State switching
- Ready to pending :suspend
Suspend to close :delete,detach
Run to close :exit
4. The system clock
- System tick timer : heartbeat 100hz
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq();
systick_cofing The frequency of ticking, the second parameter 100
5.gpio The architecture of
- void rt_pin_mode(rt_base_pin,mode)
6. Delayed api:
- rt_thread_delay(50)
rt_thread_mdelay(500)
rt_rtthread_sleep(50)
7. Event slice and priority
-
Time slice parameters : The ability to hold the processor for a long time The unit of clock beat is
With the same priority , The length of time film accounts for cpu Long time -
priority : The ability of threads to compete for processor resources 256
Maximum setting :RT_THREAD_PRIORITY_MAX macro
stm32:32 individual
8. Idle threads and hook functions
-
Idle Thread : System threads , Lowest priority
Recycling , Remove the shutdown thread idle.C -
Hook function : Let the system execute some non urgent transactions when the thread is idle , Let's say LED Light flashing, etc
Set up :rt_err_t rt_thread_idle_sethook(void(*hook)(void))
Delete :rt_err_t rt_thread_idle_delhook(void(*hook)(void))
Hook functions cannot be suspended -
System scheduling hook function : Run during task switching , Print scheduling information
rt_scheduler_sethook(void(*hook)(struct rt_thread *from,struct rt_thread *to)
rt_err_t rt_thread_idle_delhook(void(*hook)(void))
9. critical
-
Critical resources : A shared resource that can only be accessed by one thread at a time , It can be a specific hardware device , It can also be a variable , buffer
-
A critical region : Access... In each thread ( operation ) The code of critical resources is called critical area , We only allow one thread to enter the critical area
-
Two ways of protection :
1: Shut down the critical area of system dispatching protection : Lock the scheduler , No scheduling
rt_enter_critical();rt_exit_critical();
2: Turn off the interrupt protection critical zone : Task scheduling is based on interruption
rt_base_t lever;
lever = rt_hw_interrupt_disable();
rt_hw_interrupt_enable();
10.IPC
Interprocess communication
Semaphore , The mutex , event , mailbox , Message queue
11. Semaphore
Parking lot management
- Control block definition
struct rt_semaphore
{
struct rt_ipc_object parent;
rt_uint16_t value;
};
typedef struct rt_semaphore *rt_sem_t;
static state :struct rt_semaphore static_sem
dynamic :rt_sem_t dynamic_sem
- Operation initialization and disengagement of static semaphore
rt_err_t rt_sem_init(rt_sem_t sem, // Semaphore pointer
const char *name, // Semaphore name
rt_uint32_t value, // Initial value
rt_uint8_t flag); // sign
flag:
RT_IPC_FLAG_FIFO First in first out queue
RT_IPC_FALG_PRIO Priority queuing
rt_err_t rt_sem_detach(rt_sem_t sem);
- Creation and deletion of dynamic semaphores
rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag);
rt_err_t rt_sem_delete(rt_sem_t sem);
- Acquisition semaphore
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time);
rt_err_t rt_sem_trytake(rt_sem_t sem);
- Release
rt_err_t rt_sem_release(rt_sem_t sem);
12. Production and consumer relations
Producer consumer relations : Sync 2 Semaphores and mutexes 1 A semaphore
empty , full
Two hands : An empty seat holds things in one hand , The full person tells the other person whether he can take
13. Use of mutexes :
Exclusive access between threads
- Mutex control block :
struct rt_mutex
{
struct rt_ipc_object parent;
rt_unint16_t value;
rt_uint8_t original_priority;
rt_uint8_t hold;
struct rt_thread *owner;
}
Define static :struct _rt_mutex static_mutex
Define dynamics :rt_mutex_t dynamic_mutex
- Be careful : Only released by the thread holding him !
14. The priority of the thread is reversed
High priority threads , The resources used are low priority resources . Then go to the low priority task first , Then higher priority , To perform tasks of medium priority .
15. Priority inheritance :
Raise the priority of low priority tasks as high priority tasks .
16. Event set event
One 32 The number of bits , Each bit represents a semaphore , The received event bits are : And or way
17. mailbox mailbox
A thread sends data to the mailbox or Address , Another thread takes it out of the mailbox to use .
18. Message queue :
Expansion of mailbox , Receive non fixed length messages from threads and interrupt service routines , And save it in your own memory , Other threads can read and process messages from the message queue .
- Chain head , Chain tail , Free list .
Put the emergency message in the message header , General message list . - Message queuing control block :struct rt_messsagequeue
19. Software timer : System beat (os tick)
Interrupt the environment :HARDTIMER Pattern
TIMER Threads :SOFTTIMER Pattern
20. Memory pool
Memory resource allocation .
版权声明
本文为[Guistar~~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231221329781.html
边栏推荐
- SynchronousQueue 源码解析
- 甲辰篇 創世紀《「內元宇宙」聯載》
- STM32控制步进电机(ULN2003+28byj)
- leetcode:437. 路径总和 III【dfs 选还是不选?】
- Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
- Qt绘制图像
- RT-thread中关键词解释及部分API
- QT redraw events and cuts
- NPDP | how can product managers not be excluded by programmers?
- Worder font page font comparison table
猜你喜欢

worder字体网页字体对照表

QT one process runs another

STM32工程移植:不同型号芯片工程之间的移植:ZE到C8

Qt一个进程运行另一个进程

Qt进程间通信

I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings

Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years

使用Source Insight查看编辑源代码

0基础可以考CPDA数据分析师证书吗

IDEA设置版权信息
随机推荐
Kubernets Getting started tutoriel
c# 设置logo图标和快捷方式的图标
STM32CubeProgrammer基础使用说明
SQL exercise (I)
宝塔面板命令行帮助教程(包含重置密码)
网络信息安全之零信任
【vulnhub靶场】-dc2
Unlock openharmony technology day! The annual event is about to open!
Jiachen chapter Genesis "inner universe" joint Edition
关于使用Go语言创建WebSocket服务浅谈
Outsourcing for five years, abandoned
Luogu p3236 [hnoi2014] picture frame solution
QT draw image
Introduction to kubernetes
Metalama简介4.使用Fabric操作项目或命名空间
31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
How to switch PHP version in Windows 2008 system
php生成json处理中文
天梯赛赛前练习
对称加密、证书加密