当前位置:网站首页>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
边栏推荐
猜你喜欢

IDEA设置版权信息

A graphic designer's fantasy world | ones characters

Zero trust in network information security
Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion

为什么要有包装类,顺便说一说基本数据类型、包装类、String类该如何转换?

一个平面设计师的异想世界|ONES 人物

智能多线弹性云增加独立的IP地址,如何实现多线功能?

The maximum number of remote desktop servers has been exceeded

SSL证书退款说明

31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
随机推荐
Lesson 25 static member variables of classes
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
使用Source Insight查看编辑源代码
Uni app native app local packaging integrated Aurora push (jg-jpush) detailed tutorial
Stacks and queues a
Qt双缓冲绘图
SPSS之单因素方差分析
AD20补充笔记3—快捷键+持续更新
Markdown grammar learning
BUUCTF WEB [BUUCTF 2018]Online Tool
异步时钟亚稳态 的解决方案——多bit信号
C set Logo Icon and shortcut icon
SSL证书退款说明
Markdown语法学习
Number of nodes of complete binary tree
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
MySQL函数-递归函数
Idea setting copyright information
S2-062 远程命令执行漏洞复现(cve-2021-31805)