Mod Library
Sun Devil Rocketry's hardware agnostic utility library
Loading...
Searching...
No Matches
debug_sdr.h File Reference

: Interfaces for debugging SDR embedded firmware. More...

#include <stdbool.h>
#include <stdio.h>
#include "main.h"

Go to the source code of this file.

Classes

struct  _DEBUG_HANDLE

Macros

#define DEBUG_INTF_BUF_SIZE   2048
#define DEBUG_MSG_PREAMBLE_MAX_LEN   22
#define DEBUG_MSG_MAX_LEN   128
#define DEBUG_MSG_USER_MAX_LEN   (DEBUG_MSG_MAX_LEN - DEBUG_MSG_PREAMBLE_MAX_LEN)
#define debug_assert(condition, error)
 Call error_fail_fast in debug builds when the condition is false, and ignore otherwise.
#define debug_log_assert(condition, msg, level)
 Log a message in debug builds when the condition is false, and ignore otherwise.
#define debug_log_msg(msg, level)
 Log a message in debug builds, and ignore otherwise.
#define debug_ignore_emulator_warnings_start()
 Ignore certain emulator-only cross-architecture compiler warnings. Must pair with the stop macro.
#define debug_ignore_emulator_warnings_stop()
 Ignore certain emulator-only cross-architecture compiler warnings. Must come after the start macro.

Typedefs

typedef void(*) debug_write_callback(void *, size_t)
typedef void(*) overflow_callback(const char *, size_t)
typedef struct _DEBUG_HANDLE DEBUG_HANDLE
typedef enum _DEBUG_STATUS DEBUG_STATUS
typedef enum _DEBUG_LEVEL DEBUG_LEVEL

Enumerations

enum  _DEBUG_STATUS { DEBUG_OK = 0 , DEBUG_FAIL , DEBUG_OVERFLOW }
enum  _DEBUG_LEVEL { LOG_LVL_INFO , LOG_LVL_WARN , LOG_LVL_ERROR }

Functions

DEBUG_STATUS debug_init (debug_write_callback write_function, overflow_callback overflow_function)
 Initializes the debug module.
void debug_clear (void)
 Reset the circular buffer.
DEBUG_STATUS debug_log (const char *message, size_t len, DEBUG_LEVEL log_level)
 Add to the debug buffer.
void debug_callback_handler (void)
 The function to call after a write completes.

Detailed Description

: Interfaces for debugging SDR embedded firmware.

Copyright (c) 2026 Sun Devil Rocketry. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is covered under the
BSD-3-Clause.

https://opensource.org/license/bsd-3-clause

==============================================================================
                    ##### Debug module features #####
==============================================================================
[..]
(+) Write to a logging interface
******************************************************************************

Macro Definition Documentation

◆ debug_assert

#define debug_assert ( condition,
error )
Value:
do { if ( !(condition) ) error_fail_fast( error ); } while(0)
void error_fail_fast(volatile ERROR_CODE error_code)
Dispatches an error to its registered callback or default handler.
Definition error_sdr.c:104

Call error_fail_fast in debug builds when the condition is false, and ignore otherwise.

Parameters
conditionA predicate that evaluates to TRUE or FALSE.
errorThe error code to log.

◆ debug_ignore_emulator_warnings_start

#define debug_ignore_emulator_warnings_start ( )

Ignore certain emulator-only cross-architecture compiler warnings. Must pair with the stop macro.

Parameters
msgThe message to log.
levelThe severity of the message to log.

◆ debug_ignore_emulator_warnings_stop

#define debug_ignore_emulator_warnings_stop ( )

Ignore certain emulator-only cross-architecture compiler warnings. Must come after the start macro.

Parameters
msgThe message to log.
levelThe severity of the message to log.

◆ debug_log_assert

#define debug_log_assert ( condition,
msg,
level )
Value:
do { if ( !(condition) ) debug_log(msg, strlen(msg), level); } while(0)
DEBUG_STATUS debug_log(const char *message, size_t len, DEBUG_LEVEL log_level)
Add to the debug buffer.
Definition debug_sdr.c:144

Log a message in debug builds when the condition is false, and ignore otherwise.

Parameters
conditionA predicate that evaluates to TRUE or FALSE.
msgThe message to log.
levelThe severity of the message to log.

◆ debug_log_msg

#define debug_log_msg ( msg,
level )
Value:
do { debug_log(msg, strlen(msg), level); } while(0)

Log a message in debug builds, and ignore otherwise.

Parameters
msgThe message to log.
levelThe severity of the message to log.

Function Documentation

◆ debug_init()

DEBUG_STATUS debug_init ( debug_write_callback write_function,
overflow_callback overflow_function )

Initializes the debug module.

This function should be called before any other in the debug module, as it initializes pointers and buffers to their correct values.

Parameters
write_functionCallback to the function that writes over the debug interface.
overflow_functionCallback to the function that handles the buffer running out of space.

Pass (void*)NULL as the overflow callback if you want to use the default overflow handler.

Returns
The status of the debug module.

◆ debug_log()

DEBUG_STATUS debug_log ( const char * message,
size_t len,
DEBUG_LEVEL log_level )

Add to the debug buffer.

Note
Use the macros unless you know what you're doing!
Parameters
messageA C-string with the message you want to send.
lenThe length of the message you want to send.
log_levelThe severity of the debug message.
Returns
The status of the debug module.