RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ Event 的协作图:

结构体

struct  rt_event
 

宏定义

#define RT_EVENT_FLAG_AND   0x01
 
#define RT_EVENT_FLAG_OR   0x02
 
#define RT_EVENT_FLAG_CLEAR   0x04
 

类型定义

typedef struct rt_eventrt_event_t
 

函数

rt_err_t rt_event_init (rt_event_t event, const char *name, rt_uint8_t flag)
 
 RTM_EXPORT (rt_event_init)
 
rt_err_t rt_event_detach (rt_event_t event)
 
 RTM_EXPORT (rt_event_detach)
 
rt_event_t rt_event_create (const char *name, rt_uint8_t flag)
 
 RTM_EXPORT (rt_event_create)
 
rt_err_t rt_event_delete (rt_event_t event)
 
 RTM_EXPORT (rt_event_delete)
 
rt_err_t rt_event_send (rt_event_t event, rt_uint32_t set)
 
 RTM_EXPORT (rt_event_send)
 
rt_err_t rt_event_recv (rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_int32_t timeout, rt_uint32_t *recved)
 
 RTM_EXPORT (rt_event_recv)
 
rt_err_t rt_event_recv_interruptible (rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_int32_t timeout, rt_uint32_t *recved)
 
 RTM_EXPORT (rt_event_recv_interruptible)
 
rt_err_t rt_event_recv_killable (rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_int32_t timeout, rt_uint32_t *recved)
 
 RTM_EXPORT (rt_event_recv_killable)
 
rt_err_t rt_event_control (rt_event_t event, int cmd, void *arg)
 
 RTM_EXPORT (rt_event_control)
 

详细描述

宏定义说明

◆ RT_EVENT_FLAG_AND

#define RT_EVENT_FLAG_AND   0x01

flag definitions in event logic and

在文件 rtdef.h1051 行定义.

◆ RT_EVENT_FLAG_OR

#define RT_EVENT_FLAG_OR   0x02

logic or

在文件 rtdef.h1052 行定义.

◆ RT_EVENT_FLAG_CLEAR

#define RT_EVENT_FLAG_CLEAR   0x04

clear flag

在文件 rtdef.h1053 行定义.

类型定义说明

◆ rt_event_t

typedef struct rt_event* rt_event_t

在文件 rtdef.h1065 行定义.

函数说明

◆ rt_event_init()

rt_err_t rt_event_init ( rt_event_t event,
const char * name,
rt_uint8_t flag )

The function will initialize a static event object.

注解
For the static event object, its memory space is allocated by the compiler during compiling, and shall placed on the read-write data segment or on the uninitialized data segment. By contrast, the rt_event_create() function will allocate memory space automatically and initialize the event.
参见
rt_event_create()
参数
eventis a pointer to the event to initialize. It is assumed that storage for the event will be allocated in your application.
nameis a pointer to the name that given to the event.
flagis the event flag, which determines the queuing way of how multiple threads wait when the event is not available. The event flag can be ONE of the following values:
RT_IPC_FLAG_PRIO          The pending threads will queue in order of priority.

RT_IPC_FLAG_FIFO          The pending threads will queue in the first-in-first-out method
                          (also known as first-come-first-served (FCFS) scheduling strategy).

NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to
use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about
the first-in-first-out principle, and you clearly understand that all threads involved in
this event will become non-real-time threads.
返回
Return the operation status. When the return value is RT_EOK, the initialization is successful. If the return value is any other values, it represents the initialization failed.
警告
This function can ONLY be called from threads.

在文件 ipc.c1786 行定义.

1787{
1788 /* parameter check */
1789 RT_ASSERT(event != RT_NULL);
1790 RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
1791
1792 /* initialize object */
1794
1795 /* set parent flag */
1796 event->parent.parent.flag = flag;
1797
1798 /* initialize ipc object */
1799 _ipc_object_init(&(event->parent));
1800
1801 /* initialize event */
1802 event->set = 0;
1803 rt_spin_lock_init(&(event->spinlock));
1804
1805 return RT_EOK;
1806}
#define RT_IPC_FLAG_FIFO
#define RT_IPC_FLAG_PRIO
rt_inline rt_err_t _ipc_object_init(struct rt_ipc_object *ipc)
This function will initialize an IPC object, such as semaphore, mutex, messagequeue and mailbox.
定义 ipc.c:82
void rt_spin_lock_init(struct rt_spinlock *lock)
Initialize a static spinlock object.
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name)
This function will initialize an object and add it to object system management.
@ RT_Object_Class_Event
#define RT_ASSERT(EX)
#define RT_NULL
struct rt_spinlock spinlock
struct rt_ipc_object parent
struct rt_object parent

引用了 _ipc_object_init(), rt_event::parent, rt_ipc_object::parent, RT_ASSERT, RT_IPC_FLAG_FIFO, RT_IPC_FLAG_PRIO, RT_NULL, RT_Object_Class_Event, rt_object_init(), rt_spin_lock_init() , 以及 rt_event::spinlock.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [1/9]

RTM_EXPORT ( rt_event_init )

引用了 rt_event_init().

+ 函数调用图:

◆ rt_event_detach()

rt_err_t rt_event_detach ( rt_event_t event)

This function will detach a static event object.

注解
This function is used to detach a static event object which is initialized by rt_event_init() function. By contrast, the rt_event_delete() function will delete an event object. When the event is successfully detached, it will resume all suspended threads in the event list.
参见
rt_event_delete()
参数
eventis a pointer to an event object to be detached.
返回
Return the operation status. When the return value is RT_EOK, the initialization is successful. If the return value is any other values, it means that the event detach failed.
警告
This function can ONLY detach a static event initialized by the rt_event_init() function. If the event is created by the rt_event_create() function, you MUST NOT USE this function to detach it, ONLY USE the rt_event_delete() function to complete the deletion.

在文件 ipc.c1828 行定义.

1829{
1830 rt_base_t level;
1831
1832 /* parameter check */
1833 RT_ASSERT(event != RT_NULL);
1836
1837 level = rt_spin_lock_irqsave(&(event->spinlock));
1838 /* resume all suspended thread */
1839 rt_susp_list_resume_all(&(event->parent.suspend_thread), RT_ERROR);
1840 rt_spin_unlock_irqrestore(&(event->spinlock), level);
1841
1842 /* detach event object */
1843 rt_object_detach(&(event->parent.parent));
1844
1845 return RT_EOK;
1846}
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
This function will disable the local interrupt and then lock the spinlock, will lock the thread sched...
rt_err_t rt_susp_list_resume_all(rt_list_t *susp_list, rt_err_t thread_error)
This function will resume all suspended threads in the IPC object list, including the suspended list ...
定义 ipc.c:165
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
This function will unlock the spinlock and then restore current cpu interrupt status,...
rt_bool_t rt_object_is_systemobject(rt_object_t object)
This function will judge the object is system object or not.
rt_uint8_t rt_object_get_type(rt_object_t object)
This function will return the type of object without RT_Object_Class_Static flag.
void rt_object_detach(rt_object_t object)
This function will detach a static object from object system, and the memory of static object is not ...
rt_int32_t rt_base_t
rt_list_t suspend_thread

引用了 rt_event::parent, rt_ipc_object::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Event, rt_object_detach(), rt_object_get_type(), rt_object_is_systemobject(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), rt_susp_list_resume_all(), rt_event::spinlock , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [2/9]

RTM_EXPORT ( rt_event_detach )

引用了 rt_event_detach().

+ 函数调用图:

◆ rt_event_create()

rt_event_t rt_event_create ( const char * name,
rt_uint8_t flag )

Creating an event object.

注解
For the event object, its memory space is allocated automatically. By contrast, the rt_event_init() function will initialize a static event object.
参见
rt_event_init()
参数
nameis a pointer to the name that given to the event.
flagis the event flag, which determines the queuing way of how multiple threads wait when the event is not available. The event flag can be ONE of the following values:
RT_IPC_FLAG_PRIO          The pending threads will queue in order of priority.

RT_IPC_FLAG_FIFO          The pending threads will queue in the first-in-first-out method
                          (also known as first-come-first-served (FCFS) scheduling strategy).

NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to
use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about
the first-in-first-out principle, and you clearly understand that all threads involved in
this event will become non-real-time threads.
返回
Return a pointer to the event object. When the return value is RT_NULL, it means the creation failed.
警告
This function can ONLY be called from threads.

在文件 ipc.c1878 行定义.

1879{
1880 rt_event_t event;
1881
1882 RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
1883
1885
1886 /* allocate object */
1888 if (event == RT_NULL)
1889 return event;
1890
1891 /* set parent */
1892 event->parent.parent.flag = flag;
1893
1894 /* initialize ipc object */
1895 _ipc_object_init(&(event->parent));
1896
1897 /* initialize event */
1898 event->set = 0;
1899 rt_spin_lock_init(&(event->spinlock));
1900
1901 return event;
1902}
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
This function will allocate an object from object system.
#define RT_DEBUG_NOT_IN_INTERRUPT
struct rt_event * rt_event_t
rt_uint8_t flag

引用了 _ipc_object_init(), rt_object::flag, rt_event::parent, rt_ipc_object::parent, RT_ASSERT, RT_DEBUG_NOT_IN_INTERRUPT, RT_IPC_FLAG_FIFO, RT_IPC_FLAG_PRIO, RT_NULL, rt_object_allocate(), RT_Object_Class_Event, rt_spin_lock_init() , 以及 rt_event::spinlock.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [3/9]

RTM_EXPORT ( rt_event_create )

引用了 rt_event_create().

+ 函数调用图:

◆ rt_event_delete()

rt_err_t rt_event_delete ( rt_event_t event)

This function will delete an event object and release the memory space.

注解
This function is used to delete an event object which is created by the rt_event_create() function. By contrast, the rt_event_detach() function will detach a static event object. When the event is successfully deleted, it will resume all suspended threads in the event list.
参见
rt_event_detach()
参数
eventis a pointer to an event object to be deleted.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the event detach failed.
警告
This function can ONLY delete an event initialized by the rt_event_create() function. If the event is initialized by the rt_event_init() function, you MUST NOT USE this function to delete it, ONLY USE the rt_event_detach() function to complete the detachment.

在文件 ipc.c1924 行定义.

1925{
1926 /* parameter check */
1927 RT_ASSERT(event != RT_NULL);
1930
1932
1933 rt_spin_lock(&(event->spinlock));
1934 /* resume all suspended thread */
1935 rt_susp_list_resume_all(&(event->parent.suspend_thread), RT_ERROR);
1936 rt_spin_unlock(&(event->spinlock));
1937
1938 /* delete event object */
1939 rt_object_delete(&(event->parent.parent));
1940
1941 return RT_EOK;
1942}
void rt_spin_lock(struct rt_spinlock *lock)
This function will lock the spinlock, will lock the thread scheduler.
void rt_spin_unlock(struct rt_spinlock *lock)
This function will unlock the spinlock, will unlock the thread scheduler.
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.
#define RT_FALSE

引用了 rt_event::parent, rt_ipc_object::parent, RT_ASSERT, RT_DEBUG_NOT_IN_INTERRUPT, RT_FALSE, RT_NULL, RT_Object_Class_Event, rt_object_delete(), rt_object_get_type(), rt_object_is_systemobject(), rt_spin_lock(), rt_spin_unlock(), rt_susp_list_resume_all(), rt_event::spinlock , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [4/9]

RTM_EXPORT ( rt_event_delete )

引用了 rt_event_delete().

+ 函数调用图:

◆ rt_event_send()

rt_err_t rt_event_send ( rt_event_t event,
rt_uint32_t set )

This function will send an event to the event object. If there is a thread suspended on the event, the thread will be resumed.

注解
When using this function, you need to use the parameter (set) to specify the event flag of the event object, then the function will traverse the list of suspended threads waiting on the event object. If there is a thread suspended on the event, and the thread's event_info and the event flag of the current event object matches, the thread will be resumed.
参数
eventis a pointer to the event object to be sent.
setis a flag that you will set for this event's flag. You can set an event flag, or you can set multiple flags through OR logic operation.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the event detach failed.

在文件 ipc.c1964 行定义.

1965{
1966 struct rt_list_node *n;
1967 struct rt_thread *thread;
1969 rt_base_t level;
1970 rt_base_t status;
1971 rt_bool_t need_schedule;
1972 rt_uint32_t need_clear_set = 0;
1973
1974 /* parameter check */
1975 RT_ASSERT(event != RT_NULL);
1977
1978 if (set == 0)
1979 return -RT_ERROR;
1980
1981 need_schedule = RT_FALSE;
1982
1983 level = rt_spin_lock_irqsave(&(event->spinlock));
1984
1985 /* set event */
1986 event->set |= set;
1987
1988 RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(event->parent.parent)));
1989
1990 rt_sched_lock(&slvl);
1992 {
1993 /* search thread list to resume thread */
1994 n = event->parent.suspend_thread.next;
1995 while (n != &(event->parent.suspend_thread))
1996 {
1997 /* get thread */
1998 thread = RT_THREAD_LIST_NODE_ENTRY(n);
1999
2000 status = -RT_ERROR;
2001 if (thread->event_info & RT_EVENT_FLAG_AND)
2002 {
2003 if ((thread->event_set & event->set) == thread->event_set)
2004 {
2005 /* received an AND event */
2006 status = RT_EOK;
2007 }
2008 }
2009 else if (thread->event_info & RT_EVENT_FLAG_OR)
2010 {
2011 if (thread->event_set & event->set)
2012 {
2013 /* save the received event set */
2014 thread->event_set = thread->event_set & event->set;
2015
2016 /* received an OR event */
2017 status = RT_EOK;
2018 }
2019 }
2020 else
2021 {
2022 rt_sched_unlock(slvl);
2023 rt_spin_unlock_irqrestore(&(event->spinlock), level);
2024
2025 return -RT_EINVAL;
2026 }
2027
2028 /* move node to the next */
2029 n = n->next;
2030
2031 /* condition is satisfied, resume thread */
2032 if (status == RT_EOK)
2033 {
2034 /* clear event */
2035 if (thread->event_info & RT_EVENT_FLAG_CLEAR)
2036 need_clear_set |= thread->event_set;
2037
2038 /* resume thread, and thread list breaks out */
2039 rt_sched_thread_ready(thread);
2040 thread->error = RT_EOK;
2041
2042 /* need do a scheduling */
2043 need_schedule = RT_TRUE;
2044 }
2045 }
2046 if (need_clear_set)
2047 {
2048 event->set &= ~need_clear_set;
2049 }
2050 }
2051
2052 rt_sched_unlock(slvl);
2053 rt_spin_unlock_irqrestore(&(event->spinlock), level);
2054
2055 /* do a schedule */
2056 if (need_schedule == RT_TRUE)
2057 rt_schedule();
2058
2059 return RT_EOK;
2060}
#define RT_OBJECT_HOOK_CALL(func, argv)
rt_inline int rt_list_isempty(const rt_list_t *l)
tests whether a list is empty
void rt_schedule(void)
This function will perform one scheduling. It will select one thread with the highest priority level ...
#define RT_EVENT_FLAG_OR
#define RT_EVENT_FLAG_AND
#define RT_EVENT_FLAG_CLEAR
#define RT_THREAD_LIST_NODE_ENTRY(node)
rt_ubase_t rt_sched_lock_level_t
int rt_bool_t
#define RT_TRUE
unsigned int rt_uint32_t
rt_err_t rt_sched_thread_ready(struct rt_thread *thread)
rt_err_t rt_sched_lock(rt_sched_lock_level_t *plvl)
rt_err_t rt_sched_unlock(rt_sched_lock_level_t level)
rt_uint32_t set
struct rt_list_node * next
rt_err_t error
rt_uint8_t event_info
rt_uint32_t event_set

引用了 rt_thread::error, rt_thread::event_info, rt_thread::event_set, rt_list_node::next, rt_event::parent, rt_ipc_object::parent, RT_ASSERT, RT_EVENT_FLAG_AND, RT_EVENT_FLAG_CLEAR, RT_EVENT_FLAG_OR, RT_FALSE, rt_list_isempty(), RT_NULL, RT_Object_Class_Event, rt_object_get_type(), RT_OBJECT_HOOK_CALL, rt_sched_lock(), rt_sched_thread_ready(), rt_sched_unlock(), rt_schedule(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), RT_THREAD_LIST_NODE_ENTRY, RT_TRUE, rt_event::set, rt_event::spinlock , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [5/9]

RTM_EXPORT ( rt_event_send )

引用了 RT_EVENT_FLAG_AND, rt_event_send(), RT_NULL, RT_Object_Class_Event , 以及 RT_TRUE.

+ 函数调用图:

◆ rt_event_recv()

rt_err_t rt_event_recv ( rt_event_t event,
rt_uint32_t set,
rt_uint8_t option,
rt_int32_t timeout,
rt_uint32_t * recved )

在文件 ipc.c2222 行定义.

2227{
2228 return _rt_event_recv(event, set, option, timeout, recved, RT_UNINTERRUPTIBLE);
2229}
@ RT_UNINTERRUPTIBLE

引用了 RT_UNINTERRUPTIBLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [6/9]

RTM_EXPORT ( rt_event_recv )

引用了 rt_event_recv().

+ 函数调用图:

◆ rt_event_recv_interruptible()

rt_err_t rt_event_recv_interruptible ( rt_event_t event,
rt_uint32_t set,
rt_uint8_t option,
rt_int32_t timeout,
rt_uint32_t * recved )

在文件 ipc.c2232 行定义.

2237{
2238 return _rt_event_recv(event, set, option, timeout, recved, RT_INTERRUPTIBLE);
2239}
@ RT_INTERRUPTIBLE

引用了 RT_INTERRUPTIBLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [7/9]

引用了 rt_event_recv_interruptible().

+ 函数调用图:

◆ rt_event_recv_killable()

rt_err_t rt_event_recv_killable ( rt_event_t event,
rt_uint32_t set,
rt_uint8_t option,
rt_int32_t timeout,
rt_uint32_t * recved )

在文件 ipc.c2242 行定义.

2247{
2248 return _rt_event_recv(event, set, option, timeout, recved, RT_KILLABLE);
2249}
@ RT_KILLABLE

引用了 RT_KILLABLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [8/9]

RTM_EXPORT ( rt_event_recv_killable )

引用了 rt_event_recv_killable().

+ 函数调用图:

◆ rt_event_control()

rt_err_t rt_event_control ( rt_event_t event,
int cmd,
void * arg )

This function will set some extra attributions of an event object.

注解
Currently this function only supports the RT_IPC_CMD_RESET command to reset the event.
参数
eventis a pointer to an event object.
cmdis a command word used to configure some attributions of the event.
argis the argument of the function to execute the command.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that this function failed to execute.

在文件 ipc.c2265 行定义.

2266{
2267 rt_base_t level;
2268
2269 RT_UNUSED(arg);
2270
2271 /* parameter check */
2272 RT_ASSERT(event != RT_NULL);
2274
2275 if (cmd == RT_IPC_CMD_RESET)
2276 {
2277 level = rt_spin_lock_irqsave(&(event->spinlock));
2278
2279 /* resume all waiting thread */
2281
2282 /* initialize event set */
2283 event->set = 0;
2284
2285 rt_spin_unlock_irqrestore(&(event->spinlock), level);
2286
2287 rt_schedule();
2288
2289 return RT_EOK;
2290 }
2291
2292 return -RT_ERROR;
2293}
#define RT_IPC_CMD_RESET
#define RT_UNUSED(x)

引用了 rt_event::parent, rt_ipc_object::parent, RT_ASSERT, RT_IPC_CMD_RESET, RT_NULL, RT_Object_Class_Event, rt_object_get_type(), rt_schedule(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), rt_susp_list_resume_all(), RT_UNUSED, rt_event::spinlock , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [9/9]

RTM_EXPORT ( rt_event_control )

引用了 rt_event_control().

+ 函数调用图: