Introduction to RTOS Part 3 - Task Scheduling | Digi-Key Electronics

  Рет қаралды 236,617

DigiKey

DigiKey

Күн бұрын

Пікірлер: 113
@lagcisco
@lagcisco 3 жыл бұрын
Seriously great content here. Give this guy a raise. Well earned.
@Xsses
@Xsses 3 жыл бұрын
I think it is probably going to be one of the best FreeRTOS tutorials or maybe even the best.
@andriisemenov5863
@andriisemenov5863 3 жыл бұрын
Great course! Was looking for a next video, but it is super fresh. Looking forward to next ones.
@joaoagricio4585
@joaoagricio4585 3 жыл бұрын
Great work! Really happy for this series. Thank you!
@renaulth2009
@renaulth2009 3 жыл бұрын
Very good stuff, just in time for my FreeRTOS explorations. Please don't stop these video series halfway! :)
@AlwinArrasyid
@AlwinArrasyid 3 жыл бұрын
I can't thank you enough for these super useful contents.
@pedrosena2499
@pedrosena2499 3 жыл бұрын
Shawn is just amazing on teaching so much simple and clear! Congrats!
@elenobia9684
@elenobia9684 Жыл бұрын
Unbelievably ! you explained all of that in details in 10min ! Thank you so much for that great work and explaination.
@mindofisaac
@mindofisaac 3 жыл бұрын
Great series. Looking forward to the next parts
@qcnck2776
@qcnck2776 3 жыл бұрын
Thanks for doing this series in chunks. I will have to let my brain process this episode and the prior episode in an equal priority round robin manner for a while until it is pre-empted by the higher priority episode 4 :)
@mitchellscales8846
@mitchellscales8846 2 жыл бұрын
This is definitely the best FreeRTOS tutorial
@josephlai7737
@josephlai7737 3 жыл бұрын
Solid tutorials. Thank you.
@yigechongzi
@yigechongzi 2 жыл бұрын
So good, great work and thanks for sharing the code!
@pratikphadte
@pratikphadte Ай бұрын
I tried the exercise using switch case, thanks Shawn for such amazing course!
@Quarky_
@Quarky_ 3 жыл бұрын
What a series!!
@antoniopellegrini8704
@antoniopellegrini8704 3 жыл бұрын
Beautiful video, very helpful to understand the fondamental concepts of RTOS. Thank you ❤️
@ShawnHymel
@ShawnHymel 3 жыл бұрын
Most welcome! Glad it helps!
@claytube1958
@claytube1958 5 ай бұрын
Small bug in your solution. You need to increment idx in line 75, otherwise, it only accepts the last digit...
@guilhermedaolio6531
@guilhermedaolio6531 4 ай бұрын
thanks bro, i was having this issue with the example then i added the missing "++" on the line 75
@PrithaMajumder
@PrithaMajumder Ай бұрын
Thank You So Much for This Amazing Video Video Lecture - 3 Completed
@miguelfaf
@miguelfaf 9 ай бұрын
Hi! Great content. Thank you so much for producing these and making them available. Just a minor correction: on the LED control exercise solution, there's a missing increment 'i++" operator in the buf_len index.
@johnmirajkar6975
@johnmirajkar6975 3 жыл бұрын
Very nice compressed video great
@BerndFelsche
@BerndFelsche 3 жыл бұрын
IIRC, serial output may also cause a task to be not ready because it can take a tick to wait for the character to be output. In an RT application, the serial output should be in a task dedicated for the output to that physical device port. Messages are then sent to that task when output is required. That strategy avoids garbled output produced by two or more tasks outputting to the same physical device. The serial output task can wait on a message in a queue so no cycles are burned by it unless there is something to do. Similarly, some input operations duch as analog input or serial input may block. Rule of thumb is one task per physical resource. With ADC, there is usually only one converter that has its input multiplexed over several ports. So one task per converter. If you know the hardware well, then you can start the conversion and suspend the task until the conversion is complete, resuming via ISR. Scheduler may be configured to yield to the next ready task for the remainder of the tick when a task is suspended.
@shawnhymel7647
@shawnhymel7647 3 жыл бұрын
Thanks for the great advice! The idea of using one task per physical device seems very useful. I’m not sure exactly how the ESP32 handles serial output, but I know that on other Arduino boards, it relies on the UART hardware to manage it. So, once you copy your message to a buffer, the rest is non-blocking while the hardware handles outputting the message, byte-by-byte, at the specified baud rate. However, that still doesn’t mean it’s thread-safe, as another task could interrupt the process of copying data to the buffer :)
@MarlosZappa
@MarlosZappa 3 жыл бұрын
Awesome! Keep it up pretty please!
@mrlajel
@mrlajel 3 жыл бұрын
this makes my life easier, since the freeRTOS doc is not for everyone.
@MuhammadDaudkhanTV100
@MuhammadDaudkhanTV100 3 жыл бұрын
Great full ideas
@OthmanAlikhan
@OthmanAlikhan 3 жыл бұрын
Thanks for the video =)
@adamcierniak3902
@adamcierniak3902 3 жыл бұрын
Great video
@mh2000wh
@mh2000wh 2 жыл бұрын
For the solution code, why the serial port only recieve the last number? If I send "123", serial port respond "Updated LED delay to: 3 ".
@ayushpatel789
@ayushpatel789 10 ай бұрын
I am facing the same issue
@luisderani
@luisderani 2 жыл бұрын
Hi, thanks for the great work. I have a question, after writing my answer to this challenge, I copied your answer (just to get the nice formatting) and started to mess around to check things. One of the things I did was to delete the "while(1) { ... }" loop on the ReadSerial() task, thinking that the task would be executed only once after being started by the scheduler, exit, and I would never get a chance to input values. But instead of that, the ESP32 panics! I tried on my code too, almost the same as yours, and same result: works with the "while(1)" loop on ReadSerial(), panics without it. Shouldn't FreeRTOS just exit the task and continue blinking the LED forever, as it would be the only task left running?
@vincentlin7240
@vincentlin7240 5 ай бұрын
For the question at the end of the blog: Try playing around with the priorities of the tasks. What happens if you make the “Toggle LED” task priority 2? Why does everything still work? What happens if you make the “Read Serial” task priority 2 instead (and leave the toggle task at priority 1)? Why does the LED task stop blinking? Ans from ChatGPT: In FreeRTOS, tasks with higher priorities are given precedence in execution. However, lower priority tasks can still run when higher priority tasks are in a blocked state. In your case, even though `toggleLED` has a higher priority, it periodically blocks when waiting using `vTaskDelay()`, allowing `readSerial` to execute. When priorities are swapped, `readSerial` continuously executes, preventing `toggleLED` from running and causing the LED to appear continuously off.
@flowmeet
@flowmeet 2 жыл бұрын
Hi, one question, which ide/tools do you suggest to work with esp32 and implement unit testing, and debugger in the circuit?
@manfredbogner9799
@manfredbogner9799 21 күн бұрын
Sehr gut
@francescobenacci6611
@francescobenacci6611 11 ай бұрын
Thanks for the videos, i find them very informative! I have a question: when the running task calls taskDelay, is the scheduler invoked immediately? If so, isn't that "violating" its 1ms periodicity?
@sylvainlathuy2702
@sylvainlathuy2702 3 жыл бұрын
Very nice video, thank you. It would have been nice if at this stage you would have told us what happens with your own interrupt routine in case it is itself interrupted by a scheduler tick. Because you may write your interrupt code as short as you want, there is always a moment where this will happen.
@ShawnHymel
@ShawnHymel 3 жыл бұрын
Good question! Most of the time, I have found that the scheduler tick timer interrupt is at a lower priority than other hardware interrupts. For processors that supported nested interrupts (e.g. NVIC), you'd likely find that your interrupt will take priority over the scheduler (tick timer ISR). I suppose it's possible to set it so the tick timer interrupt is higher priority, though. In that case, I imagine that the tick timer ISR might choose a task to run that would not start running until after your ISR is done. Here's some good info on how the tick timer works: www.freertos.org/implementation/a00011.html
@sylvainlathuy2702
@sylvainlathuy2702 3 жыл бұрын
@@ShawnHymel Thank you! I think that the "Interrupted interrupt" is a topic way too often eluded in many courses about interrupts on Arduino. I just found more general notions about interrupted interrupts in this thread: stackoverflow.com/questions/5111393/do-interrupts-interrupt-other-interrupts-on-arduino . Mentioning this because I initially thought that interrupt calls would be "nested", but it is not the case and I believe it is very important to understand this first.
@Jayang5540
@Jayang5540 3 жыл бұрын
nice video
@LaeeqKhan01
@LaeeqKhan01 Жыл бұрын
Superb intro to FreeRTOS. One clarification, in the solution to the challenge problem, you are not incrementing the idx variable after reading a byte from serial port. Is it a typo or am I missing something.
@johnhiggins716
@johnhiggins716 Жыл бұрын
Great Video. What happens if the interrupt is still running when it's time for an OS "Tick"? what has highest priority? Assuming OS but then what? My guess is TASK A -> INT -> OS -> INT -> TASK (A?)
@maximilliancarvajal4489
@maximilliancarvajal4489 2 жыл бұрын
Is it necessary to check that task_1 handle is != Null because if it is equal to Null then the loop task is what gets deleted?
@Hermaeus7
@Hermaeus7 2 жыл бұрын
What is the priority of the "third" task (void loop()) ?
@xxportalxx.
@xxportalxx. 3 жыл бұрын
Weird how priority is increasing in these examples, usually lower numbers means higher priority (arm and Linux both do it this way) but here priority 1 runs before priority 0, strange
@ShawnHymel
@ShawnHymel 3 жыл бұрын
Yup! High number means high priority in FreeRTOS and low number means high priority in Linux and Arm.
@nicolaskeroack7860
@nicolaskeroack7860 Жыл бұрын
welcome to programming lol
@xxportalxx.
@xxportalxx. Жыл бұрын
@@nicolaskeroack7860 yeah it's like I'm making a new thing, let me just change all the fundamental conventions you're used to, that should be fun 🤦‍♂️
@SaidSaid-xe3mw
@SaidSaid-xe3mw Жыл бұрын
Thinks a lot
@bayanicustodio3998
@bayanicustodio3998 3 жыл бұрын
Is there also talk about CANBUS anywhere in here?
@tadm123
@tadm123 4 ай бұрын
Hello guys, trying to understand, so the loop() function will be a third task that has highest priority than all the task that we defined?
@sivapurapuchowdaiah1424
@sivapurapuchowdaiah1424 4 ай бұрын
Here this code is need to place in the freertos directory then load free rtos code in controller? Is this right? Correct me if I am wrong
@guilhermedaolio6531
@guilhermedaolio6531 4 ай бұрын
there's a bug in your example, in the line 75 you need to increment the idx variable, otherwise it will only return the last character you wrote on the serial, like "400" it will return 0
@siqingzhang8061
@siqingzhang8061 2 ай бұрын
idx++; // it was idx ; for some reason
@guna6751
@guna6751 10 күн бұрын
why is that (void *parameter) used? What work it does?
@phillipneal8194
@phillipneal8194 3 жыл бұрын
Nice 8-)
@raghuramchary9119
@raghuramchary9119 3 жыл бұрын
RTOS is run only on MicroControllers right ?? You meant Single core processor as Microcontroller, Correct ?? Thanks
@danielelmuneco1994
@danielelmuneco1994 11 ай бұрын
There is something weird (for me) happening when task_1 is deleted: Serial port just stops printing to console. I asked ChatGPT and it says the problem is the collision of the serial port access between the tasks, but I don't know really how to solve it.
@seekerytomfain194
@seekerytomfain194 2 жыл бұрын
HEY...good video.
@duncanwalduck7715
@duncanwalduck7715 2 жыл бұрын
( 8:56 ) - Despite being warned that BAD THINGS will happen, it seems that we don't need to go too far to see a •vTaskDelete(NULL);• used in earnest: like the solution to exercises for the reader (to kill the 'setup and loop' task there, apparently.) Hmmm. I imagine clarity must be in the docs somewhere - I can't imagine you're deliberately driving it off a cliff there!
@KISHANPATEL96
@KISHANPATEL96 Жыл бұрын
I am wording the same, vTaskDelete(task_1); is causing the program to crash.
@ziadal2397
@ziadal2397 3 жыл бұрын
Hello i have a question sir does the schedular runs as a task itslef ? If so when exaclty a task Can change state from blocked to running i suppose a part of the main Memory . Also thanks you for thé videos.
@ShawnHymel
@ShawnHymel 3 жыл бұрын
Great question! In some operating system, the scheduler could be a task. In FreeRTOS it is simply a timer interrupt service routine (ISR) that runs every time the tick timer overflows (default: 1 ms). The ISR then figures out which task needs to run and sets it to running. For a task to get out of the "blocked" state, some external event must occur. This is something like releasing of a mutex/semaphore or a delay timer expiring. A blocked task may only return to the ready state (or be put in the suspended state). The scheduler (the ISR) looks at the list of ready tasks, determines the highest priority, and chooses it to run. Here is a good article on what is happening in the scheduler: www.freertos.org/implementation/a00011.html Hope that helps!
@ziadal2397
@ziadal2397 3 жыл бұрын
@@ShawnHymel thanks you !
@olawaleipadeola7916
@olawaleipadeola7916 Жыл бұрын
I checked for a valid taskHandle but when I deleted task_1 my program crashed. I had to change priority of both task_1 and task_2 to 2 and 3 respectively to get it to work.
@krisnaresi623
@krisnaresi623 3 жыл бұрын
Good videos, but now I wonder, the ISR reside in which core? Core 0? Core 1?
@ShawnHymel
@ShawnHymel 3 жыл бұрын
The ISR executes in whichever core it was created (attached). So if you attach the ISR to an interrupt in a task in Core 0, it will execute in Core 0. We cover Hardware interrupts in a later episode.
@ahsanalirafaq805
@ahsanalirafaq805 Жыл бұрын
How the value of task_1 changes from NULL because there isn't any instruction that does so.
@lxzhang4911
@lxzhang4911 3 жыл бұрын
Thanks for this great stuff. A question at 2:17, what if as the Tast A is blocked (OS in Idle) and at the third tick the Task B and C are in ready state? Will the scheduler let them run in the 3rd tick?
@ShawnHymel
@ShawnHymel 3 жыл бұрын
Yes, whenever Task B or C enter into the ready state, the scheduler will let them run. Something that's not shown in the diagram: if Task B and C enter the ready state while Task A is running, the scheduler will interrupt Task A (even not on a tick) to let the higher priority task run (assuming preemption is enabled, which it is by default in the ESP32). This post has a good discussion on how this works: www.freertos.org/FreeRTOS_Support_Forum_Archive/May_2016/freertos_Does_the_highest_priority_task_run_at_all_times_b8195787j.html. Hope that helps!
@lxzhang4911
@lxzhang4911 3 жыл бұрын
@@ShawnHymel as each task is a thread (CPU utilization), could several Tasks run at the same Tick (the so called multithreading?)? In other words, is the case in your video the so called 'single threading'?
@ShawnHymel
@ShawnHymel 3 жыл бұрын
@@lxzhang4911 You can only run one task at a time in a single-core CPU. If you have a multi-core CPU, you could run several tasks at the same time. In the single-core example that I've shown in the videos, the CPU must split its time between tasks. This is still "multithreading" in a single core.
@lxzhang4911
@lxzhang4911 3 жыл бұрын
@@ShawnHymel So in your example is it a RTOS or general purpose OS? Because in your this video (kzfaq.info/get/bejne/hbailtOTsLS3mok.html&ab_channel=Digi-Key) the example of general purpose OS is quite similar with the example here in this video. It makes me quite confused. I thought in a general purpose OS the OS will not check at each tick if it need to switch context to another task. Is it?
@ShawnHymel
@ShawnHymel 3 жыл бұрын
@@lxzhang4911 Most general purpose operating systems (e.g. Linux) still have a scheduler, which is some code that must run periodically in order to determine which task/thread to run next. Usually, this happens at some pre-determined frequency (in Linux, this is determined by the "timeslice" setting). This ends up looking much the same in both GPOS and RTOS cases: there's a small sliver of time in which the OS scheduler must run periodically to determine which task to run for the remainder of the timeslice. Here's a good article about how one such Linux distro handles timeslices: doc.opensuse.org/documentation/leap/archive/42.1/tuning/html/book.sle.tuning/cha.tuning.taskscheduler.html
@eslamsayed8405
@eslamsayed8405 3 жыл бұрын
Thanks for this series. But I need to know the answer of question in the challenge. Why toggeling is stoped when making the periority of led_toggle is 1 and the other task 2 ??
@ShawnHymel
@ShawnHymel 3 жыл бұрын
If you look at the code for the readSerial() task, you'll see that it never uses vTaskDelay(), which means that it will never yield the processor if it is the highest priority task (which is what happens when you set it to priority 2 and the toggleLED() task to priority 1). If it's hogging the processor, the LED task will never run. You either need to make it the same or lower priority than toggleLED() or put a vTaskDelay() in the readSerial() task to force it to yield the processor some of the time. Hope that helps!
@eslamsayed8405
@eslamsayed8405 3 жыл бұрын
@@ShawnHymel Really thanks, Sure it helped. but this will lead me to another question.. is that mean if i have 3 tasks , i must block 2 of them during their execution to enable the third one to be executed?!!
@ShawnHymel
@ShawnHymel 3 жыл бұрын
@@eslamsayed8405 It depends on how you set the priority of each of the tasks. If they are all set at the same priority, then the scheduler will execute each one for 1 tick in a round-robin fashion (so they'll all get a chance to run). If one is a higher priority than the other two, then you'll need to make sure that the higher-priority task delays or blocks itself to let the others run. Hope that helps!
@eslamsayed8405
@eslamsayed8405 3 жыл бұрын
@@ShawnHymel OK got it. thanks.
@phizaics
@phizaics 2 жыл бұрын
I have used exactly the same code as given in the solution except that I used Serial.parseInt() to get integer value from serial port and the program is not working right and the ESP keeps resetting (watchdog resets in readSerial function). Also it shows that the blink delay was updated but immediately gets set to 0 after and the program crashes. What am I doing wrong?
@seferideveloper6933
@seferideveloper6933 Жыл бұрын
If you use firefox and copied the code to paste to your IDE; some characters does not appear on Digikey website when Firefox is used. So the problem might be that :D
@amiral3187
@amiral3187 2 жыл бұрын
I hope Shawn or anyone could explain to me the output on the Serial terminal at the last Example, where the 2nd Task should interrupt the 1st every 100mSec (10 Times/Sec) This should result in 10 Astrix per every Sentance (as the sentences are printed every 1 Sec) but the output is different and we can see the whole sentence is completely printed most of the times. Why is that?
@vinivinitha5011
@vinivinitha5011 2 жыл бұрын
same doubt
@olawaleipadeola7916
@olawaleipadeola7916 Жыл бұрын
A year later but incase anyone still has the doubt. You must have missed that the loop task suspends and resumes task_2 every 2 seconds as well.
@josephlai7737
@josephlai7737 3 жыл бұрын
I am using Arduino UNO. Most of the sketch is the same as the one in the video. I left the loop function empty for simplicity but there is still an error. Does anyone know what might cause the characters in msg being replaced by *? Instead of something like: Ba*rkadeer brig* Arr booty rum. some of the characters in msg are replaced by * in my program: Ba*kadeer brig Arr*booty rum. Thanks in advance!
@ShawnHymel
@ShawnHymel 3 жыл бұрын
Good to know the UNO works with FreeRTOS! I have not tested it yet. The * issue is an odd one that I have not seen. It might have to do with the baud rate of the UART. Could you try slowing it down? Maybe 9600 or even 1200?
@josephlai7737
@josephlai7737 3 жыл бұрын
@@ShawnHymel Thanks for your reply! I was using 1200 already and I even tried 300 but the output became gibberish. I guess this is why we want one task only to handle serial communication.
@tehmudjinkhan2207
@tehmudjinkhan2207 3 жыл бұрын
RTOS solves a lot of timing problems.
@mohamedhassanin6054
@mohamedhassanin6054 2 жыл бұрын
1:02 preemptive scheduling 4:30 task states 7:00 vTaskSuspend() and vTaskResume() example
@aymanmiri2236
@aymanmiri2236 2 жыл бұрын
But if anyone is paying attention, they will tell you that the example won't run as expected, because if we go back to the video and see the priority you've done for each task, we'll see task 2 won't run as well as at the end of the video
@therealspixycat
@therealspixycat 2 жыл бұрын
Is FreeRTOS using a cooperative scheduler?
@ShawnHymel
@ShawnHymel 2 жыл бұрын
FreeRTOS uses a pre-emptive scheduler by default. However, you can turn off pre-emption (look for a #define of something like portUSE_PREEMPTION) to make it a cooperative scheduler.
@zee-lab-electronics
@zee-lab-electronics 3 жыл бұрын
Hi Shawn. I think you have stopped working on your own channel By the way, nice video series on FreeRTOS.
@ShawnHymel
@ShawnHymel 3 жыл бұрын
I did :( Too much other work for clients in the past few months (I can't really complain about that, though :)
@pujabaur4969
@pujabaur4969 Жыл бұрын
Gotem
@tobiask8490
@tobiask8490 3 жыл бұрын
Very good series, but in this video the 2nd half was a bit too fast for me, had to re-watched it again)
@sampritineog5657
@sampritineog5657 3 жыл бұрын
I agree. Overall video was good though.
@happysoul4024
@happysoul4024 3 жыл бұрын
Good explanation. But, my dude, you should put a bit of gap between sentences...
@cabobsstopmotion4983
@cabobsstopmotion4983 2 ай бұрын
pirate ipsum
@keithsummers1889
@keithsummers1889 3 жыл бұрын
This guy is just reading a script and not pausing during important moments. He doesn't know the material himself. Sounds very much like the written documents.
@AbuzarToronto
@AbuzarToronto 5 ай бұрын
Awwww man, Arduino ruined it. You just needed to use the IDF and these videos would've been great. So sad.
#253 Accurate Task Scheduler for the Arduino (and STM32, ESP32...)
21:37
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 53 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 19 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 34 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 51 МЛН
Introduction to ESP32 - Getting Started
47:57
DroneBot Workshop
Рет қаралды 1,6 МЛН
Real Time Operating Systems (RTOS) - Nate Graff
35:02
White Hat Cal Poly
Рет қаралды 48 М.
Introduction to RTOS Part 5 - Queue | Digi-Key Electronics
12:01
#328 ESP32 Secrets: Interrupts, and Deep-Sleep under the Hood
18:57
Andreas Spiess
Рет қаралды 174 М.
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 2,1 МЛН
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 26 МЛН
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 25 МЛН
Здесь упор в процессор
18:02
Рома, Просто Рома
Рет қаралды 162 М.