Skip to content

Commit fe93a16

Browse files
committed
Updating docs.
1 parent f84333a commit fe93a16

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

src/main.rs

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#![no_main]
22
#![no_std]
33

4-
use neotron_bmc as _;
5-
6-
use neotron_bmc::monotonic::{Instant, Tim3Monotonic, U16Ext};
7-
8-
use cortex_m_rt::exception;
9-
4+
///! Neotron BMC Firmware
5+
///!
6+
///! This is the firmware for the Neotron Board Management Controller (BMC). It controls the power, reset, UART and PS/2 ports on a Neotron mainboard.
7+
///! For more details, see the `README.md` file.
8+
///!
9+
///! # Licence
10+
///! This source code as a whole is licensed under the GPL v3. Third-party crates are covered by their respective licences.
11+
use cortex_m::interrupt::free as disable_interrupts;
1012
use rtic::app;
11-
1213
use stm32f0xx_hal::{
1314
gpio::gpioa::{PA10, PA11, PA12, PA9},
1415
gpio::gpiob::{PB0, PB1},
@@ -19,11 +20,16 @@ use stm32f0xx_hal::{
1920
serial,
2021
};
2122

22-
use cortex_m::interrupt::free as disable_interrupts;
23+
use neotron_bmc as _;
24+
use neotron_bmc::monotonic::{Instant, Tim3Monotonic, U16Ext};
2325

26+
/// Version string auto-generated by git.
2427
static VERSION: &'static str = include_str!(concat!(env!("OUT_DIR"), "/version.txt"));
2528

29+
/// At what rate do we blink the status LED when we're running?
2630
const LED_PERIOD_MS: u16 = 1000;
31+
32+
/// How often we poll the power and reset buttons in milliseconds.
2733
const DEBOUNCE_POLL_INTERVAL_MS: u16 = 75;
2834

2935
/// The states we can be in controlling the DC power
@@ -63,6 +69,12 @@ const APP: () = {
6369
dc_power_enabled: DcPowerState,
6470
}
6571

72+
/// The entry point to our application.
73+
///
74+
/// Sets up the hardware and spawns the regular tasks.
75+
///
76+
/// * Task `led_status_blink` - blinks the LED
77+
/// * Task `button_poll` - checks the power and reset buttons
6678
#[init(spawn = [led_status_blink, button_poll])]
6779
fn init(ctx: init::Context) -> init::LateResources {
6880
defmt::info!("Neotron BMC version {:?} booting", VERSION);
@@ -136,6 +148,10 @@ const APP: () = {
136148
}
137149
}
138150

151+
/// Our idle task.
152+
///
153+
/// This task is called when there is nothing else to do. We
154+
/// do a little logging, then put the CPU to sleep waiting for an interrupt.
139155
#[idle(resources = [])]
140156
fn idle(_ctx: idle::Context) -> ! {
141157
defmt::info!("Idle is running...");
@@ -145,6 +161,10 @@ const APP: () = {
145161
}
146162
}
147163

164+
/// This is the USART1 task.
165+
///
166+
/// It fires whenever there is new data received on USART1. We should flag to the host
167+
/// that data is available.
148168
#[task(binds = USART1, resources=[serial])]
149169
fn usart1_interrupt(ctx: usart1_interrupt::Context) {
150170
// Reading the register clears the RX-Not-Empty-Interrupt flag.
@@ -158,6 +178,10 @@ const APP: () = {
158178
}
159179
}
160180

181+
/// This is the LED blink task.
182+
///
183+
/// This task is called periodically. We check whether the status LED is currently on or off,
184+
/// and set it to the opposite. This makes the LED blink.
161185
#[task(schedule = [led_status_blink], resources = [led_status])]
162186
fn led_status_blink(ctx: led_status_blink::Context) {
163187
// Use the safe local `static mut` of RTIC
@@ -177,6 +201,9 @@ const APP: () = {
177201
ctx.schedule.led_status_blink(next).unwrap();
178202
}
179203

204+
/// This task polls our power and reset buttons.
205+
///
206+
/// We poll them rather than setting up an interrupt as we need to debounce them, which involves waiting a short period and checking them again. Given that we have to do that, we might as well not bother with the interrupt.
180207
#[task(schedule = [button_poll], resources = [led_power, button_power, button_power_short_press, button_power_long_press, dc_power_enabled])]
181208
fn button_poll(ctx: button_poll::Context) {
182209
// Poll button
@@ -244,11 +271,7 @@ const APP: () = {
244271
}
245272
};
246273

247-
#[exception]
248-
unsafe fn DefaultHandler(value: i16) {
249-
defmt::panic!("DefaultHandler({})", value);
250-
}
251-
274+
// TODO: Pins we haven't used yet
252275
// SPI pins
253276
// spi_clk: gpioa.pa5.into_alternate_af0(cs),
254277
// spi_cipo: gpioa.pa6.into_alternate_af0(cs),

0 commit comments

Comments
 (0)