Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
assert.hpp File Reference

Assert and panic for embedded firmware. More...

Detailed Description

Assert and panic for embedded firmware.

Provides SBL_ASSERT(cond) and SBL_PANIC(msg) macros that output diagnostic info and halt the processor.

The output sink is SBL_FAULT_OUTPUT, a type with static void write(const char*). The default writes nothing: the fault still halts, silently, and needs no hardware. An app that wants the message defines SBL_FAULT_OUTPUT before including this header; the polling UART sink is sbl::uart::FaultOutput in <sbl/hw/hal/uart/log_output.hpp>. Fault handlers run with interrupts off, so the sink must write by polling. For HardFault register dumps, also include <sbl/system/fault.hpp>.

Usage:

void process(float* buf, uint16_t frames) {
SBL_ASSERT(buf != nullptr);
SBL_ASSERT(frames <= 48);
// ...
}
if (something_unrecoverable) {
SBL_PANIC("DMA config failed");
}
Assert and panic for embedded firmware.

Configuration:

SBL_ASSERT_ENABLED - 1 (default) to enable, 0 to compile out
SBL_FAULT_OUTPUT - output sink class (default: a sink that writes nothing)

Definition in file assert.hpp.

#include <cstdint>
#include <sbl/common/log/format.hpp>

Go to the source code of this file.

Namespaces

namespace  sbl
 Root namespace for all Sound Byte Libs code.
 
namespace  sbl::system
 The system layer: execution levels, the control critical section, ring buffers, assertions and the fault handler, profiling, and the port contracts.
 
namespace  sbl::system::fault
 Assertions, panic and the HardFault handler.
 

Macros

#define SBL_FAULT_OUTPUT   sbl::system::fault::detail::NullFaultOutput
 
#define SBL_PANIC(msg)   sbl::system::fault::panic("PANIC: " msg, __FILE__, __LINE__)
 
#define SBL_ASSERT_ENABLED   1
 
#define SBL_ASSERT(cond)   ((void)0)
 

Functions

void sbl::system::fault::panic (const char *msg, const char *file, int line)
 Halt with a diagnostic message. Does not return.
 

Macro Definition Documentation

◆ SBL_FAULT_OUTPUT

#define SBL_FAULT_OUTPUT   sbl::system::fault::detail::NullFaultOutput

Definition at line 54 of file assert.hpp.

◆ SBL_PANIC

#define SBL_PANIC (   msg)    sbl::system::fault::panic("PANIC: " msg, __FILE__, __LINE__)

Definition at line 83 of file assert.hpp.

◆ SBL_ASSERT_ENABLED

#define SBL_ASSERT_ENABLED   1

Definition at line 86 of file assert.hpp.

◆ SBL_ASSERT

#define SBL_ASSERT (   cond)    ((void)0)

Definition at line 97 of file assert.hpp.