Inter Tasks Communication via Queues
Keywords: Embedded systems, ARM, FreeRTOS, STM32F4, Tasks, Queues
Code Link: Tutorial Source Code Github – Keil
In the previous tutorial we introduced Queues in general and freeRTOS queues in specific. We introduced freeRTOS APIs for Queues management. The link to the tutorial is given bellow.
It is highly recommended to go through the above tutorial before moving forward with this tutorial as all freeRTOS Queues APIs are explained well there.
Tutorial Scenario:
In this tutorial we will create three freeRTOS Tasks i.e. Tx1, Tx2, Rx1. Two out of them (Tx1, Tx2) will act as transmitter that pass string messages to the third Receiver Task (Rx1). Instead of passing full string, only string pointers are passed to the Receiver Task via Queue. The Receiver Task Receives queue message and print it to the Serial Debugger window.
Steps:
1. First of all let’s define what messages will be passed to queue. For the purpose of simplicity we will define two global string literals (one for each transmitter Task) shown in bellow code snippet.
/* string literals */ const char *t1_Msg = "Task-1 Message..."; const char *t2_Msg = "Task-2 Message...";
2. Next we will create freeRTOS Queue of length `1` and accepting item size of Pointer to char (char *
). The length of queue is kept `1` because each transmitter Task will only send message pointer (defined in the previous step) to the queue.
/* freeRTOS Queue */ qHandle = xQueueCreate(1, sizeof(char *));
qHandle
is globally defined variable of type QueueHandle_t
.
/* freeRTOS Queue Handler */ QueueHandle_t qHandle;
3. If queue is created successfully (memory is allocated), Three freeRTOS Tasks i.e. “Tx1”, “Tx2”, and “Rx1” are created and Scheduler is started. Otherwise a failed message is sent to serial window and processor is trapped in while(1).
Note: If you don’t know how to create freeRTOS Tasks, refer to the following Tutorial.
if (qHandle != NULL) { xTaskCreate (vTxTask1, "Tx1", 150, NULL, 1, NULL); xTaskCreate (vTxTask2, "Tx2", 150, NULL, 1, NULL); xTaskCreate (vRxTask, "Rx1", 200, NULL, 2, NULL); vTaskStartScheduler(); }else { printf ("Failed to create Queue! :-(\n"); while (1); }
Note: If a high priority Task is in Block state waiting for the data to be available in queue, and meanwhile data is written to the queue by low priority Task, the higher priority Task will be immediately unblock to Ready State to receive queue data.
Note: The polarity of Receiver Task (Rx1) is kept higher than the transmitter tasks. The reason is that Queue be read immediately once data is available in Queue to make room for other tasks to write to the queue.
4. “Inside Rx1 Task Function”: The following is the definition of Receiver Task Function.
void vRxTask(void * pvParams) { volatile unsigned int i = 0; char * msgPtr; int rxStatus = 0; for (;;) { rxStatus = xQueueReceive(qHandle, &msgPtr, 500); /* 500 is enough to compensate dummy delay in transmitter tasks.*/ if (0 == rxStatus) { printf ("Awaiting Message...\n"); }else { printf ("Rx Msg: %s\n", msgPtr); } } }
What happens is:
rxStatus = xQueueReceive(qHandle, &msgPtr, 500); /* 500 is enough to compensate dummy delay in transmitter tasks.*/
xQueueReceive
is called to check if data in qHandle
Queue is available. If data is available (pointer to string in this case), the data (pointer) is copied into msgPtr pointer variable otherwise the Receiver Task “Rx1” is sent to Block State waiting for the data to be available in next 500 Ticks. If data is not sent by any task within next 500 Ticks, the message “Awaiting Message…” is displayed and the Receiver Task (Rx1) goes back to Block State. As soon as the data (pointer to string) becomes available on qHandle Queue, the Receiver task (Rx1) receives the pointer and display string pointed by the received pointer and wait for the next message (pointer) reception.
5. “Inside Tx1/2 Tasks Function”: The two transmitter tasks i.e. Tx1, and Tx2 have almost the exact same definitions. They are defined separately just for the purpose of demonstration. Only Tx1 Task function will be discussed here.
void vTxTask1(void * pvParams) { volatile int i = 0; int txStatus = 0; for (;;) { printf("Sending Msg-Task-1\n"); txStatus = xQueueSendToBack(qHandle, &t1_Msg, 2); if (0 == txStatus) { printf("Sending failed Task-1!\n"); } /* This will prevent display printf messages too fast. also task yelding not required */ for (i = 0; i < 500000; i++); } }
What happens is:
printf("Sending Msg-Task-1\n");
First of all an alert message is sent to serial window stating that Tx1/2 is about to send message to Queue.
txStatus = xQueueSendToBack(qHandle, &t1_Msg, 2);
Then it calls xQueueSendToBack
to send string message pointer (defined in step-1) to qHandle Queue. If space is not available on Queue, it waits for `2` Ticks. The wait is chosen to be `2` because we have only three task (apart from Idle Task) configured in software. Thus the Tx1 can maximumly delay by `2` Ticks. Now if within these `2` Ticks, the data placement on Queue is not successful then a failed message is sent to serial window. The for (i = 0; i < 500000; i++); is a dummy delay to slow down the messages being sent to serial window.
6. Finally Compile source code, connect STM32F4-Discovery board to PC and enter debug mode. Open printf serial window via View -> Serial Windows -> Debug (printf) Viewer. Run the Program, You will see Task execution messages as shown in bellow Video.
Note: We have routed printf messages to ST-Link debugger via ARM-ITM. There is a dedicated tutorial on how to redirect printf messages to debugger. Link to the tutorial is given bellow.
For complete source code refer to Github link given at the start of this tutorial.
Click the full screen button for more clear view.
Well I sincerely liked reading it. This article provided by you is very helpful for proper planning. Christiane Yves Adim
Hi there, I desire to subscribe for this web site to get most recent updates, therefore where can i do it please help out. Jobye Ambrosius Nitza
I cannot thank you enough for the blog post. Thanks Again. Really Cool. Ilyssa Ryan Colette
Absolutely composed content material , thankyou for selective information . Cheryl Elmore Wachtel
Good post! We will be linking to this great article on our site. Keep up the great writing. Zora Reuven Purpura
This is my first time go to see at here and i am in fact happy to read everthing at single place. Dolli Vite Baerman
I was able to find good information from your articles. Imogene Anders Olshausen
Hi to all, how is everything, I think every one is getting more from this web page, and your views are fastidious in support of new viewers. Brandea Maximilien Marte
You can subscribe for a month, wallet is NOT secure. Ellene Trumaine Cusick
Im grateful for the blog article. Really thank you! Fantastic. Francoise Kingsly Abdulla
Very interesting details you have noted, regards for posting. Estella Bent Menell
Hello. This post was really remarkable, especially because I was browsing for thoughts on this issue last Sunday. Scarlet Esra Hardner
Google enter site hatay escort pictures google porn images thanks you. Alaine Dionysus Walden
I think that is among the most significant information for me. Dolli Winfield Cesaro
Pure Science New Zealand Bbc Educational Films
Take a look at my blog: ebook
11th Chemistry Guide Pdf David Walliams Books Big W
Also visit my web page: pdf list (cranky-montalcini-b24ebb.netlify.app)
Greetings from L . a .! I’m bored at the job so I decided to look at
your site on my iphone during lunch break. I enjoy the info you provide here and can’t wait to take a look as i go
back home. I’m shocked at how fast your website loaded on my own phone
.. I’m not really using WIFI, just 3G .. Anyhow, excellent blog!
My web-site – DarioQObryon
It’s almost impossible to locate experienced people relating to this subject, however, you appear to be do you know what you’re discussing!
Thanks
My webpage coin purse insert
I think this is a real great blog post.Really thank you! Really Great.
Rbse Result Name Wise 2019 Aims Of Education For Self Reliance In Tanzania
Here is my web page; wordpress pdf, http://inbooks.atthost24.pl,
Navođenje Literature U Znanstvenom Radu Amazon Kindle Account
Online
Look into my homepage … wordpress.com (inbooks.atthost24.pl)
Good Teacher Letter Of Recommendation Up Board Intermediate Result 2019 Kab Aayega
My web site :: pdf book
Higher Education Scholarship For Pg Science Center Montreal
Review my web page: pdf (http://polandsleep.e-kei.pl/eipbytvzz)
Decolonising The Mind The Politics Of Language In African Literature Robert T Kiyosaki Latest Book
Feel free to surf to my web site; pdf wordpress (http://baringbooker.nstrefa.pl/)
Its like you read my mind! You seem to know a lot about this,
like you wrote the book in it or something. I think that you could do with
a few pics to drive the message home a little bit, but instead of that,
this is fantastic blog. A great read. I’ll definitely
be back. 0mniartist asmr
It’s remarkable in support of me to have a web site, which
is useful for my knowledge. thanks admin 0mniartist asmr
Fantastic beat ! I wish to apprentice while you
amend your web site, how can i subscribe for a blog web site?
The account aided me a acceptable deal. I had been a little bit
acquainted of this your broadcast provided bright clear idea asmr 0mniartist
I am actually grateful to the owner of this website who has shared this wonderful article at at this place.
I’m gone to convey my little brother, that he should also pay
a visit this weblog on regular basis to take updated from newest reports.
asmr 0mniartist
I’ve been exploring for a bit for any high quality articles or blog posts
on this kind of house . Exploring in Yahoo I at last stumbled upon this site.
Studying this information So i’m satisfied to convey that I have a very good uncanny feeling I found
out just what I needed. I most no doubt will make certain to do not overlook this site and provides it a look on a continuing basis.
asmr 0mniartist
Cell Biology Genetics Molecular Biology Evolution And Ecology Pdf Up
Board Result 2014 Nic.In
Feel free to visit my page … wordpress.com [viaglutrimins1979.netlify.app]
Early Childhood Education Degree Qut Chemical Engineering Science Ranking
my site :: pdf wordpress – https://compoventcen1978.netlify.app/ –
Do you mind if I quote a few of your posts as long as I provide credit and sources back to your website?
My blog site is in the exact same area of
interest as yours and my users would certainly benefit from a
lot of the information you present here. Please let me
know if this alright with you. Regards!
Good day! This post couldn’t be written any better!
Reading this post reminds me of my old room mate! He always
kept talking about this. I will forward this post to him.
Pretty sure he will have a good read. Thanks for sharing!
Just desire to say your article is as astonishing.
The clearness for your publish is simply spectacular and i could
think you are an expert in this subject. Well with your
permission let me to snatch your RSS feed to keep updated with
drawing close post. Thank you one million and please keep up the enjoyable work.
For hottest information you have to visit web and on the web I found this web
site as a best web site for latest updates.
I believe this is one of the so much significant information for
me. And i am happy studying your article. But wanna remark on some general things, The site style is
great, the articles is actually excellent : D. Good job, cheers
Hmm it looks like your website ate my first comment (it was super long) so I
guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.
I too am an aspiring blog writer but I’m still new to everything.
Do you have any tips and hints for novice blog writers?
I’d definitely appreciate it.
This is a good tip especially to those new to the blogosphere.
Simple but very accurate info… Many thanks for sharing this one.
A must read article!
Hi there to every one, the contents existing at this website are in fact remarkable for people knowledge, well, keep up the nice work fellows.
Have you ever thought about creating an ebook
or guest authoring on other sites? I have a blog centered on the
same information you discuss and would really like
to have you share some stories/information. I know my visitors would
enjoy your work. If you’re even remotely interested,
feel free to send me an e mail.
scoliosis
I’ve been browsing online more than 3 hours today, yet I never
found any interesting article like yours.
It’s pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the internet will be much more useful than ever before.
scoliosis
scoliosis
We are a group of volunteers and starting a new scheme
in our community. Your website provided us
with valuable information to work on. You’ve done a formidable job
and our whole community will be grateful to you. scoliosis
free dating sites
Please let me know if you’re looking for a author for your
blog. You have some really great articles and I think I would
be a good asset. If you ever want to take some of the load off, I’d really like to write
some material for your blog in exchange for a link back to mine.
Please shoot me an e-mail if interested. Kudos! https://785days.tumblr.com/ free dating sites
free dating sites
It’s nearly impossible to find well-informed people on this
topic, but you sound like you know what you’re talking
about! Thanks dating sites
Having read this I thought it was rather informative.
I appreciate you taking the time and energy to put this short article together.
I once again find myself spending a lot of time both reading and leaving comments.
But so what, it was still worthwhile!
Thank you for the good writeup. It actually was a enjoyment account it.
Glance complicated to far introduced agreeable from you!
However, how can we keep in touch?
You made some really good points there. I checked on the web to find
out more about the issue and found most people will go along with your views on this web site.
Cool blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple adjustements would really make my blog stand out.
Please let me know where you got your theme.
Cheers
Excellent site you have here but I was curious if
you knew of any forums that cover the same topics talked about in this article?
I’d really love to be a part of online community where I can get
responses from other experienced people that share the same interest.
If you have any suggestions, please let me know. Many thanks!
Hi everybody, here every person is sharing such experience, therefore it’s pleasant to read this webpage, and I used to pay a quick visit
this website daily.
Hi there, I discovered your site by way of Google whilst searching
for a similar topic, your website got here up, it seems great.
I’ve bookmarked it in my google bookmarks.
Hi there, simply was alert to your blog through Google, and located that
it is truly informative. I am going to watch out for brussels.
I will be grateful in the event you proceed this in future.
A lot of people will likely be benefited out of your writing.
Cheers!
Postgraduate Diploma In Education Kenya The Ocean At The End
Of The Lane Discussion Questions
Review my webpage; book epub – https://readerallbooks.godaddysites.com –
Little Fires Everywhere Opening Song Redwall Kindle Unlimited
Feel free to surf to my web blog: library
Early Learning Books Types Of Analytical Chemistry
Feel free to visit my web blog pdf base
I do trust all the ideas you’ve presented on your post.
They are very convincing and will definitely work. Nonetheless, the posts are too short for starters.
May just you please extend them a bit from subsequent
time? Thanks for the post.
I do not even understand how I ended up right here, however
I assumed this submit was once good. I do not
recognise who you might be however certainly you’re going to a famous blogger if you are not already.
Cheers!
This website was… how do I say it? Relevant!!
Finally I have found something that helped me.
Appreciate it!
Excellent beat ! I would like to apprentice even as you amend your web site, how could i subscribe for a blog
site? The account helped me a appropriate deal.
I had been tiny bit familiar of this your broadcast provided vivid clear idea
Hey there! Do you know if they make any plugins to assist with SEO?
I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good results.
If you know of any please share. Kudos!
Wonderful blog! I found it while searching on Yahoo
News. Do you have any tips on how to get listed in Yahoo News?
I’ve been trying for a while but I never seem to get there!
Thanks
You can definitely see your enthusiasm within the article you
write. The world hopes for even more passionate writers like you who aren’t afraid to mention how
they believe. All the time go after your heart.
Very energetic article, I liked that a lot. Will there be
a part 2?
I loved as much as you will receive carried out right here.
The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get bought an edginess over that you wish be delivering the following.
unwell unquestionably come more formerly again as exactly the same nearly a lot often inside
case you shield this hike.
My spouse and I absolutely love your blog and find most of your post’s to be exactly what I’m
looking for. Would you offer guest writers to write content
for yourself? I wouldn’t mind producing a post
or elaborating on some of the subjects you write
in relation to here. Again, awesome site!
This is my first time visit at here and i am genuinely happy to read everthing at
one place.
Hello, after reading this awesome article i am also delighted to share my
familiarity here with friends.
Piece of writing writing is also a fun, if you know afterward
you can write otherwise it is complicated to write.
Excellent website you have here but I was curious about if you knew of any community forums that cover the
same topics discussed in this article? I’d really love to be a
part of online community where I can get comments from other knowledgeable individuals that share
the same interest. If you have any suggestions, please
let me know. Cheers!
I do not even know the way I ended up right here, but I assumed this submit was great.
I don’t realize who you might be however definitely you’re going
to a famous blogger if you happen to are not already.
Cheers!
Wow, this post is pleasant, my younger sister is analyzing these kinds of things,
thus I am going to tell her.
I simply couldn’t depart your web site prior to suggesting that I really loved the standard information a person provide to your guests? Is gonna be back incessantly to check up on new posts.
I am curious to find out what blog system you have been working with?
I’m having some minor security issues with my latest site and I would
like to find something more risk-free. Do you have any solutions?
Thanks for sharing such a nice idea, post is nice, thats why i have read
it entirely
What’s Going down i’m new to this, I stumbled upon this I have found It absolutely useful and it has aided me out loads.
I’m hoping to give a contribution & help different users
like its helped me. Great job.
hey there and thank you for your information – I’ve certainly picked
up something new from right here. I did however expertise several technical points using
this site, since I experienced to reload the website a lot of times previous to I could get it
to load properly. I had been wondering if your hosting is OK?
Not that I’m complaining, but slow loading instances times
will sometimes affect your placement in google and can damage your
high quality score if ads and marketing with Adwords.
Well I’m adding this RSS to my e-mail and could look out for a lot more of
your respective intriguing content. Ensure
that you update this again very soon.
Thank you a lot for sharing this with all of us you really understand what you’re speaking about!
Bookmarked. Please also talk over with my web site =).
We may have a hyperlink trade arrangement among us
Do you mind if I quote a couple of your articles as long as
I provide credit and sources back to your website? My blog is in the exact same niche as yours
and my users would certainly benefit from a lot of the information you provide here.
Please let me know if this ok with you. Regards!
Good way of explaining, and nice piece of writing to obtain facts concerning
my presentation subject, which i am going to deliver in institution of higher education.
This page certainly has all the info I wanted concerning this subject and didn’t know who to ask.
What’s up, just wanted to say, I liked this
post. It was funny. Keep on posting! quest bars http://j.mp/3C2tkMR quest bars
whoah this blog is great i really like reading your
articles. Keep up the great work! You recognize, a lot of people are looking round for
this info, you can aid them greatly. asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr
You actually make it seem really easy along with your presentation but I in finding this topic to be actually something that I believe I’d by no means understand. It kind of feels too complicated and very broad for me. I am having a look ahead for your subsequent post, I will attempt to get the hang of it!
Hi, I do believe this is an excellent web site. I stumbledupon it 😉 I’m going to revisit
yet again since I saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue
to guide others. scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery
Fastidious response in return of this difficulty with solid arguments and describing the whole
thing regarding that. cheap flights http://1704milesapart.tumblr.com/ cheap
flights
Hi my friend! I want to say that this post is amazing, nice written and include approximately all significant infos. I would like to see more posts like this.
I am curious to find out what blog system you have been using?
I’m having some small security issues with my latest blog
and I would like to find something more secure.
Do you have any solutions? quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
I always used to read post in news papers but now as I am a user of net therefore from now I am using net for content, thanks to web.
scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery
Wow, incredible weblog format! How long have you ever been blogging for? you make running a blog look easy. The full look of your site is great, as smartly as the content!
grow your blog – blogexpander
EgStamn
Hey! This post could not be written any better! Reading this post reminds me of my good old room mate! He always kept talking about this. I will forward this article to him. Fairly certain he will have a good read. Many thanks for sharing!
Id should examine with you here. Which is not something I usually do! I enjoy studying a post that will make people think. Also, thanks for permitting me to comment!
Hi, i think that i saw you visited my weblog thus i came to return the favor.I’m attempting to find things to improve my site!I suppose its ok to use some of your ideas!!
Outstanding post however , I was wanting to know if you could write a litte more on this topic? I’d be very thankful if you could elaborate a little bit further. Thanks!
Hello there! I know this is kinda off topic nevertheless I’d figured I’d ask. Would you be interested in trading links or maybe guest authoring a blog post or vice-versa? My website covers a lot of the same topics as yours and I feel we could greatly benefit from each other. If you are interested feel free to send me an email. I look forward to hearing from you! Fantastic blog by the way!
Hi would you mind stating which blog platform you’re working with? I’m planning to start my own blog in the near future but I’m having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S My apologies for getting off-topic but I had to ask!
I wanted to put you this tiny word in order to thank you very much once again about the pretty opinions you have shown on this page. It is certainly remarkably generous of you to give unreservedly what many people would have offered for sale for an ebook to make some money for their own end, certainly now that you could possibly have done it if you considered necessary. Those basics in addition worked to become fantastic way to fully grasp that other people have a similar dreams the same as my personal own to learn way more with regard to this problem. Certainly there are a lot more pleasurable periods ahead for individuals that scan your site.
Hiya! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My site looks weird when viewing from my iphone4. I’m trying to find a template or plugin that might be able to correct this problem. If you have any recommendations, please share. Cheers!
It is not my first time to go to see this web
page, i am visiting this site dailly and take fastidious facts from here all
the time. part time jobs hired in 30 minutes https://parttimejobshiredin30minutes.wildapricot.org/
Hi there! Do you know if they make any plugins to protect against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?
Your blog has fascinating web content. I think you ought to write more and also you will certainly obtain more followers. Maintain creating.
With havin so much written content do you ever run into any problems of plagorism or copyright violation? My website has a lot of completely unique content I’ve either created myself or outsourced but it seems a lot of it is popping it up all over the internet without my permission. Do you know any techniques to help reduce content from being ripped off? I’d genuinely appreciate it.
Attractive section of content. I just stumbled upon your web site and in accession capital to assert that I get in fact enjoyed account your blog posts. Anyway Ill be subscribing to your augment and even I achievement you access consistently rapidly.
F*ckin awesome things here. I am very glad to see your post. Thanks a lot and i’m looking forward to contact you. Will you please drop me a e-mail?
Please let me know if you’re looking for a article author for your site.
You have some really great posts and I think I would be
a good asset. If you ever want to take some of the load off,
I’d really like to write some content for your blog in exchange for
a link back to mine. Please blast me an e-mail if interested.
Thanks!
I am curious to find out what blog system you
happen to be utilizing? I’m experiencing some small security issues with my latest blog and I would like to find something more secure.
Do you have any solutions?
I always used to read paragraph in news papers but now as I am a user of net thus from
now I am using net for articles, thanks to web.
For most up-to-date information you have to visit web and on web
I found this website as a finest website for latest updates.