Hello, welcome back.
And this lesson, we going to see how to use the task parameters when we created our tasks, we realize
our task functions take arguments.
We're going to see how to use those arguments that the task function takes.
OK, so I'm going to make a copy of our first project task creation over here.
I'll say copy.
And then I'll paste over here.
And I renamed this to number three.
Task Perimeter's.
And I'll see copy.
OK, so this is our project.
So over here may not see, OK, so this is our project with three tasks.
OK, so what I'm going to do here is we going to enable four groups.
We're going to enable four groups on iReport, and then we're going to see how these pins Tokyo when
we place them in respective tasks.
If you have the discovery board, these pins will be connected to the four LEDs on the discovery board.
But if you have the nuclear board, you need not worry.
We're going to observe these pins using the debugger.
We're going to see them together.
You need not.
Right.
But we're going to write the firmware.
So we're going to nominate PD 12, 13, 14 and 15.
These are the pins we will use.
So we already have dysfunction here, down here called all giu in it, so because what we're going to
do is also about you initialization, we're going to put that code in here.
So I'm going to extend this.
What we would do is we would enable clock access to these particular port.
Once that is done, we would reset the pins, its advice to reset the pins before you configure them,
and then we would configure the pins.
And then.
Initialise pins, so these are the four items we need to accomplish here.
Michelle?
OK, so we said access to ports, we're simply going to copy this and then paste this over here, this
time we want port deal so we change HD over here.
So research means research means simply means tender pince of our rights, zero to the peons.
So we're going to use the whole GPA right function.
So this function takes three arguments.
The first argument is the port.
The second argument is the PIN number.
And a third argument is the state.
You want to write to this particular pin at that particular port.
OK, so come over here.
I'll see how.
Are on this cool.
Right in the first argument is G.P.A., the second argument, GP2 Unaskable, Unaskable 12, the third
argument, we want to write zero to it so I can say zero or I can use a micro defined code GPL.
You underscore Pend underscore Racette.
This is the same as zero.
OK, so this function exists in our whole GPL.
You don't eightfold and this GPL you d is already defined.
This pentru is also already defined.
That is why I can simply use these texts.
Right.
So if you want to know whether something is already defined in its existing, if all you Double-Click.
Right click open declaration.
And over here, it's telling us the meaning of Jeopardy, so Jeopardy is equal to this, the base address
of GPA, you bought the OK.
So once this is done, we said we're going to have full peace so I can simply copy this paste and change
12 year to 13 page again, change 12 to 14 based again, change 12 to 15.
Right.
I can do this or I can combine all of this into this second argument by using the operator such that
I can see all 13 over here.
And then another all.
Fourteen and then finally or.
Fifteen over here like this, and then I can clean all of this, right?
So with this single line we're going to write being 12, 13, 14, 15, we're going to write zero to
these pens.
So the entire second argument is all of this.
You see, the comma is here and here, we don't have comma between them.
OK.
So once that is done, we can figure out a way to configure the pins, we need to create an instance
of the the GPO in its structure.
So I'll come up here and then I'll see.
GPA, you know, school in it, typedef, and then I'm going to call this.
GPA, you underscore, and its structure like this, and if you want to know what this is, we can double
click this right click open declaration.
And this is just a structure.
This structure has various members that pin the mood pool speed alternate.
And then what we're going to do is we've created an instance of this structure.
So we're going to assign a value to each member of this structure.
And this structure is taken as argument by the GPA you initialization function.
So after we've assigned values to the structure members, we're going to pass the structure as argument
to a function that would initialize our ports using the structure member values.
We shall see how that goes.
So come over here.
We created this structure instance.
We we're calling it in its structure.
So we first want to access the member and we can still use our operator here to.
Gets all of our pins and then once that is done, we going to access the mood member.
So I said, what moved over here and the mood over here is Jhpiego mood, we said we want output.
So we say output ppy meaning output.
Push-Pull to see what other moods we have, we can double click on this right.
Click open declaration.
And you can see we have various modes here.
There's a mode for inputs.
There is output, Push-Pull output, open drain.
And this is another type of output mode that we use for peripherals such as the spy pens and the U.S.
pens.
So the normal output is the the Push-Pull or the PPP.
OK.
So once that is done, we're going to set a pool of copy this.
And then the member we want is the pool and we're going to say we don't want to pull up my caps, lock
freezes sometimes.
OK, so we can see you on a school, no pool, and then once they start, we can set the speed.
So we want to access the speed member of the structure.
So we're going to say you on a score speed, Alesco, Phreak.
Low for low frequency.
OK, so once that is done, we're going to call our Jhpiego in its function.
So I'll say it over here.
I'll underscore Jhpiego underscore.
In it and then this takes two argument, the first argument is the port you want to initialize.
So you quoted the second argument is the init structure.
Remember, we've assigned these values to this structure, remember?
OK, so we're going to parse this structure address over here, right?
OK, so we are done, so this function makes you in it as code in our main function, so we need not
call it again.
So it's over here.
OK, so what I'm going to do next is I'm going to create some macros here.
At the top here, I'm going to define green, orange, red, blue, and this I'm going to assign the
PIN number to these words, if you may.
So I'll see.
Define over here green.
Greenest European 12 GPA, you call this GPA, you or it is called GPA, you.
PIN 12, I should very I should be careful of my language.
So what we are doing here is we want to call 12 green.
That's what this means.
This this has been defined somewhere, but we want to be able to use the word green to access whatever
this is.
OK, I'm going to make a copy paste this over here.
I'll call this orange.
Orange Espin, 13, make a copy pasted over here, I call this red.
This has been 14 a page this over here called this blue and this been 15.
OK, so I can just use green, orange, red, blue to access these pins.
OK.
So what are we going to do is we currently have three tasks I'm going to create another task known as
the Orange Task, because we don't have orange control of the task here.
I'll copy this page.
This change the word green here to orange.
Sorry about that.
Like cops look, GIPS disappointed me orange, OK, and I'm going to create a profile of for it.
And then over here, this is where we create our task, I'm going to make a copy of this controversy
to copy.
And then I call this.
Orange, call this orange.
And then I'll create a task function for it, I'll make a copy of this one here and then change this
word green.
To orange and then orange.
OK, let's it and see what we have, I'll click over here to build.
We have no error, no warning or download onto the board by clicking over here.
We need this.
I say, OK.
Switch.
I see, so I'm going to add our orange profiler.
To our live expressions window double click control to copy.
Contrary to hits, enter a click here to run, so we have all of our four tasks running at almost the
same rate.
OK, so we're looking good now.
We're going to let each of them talk their respective pins, OK, to do that.
I'm going to drop in the whole GPU.
I'll see how Alesco GPU.
There's a function called How You Toggle PIN and this target, the pin.
This function takes two argument.
It takes to the port and then the pin you want to toggle.
Tokyo simply means if it's own, set it off if it's offset at all.
So this is going to go on off on off because it's in an infinite loop.
So the what we're dealing with this GPA, you'd keep D and we are in the blue task controller, so we
want to toggle blue here, OK?
Right.
So I'm going to comment on this, our profiler, and then I'll copy this Tokyo line or come to read
or comment or the profiler and then.
You can yeah, I'm just commenting to profile.
It's not going to affect this experiment, but yeah.
So now I'll go to Green, I'll comment on this line.
Green over here, then orange.
Should be all cups.
OK, now let's build.
A click over here to build.
It's built successfully click here to download onto the board.
I'll click switch over here, and this time what I'm going to do is come over here to this top SFR as
I click over here.
And over here, we have our various peripherals, I'm going to scroll down to where Cupido is located,
there is G.P.A. here.
G.P.A. is what we are interested in, a click to dropdown.
And what we want to see is the output data register, because when you are turning a pen on and off
your turn its respective bits in the output data register.
So Odera here, I'm going to expand it.
And what we are interested in is these are 12, 13, 14, 15, OK.
So I'm going to click to run.
And let's see.
Nothing has happened in.
Lasse.
OK, when I posted.
We see that the AR 15 is one of the AR 14 is one Odia, 13 is zero or the AR 12 is one.
OK, perhaps it's not fast enough to give us live updates.
So I'm running again.
I'm going to pause it.
And I can see this time, Odera, 15 is one, 14 is one of the 13 is one, Audiard 12 is zero.
And then I'll run again.
And then opposite, I can see you are suppose, when these are the ones where other zero states, but
to confirm or to know that our threats are toggling these pins, you would see that from 11 downwards,
everything to zero is just our respective opinions that change that Tokyo from one to zero.
But we cannot it doesn't appear life.
So we have to pause.
So I'll come here, pause again, as you can see.
This what we have are running in.
And then pause.
OK.
Right.
And if we want to display their values in decimal notation, we can click here.
OK, so now let's run again.
I'm running our ports.
You see, we've had.
One one 00 here, let's try it again.
Then I'll pause.
OK, run again, in a way, you get a point, so if you have the Discovery boat, you would see Allard's
Togo here.
So these are the opinions we're talking 12, 13, 14, 15.
But the threats are running too fast.
We cannot see this go on and off.
On and off.
It's.
OK.
So now we going to do what we came here for.
We said we're going to make use of the task parameters.
So the task, the task parameters allows us to minimize the number of task functions that we require.
As you can see, as our current our water system looks, we have four tasks.
They all do the same thing.
The only difference is they totally separate spin.
But they also Gilpin's the only difference is the PIN number that they told you.
So all of these.
It seems redundant, so there is a way to solve this problem by passing the PIN number as argument to
a single task function.
And then the task will be created to just deal with a PIN number rather than we explicitly created multiple
task functions here.
I'll show you what I mean, so.
Rather than have four task functions, I'm going to delete three of them.
OK, so now we have just blew task function, blew TASC function is going to become generic.
So I'm going to change the word blue TASC Blue, I should call it, by its proper name.
Blue ality controller task is the blue task function.
So I'm going to change the name to the controller task rather than blue.
So I change over here to the controller task.
No way to copy this.
I'm still going to create four tasks here, but at the position of task function, they are all going
to use the controller task as the task function.
Like this and everything else remains the same.
So over here, I'm going to delete these prototypes and then we have a single one lady controller task,
right?
So the difference here is that when I'm creating blue lady controller task, which is this first one,
the task function is the same ALYDA controller task.
But I'm going to pass on documents of blue here.
Remember, in our previous lesson, we gave no argument.
So this is now I'm going to pass a pointer to Blue here to do that.
I'm going to come up here to define a number of pointers.
So I'll come over here.
I'll see constant.
You ain't 16 and a.
Star Blue Lady, and over here, Blue Lady, this is going to point to this.
Sorry about that.
Going to typecasts to you in 16, unless t point to.
OK, then I'm going to copy this paste.
Paced, and then this year I'm going to change it to red and then.
I'm going to change this to red.
Then.
I'm going to change this to green, and this will be for green.
Then finally, it's going to be one for orange.
OK, so now I'm going to parse these pointers as the arguments over here.
Right, so I'm going to copy.
Blew the lid and then over here, I have to typecast it to avoid pointer.
And then I'm going to copy this, and then when I come over here Green, I'm going to pass Green Lady
here.
And then when I come over here, orange bellied.
Orange here seems to be missing red.
Green, orange.
OK, red.
Over here.
Read aloud.
OK, so this what we have, right?
Everything else is the same.
OK?
And these pointis have access to our green, orange, red, blue.
So now when I come to our generic task function that we have over here, over here, I'm simply going
to say grab parameters, parameters here.
It's going to be here and I'm going to typecast it to you in 16.
Like this, so I'm going to click over here to build.
We have one warning.
I see.
OK, it says constant August from point to integer of different size.
OK.
Let's see up here, you in 16, an escort that we use you in 16.
We used you in 16 here.
OK, let's run and see.
I'll leave this one and let's put a bit of delay and see if we add some delay, could we see our pins
Tokyo so that we wouldn't need to pause to observe.
So I'll see for our creates a pseudo delay by simply saying for I.
Which I shall create over here and I say for I, because zero is less than, let's say sixty thousand.
Plus, plus.
When we open and close.
OK, let's build a click over here.
See?
Then I'll click over here to download onto the board.
OK, let's switch over here.
And I'm going to scroll down here.
You deliver here, are over here and click to run.
And then pause.
And quick to run.
And then pause, OK, so it's not changing, so let's take a look at our warning warning that.
We were given.
So let's inspect our code from the top here.
We created these pointis blue for our blue values here, red for red value, green for green over here.
Orange has to be orange.
OK, so that's the first anomaly.
But we were receiving a warning down here.
Let's check the second argument taken by this function.
Right.
Our double click on this function open declaration.
The second argument is you in 16, unaskable 30.
So that is fine.
It shouldn't be a problem.
OK, so I think what is happening is because we run in pause.
Sometimes when we pause, we pause at a position where the Tokyo for all the threats are zero.
So we would have to try a few times.
But if you connect Leidy's to these boards, you should see the elitist Tokyo.
Almost at the same rate.
OK, so I click over here to build again.
And then I'll go over here to beg for you.
And switch.
And then going to open a window open argued over here.
ODI register.
And then I'm going to click to run.
And I'm going to pause, I'm going to click to run again and impose, I'm just hoping to get it at a
position where we pause are the.
At a point where some of the threads have to go to the one state.
So pause, OK?
We were lucky this time, so we have all the threats, that one, I hope you understand what's going
on.
It's toggling rapidly and when it's totally rapidly, we don't get this updated rapidly.
So we pause to try to see what is its current status.
And often when we pause, we find it.
That's the state where all of them have to go to zero.
And this time we'll be able to find them at where all of them have two to one so we can run again.
I run again and then stop run again and then stop, run again and I stop.
OK, so this is a if it connects is to them, you should see them together.
And if you have the discovery, both of these are connected to these pins.
So you should see your facilities.
Told you.
But that's what we Flindt.
We have a single.
Tosk function here.
We have a single task function here, however, we have four tasks.
And the way we are able to execute all of our four tasks using this single task function is by adding
to that task parameter to the tasks when we create them.
OK.
So this is it, I'll see you later.