Verified Commit 1536da34 authored by Rahix's avatar Rahix
Browse files

feat(epicardium): Add a panic() function

In unrecoverable situations we should provide a common way to output the
cause of the error and then reset the CPU.  The panic() function is
mean to be exactly that.  It outputs the error-cause, stack-trace, and
firmware revision, accompanied by a link to the issue-tracker to
encourage people to report the error.  After a timeout of ~1.5s it
resets the CPU and reboots.

Future Work:

 - Right now, the stack-trace only has a depth of one which is the
   return address from where panic() was called.  In the future it might
   make sense to provide a deeper stack-trace if a robust implementation
   is possible.
 - Integration of @msgctl

's faultscreen (!79) so users who don't have
   the serial console open at all times can also see what happened.
Signed-off-by: Rahix's avatarRahix <>
parent 5e25bc89
......@@ -14,6 +14,7 @@ module_sources = files(
......@@ -8,6 +8,10 @@
#include <stdint.h>
#include <stdbool.h>
/* ---------- Panic -------------------------------------------------------- */
void panic(const char *format, ...)
__attribute__((noreturn, format(printf, 1, 2)));
/* ---------- Dispatcher --------------------------------------------------- */
void vApiDispatcher(void *pvParameters);
void dispatcher_mutex_init(void);
* Panic
* =====
* Under some conditions the firmware should crash and reboot automatically.
* This module provides the necessary facilities to do so.
* Note that a panic should indicate **only** logic-errors in the firmware or
* unrecoverable hardware conditions.
#include "modules/log.h"
#include "modules/modules.h"
#include "card10.h"
#include "card10-version.h"
#include <stdio.h>
#include <stdarg.h>
void __attribute__((noreturn)) panic(const char *format, ...)
/* Turn off interrupts. We won't get back from here anyway. */
__asm volatile("cpsid i" ::: "memory");
* Turn off asynchronous printing because that won't ever work from
* here ...
printf("\x1b[31;1m --- SYSTEM PANIC ---\n"
"\x1b[0;31m --- ---\n"
" --- ---\n"
"\x1b[0m A fatal error occured:\n \x1b[1m");
va_list ap;
va_start(ap, format);
vprintf(format, ap);
" Firmware Version:\n"
"\x1b[35m %s\n",
" Stack Trace:\n"
"\x1b[36m %p\n",
" Please report this error to the card10 firmware team!\n"
"\x1b[0m -> <-\n"
"\x1b[31m --- ====== ===== ---\x1b[0m\n");
for (int i = 0; i < 96000000; i++) {
__asm volatile("nop");
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment