ECEC 201 · Week 10
Modern Computer: Von Neumann
The demo is one C program: each button press logs one decoded register reading to a file.
Week 10 of 10 · Das Frite
ECEC 201 · Week 10 · In class
The demo is one C program: each button press logs one decoded register reading to a file.
- It builds with
makeand runs clean under valgrind. - Write two questions a partner might ask about pointers or memory in your code, and your answers, before the demo.
- That writing is the homework.
ECEC 201 · Week 10 · In class
Each partner answers one question about their own code.
- Keep the repository as it was at the demo.
ECEC 201 · Week 10 · Lecture
One loop, three jobs
for (;;) {
if (!wait_for_press(line_fd)) /* week 9 */
break;
int raw = read_reg(dev, addr, reg); /* week 8 */
if (raw < 0)
continue; /* log the failure? */
log_reading(log_fd, raw); /* week 7 */
}
- Each job is a function you already tested on its own week.
mainopens what the loop needs, runs the loop, and closes everything after it.
ECEC 201 · Week 10 · Lecture
Who owns what
| Resource | Acquired by | Released by |
|---|---|---|
| Heap block | malloc | free, once |
| File descriptor | open | close |
| GPIO line | the line request | close on its descriptor |
Write each release on the path out, including the error paths.
ECEC 201 · Week 10 · Lecture
Clean under valgrind
valgrind --leak-check=full ./progmust end with no blocks "definitely lost" and no invalid reads or writes.--track-fds=yesalso lists descriptors still open at exit.- Run it through a real session: press the button, let readings log, then stop the program the way the demo will.
ECEC 201 · Week 10 · Lecture
Freeze the demo
git cloneinto a new directory, thenmakethere: that proves the repository builds without files only your board has.git tag demomarks the commit you showed; later work does not move it.- The
Makefile, the sources, and nothing generated: no.ofiles or binaries in git.
ECEC 201 · Week 10 · Lab
Lab
- Demonstrate the project: each button press logs one decoded register reading to a file.
- Each partner answers one question about pointers or memory in their own code. Second pass: run the demo under valgrind and show no leaks.
- Assemble the lab hand-in: The demo, the repository with its `Makefile`, and the valgrind summary.
ECEC 201 · Week 10 · Lab
Hand in
The demo, the repository with its `Makefile`, and the valgrind summary.
ECEC 201 · Week 10 · Homework
Homework
- Write two questions a partner might ask about pointers or memory in your code, and your answers, before the demo.
ECEC 201 · Week 10 · Homework
Turn in
The two questions and the two answers.
ECEC 201 · Week 10 · Read
Read
On the lab site: Module 12, A whole system, is a full product. This week grades one C program that joins a register and a button.