C12 Embedded systems in MicroPython and C · Practice
Superloops and cooperative scheduling
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
Task 1 takes 0.2 ms every 5 ms; task 2 takes 10 ms every 250 ms. What's the processor's utilization?
Check
In a superloop, task A's turns take up to 0.5 ms and task B's up to 8 ms. How late can each task's turn start, at worst, because of the other? Give the larger of the two.
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A task runs every 25 ms. How many times does it run in 1 seconds?
Check
A task's 60 ms of work is split into pieces of 1 ms, one per turn. How many turns does it take?
Check
A task's next due time is 4294967290 ms on a 32-bit clock, and its period is 10 ms. After next += period, what does next hold?
Check
Toggle P0 every A ms (125) and P1 every B ms (30) from one superloop, without blocking either.
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
The same in MicroPython: toggle P0 every 100 ms and P1 every 40 ms from one loop.
MicroPython on the course's board: machine (Pin, PWM, ADC, DAC, UART, I2C, SPI, Timer, WDT) and time. Each call into the hardware takes about 40 µs. Tab indents; press Esc and then Tab to move on.
Check
Three tasks run 0.5 ms every 5 ms, 4 ms every 50 ms and 5 ms every 100 ms.
(a)
What is the processor's utilization?
(b)
In a round-robin superloop, what's the longest the first task can wait for its turn?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
150 ms of slow work is split into slices of 5 ms so other tasks can run between them.
(a)
How many slices?
(b)
What is the longest it now holds the processor at once?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
Utilization of (0.5 ms every 10 ms) and (15 ms every 500 ms)?
Check
Runs of a 20 ms task in 5 s?
Check
Turns for 90 ms of work in 3 ms pieces?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12