|
stm32-async-1wire 3.2.0
Non-blocking 1-Wire master for STM32 with DS18B20 temperature and DS2431 EEPROM drivers
|
1-Wire signal statistics — optional compile-in module. More...
Go to the source code of this file.
Data Structures | |
| struct | ow_stats_sensor_t |
| Per-sensor statistics record. More... | |
| struct | ow_stats_t |
| Aggregate statistics context. More... | |
Macros | |
| #define | OW_STATS_MAX_SENSORS 8 |
| #define | OW_STATS_HIST_BUCKETS 16 |
Functions | |
| void | ow_stats_init (void) |
| Zero-initialise the statistics context. | |
| void | ow_stats_capture_pulse (const volatile uint8_t *pulse, uint8_t n, const uint8_t *rom) |
| Snapshot raw pulse durations before decode_scratchpad(). | |
| void | ow_stats_count_error (int16_t error, const uint8_t *rom) |
| Record an error event. | |
| void | ow_stats_capture_overrun (void) |
| Record a capture overrun (TIMx_SR.CC4OF). | |
| void | ow_stats_dump_start (void) |
| Begin a non-blocking stats dump via UART. | |
| uint8_t | ow_stats_dump_poll (void) |
| Advance the non-blocking stats dump by one line. | |
| void | ow_stats_reset (void) |
| Reset all counters and histogram, keep sensor ROM table. | |
| uint32_t | ow_stats_tick (void) |
| Increment the cycle counter (called from the demo callback). | |
Output callbacks (weak, user-provided) | |
The statistics dump module needs a minimal UART output interface. Default weak implementations in ow_stats.c do nothing; the user supplies strong definitions to enable the dump. Only needed when OW_STATS_ENABLE is 1. | |
| void | ow_stats_putchar (char c) |
| Write a single character to the output. | |
| void | ow_stats_puts (const char *s) |
| Write a NUL-terminated string to the output. | |
| void | ow_stats_print_int (int32_t v) |
| Write a signed integer in decimal to the output. | |
| void | ow_stats_print_hex (uint8_t v) |
| Write a byte as two hex digits to the output. | |
| void | ow_stats_tx_enqueue (char c) |
| Enqueue a single character into the TX ring buffer (non-blocking). | |
1-Wire signal statistics — optional compile-in module.
Collects per-sensor pulse-width statistics, a global pulse histogram, and error counters. Enabled by setting OW_STATS_ENABLE to 1 at build time (e.g. -DOW_STATS_ENABLE=1). When the macro is 0, every inline body compiles away to nothing so there is zero overhead in production builds.
The dump is non-blocking: ow_stats_dump_start() initiates it, ow_stats_dump_poll() advances the dump by one line per main-loop call.
| #define OW_STATS_HIST_BUCKETS 16 |
Number of histogram buckets (logarithmic, 0–60+ us).
| #define OW_STATS_MAX_SENSORS 8 |
Maximum number of sensors tracked simultaneously.
| void ow_stats_capture_overrun | ( | void | ) |
Record a capture overrun (TIMx_SR.CC4OF).
Called by the port when a capture event arrived before the DMA read the previous one. A failed Search ROM that returns 0 devices with the FNV-1a offset basis (811C9DC5) looks like an empty bus; this counter separates the two on a board where the DMA counters are not readable.
| void ow_stats_capture_pulse | ( | const volatile uint8_t * | pulse, |
| uint8_t | n, | ||
| const uint8_t * | rom ) |
Snapshot raw pulse durations before decode_scratchpad().
| [in] | pulse | Pointer to the capture buffer (one captured pulse duration per bit slot). |
| [in] | n | Number of pulse slots (typically DS18B20_SCRATCHPAD_BITS = 72). |
| [in] | rom | 8-byte ROM of the current sensor, or NULL for Skip ROM. |
The function copies pulse data into the histogram and updates per-sensor min/max counters. Must be called BEFORE decode_scratchpad() overwrites the buffer via the union alias.
| void ow_stats_count_error | ( | int16_t | error, |
| const uint8_t * | rom ) |
Record an error event.
| [in] | error | The ds18b20 error code (DS18B20_TEMP_ERROR_*). |
| [in] | rom | 8-byte ROM of the current sensor, or NULL for Skip ROM. |
| uint8_t ow_stats_dump_poll | ( | void | ) |
Advance the non-blocking stats dump by one line.
Outputs one sensor line (or the header/histogram/total) per call into the non-blocking UART TX ring buffer. The main loop drains the ring via uart_poll_tx() (this function never calls it). Call repeatedly from the main loop until it returns 1.
| void ow_stats_dump_start | ( | void | ) |
Begin a non-blocking stats dump via UART.
Initiates the dump; call ow_stats_dump_poll() from the main loop to advance it by one line per iteration. Returns immediately.
| void ow_stats_init | ( | void | ) |
Zero-initialise the statistics context.
| void ow_stats_print_hex | ( | uint8_t | v | ) |
Write a byte as two hex digits to the output.
| void ow_stats_print_int | ( | int32_t | v | ) |
Write a signed integer in decimal to the output.
| void ow_stats_putchar | ( | char | c | ) |
Write a single character to the output.
| void ow_stats_puts | ( | const char * | s | ) |
Write a NUL-terminated string to the output.
| void ow_stats_reset | ( | void | ) |
Reset all counters and histogram, keep sensor ROM table.
| uint32_t ow_stats_tick | ( | void | ) |
Increment the cycle counter (called from the demo callback).
| void ow_stats_tx_enqueue | ( | char | c | ) |
Enqueue a single character into the TX ring buffer (non-blocking).