Skip to content

Commit

Permalink
Merge pull request #1036 from tock/panic-at-the-disco
Browse files Browse the repository at this point in the history
kernel: allow multiple LEDs for panic blinks
  • Loading branch information
ppannuto committed Jun 27, 2018
2 parents 8bc5ce8 + 5d6be29 commit ea2a2ce
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion boards/ek-tm4c1294xl/src/io.rs
Expand Up @@ -44,5 +44,5 @@ impl Write for Writer {
pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
let led = &mut led::LedLow::new(&mut tm4c129x::gpio::PF[0]);
let writer = &mut WRITER;
debug::panic(led, writer, pi, &cortexm4::support::nop)
debug::panic(&mut [led], writer, pi, &cortexm4::support::nop)
}
2 changes: 1 addition & 1 deletion boards/hail/src/io.rs
Expand Up @@ -51,5 +51,5 @@ pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {

let led_red = &mut led::LedLow::new(&mut sam4l::gpio::PA[13]);
let writer = &mut WRITER;
debug::panic(led_red, writer, pi, &cortexm4::support::nop)
debug::panic(&mut [led_red], writer, pi, &cortexm4::support::nop)
}
2 changes: 1 addition & 1 deletion boards/imix/src/io.rs
Expand Up @@ -42,5 +42,5 @@ impl Write for Writer {
pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
let led = &mut led::LedLow::new(&mut sam4l::gpio::PC[10]);
let writer = &mut WRITER;
debug::panic(led, writer, pi, &cortexm4::support::nop)
debug::panic(&mut [led], writer, pi, &cortexm4::support::nop)
}
2 changes: 1 addition & 1 deletion boards/launchxl/src/io.rs
Expand Up @@ -41,5 +41,5 @@ pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {

let led = &mut led::LedLow::new(&mut cc26xx::gpio::PORT[LED_PIN]);
let writer = &mut WRITER;
debug::panic(led, writer, pi, &cortexm4::support::nop)
debug::panic(&mut [led], writer, pi, &cortexm4::support::nop)
}
2 changes: 1 addition & 1 deletion boards/nordic/nrf51dk/src/io.rs
Expand Up @@ -44,5 +44,5 @@ pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
const LED1_PIN: usize = 21;
let led = &mut led::LedLow::new(&mut nrf5x::gpio::PORT[LED1_PIN]);
let writer = &mut WRITER;
debug::panic(led, writer, pi, &cortexm0::support::nop)
debug::panic(&mut [led], writer, pi, &cortexm0::support::nop)
}
2 changes: 1 addition & 1 deletion boards/nordic/nrf52840dk/src/io.rs
Expand Up @@ -44,5 +44,5 @@ pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
const LED1_PIN: usize = 13;
let led = &mut led::LedLow::new(&mut nrf5x::gpio::PORT[LED1_PIN]);
let writer = &mut WRITER;
debug::panic(led, writer, pi, &cortexm4::support::nop)
debug::panic(&mut [led], writer, pi, &cortexm4::support::nop)
}
2 changes: 1 addition & 1 deletion boards/nordic/nrf52dk/src/io.rs
Expand Up @@ -44,5 +44,5 @@ pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
const LED1_PIN: usize = 17;
let led = &mut led::LedLow::new(&mut nrf5x::gpio::PORT[LED1_PIN]);
let writer = &mut WRITER;
debug::panic(led, writer, pi, &cortexm4::support::nop)
debug::panic(&mut [led], writer, pi, &cortexm4::support::nop)
}
2 changes: 1 addition & 1 deletion doc/courses/sensys/exercises/board/src/io.rs
Expand Up @@ -51,5 +51,5 @@ pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {

let led_red = &mut led::LedLow::new(&mut sam4l::gpio::PA[13]);
let writer = &mut WRITER;
debug::panic(led_red, writer, pi, &cortexm4::support::nop)
debug::panic(&mut [led_red], writer, pi, &cortexm4::support::nop)
}
22 changes: 14 additions & 8 deletions kernel/src/debug.rs
Expand Up @@ -52,7 +52,7 @@ use returncode::ReturnCode;
///
/// **NOTE:** The supplied `writer` must be synchronous.
pub unsafe fn panic<L: hil::led::Led, W: Write>(
led: &mut L,
leds: &mut [&mut L],
writer: &mut W,
panic_info: &PanicInfo,
nop: &Fn(),
Expand All @@ -62,7 +62,7 @@ pub unsafe fn panic<L: hil::led::Led, W: Write>(
// Flush debug buffer if needed
flush(writer);
panic_process_info(writer);
panic_blink_forever(led)
panic_blink_forever(leds)
}

/// Generic panic entry.
Expand Down Expand Up @@ -124,20 +124,26 @@ pub unsafe fn panic_process_info<W: Write>(writer: &mut W) {
///
/// If a multi-color LED is used for the panic pattern, it is
/// advised to turn off other LEDs before calling this method.
pub fn panic_blink_forever<L: hil::led::Led>(led: &mut L) -> ! {
led.init();
///
/// Generally, boards should blink red during panic if possible,
/// otherwise choose the 'first' or most prominent LED. Some
/// boards may find it appropriate to blink multiple LEDs (e.g.
/// one on the top and one on the bottom), thus this method
/// accepts an array, however most will only need one.
pub fn panic_blink_forever<L: hil::led::Led>(leds: &mut [&mut L]) -> ! {
leds.iter_mut().for_each(|led| led.init());
loop {
for _ in 0..1000000 {
led.on();
leds.iter_mut().for_each(|led| led.on());
}
for _ in 0..100000 {
led.off();
leds.iter_mut().for_each(|led| led.off());
}
for _ in 0..1000000 {
led.on();
leds.iter_mut().for_each(|led| led.on());
}
for _ in 0..500000 {
led.off();
leds.iter_mut().for_each(|led| led.off());
}
}
}
Expand Down

0 comments on commit ea2a2ce

Please sign in to comment.