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

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

#include <stdio.h>
#include "main.h"
#include "debug_sdr.h"
#include "error_sdr.h"
#include "timer.h"

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

==============================================================================
                    ##### Integration Guide #####
==============================================================================
[..]
(+) Provide an async debug write callback using debug_init(). If your debug
    write callback is not asynchronous, you risk blocking in the middle of
    a real-time event or otherwise hiding the true performance of the system.
(+) Ensure you call debug_init() in your initialization sequence before ever 
    logging to it. This can be initialized as soon as the debug write interface 
    is initialized, so consider HAL -> debug write intf -> debug module -> rest
    of init to ensure you get useful logging throughout.
(+) Register debug_callback_handler (the callback handler) to your async write 
    function's callback handler.
(+) Optionally, register an overflow handler callback to handle circular buffer
    overflows. This takes the full, constructed message that triggered the 
    overflow as an argument. Pass NULL to use the default handler.
(+) Do not use the _debug functions directly! Use the macros so that you have
    protection against release builds.
(+) If you want to log in release builds, use the error_sdr logging functions.
******************************************************************************

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.