Hello, welcome back.
In this lesson, we're going to see how to interact with our drivers further, we going to see how to
receive data from the Ewart's and then started data in a queue and then use it for whatever we want
to use it for.
The reason we want to see this is because we want to compare two methods of achieving this.
In this first lesson, we're going to pull the US mean and we're going to check whether there's new
data to collect.
And this would save us the lesson that would give us a bit of understanding before we go and implement
uninterrupted version of this.
And by implementing the interruptive version, we'll see how to properly interact with Incorrupt.
Interactivity interrupts That's quite somewhat OK, we'll see how to properly interact with interrupt
without disturbing our Toscano.
So I'm going to make a copy of how some drivers.
Uh, project over here, a copy this and then I'll paste this over here and I'll call this.
Interacting with drivers.
And then this is you are Torex, we said we're going to make.
OK.
We're going to explain this and then get out, may not see foul play here.
OK, what we have here, we simply have our driver snow tax.
OK, so we going to create a number of.
Tasks will create one task to pull the ads for new data and then another task to handle the data.
OK.
OK, so we're going to start off by defining our stock size, going to define a stock of five one two
bytes rather than put a stock size in the function we can just represent with a symbolic name here.
I'm just trying to show you a more readable way of writing what we've been writing off and we've been
putting these stock sized value directly in the Eckstut task rate function.
But we can define it over here so that we can represent it with this value.
OK, once that is done, I'm going to create a queue.
This queue will be used to hold the data received by the others.
And what I mean by creating a queue is actually declared a queue hondo because we have to explicitly
create the queue.
So we have this queue Hondo.
Right.
And we going to create our UAT to ask this.
We are familiar with X task create.
This is going to be the name of the task function.
POJ you are to receive is the name of the what is the name of the task.
And a stack size is what we define over here.
We don't have any arguments and we're not using task on those over here and this one too.
This is an interesting way of writing a task priority rather than putting an absolute value here.
We can simply see let this task have a priority of let's this task priority be to above the lowest priority.
The lowest priority in our ARTUS is the ideal task which we shall visit.
We shall experiment with the ideal task later that.
If we've not already we have, based on where I'm going to position the lesson in the course, if you've
not dealt with the ideal task already, there is a lesson for it.
But if you have already, then you know what I'm talking about.
The ideal task has the lowest priority.
So we're saying give this priority, this task a priority to above the ideal task and this a more readable
way of writing task priorities.
OK, so once that is done, we're going to create a task to handle the Ewart's data.
So we're going to simply call this the handler task.
That's going to be the name of the task function.
And we'd given it its name, its task name as you are to bring to task.
And we've given this a priority above the pool.
You ought to ask.
OK, once that is done, we're going to create our Q.
Remember, our Q Hundun is called this, you are two by two received, we're going to see the Q should
hold a maximum of ten items, OK, we create a Q A simple as this.
And once we've created a Q, we're going to start our scheduler, OK, like this.
Now what we have to do is write the task functions of our of our tasks.
We have to task.
The first one is called the Post you add.
Over here, we simply come down and create a task function.
And here we have an infinite loop.
OK, so remember, this is how some drivers project where we initialize our CPU and then our ADC here,
we don't need this.
We don't need ADC for this experiment.
We don't need our GPU as well.
What we need is our Ewart's, but in our mode.
So I'm going to cut to this.
You add in it and bring it to our you are to receive and when this task execute is going to initialize
you at once.
That is why this is outside of the one loop.
We're going to do one initialization of the out like this.
OK, you are Torex.
And one thing, let's go to our you see fault.
This is our you other sifa.
We have two functions.
We we have two initialization functions.
IREX, we have Ewart's right over here but we don't have you are to receive so we have to implement
a you are to receive function they receive is the same as right over here.
You Ewart's right.
We write into the data register so receive means just return the content of the data register like we
did in the, like we did with regards to the ADC where we simply return the content of the data register.
So the function is quite straightforward.
This is how the function would appear.
So we first pull, we wait until the character arrives just in the ADC.
Listen, we waited for the conversion to be ready and we run.
We wait by running an end operation with a particular bit in the you ought to start this register and
once the character arrives, we simply return the content of the user to data register and this is our
user to read function.
OK, so I'm going to copy this function prototype and I'll put it in the 80s four.
I'll open it that H over here from our includes foda base this over here.
Like this.
OK, so then we can go back to not see far, no, we said who pull you at received task is thought of
by initialise in the U.S. for our X for reception.
I'm going to create a variable here, a local variable here to store the bite's received.
So I'll see you in eight and a squatty.
Call this next byte.
And then what we want to do is we want to call our receive function or you are to read function that
we've just written.
So you start to read, use that to underscore, read.
That's the name of the function.
OK, so we said this will return the character, which is a bright story here.
And once we've received this, what we want to do is send this to our queue so we use our excuse and
function.
You simply saying this, and we given a block time of zero, OK, so this will send it once it's sent.
Remember, this task simply receives and sends its checks.
We know it's poulain because we know our users to read is basically waiting for the character.
It gets stuck waiting for the character to become available.
OK, so then we would go ahead and implement our other task, the task over here, which will handle
what is received.
OK, so this is the handler task.
We have our infinite loop in here.
And what we want to do is wait for.
New data to become available in the queue and what also we want to do is declare a global variable here,
which we can observe in the live expressions window.
Since we're going to be using our you for our X, would you be able to see what we receive?
So I'll see character over here.
I receive byte to indicate the bytes that we received.
OK, so then we going to come over here and see execute, receive.
We want to receive, we pass our you out to buy to received which is the handle of the of the queue
that we want to receive from.
And this way we want to store the received data and we want to delay Portsmouth's delay.
So meaning we delay until we receive the data.
OK.
So we're looking good now, let's see what we get with this.
I'm going to click here to build.
OK, we have a number of.
A number of anomaly's.
OK, so we've got you, um, we've got you enable you to go to enable.
Let's see.
We've got to enable Kyuss.
What I mean by that is include the cues that each fall remember this project or the project?
We made a copy of some driver's that's the name of the project that was just experimenting with some
drivers.
So we've now got some of our ARTUS components.
So I'm going to double click on all the emphasis placed on each file open over here.
And I'll scroll down here.
We have this task be each, you see.
So I'm going to include tutorage.
OK, let's go back and let's build this and see what we've got.
OK, we've got other anomalies.
This has got some other reason.
Let's see.
Pull you out.
OK, so we've not put the function prototypes at the top of the of the file.
The function is unreachable.
I'll copy this.
Put this over here and then I'll come down here, controversy to copy.
Put this over here, let's build take over here to build.
OK, it's successful.
And we're going to right click over here and see Debuggers Ystem 32, double click over here and then.
OK.
And then switch.
OK, so I'm going to.
OK, we have real time here from our previous project.
I'm going to clear this, and what I'm going to do is I'm going to go to our.
A website received global variable here I received.
So when the queue receives, the data is going to store it in our website, so I'm going to.
Going to view our debate in our live expression's window, so a copy RACV right over here, controversy
to copy and I'll drop it over here and then hit enter.
OK, so what I'm going to do is over here.
All we simply need to do is come over here, click in here this side where we have the arrow blinking.
We click in here and then we press you on our keyboard and we expect to see that received and displayed
here.
I'm going to click to run over here.
And I'm going to reset the port by clicking open and then it's enter again, and then I just pressed
one on my keyboard.
You see, this is one this it's ASCII value.
I'm going to press E, this is E, I'm going to press B, I'm going to press M.
I'm going to press C.
As you can see, I'm going to press F, make sure you click in here.
You have to click in this dark area to to press.
So I press G OK, so we're receiving the data.
So this is very simple, very straightforward.
We wanted to design a system that can receive data from the Ewart's and then another one, the system
that receives data from the US.
And we designed a project in a way that we have the task that deals with receiving the data itself.
And another task, the handles the data such as printing or disk will be.
In a more complex system, this could be a task receiving the data in another task, processing the
data and display and displaying it.
So this one here, our handler, is the one that processes the data.
Right.
So this is very simple, very straightforward.
However, this implementation is not quite efficient.
There are there is a lot of process or time wasted here because we are Poulan.
We are waiting for the character to become available.
A better implementation of this will be to use and interrupt such that we don't wait for the new bytes
to become available.
We just the process or just goes on to do its thing.
And when the new byte is available, then we are told that the new bytes is available and we take it
and handle it as we want.
OK, so in the next lesson, we shall see how to write an interrupted version of this project.
OK, so this all the see in the next lesson.