Create fatal component to handle fatal errors
This commit is contained in:
parent
cc020d12bf
commit
ae1d470b4b
5
components/fatal/CMakeLists.txt
Normal file
5
components/fatal/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS "fatal.c"
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES esp_system log
|
||||||
|
)
|
17
components/fatal/fatal.c
Normal file
17
components/fatal/fatal.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fatal.h"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
|
||||||
|
#define TAG "Fatal"
|
||||||
|
|
||||||
|
void _fatal(const char *func, const char *file, unsigned line)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "%s() @ %s:%u", func, file, line);
|
||||||
|
while (1) { }
|
||||||
|
}
|
21
components/fatal/fatal.h
Normal file
21
components/fatal/fatal.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
|
*
|
||||||
|
* Fatal error module.
|
||||||
|
*
|
||||||
|
* This small module provides the FATAL() macro, intended to be used
|
||||||
|
* to signal a fatal error. This prompts a system restart.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FATAL_H
|
||||||
|
#define FATAL_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signals a fatal error.
|
||||||
|
*/
|
||||||
|
#define FATAL() _fatal(__func__, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
void _fatal(const char *func, const char *file, unsigned line);
|
||||||
|
|
||||||
|
#endif
|
@ -1 +1,5 @@
|
|||||||
idf_component_register(SRCS "main.c")
|
idf_component_register(
|
||||||
|
SRCS "main.c"
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES fatal
|
||||||
|
)
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
* Copyright (c) Camden Dixie O'Brien
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "fatal.h"
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
FATAL();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user