Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: allow multiple LEDs for panic blinks #1036

Merged
merged 2 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/ek-tm4c1294xl/src/io.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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