So what I’ve got here is a very simple main function and what it does is it calls an ex task, create function of free artists, it’s very simple, and you only need three parameters which are important. The first is the function name itself, so this is simply a void function with a void star parameter over here. The second parameter is the task name. This could be anything you want to call it. It is just for a descriptive purpose. So if you have a task list function, it will list the tasks with this name. The third function is called. The third parameter is called the stack size and hope you guys have read the tutorial already. So the minimum stack is usually about 512, but I’ve got 1k here, so it’s, okay, the the last three parameters are not as important this one’s optional and this one’s also optional. I believe the last one is the task handle which I’m not going to use, and this one is the parameter which is passed into the task. So this is the P over here. Whatever you pass here will end up in the parameter over here, and this is the priority so I’m, just gon na use one priority. Lower numbers means lower priority, so I’ve compiled this project already and if I run this you’ll see that um my screen is gon na be spammed with hello world. So, as you see, the hello world is printing non stock and obviously that’s because there this.
This is a infinite loop, so the first thing I’m going to teach you guys is a V tastily now in depending on your system, this Vitesse delay is a function that will put this task to sleep now. It should be usually configured with one unit being one millisecond, but on this simulator it’s a little bit different, so I’m gon na compile this now and let’s enhance our message a little bit and as you see now, we see hello world one, two, three four five And so forth, as you can see, it’s not really a hundred millisecond delay, but on an embedded processor should be usually a hundred millisecond precisely so. This is a very simple task that prints hello world and one of the rules you have to follow is your task. Must not exit, so it must always be in an infinite loop. So let’s elaborate this project, the sample project and we are now going to create two two separate tasks so I’m, just gon na copy and paste this task and let’s name this. The sender task and let’s name this receiver, okay, and what I’m going to try to do is the sender task is going to send something over to the receiver task so I’m going to change this message and say: send or senpai will receive or task and let’s Increase this time out the sleep to approximately three seconds, I think it’s gon na be longer than that, and this task will be your seating so received.
So this is a skeleton I haven’t actually sent anything over. This is just a skeleton where I’m gon na send it and increment I by one and I’m gon na, receive it here. Okay, so this I can we named more name better, so maybe we’ll call it our excellent okay and then what we have to do is create a queue. So in pre our toss as long as you have included QH, you can create a queue so for simplicity. I’M, just going to have a global queue, handle i discards using global variables, but I’m gon na use it here just for demonstration purpose and before we create a task. Now we’re gon na create the queue so I’m gon na, say global you handle equals to execute, create you guys might be wondering why every function starts with an X or a B, and the reason why is because X means it returns and sign in is your Back so X, cube create and the first parameter is queue length. So this is how many items you can hold in and queue and I’m just gon na, say 3 and the next one is size of one item and since I’m, sending one integer, I’m gon na, say size of int. Now, what I haven’t done here is create a second task, so I’m, just gon na copy and paste. This call call it sender, tasks, receiver tasks, just the descriptive name and for this one is gon na be the task is going to be receiver tasks.
Okay, so once I have a queue handle now, I can send items to the queue so let’s just go ahead and save xq sin and XQ sent is looking for three parameters. The first is the queue handle itself so that’s, my global queue handle the next. One is the item you want to queue it’s, always by a pointer and vr is gon na copy data from this pointer and the next one is how many ticks you’re willing to wait. Let me just say 1000 right now, and what I’m gon na do here is a simple print message saying: if I can’t send to the queue then print this message, and we will get to this in a little bit, so that’s that’s pretty much it. This task starts up and it’s gon na send integers every three seconds granted that the queue is not full. On the other side, you might guess, it’s, just gon na be xq, receive queue, handle it and pv buffer is where you want to copy the data that’s. My RX int, and how long are you willing to wait, I’m, gon na, say 1000, so let’s talk about when I’ll get to the else statement so XQ receive is an intelligent function. When you call it you’re saying that I’m willing to wait. One second to receive an item and within one second, if I don’t get anything then you’ll get here. This is very important, because this timeout is not a dumb timeout.
The CPU is going to be put to sleep if nobody cues anything for us and as soon as somebody cues data for us, the CPU will wake up this task. So this is a sensory saying: I’m gon na wait, 1000, milliseconds and anytime. You have somebody send data to the queue wake me up, but if 1000 millisecond in lapses, then the x cube receive is going to fail. Therefore, I’ll get you over here, so I’m gon na compile this and let’s see how it runs so I’m. Gon na stop. This program right here and I’m gon na talk about the first two lines what’s happening here is this star is task, starts up and it says, send zero to receive a task, and then this task went to sleep for three seconds that’s why nothing came out after? Meanwhile, as soon as you sent an item over here, three artists woke up this task and this task immediately printed received zero as you see over here. So this is a very simple demonstration of how one task is sending data to the other task and and conceptually you can say that okay what’s a big deal just sending data, but the important thing is free R toss is waking up this task only when this Receive of and there’s something to receive so free artists, autumn, matically, switches context inside of this function over to this function, I’m going to run the program again and this time I decreased the time out so pretty soon.
Two seconds later, we will receive an item and I’ll talk about this one as well, so let’s stop over here. So this one I already went over and let’s discuss what’s happening after that now remember. This sender task is only sending data every two seconds. The receiver task is only willing to wait for one second, so the first time we received the data because the sender task sent their data right away. The reason why we see this message here is because the receiver task, when it looped around the second time it did an executor sieve and it did not receive anything for one second and therefore a printed field to receive data from queue. The third time it printed. This message, because, meanwhile, the sender task did send a new item in the queue. So in summary, these are sender and receiver tasks and what’s. Important to note is the receiver. Tasks will be automatically put to sleep for a maximum of one. Second, if we don’t receive anything so remember how we started with the infinite loop of printf. Well, this loop is infinite, but the CPU pays very little attention to it. In fact, it only pays attention to it once the X Q received succeeds or fails.
arduino queue Video
arduino queue news
Posted on Tuesday April 09, 2019AEC turns to data analytics to bust queues at polling stations iTnewsVoters might like their democracy sausage, but when it comes to actually casting a ballot it seems nobody much likes standing in line to get their name crossed … … Continue Reading »
Posted on Friday August 09, 2019A Macro Keyboard In A Micro Package HackadayRemember back in the early-to-mid 2000s when pretty much every cheap USB keyboard you could find started including an abundance of media keys in its … … Continue Reading »
Posted on Sunday February 17, 2019How To Program A Really Cheap Microcontroller HackadayThere are rumors of a cheap chip that does USB natively, has an Open Source toolchain, and costs a quarter. These aren’t rumors: you can buy the CH552 … … Continue Reading »
arduino queue Social
Originally posted 2017-06-28 09:52:27.