Hello, welcome back.
So in this lesson, we going to create our tasks, we configured our system in the previous lesson by
including our Ewart's configuration, and then we cleaned up the system and then we said we're going
to use free ARTUS functions, not the the cube, not the societies functions, I should say.
OK, so we're going to work with our very first function to the very first function as the create task
function.
Or the task created to function as it is written, so this function allows us to create a task.
And the function is quite simple, it takes six argument, the first argument is a pointer to the task
function.
Remember, each task has a function which has an infinite loop.
And it's within this task function, that's what we want a task to perform is pleased.
OK, so the first argument of this state, this task creates function, is appointed to this task function.
I keep saying function the function, let's get to it so that we see that it's not just me messing up
with names.
So to start off, I'm going to come over here.
I'm going to create a task I call the function.
The function here is X task create.
OK.
So.
The first argument has to be our task function, let's say I'm going to have a task called.
Blue lady control.
Let's just see tasks controlling various abilities, so I'll come down here to create a function for
this task, so I'll see void over here.
Task functions have to have to return void, meaning they retain nothing and they have to take a single
parameter.
So I call this V Blue Alyda controller task.
And then I'll see Voight over here and then P v over here parameters.
And then in here, I'm going to have a while, one loop.
OK, so when we execute in this, we'll get stuck here, the only way you come out of this one loop
is when the scheduler switches to the next task.
OK, so this is a task function.
When we say a task function, this is it.
So we're going to create a task for blue led to control Blue Alyda.
We just assuming we have a system that has various leads and each of them is managed by its own task.
OK, so we have this task function here.
So once we've created this function, I'll copy its prototype and bring it to the top here because we
want to access it in the main function and the main function is above this function.
So we have to put a prototype here.
OK, so this is our task function X task create the first document is the name of our task function,
so I'll copy this place, this over here, the second document.
This is a name we can give to this, a string, this will allow us to be able to view it in a certain
debuggers.
So it's supposed to be a string, a human readable name.
You want to recognize this by.
So I call this blue controller.
The deferred argument is stuck.
The amount of stock you want to allocate to this function will pass 100 here.
And then the fourth argument is the argument you want to pass, the argument you want to pass to this
task or the parameters.
Remember Peevey parameters here.
We'll see how to make use of this for arguments later.
But for now, I'm going to pass null.
Right.
And then the next argument, arguments number five, is the task priority.
I'm going to pass one over here.
And then finally, the last argument is a Hando for the task.
You want to create a handle and from the handle, like the name implies, you can use it to reach the
task information and to make that task do other functions.
For now, we're not going to use Hindoos.
So I'm going to pass Nalle over here as well.
Like this, OK, so essentially we've created a task and a task here is going to be executing the content
of this function here.
Code blue ality controller, we've allocated this amount of stock for it and then we've given it this
priority inside this task, blue lairy controller.
I'm going to drop a simple message here.
I'll say printf is the reason we have to include.
Printf printf.
And then I simply see.
OK, I'll see Blue Lady Controller TASC running, OK?
OK, so.
After we've done this, all we have to do is call the task start.
We have to start as scheduled so that our schedule starts, you know, scheduling and managing the tasks,
OK?
So currently we have just one task.
So void task starts scheduler.
OK.
Click over here to build.
No error, no warning.
OK, I'm going to go to the back over here.
uSwitch.
I'm going to open Terrytown to see what we have open in real time.
This is real Tim Aiport over here, as we know, is this boat, right?
And my port eSports number 16.
I'll click open over here and then I'll click run and then I'll minimize this so that we can see the
contents of real Tim.
As you can see, the lead controller task is running, right?
OK, so what can we learn from this?
I'm going to come out here.
As you can see, we have.
We have nothing in our.
OK, and this is actually interesting, right, so we have our hello from SDM 32 printf statements that
existed from our previous previous project when we configured the system.
Right, but when we check rootin, we don't see any of that executing, so because our scheduler started
this block of code is not reachable, it is unreachable.
So that is why we don't see this.
And more interesting, you don't find anywhere in main function that we are sort of executing this.
We are printing this.
So this shows that we actually execute in the function of the artist.
OK, so I'm going to delete this now.
We're not going to be using one loop here or we have to do is create a task and then a task over.
I'm going to add another task.
I'll make a copy of this task.
Control and then control, easy to copy control of each patient, I'll call this one red alert controller.
And then.
I'll create a task function for this code red alert controller, so I'm simply going to copy this.
Controversy and then I'll change the name here, red alert controller change.
What is going to be printed red the controller and then out its prototype here, control to copy, control
V to paste.
And then the name here, this red light controller.
And then I'm going to add another one controversy.
This one, I'm going to call it Blue Élodie controller, and then this one here is blue.
And then.
Oh, goodness, I'm losing my mind.
We already have blue, so this could be green green LEDs controller.
Green light controller.
And I'm going to make a copy, I'm going to create a task function for this, I'll call this green lady
controller.
So this word red becomes green.
So there is green algae control here, green algae, control of green algae control, I'm going to create
a prototype for this controversy controversy.
And then this is green algae controller.
This has to be up to.
OK, so let's build this and see now we have three tasks, each of them have the task functions to click
over here control.
I'll click over here to build Sloboda.
I'm used to other ideas where you can just, you know, press shortcuts.
This probably has a shortcuts to build, but.
Yeah, so anyway, we've got no error, I'll click over here, Dybbuk.
uSwitch.
This is real time, I'll real to take over here to Claire and then I'll click it play no less you real
to.
Term is not responding.
Let's stop and see what we have.
All you transmutes that's come out.
OK, so real time is not responded in this course was going to happen is we're going to debunk everything
together.
I'm not going to make a clean course where there are no issues and there are no opportunities to debug.
I think that's really useful.
So.
I I'm coming back here.
I went out of the bag for you.
I'm coming back into the bag for you.
I'm going to click play again.
OK, click here to play.
The reason I'm laughing is because this another learning opportunity, a click here to clean and then
open real time again.
You see, real time is not responding, writes.
I'll come out here, I'll come out again, just bear with me, and what I'm going to do is I'm going
to comment the printf statement in two of the tasks such that just one task has printf.
So we just blew has printf or because we've seen blue before, I'm just going to make sure just read
Hotspring.
If the others do not, I'll click over here to build.
And then I'll click over here, debark.
Switch over here, a school to to OK, this real time, I'll Clarington first.
And then.
I'll quickly over here.
I'm going to restart Realto.
OK, so.
This real iSelect.
This, then Kosilek, this.
You know, play.
OK, real time is not responded.
OK, let's exit this, I would explain the landing opportunity, I meant before that.
Let's see this.
Let's make sure our system is configured properly.
So this is green and red leidy's.
And then the tasks.
All of them have their prototypes, as they ought to have.
And we use them printed only in red red me control controller running, OK.
So.
So one thing we would notice here is all our tasks have the same priority, all of them have a priority
of one.
And in the free AHTO system, the lower the priority number, the higher it is.
So if I change the priority of other tasks, let's say I change blue to two and then green to three,
then task red would have the highest priority.
But currently they all have the highest.
They all have the same priority.
So no one is given preferential treatment over the other and they are all expecting to have access to
the Processo.
So the process of Rosewarne for a bit.
And then he goes on to the next one and then he runs the next one and then he goes on to the third.
OK, but we want to see that reducing this, making sure just enough is left.
We want to see if this allows us making sure just red task issues in print, if this allows us to print
this, if this doesn't allow us to print this, then there are a number of things we can learn from
this.
OK, I'll click to build again.
What is really going to happen.
Let's see a click to go to the debug view.
And this is.
A switch over here.
OK, so whenever we run, we see something a little happen here.
OK, this means our real time is fine.
It's just the firmware given the data.
OK, so we run in by real time.
It's not printing everything.
OK, so I'll let you guess what is happening.
What I'm going to do is I'm going to comment out one task.
I'll comment on screen, OK, we comment on green.
Meaning green no longer exist.
We can leave that task function as it is a click over here to build.
And then click over here to go to the box you.
And then switch over here.
And then I'll click to run the AC.
I open my port here.
OK, see?
Oh, this is my sports.
Right.
So we getting the idea that there's a problem to do with time.
It's as if the task is not getting enough time to print what it's supposed to print, right, to confirm
this, what I'm going to do is I'm going to comment out blue task.
I'm going to comment on blue task such that we just have red task and let's see what would happen.
Click over here to build.
And then go to debulked you over here.
Switch.
And then where is Terrytown?
OK, it's actually started on its own, I'll click over here to run, as you can see, read ality controller
task is running, OK?
So what does this mean?
Does it mean we can have just one task?
Right.
It's necessary that we went through all the roadblocks to get to this rather than me telling you what
has to be done.
What does this mean?
This means that the hardware that we're trying to access takes too much time.
It takes more time than the the tiny piece of time allocated for each task to execute before the scheduler
switches to the next task.
So there's something known as a time slice or a time quanta when you have tasks, multiple tasks of
the same priority, each task will run for a particular time quanta.
And as soon as that timeout occurs, regardless of whether you are done executing something important
or not, the scheduler would pause that task and then go onto the next one.
So because of where you are to requires more time to produce all of what he has to produce or print
out all of what he has to print out, it never gets the amount of time it requires to perfectly print
out its information or to print out all of its information before the scheduler is taken from the task
and then given to another task.
So that is what we just we just experienced.
Later on, we shall see how to assign priorities to tasks such that we know that, OK, each task is
treated with this amount of time.
But this particular task, we want you to give this one priority.
We'll see how to assign priorities.
And even when we start assigning priorities, would still face instances where you would have two tasks,
trying to access the same resource at the same time.
And with that, we would use another ARTUS tool known as semaphores and mutex.
We use them to to enable exclusive access to a particular resource.
And a resource can be an LCD screen that you, outsports, et cetera.
So this simple experiment has shown us some of the issues that we would have to be keeping in mind and
designing our system to conform around.
Right.
So then the question becomes, OK, now we see that we can.
We can print from just one task, this long sentence, so then how do we know the other tasks are executing?
This will introduce us or this brings us to one other debugging tool that we shall use.
This is known as the task profiler.
We're going to create task profilers.
And these are just global variables that we would place in each task.
And when the global variable increments, we know that a task is executed and when the incremental value
of all global variables are the same, then we would know that the tasks executed at the same rate the
order are offered the same amount of time.
So to do that, I'm going to comment.
All of our other tasks here will come up with three tasks over here, so I'm going to I'm going to take
out the prenups.
OK.
Right.
So then I'm going to come over here, I'll use I'll say typedef typedef is used to create a new type
to rename it an already existing type.
So she typed a few into that to underscore T and then I'll see this.
I want to call task profiler.
So now, whenever I want to whenever I want to say you said it to an escort, you could simply use the
word typedef, OK, and we use TYPEDEF to improve readability.
So now I'll come, I'll come down here, say typedef and then I'll say.
Blue Tosk.
Profiler and then I have another one for Red.
We have read, we do have read, and then I'll have another one for Green.
OK, so then what is going to happen is I'm going to copy Blue Task profile up and then I'm going to
drop it inside a blue one and then increment and then red.
I'll drop it inside red and then this increment.
And then green or drop it inside green over here.
Then this increments.
OK, so I'm going to click over here to build.
Oh, goodness, Castle.
I want to build first click over here to build.
OK, we have no warning, no error.
Click here to go to Debugger.
As the debugger opening, OK, it's opening up.
uSwitch.
So what we want to do is come over here, we have live expressions window here, we want to put our
global variables here to observe them.
In other ideas, like how you vision, this is known as the watch window, OK, so to put this in that
live expression, I'm going to copy this global variable Code Blue Task profile, copy this and then
I'll come to live expressions and then I'll paste our hits, enter and then I'll copy Red.
Copy this, a paste or hit enter and then I'll copy Green copy this or paste and then I'll hit enter
and then I'll click here to run.
As you can see, the variables are incrementing and they have almost the same value, meaning each task
is given the same amount of time to execute because they have the same priority as we saw.
So this is another way of knowing whether your task is executed or not executed.
These are simple ways.
Of course, they are more elaborate ways of measuring the Arktos time, using other proofs.
But this will suffice for someone who just has the board and wants to do some simple tests to know whether
a task is functioning or not functioning.
OK, so we've seen how to profile in this lesson.
We also learned that when the hardware you are accessing requires more time than the amount of time
allocated to the task, you might not get it to work.
So that is what happened with we trying to print the sentence using the Ewart's in all of our tasks,
no single task had enough time to bring the sentence.
So that's the lesson here.
OK, and also I want to reiterate that you find it essential that we went through this process together,
hitting the roadblocks and coming back to test other things, to comment out on the part of the system
to see what the cause could be.
I could have cut to this bit out of the the lesson.
I could have just edited this bits out and then given you a perfect lesson with this is how you create
a single tax.
This is how you create a single task, I should say.
And then when you put all you add in the three tasks, it wouldn't work.
So we do this.
I could have done all of that, but rather we saw it together.
So I hope you appreciate it this week.
I don't want some of you to complain.
There's so many fixing of errors.
I mean, I really hope you see this points to some, if you like, getting me in the reviews.
So that is why I'm saying this.
If you are not one of those people, that is fine, but it needs to be stated.
OK, so have a nice day.
If you have any questions, of course you can leave it in the questions and answers area.
And I'll see you later.
Have a nice day.