当前位置:网站首页>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
边栏推荐
- Stacks and queues a
- How much does software testing help reduce program bugs?
- 异步时钟亚稳态 的解决方案——多bit信号
- Symmetric encryption, certificate encryption
- BUUCTF WEB [BUUCTF 2018]Online Tool
- Stm32cubeprogrammer basic instructions
- What are the forms of attack and tampering on the home page of the website
- Buuctf Web [gxyctf2019] no dolls
- flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
- Metalama简介4.使用Fabric操作项目或命名空间
猜你喜欢
Please help me see what this is, mysql5 5. Thanks
QT draw text
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Plato farm - a game of farm metauniverse with Plato as the goal
电脑系统卡如何解决?
宝塔面板命令行帮助教程(包含重置密码)
bert-base-chinese下载(智取)
Qt双缓冲绘图
Message queuing overview
Pre competition practice of TIANTI competition
随机推荐
One way ANOVA of SPSS
SQL exercise (I)
S2-062 远程命令执行漏洞复现(cve-2021-31805)
Uni app native app local packaging integrated Aurora push (jg-jpush) detailed tutorial
Intelligent multi line elastic cloud adds independent IP address. How to realize multi line function?
Introduction to metalama 4 Use fabric to manipulate items or namespaces
一个平面设计师的异想世界|ONES 人物
Idea setting copyright information
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
免费试用一个月的服务器,并附上教程
Recommended programming AIDS: picture tool snipaste
MySQL function - recursive function
Can I take the CPDA data analyst certificate for 0 foundation
How to solve the computer system card?
Image attribute of input: type attribute of fashion cloud learning -h5
mysql中 innoDB执行过程分析
洛谷P3236 [HNOI2014]画框 题解
How to switch PHP version in Windows 2008 system
C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
RT-thread中关键词解释及部分API