May 2020
Intermediate to advanced
496 pages
13h 54m
English
Often, an RTOS is used because many different activities need to happen almost simultaneously. When a task needs to take action because an event occurs, there are a few ways of monitoring for the event.
Polling is when a value is continuously read in order to capture a transition. An example of this would be waiting for a new ADC reading. A polled read might look something like this:
uint_fast8_t freshAdcReading = 0;while(!freshAdcReading){ freshAdcReading = checkAdc();}
While this code will detect when a new ADC reading has occurred, it will also cause the task to continually be in the Running state. If this happens to be the highest priority task in the system, this will starve the other tasks of CPU time. ...