当前位置:网站首页>[practice] stm32mp157 development tutorial FreeRTOS system 3: FreeRTOS counting semaphore
[practice] stm32mp157 development tutorial FreeRTOS system 3: FreeRTOS counting semaphore
2022-06-21 09:13:00 【Huaqing vision it open laboratory】
1. Write it at the front :
This article is 《STM32MP157 Developing a tutorial FreeRTOS Operating system 》 One in a series , The development platform used by the author is Huaqing vision FS-MP1A Development board (STM32MP157 Development board ).stm32mp157 yes ARM Dual core ,2 individual A7 nucleus ,1 individual M4 nucleus ,A7 You can run on the core Linux operating system ,M4 You can run on the core FreeRTOS、RT-Thread And other real-time operating systems ,STM32MP157 Development board, so you can learn Embedded linux, You can also learn. stm32 Single chip microcomputer .
in the light of FS-MP1A Development board , except FreeRTOS Outside the operating system , There are also many other series of tutorials , Include Cortex-A7 Development of article 、Cortex-M4 Development of article 、 Expansion board driver transplantation 、Linux Application development 、Linux System transplantation 、Linux Driving development 、 Hardware design 、 Artificial intelligence machine vision 、Qt Application programming 、Qt Comprehensive project practice, etc . Welcome to your attention , more stm32mp157 Develop tutorials and videos , Technical exchange can be added Q Group 459754978, Thank you for attention .
FS-MP1A Development board Details :https://item.taobao.com/item.htm?id=622457259672
2.FreeRTOS Counting semaphores
2.1. Introduction to counting semaphore
Counting semaphores are also called numeric semaphores , Equivalent to a value greater than 1 Queues , Users don't need to care what data is stored in it , Just care whether it is empty , It is mainly used for event counting and resource management .
2.1.1 Event count
On this occasion , Each time an event occurs, the semaphore is released in the event handler function ( Increase the count of semaphores
value ), Other tasks get semaphores ( The semaphore count value minus one , The semaphore value is the queue structure member variable
uxMessagesWaiting) To deal with Events . The initial count value of the count semaphore created in this case is 0.
2.1.2 Resource management
On this occasion , The semaphore value represents the available quantity of the current resource , For example, the number of seats remaining in the room .
A task wants to obtain the right to use resources , First, the semaphore must be obtained , After the semaphore is successfully obtained, the semaphore value will be reduced by one . When the semaphore value is 0 It means that there are no resources . When a task uses up resources, it must release semaphores , After releasing the semaphore, the semaphore value will be increased by one . The initial value of the count semaphore created in this case should be the number of resources , For example, there are... In the room 50 A seat , When creating a semaphore, the semaphore value should be initialized to 50.
2.2. Counting semaphore function
2.2.1 Create semaphores
Same as binary semaphores , If you want to use , You must first create a semaphore , In the new FreeRTOS in , In general use xSemaphoreCreateCounting() Function to dynamically create a counting semaphore . This function is a macro , The function prototype is as follows :
SemaphoreHandle_t xSemaphoreCreateCounting(UBaseType_t uxMaxCount,
UBaseType_t uxInitialCount)
Parameters :
uxMaxCount: Maximum count value of semaphore , When the semaphore value is equal to this value, releasing the semaphore will fail
uxInitialCount: Count semaphore initial value
Return value :
NULL: Count semaphore creation failed
Other values : Create a handle to a successful count semaphore
2.2.2 Release semaphore
The function of releasing semaphore is the same as that of binary semaphore , Please refer to FreeRTOS Binary semaphores .
2.2.3 Acquisition semaphore
The function of acquiring semaphores is the same as that of binary semaphores , Please refer to FreeRTOS Binary semaphores .
2.3. Operation experiment
2.3.1 Experimental design
Counting semaphores are generally used for event counting and resource management , In this experiment , By scanning the keys , When the key is pressed, the semaphore is released and obtained , The value of the semaphore can be displayed through the serial port .
The tasks and their functions are as follows :
StartTask02(): scanning KEY1 key , When the key is pressed , Release the semaphore , By the way, get the semaphore value , Display through serial port output .
StartDefaultTask(): scanning KEY2 key , When the key is pressed , To acquire semaphores , By the way, get the semaphore value , It is also displayed through serial port output .
Under normal circumstances , Every time the semaphore is released , Semaphore value plus 1, When you get it , Value minus 1.
2.3.2 Experimental process and analysis
First , Configure... According to the previous chapters KEY、UART4, Among them, the KEY Set to GPIO_input, Configure... According to the previous section “FREERTOS”, Generate code when finished . stay StartDefaultTask() And StartTask02() Add the following code to .
May refer to 12.3.2 Chapter to import the existing project , Project storage path 【 Huaqing vision -FS-MP1A Development of information \02- Program source code \ARM Architecture and interface technology \FreeRTOS\2_MP1A-FreeRTOS-COUNT】


The experimental results are shown in the figure

When pressed KEY1 Key time , Semaphore release , The semaphore will increase 1, Now press KEY2 Key time , After getting the semaphore , The number of semaphores decreases 1.
Hardware platform : Huaqing vision FS-MP1A Development board (STM32MP157) Download some development tutorials : Add QQ Group 459754978, There are in the group file .
Watch some video courses :https://space.bilibili.com/670826565/channel/detail?cid=145472
Taobao purchase link :https://item.taobao.com/item.htm?id=622457259672
Mobile Taobao sharing code : Copy the text of this line and open hand Amoy ₤T4FPXn3YYJ2₤
边栏推荐
- 【JUC系列】Executor框架之CompletionService
- android 数据库升级
- Common basic functions of R language: call the data editor with edit function to manually customize and edit the data object without changing the content of the original data object, and call the data
- Verification code ----- SVG captcha
- ADO. Net - invalid size for size property, 0 - ado NET - The Size property has an invalid size of 0
- 基于Retrotfit2.1+Material Design+ijkplayer开发的一个APP
- finally block can not complete normally
- Unity . Net framework
- finally block can not complete normally
- Introduction to list operation in C #
猜你喜欢

Job hopping is better than promotion
![[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface](/img/04/a7455760caa4fc0480a034de1e24b8.png)
[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface
![[early knowledge of activities] list of recent activities of livevideostack](/img/8c/f8007931b1a5944f3a0a243a5afcc4.png)
[early knowledge of activities] list of recent activities of livevideostack

Mono of unity 5 can also support C # 6

The next stop of Intelligent Manufacturing: cloud native + edge computing two wheel drive

It is said that this year gold three silver four has become gold one silver two.

Mono fourni avec l'unit é 5 peut également supporter C # 6

Unity write multithreading considerations

【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器
![[Mgt] model Mgt for code interpretation](/img/4f/694e7b93626436007021b718ad69b5.png)
[Mgt] model Mgt for code interpretation
随机推荐
Abstractqueuedsynchronizer (AQS) source code analysis - cyclicbarrier source code analysis
Style penetration of vant UI components -- that is, some styles in vant UI components cannot be modified
Junit5 unit test
Leetcode: print the common part of two ordered linked lists
Client construction and Optimization Practice
[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface
Alibaba cloud OSS uploading and intelligent image recognition garbage recognition
TiDB、mysql修改系统变量/常用语句(杀死process中的进程)
【实战】STM32MP157开发教程之FreeRTOS系统篇3:FreeRTOS 计数型信号量
Dumpling備份數據庫
finally block can not complete normally
Adapt to the pits in Huawei models
Waiting in webdriver
Retrofit extended reading
Observation on the salary data of the post-90s: poor, counselled and serious
Source insight shortcut key cross reference
【JUC系列】Executor框架之CompletionService
The R language uses the fix function to modify the name of the data variable through the editor. For example, use the fix function to modify the name of the dataframe data column
R language uses the < - operator to create a new variable, uses the existing data column (sum, mean) to create a new data column, uses the ifelse function or conditional judgment to create a discrete
Figure out how MySQL works