0% found this document useful (0 votes)
83 views

Chapter 09

Event flags in μC/OS-II consist of a series of bits that tasks wait on to be set or cleared. When an interrupt service routine posts an event flag, it can ready a waiting task to run. Functions like OSFlagCreate() and OSFlagPend() manage the creation of event flag groups and tasks waiting on events. OSFlagPost() and OSFlagTaskRdy() handle setting events and readying tasks. The event flag module uses doubly linked lists and control block structures to track pending tasks and post events efficiently.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Chapter 09

Event flags in μC/OS-II consist of a series of bits that tasks wait on to be set or cleared. When an interrupt service routine posts an event flag, it can ready a waiting task to run. Functions like OSFlagCreate() and OSFlagPend() manage the creation of event flag groups and tasks waiting on events. OSFlagPost() and OSFlagTaskRdy() handle setting events and readying tasks. The event flag module uses doubly linked lists and control block structures to track pending tasks and post events efficiently.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 35

Chapter 9:

Event Flag Management

1
Event Flag Management

• Event flags consists of


– A series of bits (either 8, 16, or 32 bits)
– A list of tasks waiting for a combination of bits to be ether
set of cleared
• The relationship between tasks, ISRs, and event flags:
OSFlagCreate() OSFlagAccept()
OSFlagDel() OSFlagPend()
Task OSFlagPost() OSFlagQuery() Task

Event Flag Group

OSFlagPost() OSFlagAccept()
ISR OSFlagQuery() ISR
2
Functions
• OSFlagCreate()
– Creating an event flag group
• OSFlagDel()
– Deleting an event flag group
• OSFlagPend()
– Waiting for events
– OS_FlagBlock()
• OSFlagAccept()
– Looking for events
• OSFlagPost()
– Setting or clearing events
– OS_FlagTaskRdy()
• OSFlagQuery()
– Querying an event flag group

3
Example - 1
H

ready pend(0x03) continue

post(0x01)

post(0x02)
4
Example - 2
H

ready post(0x03) TimeDly

ready continue TimeDly

L pend(0x01)

pend(0x02) continue
5
Event flag group,
event flag nodes and TCBs
OS_EVENT_TYPE_FLAG OS_Flag_GRP
OSFlagWaitList
OS_Flag_NODE
OSFlagFlags
OS_TCB

OS_FlagNodeNext OS_FlagNodeNext OS_FlagNodeNext


OS_FlagNodePrev OS_FlagNodePrev OS_FlagNodePrev
OS_FlagNodeTCB OS_FlagNodeTCB OS_FlagNodeTCB
OS_FlagNodeFlagGrp OS_FlagNodeFlagGrp OS_FlagNodeFlagGrp
OS_FlagNodeFlagFlags OS_FlagNodeFlagFlags OS_FlagNodeFlagFlags
OS_FlagNodeWaitType OS_FlagNodeWaitType OS_FlagNodeWaitType

OSTCBFlagNode OSTCBFlagNode OSTCBFlagNode

6
OS_FLAG_GRP &
OS_EVENT
OS_EVENT_TYPE_FLAG .OSEventType
OSFlagWaitList .OSEventGrp
OSFlagFlags .OSEventCnt
.OSEventPtr
7 6 5 4 3 2 1 0

15 14 13 12 11 10 9 8

.
.
.
55 54 53 52 51 50 49 48

63 62 61 60 59 58 57 56

7
Event flag group,
event flag nodes
OS_EVENT_TYPE_FLAG
OSFlagWaitList
OSFlagFlags

OS_FlagNodeNext
OS_FlagNodePrev
OS_FlagNodeTCB
OS_FlagNodeFlagGrp
OS_FlagNodeFlagFlags
OS_FlagNodeWaitType 8
.OSFlagNodeWaitType

OS_FlagNodeNext
OS_FlagNodePrev
OS_FlagNodeTCB
OS_FlagNodeFlagGrp
OS_FlagNodeFlagFlags
OS_FlagNodeWaitType 9
OSFlagCreate()

• Notice that the return type of the function is


OS_FLAG_GRP
– A pointer to an event flag group or a NULL pointer
if no more groups are available

• Must specify a initial value of the event flag

10
OSFlagCreate()

OS_EVENT_TYPE_FLAG
OSFlagWaitList
OSFlagFlags
11
OSFlagDel()
opt =?

DEL_ALWAYS DEL_NO_PEND

N
pnode==0 Pnode== 0
Y

N Y

FlagTaskRdy Free(Flag)
N

pnode==0
reterun err
12
12
Y
OSFlagDel()
OS_DEL_NO_PEND
OS_DEL_ALWAYS

13
OSFlagDel()

14
OSFlagPend()
Y Y
Type = SetALL? Match? Return

N
N
FlagBlock

OSSched

Type = ClrAny? !=Rdy


TCBStat=? FlagUnlink

==Rdy

Return;

15
OSFlagPend()

OS_FLAG_WAIT_CLR_ALL
OS_FLAG_WAIT_CLR_ANY
OS_FLAG_WAIT_SET_ALL + OS_FLAG_CONSUME
OS_FLAG_WAIT_SET_ANY

16
OSFlagPend()

17
OSFlagPend()

18
OSFlagPend()

19
OS_FlagBlock()

OS_FlagNodeNext
OS_FlagNodePrev
OS_FlagNodeTCB
OS_FlagNodeFlagGrp
OS_FlagNodeFlagFlags
OS_FlagNodeWaitType 20
21
OSFlagPost()

OSFlagFlags =
hasNext?
newValue N

Y
OSSched
Is the task
Rdy?
N
Y

FlagTaskRdy

22
OSFlagPost()

23
OSFlagPost()

24
OSFlagPost()

25
OS_FlagTaskRdy()
• Make a task ready to run

• Call flag unlink to remove itself from the wait


list

26
OS_FlagTaskRdy()

27
OS_FlagUnlink()
• The unlinking of the OS_FLAG_NODE is
performed by the function

• It remove the node from a double linked list

• It also maintain some pointers of the TCB


structure

28
OS_FlagUnlink()

29
OSFlagAccept()

30
OSFlagAccept()

31
OSFlagAccept()

32
OS_FlagInit()
• This function is called by μC/OS-II to initialize
the event flag module.

• Your application must not call this function. In


other words, this function is internal to
μC/OS-II.

33
OS_FlagInit() OS_EVENT_TYPE_FLAG
OSFlagWaitList
OSFlagFlags

34
OS_FlagInit()

35

You might also like