Hello, guys, and welcome back and this lecture, we're going to start writing our first multithreaded
program using Auto's.
Now we're going to write a very simple sketch that is going to be doing two tasks.
One of them is going to handle the serial port and the other one is going to handle the blinking.
The thing is, they'll be running almost at the same time.
The microcontroller on the original owner is going to be switching between those tasks like almost 70
times every one seconds.
So as you have explained about Arktos and MultiThreaded, it will be executing a chunk of the first
task.
Then it will jump and execute a chunk of the other task and it will keep flipping in between dusk all
the time.
So unlike executing the line by line, we are going to be doing something totally new.
And you're going to see this in every embedded system application that is a little bit sophisticated
because sometimes you want to be reading from sensors, doing other stuff at the same time without this
task interrupting each other.
Now we're going to start simply by including our auto's library.
So we'll include.
The library is called or Adreno.
Underscore free.
Arktos.
H, this is my library, and right now I'm just going to find the pen for blinking.
Now, blinking happens on something 13 in the Audrina.
Oh no, remember all of this is on the Audrina.
Oh, no, not you cannot run this version of Free Auto's.
There is a totally different process for that because Free Arktos is architecture oriented.
So it depends heavily on the architecture of the microcontroller in order to implement it.
And since the architecture of the MCU is different than the avy or the ordering audio we are using,
we cannot be using the same library.
So first, let me define my pen.
It's going to be a constant integer, as usual, LSD.
And we're going to call it Blink LSD, that starts playing with a small letter.
So this is my Blinkx LSD and it's equal to 13.
OK.
Next, we're going to start the voice set up and here's what we're going to do.
We're going to create a new task by calling the following function.
The function is called X Task Create.
So this is how we create the task.
Now, there is a lot of parameter we need to pass.
I'm going to do this.
And I'm going to start writing the parameters on different lines, so the first parameter I want to
pass is the function name.
In my case, I'm going to create a function later, which is my task, and it's going to be called task.
Lida Blinkx, OK, this is the name of my desk, next.
I need a name that we can use only to debug, so this is compulsory, we can just try to blink and here
we cannot be having more than eight characters.
Don't try to write long names.
Maximum is eight characters.
So this is my task name.
Next, I need to specify in my stack size.
Now, a stack is usually a portion of the memory that we use in order to store functions and in order
to store valuables.
So let's say I have a function that is calling a function that is called a function.
Now there is a lot of data to be saved when we are doing that and the portion of memory that we do in
order to save this is the stack.
So it's important to specify the stack size really carefully.
Now for a small task, one hundred twenty eight bytes should be enough, but for other tasks we might
need larger stacks and remember the whole memory size for the owner with two kilobytes.
So we really need to be careful in sizing our task.
Now, as I said, for this simple task, 128 is just good 128 bytes.
Next, I need to pass a null pointer.
Now, this is a pointer to some predefined data structure that you would pass to this desk function.
Now, since this is a beginner example, I'm not going to get into that.
I'm not going to be passing any structures to my desk right here.
So I'm just going to leave this parameter because it's a little bit advanced.
Next one is the priority.
Now, priority is a pretty important when it comes to scheduling and multithreaded because every task
has a priority.
I'm going to leave it at one for the blinking.
That's totally fine.
The next one is actually the desk handle.
And well, this is also a little bit of an advanced topic and we won't be needing this parameter for
now.
We're going to skip it and we're going to stick to our simple example of flipping between two desks
and that's it.
This is my first task.
This is all we need to do in order to define it.
Now, I'm going to close this was a column.
Now, as I said, this is just a function of these are the parameters that we are passing to it.
So we are just ordering them line by line.
That's the only difference.
I mean, after all, this is just two parenthesis and a semicolon as usual.
So don't be really confused by the way I have arranged them vertically like that.
Next, I'm going to create my second task.
I'm going to do the same thing.
I'm going to say X task.
Create I'm going to create a simple parenthesis.
And I'm going to do the same thing, I'm going to copy all of this and change only what I need to change.
Along this column as well.
So this one is going to be called Dariel.
Again, this was going to take the same thing, the twenty eight points, no priorities, the same,
and again, to leave everything as it is now.
Let me put the semicolon here.
And by that I have create both of my tasks.
Next, I'm just going to define some serial begin.
Because I'm going to pour into the cereal and by that I'm going to end my setup.
Now, the next lecture, we're going to continue writing the death function itself.