diff --git a/headers/private/kernel/boot/platform/raspberrypi_arm/platform_debug.h b/headers/private/kernel/boot/platform/raspberrypi_arm/platform_debug.h new file mode 100644 index 0000000000..f665bebf7c --- /dev/null +++ b/headers/private/kernel/boot/platform/raspberrypi_arm/platform_debug.h @@ -0,0 +1,45 @@ +/* + * Copyright 2012, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _PLATFORM_DEBUG_H_ +#define _PLATFORM_DEBUG_H_ + +#define DEBUG_DELAY_SHORT 200 +#define DEBUG_DELAY_MEDIUM 500 +#define DEBUG_DELAY_LONG 1000 + +void debug_delay(int time); +void debug_set_led(bool on); + +void debug_toggle_led(int count, int delay = DEBUG_DELAY_MEDIUM); + // Toggles the led count times with the delay for both on and off time. + +void debug_blink_number(int number); + // Implements a blink pattern to output arbitrary numbers: + // + // 1. Led turns off and stays off for a long delay. + // 2. Led blinks x times with a short delay, where x is the current + // decimal place + 1 (so 0 values are easier to see). + // 3. Led stays off for a long delay to indicate the move to the next + // decimal place and step 2. is repeated until all the rest of the + // number is 0. + // 4. The led turns on and stays on with a long delay to indicate finish. + // 5. Led state is reset to the original value. + // + // The lowest decimal is output first, so the number will be reversed. As an + // example the number 205 would be blinked as follows: + // long off (start indicator), 6 blinks (indicating 5), + // long off (moving to next decimal), 1 blink (indicating 0) + // long off (moving to next decimal), 3 blinks (indicating 2) + // long on (finish indicator) + +void debug_halt(); + // Stalls execution in an endless loop. + +void debug_assert(bool condition); + // Flashes the led 20 times rapidly and stalls execution if the condition + // isn't met. + +#endif // _PLATFORM_DEBUG_H_ + diff --git a/src/system/boot/platform/raspberrypi_arm/debug.cpp b/src/system/boot/platform/raspberrypi_arm/debug.cpp index b2a987c757..7fa7ae0c5a 100644 --- a/src/system/boot/platform/raspberrypi_arm/debug.cpp +++ b/src/system/boot/platform/raspberrypi_arm/debug.cpp @@ -6,7 +6,9 @@ * All rights reserved. Distributed under the terms of the MIT License. */ +#include "platform_debug.h" +#include "gpio.h" #include "serial.h" #include @@ -14,6 +16,77 @@ #include +extern addr_t gPeripheralBase; +static bool sLedState = true; + + +void +debug_delay(int time) +{ + for (; time >= 0; time--) + for (int i = 0; i < 10000; i++) + asm volatile ("nop"); +} + + +void +debug_set_led(bool on) +{ + gpio_write(gPeripheralBase + GPIO_BASE, 16, on ? 0 : 1); + sLedState = on; +} + + +void +debug_toggle_led(int count, int delay) +{ + for (count *= 2; count > 0; count--) { + debug_set_led(!sLedState); + debug_delay(delay); + } +} + + +void +debug_blink_number(int number) +{ + bool previousState = sLedState; + + debug_set_led(false); + debug_delay(DEBUG_DELAY_LONG); + + while (number > 0) { + debug_toggle_led(number % 10 + 1, DEBUG_DELAY_SHORT); + debug_delay(DEBUG_DELAY_LONG); + number /= 10; + } + + debug_set_led(true); + debug_delay(DEBUG_DELAY_LONG); + + debug_set_led(previousState); +} + + +void +debug_halt() +{ + while (true) + debug_delay(DEBUG_DELAY_LONG); +} + + +void +debug_assert(bool condition) +{ + if (condition) + return; + + debug_toggle_led(20, 20); + debug_halt(); +} + + extern "C" void panic(const char* format, ...) {