stm32-async-1wire 3.2.0
Non-blocking 1-Wire master for STM32 with DS18B20 temperature and DS2431 EEPROM drivers
Loading...
Searching...
No Matches
ow_stats.h File Reference

1-Wire signal statistics — optional compile-in module. More...

#include "ow_config.h"
#include "ow_version.h"
#include <stdint.h>

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).

Detailed Description

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.

Note
RAM cost: ~304 bytes (8 sensors × 28 B + 16-entry uint32_t histogram [64 B] + cycle/error/overrun counters + 8 B of dump state; 13 of the 16 histogram buckets, indices 0–12, are populated).
Emitted by the DS18B20 driver (ds18b20.c): pulse widths, ROM addresses and DS18B20_TEMP_ERROR_* codes are driver-owned concepts, so the driver — not the onewire layer — feeds this module.

Macro Definition Documentation

◆ OW_STATS_HIST_BUCKETS

#define OW_STATS_HIST_BUCKETS   16

Number of histogram buckets (logarithmic, 0–60+ us).

◆ OW_STATS_MAX_SENSORS

#define OW_STATS_MAX_SENSORS   8

Maximum number of sensors tracked simultaneously.

Function Documentation

◆ ow_stats_capture_overrun()

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.

◆ ow_stats_capture_pulse()

void ow_stats_capture_pulse ( const volatile uint8_t * pulse,
uint8_t n,
const uint8_t * rom )

Snapshot raw pulse durations before decode_scratchpad().

Parameters
[in]pulsePointer to the capture buffer (one captured pulse duration per bit slot).
[in]nNumber of pulse slots (typically DS18B20_SCRATCHPAD_BITS = 72).
[in]rom8-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.

◆ ow_stats_count_error()

void ow_stats_count_error ( int16_t error,
const uint8_t * rom )

Record an error event.

Parameters
[in]errorThe ds18b20 error code (DS18B20_TEMP_ERROR_*).
[in]rom8-byte ROM of the current sensor, or NULL for Skip ROM.

◆ ow_stats_dump_poll()

uint8_t ow_stats_dump_poll ( void )

Advance the non-blocking stats dump by one line.

Returns
1 when the dump is complete, 0 if more output remains.

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.

◆ ow_stats_dump_start()

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.

◆ ow_stats_init()

void ow_stats_init ( void )

Zero-initialise the statistics context.

◆ ow_stats_print_hex()

void ow_stats_print_hex ( uint8_t v)

Write a byte as two hex digits to the output.

◆ ow_stats_print_int()

void ow_stats_print_int ( int32_t v)

Write a signed integer in decimal to the output.

◆ ow_stats_putchar()

void ow_stats_putchar ( char c)

Write a single character to the output.

◆ ow_stats_puts()

void ow_stats_puts ( const char * s)

Write a NUL-terminated string to the output.

◆ ow_stats_reset()

void ow_stats_reset ( void )

Reset all counters and histogram, keep sensor ROM table.

◆ ow_stats_tick()

uint32_t ow_stats_tick ( void )

Increment the cycle counter (called from the demo callback).

Returns
The new cycle count.

◆ ow_stats_tx_enqueue()

void ow_stats_tx_enqueue ( char c)

Enqueue a single character into the TX ring buffer (non-blocking).