Skip to content
Snippets Groups Projects
Select Git revision
  • 2b12800dfb677d37f808b380c9d9fe2a0fc528ab
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
36 results

panic.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    panic.c 4.50 KiB
    /*
     * 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 "gfx.h"
    #include "display.h"
    #include "LCD_Driver.h"
    
    #include <stdio.h>
    #include <stdarg.h>
    
    static void faultsplash(const char *msg);
    
    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 ...
    	 */
    	serial_return_to_synchronous();
    
    	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);
    	va_end(ap);
    
    	printf("\n"
    	       "\x1b[0m\n"
    	       " Firmware Version:\n"
    	       "\x1b[35m     %s\n",
    	       CARD10_VERSION);
    
    	printf("\x1b[0m\n"
    	       " Stack Trace:\n"
    	       "\x1b[36m     %p\n",
    	       __builtin_return_address(0));
    
    	printf("\x1b[33m\n"
    	       " Please report this error to the card10 firmware team!\n"
    	       "\x1b[0m -> https://git.card10.badge.events.ccc.de/card10/firmware/issues/new <-\n"
    	       "\x1b[31m           --- ====== ===== ---\x1b[0m\n");
    
    	char faultsplash_buffer[14 * 4];
    	va_start(ap, format);
    	vsnprintf(faultsplash_buffer, sizeof(faultsplash_buffer), format, ap);
    	va_end(ap);
    	faultsplash(faultsplash_buffer);
    
    	for (int i = 0; i < 96000000; i++) {