0:07
hello everyone welcome to controllers
0:11
tech as I promised to continue the free
0:14
rtos tutorials today I brought to you
0:18
another video on our TOS in this video
0:22
we will see the various operations that
0:25
we can perform on the tasks let's start
0:28
by creating the project in cube ID first
0:31
I am using stm32f4 for 6 our controller
0:45
give some name to it and click finish
1:01
now first of all I am going to select
1:13
I am using CM sis version one as it it's
1:17
supported majority of the stm32 devices
1:20
leave everything as it is
1:22
just enable the V task delay until it's
1:27
an important parameter and I will
1:29
explain you how it works
1:41
in the SIS time based source select any
1:44
source other than cystic I am using
1:47
timer one next set up the clock and
1:51
click Save to generate the project
2:19
I am including stdio dot H file because
2:23
I am going to use the printf to debug we
2:26
have to define a new write function I
2:28
already made a video about printf
2:31
debugging check that on the top right
2:33
corner first of all let's see if the
2:37
things are working properly before
2:51
a default task is already defined by
2:56
default this is to check if the task
2:59
runs or not giving a delay of one second
3:09
for this task let's build the code
3:22
in the debug configuration enable the
3:26
serial wire viewer in the core clock
3:29
type the frequency of the HC LK
3:43
now go to windows show view SWV and
3:48
select I TM data console in the setting
3:52
enable the comparator 0 and check the
3:55
stimulus port 0 press the red button to
3:58
start recording now you can see the
4:06
printf string being printed on the
4:08
console this means that the default task
4:11
is running well every one second
4:33
now let's create another task to do so
4:37
first we need to define the task handler
4:45
next define the entry function for the
4:56
now inside the main function first to
4:59
find the thread also thread deaf takes
5:02
the following parameters name of the
5:08
task entry function for the task
5:10
priority I am giving it higher priority
5:14
than the default task instance and stack
5:17
size next we need to assign the ID of
5:21
this task to its handler
5:44
now I am writing the entry function for
6:03
it will print the value of the index
6:05
variable and a delay of two seconds
6:08
let's build it and I will explain you
6:30
make sure you press the record button
6:51
okay let's see starting is printed at
6:56
the beginning now the control will be
6:58
transferred to the colonel the colonel
7:01
have two tasks in the ready state
7:03
default task and tasked to the priority
7:07
of task 2 is higher and that's why it
7:10
will run first after running the printf
7:18
statement the task will go in the
7:20
blocked state for two seconds Colonel
7:23
will now run the default task after
7:26
executing the printf statement this task
7:29
will also go into block state for one
7:32
nothing will run for this one second now
7:35
after one second default task will again
7:38
become ready and Colonel will run it
7:41
after printing the task will again go in
7:44
the blocked state for one second nothing
7:47
will run for another second after one
7:50
second both the tasks will be in ready
7:53
state again because it's been two
7:55
seconds since the task 2 was blocked the
7:58
colonel now again have two tasks ready
8:01
to run but it will run the task 2 first
8:04
because of the higher priority and this
8:07
whole process will continue again and
8:31
let's take a look at some other
8:33
functions available for task management
8:45
we are going to take a look at OSD spend
8:49
and OS thread resume functions both of
8:53
them take thread ID as the argument of
8:55
course the thread ID of the thread that
8:58
you want to suspend or resume if index
9:07
becomes for the default tasks should
9:30
and if index becomes seven the default
10:02
make sure you enable the record button
10:27
okay you see it happened now let me
10:31
explain what's happening here
10:42
let's take a look at the task to code
10:51
you see when the index was three it will
10:55
be printed and the index will increment
10:57
to four after this the task will go in
11:01
the blocked state for two seconds when
11:03
the task resumes after two seconds index
11:06
have the value of four and control will
11:09
go inside the if loop the default task
11:12
will be suspended after that this loop
11:15
will not be executed and control will go
11:18
back to the beginning where the value of
11:20
the index will be printed and index will
11:23
be incremented to five the task will be
11:26
blocked for two seconds as there is no
11:29
default task anymore
11:30
this will keep executing every two
11:32
seconds the same thing will happen when
11:36
the index becomes seven the default task
11:39
will resume this time so this was the
11:42
demo for suspend and resume tasks let me
11:46
comment all this next I am going to
11:49
terminate the task to itself
12:05
OS thread terminate also requires the
12:08
thread ID as the argument let's run this
12:11
one now as you can see here the tasked
12:19
who gets terminated and default task
12:21
runs only afterwards we can also
12:24
terminate default tasks
12:26
just give the thread ID of the same once
12:29
the task is terminated
12:31
it can't be resumed this is the
12:33
difference between suspend and terminate
13:03
we can also suspend all or resume all
13:06
threads OS delay until is another
13:09
function I wanted to show you guys it
13:13
blocks the task for some time and
13:14
resumes automatically as you can see the
13:18
description we need to define a variable
13:20
to store the elapsed time
13:44
again I am going to run this under a
13:47
specific condition and once the
13:49
condition is reached the task will be
13:51
blocked for three seconds
14:20
let's run it as you can see the exact
14:24
thing happening here the task you can
14:27
block for three seconds and resumes
14:46
there are more functions available for
14:48
tasks and I can't cover all of them
14:51
OS thread yield passes the control to
14:54
the next thread that's ready to execute
14:57
again we can use it under some condition
15:00
also there are functions like set
15:03
priority or get priority and so on this
15:08
this video covered many functions for
15:11
task operations I will continue this
15:14
series of our tos and we will cover
15:17
semaphores messages queues etc in the
15:20
coming videos I hope you understood the
15:23
video you can download the code from the
15:26
link in the description have a nice day