rust-raspberrypi-OS-tutorials/0A_power
Andre Richter 3f92aab6e7
Bump extern crates
cortex-a -> 2.2.1
panic-abort -> 0.3.1
2018-10-02 23:47:09 +02:00
..
.cargo Use aarch64-unknown-none target in nightly 🎉 2018-08-19 23:42:24 +02:00
raspi3_boot Bump extern crates 2018-10-02 23:47:09 +02:00
src Makefile: Don't delete kernel8 2018-10-02 23:34:01 +02:00
Cargo.lock Bump extern crates 2018-10-02 23:47:09 +02:00
Cargo.toml Bump extern crates 2018-10-02 23:47:09 +02:00
kernel8 Bump extern crates 2018-10-02 23:47:09 +02:00
kernel8.img Bump extern crates 2018-10-02 23:47:09 +02:00
link.ld Alignment. Binaries from newer Rust version. 2018-10-02 23:16:04 +02:00
Makefile Makefile: Don't delete kernel8 2018-10-02 23:34:01 +02:00
README.md Rewrite for register-rs. 2018-07-16 21:24:33 +02:00

Tutorial 0A - Power management

For embedded systems, power consumption is critical. The Raspberry Pi 3 has a very sophisticated PM interface. You can turn each device on and off independently. There's a catch though. The GPIO VCC pins are hardwired, there's no way to turn them off programmatically. This means if you connect some devices to them, you'll have to implement a way to turn those devices off (with a transistor connected to a data GPIO pin for example).

power.rs

Unfortunately, the documentation about the PM interface is very very rare. We will therefore more or less implement a carbon copy of respective functions of Linux' bcm2835_wdt.c driver.

The power management controller is one of the peripherals that are not emulated properly by QEMU. Our implementation therefore works on real hardware only.

Power::off(&self, mbox: &mut mbox::Mbox, gpio: &gpio::GPIO) shuts down the board to an almost zero power consumption state.

Power::reset(&self) reboots the machine. Also handled by the PMC, and since the Raspberry Pi does not have a hardware reset button, it's very useful.

When using make raspboot and choosing reset(), you can see your code in action nicely as you generate a boot-loop.

gpio.rs

We introduce a lot of new GPIO pins. It's a good time to refactor the GPIO MMIO interface into its own type with the common RegisterBlock implementation that you already know from the other components.

main.rs

We display a simple menu, and wait for user input. Depending on the input, we reboot the system or power it off.