ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
baudrate_monitor.c File Reference
#include "baudrate_monitor.h"
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "hardware/gpio.h"
#include "hardware/sync.h"
#include "hardware/timer.h"
#include "pico/time.h"
#include "pico/types.h"
#include "platform/pinmap.h"
#include "system/common.h"
Include dependency graph for baudrate_monitor.c:

Go to the source code of this file.

Macros

#define PIN_COUNT   25
 
#define BAUD_STALE_US   50000U
 
#define BAUD_TIMER_MS   20
 
#define BAUD_EMA_ALPHA   0.2F
 

Functions

static void rxc_edge_isr (uint gpio, uint32_t events)
 
float baudrate_estimator_get_current_estimation (V24_PIN_T pin)
 Get latest baudrate estimate.
 
static bool baud_timer_cb (repeating_timer_t *timer)
 
void baudrate_estimator_init (V24_PIN_T pin)
 Initialize baudrate estimator on a specific RX clock pin.
 

Variables

static volatile uint32_t edge_count [PIN_COUNT] = {0}
 
static repeating_timer_t baud_timer
 
static volatile bool baud_ready [PIN_COUNT] = {false}
 
static volatile float baud_hz [PIN_COUNT] = {0.0F}
 
static size_t current_pin_count = 0
 
static volatile uint8_t monitored_pin [PIN_COUNT] = {0}
 
static volatile uint64_t first_edge_time_us [PIN_COUNT] = {0}
 
static volatile uint64_t last_edge_time_us [PIN_COUNT] = {0}
 

Macro Definition Documentation

◆ BAUD_EMA_ALPHA

#define BAUD_EMA_ALPHA   0.2F

Definition at line 40 of file baudrate_monitor.c.

◆ BAUD_STALE_US

#define BAUD_STALE_US   50000U

Definition at line 36 of file baudrate_monitor.c.

◆ BAUD_TIMER_MS

#define BAUD_TIMER_MS   20

Definition at line 38 of file baudrate_monitor.c.

◆ PIN_COUNT

#define PIN_COUNT   25

Definition at line 34 of file baudrate_monitor.c.

Function Documentation

◆ baud_timer_cb()

static bool baud_timer_cb ( repeating_timer_t *  timer)
static

Definition at line 71 of file baudrate_monitor.c.

References BAUD_EMA_ALPHA, baud_hz, baud_ready, BAUD_STALE_US, current_pin_count, edge_count, first_edge_time_us, last_edge_time_us, monitored_pin, and US_PER_SECOND.

Referenced by baudrate_estimator_init().

Here is the caller graph for this function:

◆ baudrate_estimator_get_current_estimation()

float baudrate_estimator_get_current_estimation ( V24_PIN_T  pin)

Get latest baudrate estimate.

Parameters
pinV.24 clock pin being monitored.
Returns
Estimated baudrate in Hz.

Definition at line 65 of file baudrate_monitor.c.

References baud_hz, and baud_ready.

Referenced by print_status_event().

Here is the caller graph for this function:

◆ baudrate_estimator_init()

void baudrate_estimator_init ( V24_PIN_T  pin)

Initialize baudrate estimator on a specific RX clock pin.

Parameters
pinV.24 clock pin to monitor.

Definition at line 118 of file baudrate_monitor.c.

References baud_timer, baud_timer_cb(), BAUD_TIMER_MS, current_pin_count, monitored_pin, PIN_COUNT, and rxc_edge_isr().

Referenced by main().

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

◆ rxc_edge_isr()

static void rxc_edge_isr ( uint  gpio,
uint32_t  events 
)
static

Definition at line 51 of file baudrate_monitor.c.

References edge_count, first_edge_time_us, and last_edge_time_us.

Referenced by baudrate_estimator_init().

Here is the caller graph for this function:

Variable Documentation

◆ baud_hz

volatile float baud_hz[PIN_COUNT] = {0.0F}
static

Definition at line 44 of file baudrate_monitor.c.

Referenced by baud_timer_cb(), and baudrate_estimator_get_current_estimation().

◆ baud_ready

volatile bool baud_ready[PIN_COUNT] = {false}
static

Definition at line 43 of file baudrate_monitor.c.

Referenced by baud_timer_cb(), and baudrate_estimator_get_current_estimation().

◆ baud_timer

repeating_timer_t baud_timer
static

Definition at line 42 of file baudrate_monitor.c.

Referenced by baudrate_estimator_init().

◆ current_pin_count

size_t current_pin_count = 0
static

Definition at line 45 of file baudrate_monitor.c.

Referenced by baud_timer_cb(), and baudrate_estimator_init().

◆ edge_count

volatile uint32_t edge_count[PIN_COUNT] = {0}
static

Definition at line 41 of file baudrate_monitor.c.

Referenced by baud_timer_cb(), and rxc_edge_isr().

◆ first_edge_time_us

volatile uint64_t first_edge_time_us[PIN_COUNT] = {0}
static

Definition at line 48 of file baudrate_monitor.c.

Referenced by baud_timer_cb(), and rxc_edge_isr().

◆ last_edge_time_us

volatile uint64_t last_edge_time_us[PIN_COUNT] = {0}
static

Definition at line 49 of file baudrate_monitor.c.

Referenced by baud_timer_cb(), and rxc_edge_isr().

◆ monitored_pin

volatile uint8_t monitored_pin[PIN_COUNT] = {0}
static

Definition at line 46 of file baudrate_monitor.c.

Referenced by baud_timer_cb(), and baudrate_estimator_init().