C12 Embedded systems in MicroPython and C · Practice
Ring buffers and interrupt-driven serial
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.
0 solved
0 in a row
0 of 11 kinds solid
Check
A ring buffer's head counter is 77 and its tail counter is 970. How many bytes are waiting?
Check
In a 16-slot ring buffer, which slot does counter 100 use?
Check
At 115200 baud, how often does a new byte arrive in a continuous stream?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
The main program may be busy for up to 2 ms while bytes stream in at 9600 baud. How many bytes must the buffer hold, at least?
Check
A receive ISR takes 40 cycles per byte. At 115200 baud, what share of the processor does it use?
Check
Write a 16-slot ring buffer of uint8_t with void put(uint8_t v) and int get(void) (−1 when empty). Put A bytes (10), get B (3), print how many are waiting; put 4 more and print again; then print the value of the next byte read, if the bytes put were 1, 2, 3, ... in order.
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
A program may be away for 12 ms while bytes arrive at 9600 baud.
(a)
How many bytes can arrive meanwhile?
(b)
What power-of-two buffer holds them (one slot stays empty)?
Check
A ring buffer of 64 bytes has head = 3 and tail = 200.
(a)
How many bytes are waiting?
(b)
How many more can it take?
Check
Bytes waiting with head 2049, tail 2030?
Check
Slot for counter 300 in 32 slots?
Check
Buffer bytes for 2 ms away at 57600 baud?
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