STM32 uCOS_II practice event identification group

Publisher:oplndctkl出Latest update time:2016-10-06 Source: eefocusKeywords:STM32  uCOS Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
In the chapter on interrupts, we introduced counting semaphores, which can effectively transmit a binary signal, while time stamp groups are tools that act on a task after multiple semaphores are operated. The main application scenario is to synchronize one task with more than two tasks.

At this point, you should have a certain understanding of the operation process of ucos. For the process of semaphore transmission, you can refer to another post. Here we only focus on the event identification group itself.

First, applying event identification groups requires four steps:

  1. Declare a pointer variable to identify the group.
    
    

    void *SemGrp_Task_LED1;

    This stores the pointer to the event control block, and is a global variable that needs to be globally declared (extern) in the corresponding header file. When the identification group is initialized, the event control block is initialized. The event control block is the module for managing and allocating this resource.
  2. Initialize the event identification group,
    
    

    SemGrp_Task_LED1 = OSFlagCreate(0,&err);

    Parameter 0 is the result of the final logic operation, the initial value is 0, and parameter &err is the error message;
  3. Set the waiting function in the user task,
    
    

    OSFlagPend( SemGrp_Task_LED1, // Flag group pointer
                 0x03, // Flag is the last two digits
          OS_FLAG_WAIT_SET_ALL + OS_FLAG_CONSUME, // Set and operate and clear the flag after the operation
          0,&err // No wait timeout
                 );

    There are 5 parameters in total. The first parameter sets the identification group pointer, indicating which identification group is being waited for; the second parameter is which operation bits are in the identification group. 0x03 means that there are 2 semaphores participating in this group and they are the lowest two bits of a byte; the third parameter is the combination of these semaphores to form a valid message, which is the two operations of "AND" and "OR", that is, all single semaphores are triggered when they are 1 or as long as one semaphore sends 1, and the corresponding operation relationship is to clear the single semaphore after the operation; the fourth parameter is the waiting time, the unit is the number of system heartbeats, and 0 means waiting without time limit; the fifth parameter is the error type.
  4. Set the sending semaphore function in different user tasks or trigger tasks.
    
    

    OSFlagPost(SemGrp_Task_LED1,0x01,OS_FLAG_SET,&err); // Set the first bit of the group flag

    There are four parameters in total. The first parameter is the identification group pointer, which indicates which identification group you are sending to; the second parameter indicates the number of bits you are operating on. The specific valid bit is set in the waiting function. In the sending function, it indicates which bit you are sending in the waiting function. In the code example, it is the lowest bit sent; the third parameter is whether to set it to one or zero, OS_FLAG_SET is set to one, and OS_FLAG_CLR is cleared to zero; the fourth parameter is the error type.


================================================== ===================================
    Here is the actual code inside the system:
    Step 2 and Step 3
   

void Task_LED1(void* p_arg)
{
(void) p_arg ;

SemGrp_Task_LED1 = OSFlagCreate(0,&err);
while(1)
{
OSFlagPend( SemGrp_Task_LED1, // Flag group pointer
0x03, // Flag is the last two digits
OS_FLAG_WAIT_SET_ALL + OS_FLAG_CONSUME, // Set and operate and clear the flag after the operation
0,&err // No wait timeout
);

LED1_HIGH;
OSTimeDlyHMSM(0,0,1,0);
LED1_LOW;
OSTimeDlyHMSM(0,0,1,0); // Delay to allow other tasks to run
}
}
   Two step 4 functions, respectively in the external interrupt service function:


void Interrupt_Handle_KEY2(void)
{
OSIntEnter();

// If you call the ucos system function in the interrupt service function, you must add the interrupt system function when you enter and exit the interrupt system function.

OSFlagPost(SemGrp_Task_LED1,0x01,OS_FLAG_SET,&err); // Set the first bit of the group flag EXTI_ClearITPendingBit
(EXTI_Line4); // Clear the flag bit

OSIntExit();
}




void Interrupt_Handle_KEY3(void)
{
OSIntEnter();

// If you call the ucos system function in the interrupt service function, you must add the interrupt system function when you enter and exit the interrupt system function.

OSFlagPost(SemGrp_Task_LED1,0x02,OS_FLAG_SET,&err); // Set the second bit of the group flag
EXTI_ClearITPendingBit(EXTI_Line3); // Clear the flag bit

OSIntExit();
}


Summarize:
      For the operation of event identification group, the idea is very simple. Add a waiting function in a task of the final result. When the system runs here, it will suspend this task, and then wait for each single semaphore according to the logic. There is a sending function in other tasks. According to the operation bit set in the waiting function, each bit is set high or low, so as to achieve the purpose of synchronizing multiple tasks with one task.
Keywords:STM32  uCOS Reference address:STM32 uCOS_II practice event identification group

Previous article:STM32 uCOS_II practice message mailbox
Next article:About the global reference of STM32 Systick delay function variables

Recommended ReadingLatest update time:2024-11-16 21:28

What is the ST AutoDevKit toolkit to make automotive ECU development more efficient?
Under normal circumstances, automotive ECU development in the eyes of engineers: complex 1. Demand analysis and top-level design; 2. Component selection, hardware module schematic design, PCB proofing, PCBA and unit module testing; 3. Module assembly; 4. Software development and testing; 5. System testing, m
[Automotive Electronics]
What is the ST AutoDevKit toolkit to make automotive ECU development more efficient?
STM32CubeMX timer control microsecond delay detailed explanation
Written at the beginning, why is there a need for a timer for microsecond delay?  1. In the HAL firmware library, only Systick is used as a delay counter, and the millisecond delay HAL_Delay(). In order to increase the precise microsecond delay, the Systick configuration parameters are generally changed, but the HAL f
[Microcontroller]
STM32+CC1101 low power consumption
It is not good to just read the post without posting. I will post it too. Please forgive me if it is not well written.       Two months ago, I did a low-power project in the company. Now the lowest power consumption is less than 10uA, and the average power consumption is about 40uA, which is up to standard. Because it
[Microcontroller]
STM32 - C language data types
During the programming process, different CPUs have different meanings of data types, so you must pay attention to the definition and conversion of the corresponding variable data types, otherwise uncertain errors may occur in the calculation. 1. Type data in C language Integer: int short long Real type: float dou
[Microcontroller]
stm32 4*4 matrix keyboard
stm32f030 development board. Use HAL library. The state machine performs debounce. col column, Pin is configured as PP push-pull output mode; row, the Pin is configured as Input mode and the internal pull-up resistor is enabled. code show as below: .h files /*  *  * Name: keypad.h  * Faq: www.mazclub.com 
[Microcontroller]
STM32 FSMC study notes
FSMC stands for "Flexible Static Memory Controller". FSMC includes 4 modules: (1) AHB interface (including FSMC configuration register) (2) NOR flash memory and PSRAM controller (when driving LCD, LCD is like a PSRAM with only 2 16-bit storage spaces, one is DATA RAM and the other is CMD RAM) (3) NAND flash memory
[Microcontroller]
STM32 FSMC study notes
STM32 FSMC address block division
Note: Each area has independent register control and a separate chip select pin, so each area can be connected to different peripherals.
[Microcontroller]
STM32 FSMC address block division
STM32 eight-channel AD conversion is successfully debugged with DMA transfer, and DMA transfer is not misaligned
// // #include "stm32f10x_conf.h"                          //Remove comments from DMA.h and ADC.h #include "stm32f10x.h" #include "stm32_eval.h" #include #define  N  50          //Each channel samples 50 times #define  M  8          //8 channels #define ADC1_DR_Address      ((u32)0x4001244C) vu16  After_
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号