third_party.pigweed.src/pw_assert_basic/docs.rst
Armando Montanez 179aa8eab0 pw_snapshot: Add snapshot proto
Initial commit for the pw_snapshot module that introduces the proto
format for device snapshots, and documentation that introduces the
pw_snapshot module and how to use it.

Change-Id: I63e12d245073e82de03be995a001a0ee0cc1f443
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/38103
Commit-Queue: Armando Montanez <amontanez@google.com>
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: David Rogers <davidrogers@google.com>
2021-04-30 22:46:47 +00:00

69 lines
2.1 KiB
ReStructuredText

.. _module-pw_assert_basic:
===============
pw_assert_basic
===============
--------
Overview
--------
This is a simple assert backend to implement the ``pw_assert`` facade which
relies on a single function ``pw_assert_basic_HandleFailure`` handler facade
which defaults to the ``basic_handler`` backend. Users may be interested in
overriding this default in case they need to do things like transition to
crash time logging or implementing application specific reset and/or hang
behavior.
.. attention::
This log backend comes with a very large ROM and potentially RAM cost. It is
intended mostly for ease of initial bringup. We encourage teams to use
tokenized asserts since they are much smaller both in terms of ROM and RAM.
.. _module-pw_assert_basic-custom_handler:
Custom handler backend example
------------------------------
Here is a typical usage example implementing a simple handler backend which uses
a UART backed sys_io implementation to print during crash time and then reboots.
Note that this example uses CMSIS and a psuedo STM HAL, as a backend implementer
you are responsible for using whatever APIs make sense for your use case(s).
.. code-block:: cpp
#include "cmsis.h"
#include "hal.h"
#include "pw_string/string_builder.h"
using pw::sys_io::WriteLine;
extern "C" void pw_assert_basic_HandleFailure(
[[maybe_unused]] const char* file_name,
[[maybe_unused]] int line_number,
[[maybe_unused]] const char* function_name,
const char* message,
...) {
// Global interrupt disable for a single core microcontroller.
__disable_irq();
// Re-initialize the UART to ensure it's safe to use at crash time.
HAL_UART_DeInit(sys_io_uart);
HAL_UART_Init(sys_io_uart);
WriteLine(
" Welp, that didn't go as planned. "
"It seems we crashed. Terribly sorry! Assert reason:");
{
pw::StringBuffer<150> buffer;
buffer << " ";
va_list args;
va_start(args, format);
buffer.FormatVaList(format, args);
va_end(args);
WriteLine(buffer.view());
}
// Reboot the microcontroller.
HAL_NVIC_SystemReset();
}