ChaosDMX
Open-Source DMX-Interface
Loading...
Searching...
No Matches
system.c File Reference
#include "system.h"
#include "logger.h"
#include <stdio.h>
#include <string.h>
#include "driver/temperature_sensor.h"
#include "esp_app_desc.h"
#include "esp_chip_info.h"
#include "esp_heap_caps.h"
#include "esp_mac.h"
#include "esp_system.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "system_version.h"
Include dependency graph for system.c:

Go to the source code of this file.

Macros

#define LOG_TAG   "SYSTEM"
 Log tag for the system component.

Functions

esp_err_t system_init (void)
 Initializes the system monitoring component. Sets up the internal temperature sensor and tracks initial values.
float system_get_temperature (void)
 Gets the current internal CPU temperature.
float system_get_max_temperature (void)
 Gets the highest recorded CPU temperature since boot.
uint32_t system_get_free_heap (void)
 Gets the current available free heap size (RAM).
uint32_t system_get_min_free_heap (void)
 Gets the minimum ever free heap size since boot (watermark). This is crucial for detecting close-to-OOM (Out Of Memory) conditions.
uint8_t system_get_cpu_usage (void)
 Calculates the total real-time CPU utilization. Requires CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS to be enabled.
void system_get_tasks_list (char *buffer, size_t buffer_len)
 Formats raw FreeRTOS statistics into a human-readable task list. Requires CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS to be enabled. Writes a table containing task names, status, priority, and remaining stack space.
const char * system_get_version (void)
 Gets the active firmware build version. Matches the Git commit short hash (appends '-d' if local modifications exist).
int64_t system_get_uptime_ms (void)
 Gets the system uptime since boot.
int system_get_reset_reason (void)
 Gets the reason for the last system reset.
void system_get_chip_info (sys_chip_info_t *chip_info)
 Retrieves static chip hardware information.
void system_print_info (void)
 Prints a complete, formatted overview of all system statistics to the console. Internally uses ESP_LOGI or printf to output a comprehensive snapshot of the device status.

Variables

static temperature_sensor_handle_t temp_sensor = NULL
 Handle for the internal temperature sensor.
static float max_measured_temp = -100.0f
 Highest measured temperature since boot.

Macro Definition Documentation

◆ LOG_TAG

#define LOG_TAG   "SYSTEM"

Log tag for the system component.

Definition at line 2 of file system.c.

Function Documentation

◆ system_get_chip_info()

void system_get_chip_info ( sys_chip_info_t * chip_info)

Retrieves static chip hardware information.

Parameters
[out]chip_infoPointer to the structure to be filled with chip details.

Definition at line 124 of file system.c.

References sys_chip_info_t::cores, sys_chip_info_t::model_name, and sys_chip_info_t::revision.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_get_cpu_usage()

uint8_t system_get_cpu_usage ( void )

Calculates the total real-time CPU utilization. Requires CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS to be enabled.

Returns
Current CPU usage as a percentage (0 to 100).

Definition at line 75 of file system.c.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_get_free_heap()

uint32_t system_get_free_heap ( void )

Gets the current available free heap size (RAM).

Returns
Available heap size in bytes.

Definition at line 69 of file system.c.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_get_max_temperature()

float system_get_max_temperature ( void )

Gets the highest recorded CPU temperature since boot.

Returns
The maximum temperature in degrees Celsius.

Definition at line 64 of file system.c.

References max_measured_temp, and system_get_temperature().

Referenced by system_print_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ system_get_min_free_heap()

uint32_t system_get_min_free_heap ( void )

Gets the minimum ever free heap size since boot (watermark). This is crucial for detecting close-to-OOM (Out Of Memory) conditions.

Returns
Minimum free heap size in bytes.

Definition at line 71 of file system.c.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_get_reset_reason()

int system_get_reset_reason ( void )

Gets the reason for the last system reset.

Returns
The reset reason code (maps to esp_reset_reason_t).

Definition at line 122 of file system.c.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_get_tasks_list()

void system_get_tasks_list ( char * buffer,
size_t buffer_len )

Formats raw FreeRTOS statistics into a human-readable task list. Requires CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS to be enabled. Writes a table containing task names, status, priority, and remaining stack space.

Warning
vTaskList does not perform bounds checking. Ensure the buffer is large enough (at least 40 bytes per task).
Parameters
[out]bufferDestination character buffer to write the table string.
[in]buffer_lenSize of the destination buffer in bytes.

Definition at line 106 of file system.c.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_get_temperature()

float system_get_temperature ( void )

Gets the current internal CPU temperature.

Returns
The current temperature in degrees Celsius, or 0.0f if the sensor is uninitialized.

Definition at line 50 of file system.c.

References max_measured_temp, and temp_sensor.

Referenced by system_get_max_temperature(), and system_print_info().

Here is the caller graph for this function:

◆ system_get_uptime_ms()

int64_t system_get_uptime_ms ( void )

Gets the system uptime since boot.

Returns
Total uptime in milliseconds.

Definition at line 120 of file system.c.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_get_version()

const char * system_get_version ( void )

Gets the active firmware build version. Matches the Git commit short hash (appends '-d' if local modifications exist).

Returns
Pointer to a null-terminated string containing the version.

Definition at line 118 of file system.c.

Referenced by system_print_info().

Here is the caller graph for this function:

◆ system_init()

esp_err_t system_init ( void )

Initializes the system monitoring component. Sets up the internal temperature sensor and tracks initial values.

Returns
ESP_OK on success, or an appropriate error code on failure.

Definition at line 27 of file system.c.

References LOGE, LOGI, LOGW, max_measured_temp, and temp_sensor.

Referenced by app_main().

Here is the caller graph for this function:

◆ system_print_info()

void system_print_info ( void )

Prints a complete, formatted overview of all system statistics to the console. Internally uses ESP_LOGI or printf to output a comprehensive snapshot of the device status.

Definition at line 162 of file system.c.

References sys_chip_info_t::cores, LOGI, sys_chip_info_t::model_name, sys_chip_info_t::revision, system_get_chip_info(), system_get_cpu_usage(), system_get_free_heap(), system_get_max_temperature(), system_get_min_free_heap(), system_get_reset_reason(), system_get_tasks_list(), system_get_temperature(), system_get_uptime_ms(), and system_get_version().

Referenced by app_main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ max_measured_temp

float max_measured_temp = -100.0f
static

Highest measured temperature since boot.

Definition at line 25 of file system.c.

Referenced by system_get_max_temperature(), system_get_temperature(), and system_init().

◆ temp_sensor

temperature_sensor_handle_t temp_sensor = NULL
static

Handle for the internal temperature sensor.

Definition at line 23 of file system.c.

Referenced by system_get_temperature(), and system_init().