当前位置:网站首页>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
边栏推荐
- 【csnote】ER图
- 远程桌面之终端服务器超出了最大允许连接数解决
- SQLserver怎么插入或更新当天的星期数,bit而不是文本
- QT double buffer drawing
- Kubernetes 入門教程
- How do traditional enterprises cope with digital transformation? These books give you the answer
- BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
- SynchronousQueue 源码解析
- How do programmers finalize nucleic acid statistics with 130 lines of code
- How does sqlserver insert or update the number of weeks of the day instead of text
猜你喜欢
[redis series] redis learning 13. Redis often asks simple interview questions
XinChaCha Trust SSL Organization Validated
S2-062 远程命令执行漏洞复现(cve-2021-31805)
Plato farm - a game of farm metauniverse with Plato as the goal
SPSS之单因素方差分析
Qt绘制文字
编程辅助工具推荐:图片工具snipaste
【vulnhub靶场】-dc2
Number of nodes of complete binary tree
Qt绘制图像
随机推荐
Resolve disagrees about version of symbol device_ create
Try the server for one month for free, and attach the tutorial
leetcode:437. 路径总和 III【dfs 选还是不选?】
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
Buuctf Web [bjdctf2020] zjctf, but so
AI 视频云 VS 窄带高清,谁是视频时代的宠儿
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
A graphic designer's fantasy world | ones characters
XinChaCha Trust SSL Organization Validated
Introduction to kubernetes
免费试用一个月的服务器,并附上教程
Web17——EL与JSTL的使用
C set Logo Icon and shortcut icon
worder字体网页字体对照表
远程桌面之终端服务器超出了最大允许连接数解决
Why is there a wrapper class? By the way, how to convert basic data types, wrapper classes and string classes?
Basic software testing Day2 - Case Execution
异步时钟亚稳态 的解决方案——多bit信号
Symmetric encryption, certificate encryption
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)