2023-03-21 13:36:55 +00:00
|
|
|
# RTC driver
|
|
|
|
|
|
|
|
The QEMU aarch64 virt machine has a [PL031][1] real-time clock at 0x9010000. For this exercise, you
|
2023-04-13 10:58:06 +01:00
|
|
|
should write a driver for it.
|
|
|
|
|
|
|
|
1. Use it to print the current time to the serial console. You can use the [`chrono`][2] 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`][3] inside the loop.)
|
2023-04-17 15:38:51 +01:00
|
|
|
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.
|
2023-03-21 13:36:55 +00:00
|
|
|
|
2023-04-05 16:15:42 +01:00
|
|
|
Download the [exercise template](../../comprehensive-rust-exercises.zip) and look in the `rtc`
|
|
|
|
directory for the following files.
|
2023-03-30 15:35:06 +01:00
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
`src/main.rs`:
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File src/main.rs -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```rust,compile_fail
|
|
|
|
{{#include rtc/src/main.rs:top}}
|
|
|
|
|
|
|
|
{{#include rtc/src/main.rs:imports}}
|
|
|
|
|
|
|
|
{{#include rtc/src/main.rs:main}}
|
|
|
|
|
|
|
|
// TODO: Initialise RTC and print value.
|
|
|
|
|
2023-04-13 10:58:06 +01:00
|
|
|
// TODO: Wait for 3 seconds.
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
{{#include rtc/src/main.rs:main_end}}
|
|
|
|
```
|
|
|
|
|
2023-04-17 15:38:51 +01:00
|
|
|
`src/exceptions.rs` (you should only need to change this for the 3rd part of the exercise):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File src/exceptions.rs -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```rust,compile_fail
|
|
|
|
{{#include rtc/src/exceptions.rs}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`src/logger.rs` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File src/logger.rs -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```rust,compile_fail
|
|
|
|
{{#include rtc/src/logger.rs}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`src/pl011.rs` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File src/pl011.rs -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```rust,compile_fail
|
|
|
|
{{#include rtc/src/pl011.rs}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`Cargo.toml` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File Cargo.toml -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```toml
|
|
|
|
{{#include rtc/Cargo.toml}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`build.rs` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File build.rs -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```rust,compile_fail
|
|
|
|
{{#include rtc/build.rs}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`entry.S` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File entry.S -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```armasm
|
|
|
|
{{#include rtc/entry.S}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`exceptions.S` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File exceptions.S -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```armasm
|
|
|
|
{{#include rtc/exceptions.S}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`idmap.S` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File idmap.S -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```armasm
|
|
|
|
{{#include rtc/idmap.S}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`image.ld` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File image.ld -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```ld
|
|
|
|
{{#include rtc/image.ld}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`Makefile` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File Makefile -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```makefile
|
|
|
|
{{#include rtc/Makefile}}
|
|
|
|
```
|
|
|
|
|
|
|
|
`.cargo/config.toml` (you shouldn't need to change this):
|
2023-04-03 14:14:13 +01:00
|
|
|
|
|
|
|
<!-- File .cargo/config.toml -->
|
|
|
|
|
2023-03-21 13:36:55 +00:00
|
|
|
```toml
|
|
|
|
{{#include rtc/.cargo/config.toml}}
|
|
|
|
```
|
|
|
|
|
|
|
|
Run the code in QEMU with `make qemu`.
|
|
|
|
|
|
|
|
[1]: https://developer.arm.com/documentation/ddi0224/c
|
|
|
|
[2]: https://crates.io/crates/chrono
|
2023-04-13 10:58:06 +01:00
|
|
|
[3]: https://doc.rust-lang.org/core/hint/fn.spin_loop.html
|