ThreadX IPC應用之事件標誌

2021-10-11 11:04:14 字數 2494 閱讀 1941

e-mail:[email protected]

在rtos的應用開發中,事件標誌主要是用來進行任務之間的事件通知。例如有a和b兩個任務,a任務負責接收訊息,b任務負責對訊息響應。當a任務接收到訊息後設定響應標誌,b任務監測到響應標誌被設定就執行訊息響應。事件標誌沒被設定的時候任務是不會占用cpu的,不用像裸機程式那樣不斷輪詢事件的發生。事件標誌通知的方式使得cpu的利用率更高,這也是使用rtos的優勢之一。

下面列出使用事件標誌組時常用的幾個函式

引數

返回值

uint tx_event_flags_create(

tx_event_flags_group *group_ptr,

char *name_ptr);

引數

返回值

uint tx_event_flags_delete

(tx_event_flags_group *group_ptr)

;

引數

返回值

uint tx_event_flags_get(

tx_event_flags_group *group_ptr,

ulong requested_flags,

uint get_option,

ulong *actual_flags_ptr,

ulong wait_option);

引數

返回值

uint tx_event_flags_set(

tx_event_flags_group *group_ptr,

ulong flags_to_set,

uint set_option);

該例項建立乙個事件標誌組和三個任務。標誌組中包含了兩個事件標誌,任務1檢測按鍵1的執行,任務2檢測按鍵2的執行,任務3執行對應的按鍵響應,任務之間的通知採用事件標誌的方式。

#include "main.h"

#include "usart.h"

#include "gpio.h"

#include "tx_api.h"

#define demo_stack_size (2 * 1024)

#define demo_byte_pool_size (32 * 1024)

/*事件標誌*/

#define tx_event_flag_key1 (1 << 0)

#define tx_event_flag_key2 (1 << 1)

tx_thread thread_0;

tx_thread thread_1;

tx_thread thread_2;

tx_byte_pool byte_pool_0;

uchar memory_area[demo_byte_pool_size];

/*事件標誌組*/

tx_event_flags_group tx_event_flags;

void thread_0_entry(ulong thread_input);

void thread_1_entry(ulong thread_input);

void thread_2_entry(ulong thread_input);

int main(void)

}void thread_0_entry(ulong thread_input)

else

key_cnt = 0;

} tx_thread_sleep(20);

}}void thread_1_entry(ulong thread_input)

else

key_cnt = 0;

} tx_thread_sleep(20);

}}void thread_2_entry(ulong thread_input)

if (tx_event_flag_key2 == (actual_events & tx_event_flag_key2))

}}

}

效果如下:

觸控事件之事件傳遞

uiview是如何判定這個事件是否是自己應該處理的呢?hittest withevent 方法的處理流程如下 呼叫當前view的pointinside withevent 方法來判定觸控點是否在當前view內部,如果返回no,則hittest withevent 返回nil 如果返回yes,則向當前...

iOS 控制項響應使用者控制事件之事件處理

原文 加速計事件 遠端控制事件 uitouch的作用 uitouch的方法 cgpoint locationinview uiview view cgpoint previouslocationinview uiview view 常見屬性 事件型別 property nonatomic,reado...

RT thread核心之事件

一 事件控制塊 在include rtdef.h中 ifdef rt using event flag defintions in event define rt event flag and 0x01 logic and define rt event flag or 0x02 logic or ...