1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-25 15:38:01 +02:00
Andrew Walbran c5863f6642
Add optional extension to RTC exercise (#562)
* Add methods to mask and clear interrupts.

* Start on GICv3 driver.

* Enable and use RTC interrupt.

* WFI

* Add newtype for interrupt ID.

* Add extension to use interrupt.

* Add method to send an SGI.

* Silence warnings about unused methods in provided drivers.

* Implement Debug manually for IntId.

It's useful to say what kind of interrupt it is.

* Acknowledge and log interrupt.

We should end it as well, but doing so results in a loop unless we first
clear the match.

* cargo fmt with imports_granularity = "module"

* Use arm-gic crate rather than including driver in the example.
2023-04-17 15:38:51 +01:00

2.6 KiB

RTC driver

The QEMU aarch64 virt machine has a PL031 real-time clock at 0x9010000. For this exercise, you should write a driver for it.

  1. Use it to print the current time to the serial console. You can use the chrono crate for date/time formatting.
  2. Use the match register and raw interrupt status to busy-wait until a given time, e.g. 3 seconds in the future. (Call core::hint::spin_loop inside the loop.)
  3. Extension if you have time: Enable and handle the interrupt generated by the RTC match. You can use the driver provided in the arm-gic crate to configure the Arm Generic Interrupt Controller.

Download the exercise template and look in the rtc directory for the following files.

src/main.rs:

{{#include rtc/src/main.rs:top}}

{{#include rtc/src/main.rs:imports}}

{{#include rtc/src/main.rs:main}}

    // TODO: Initialise RTC and print value.

    // TODO: Wait for 3 seconds.

{{#include rtc/src/main.rs:main_end}}

src/exceptions.rs (you should only need to change this for the 3rd part of the exercise):

{{#include rtc/src/exceptions.rs}}

src/logger.rs (you shouldn't need to change this):

{{#include rtc/src/logger.rs}}

src/pl011.rs (you shouldn't need to change this):

{{#include rtc/src/pl011.rs}}

Cargo.toml (you shouldn't need to change this):

{{#include rtc/Cargo.toml}}

build.rs (you shouldn't need to change this):

{{#include rtc/build.rs}}

entry.S (you shouldn't need to change this):

{{#include rtc/entry.S}}

exceptions.S (you shouldn't need to change this):

{{#include rtc/exceptions.S}}

idmap.S (you shouldn't need to change this):

{{#include rtc/idmap.S}}

image.ld (you shouldn't need to change this):

{{#include rtc/image.ld}}

Makefile (you shouldn't need to change this):

{{#include rtc/Makefile}}

.cargo/config.toml (you shouldn't need to change this):

{{#include rtc/.cargo/config.toml}}

Run the code in QEMU with make qemu.