|
ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
|
#include "pio_tx_rx_driver.h"#include <assert.h>#include <limits.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include "hardware/gpio.h"#include "hardware/pio.h"#include "hardware/platform_defs.h"#include "hardware/regs/pio.h"#include "pico/time.h"#include "pico/types.h"#include "drivers/gpio_driver.h"#include "drivers/v24_config.h"#include "platform/pinmap.h"#include "system/common.h"#include "led_activity_mirror.pio.h"#include "rck_rxd.pio.h"#include "tck_txd.pio.h"#include "xck_txd.pio.h"
Go to the source code of this file.
Macros | |
| #define | V24_RTS_MIN_HOLDOFF 200U |
| Minimum RTS holdoff in microseconds used as a safety floor. | |
| #define | V24_RTS_HOLDOFF_MARGIN 41U |
| RTS holdoff multiplier in bit-times. The final holdoff is: tx_rts_holdoff_us = margin * t_bit_us. This value was empirically determined to be the most stable for this system. | |
| #define | LED_MIRROR_PIO pio0 |
Functions | |
| const v24_runtime_t * | get_v24_runtime (void) |
| Returns a pointer to the v24 runtime. | |
| uint32_t | tx_clock_get_cts_toggle_seq (void) |
| Read current CTS edge sequence counter. | |
| static void | cts_raw_irq_handler (void) |
| static void | cts_irq_init (void) |
| static gpio_function_t | pio_gpio_func (PIO pio) |
| static float | baud_to_clockdiv (V24_BAUDRATE_T baudrate) |
| void | led_mirror_init (void) |
| Initialize optional LED activity mirror PIO program. | |
| void | reinit_v24_config (V24_CONFIG_T *config, V24_BAUDRATE_T baudrate) |
| Reinitialize V.24 runtime configuration and derived timing values. | |
| void | init_v24_config (V24_CONFIG_T *config, V24_BAUDRATE_T baudrate) |
| Initialize V.24 runtime configuration structure. | |
| bool | rx_clock_poll_stall (void) |
| Poll RX FIFO stall events and update the provided event counter. | |
| bool | rx_get (uint8_t *data) |
| Read one received byte from RX PIO FIFO. | |
| void | rx_clock_update_settings (V24_RX_POLARITIES_T *polarities) |
| Apply RX runtime settings to an already configured RX PIO SM. Take note that this function relies on tx_clock_init being called before. This is asserted in debug builds but otherwise UB in production. | |
| void | rx_clock_hard_reset (void) |
| Disable RX Path, clear fifos, restart SMs and CLKDIV and enable again. | |
| void | rx_clock_init (PIO pio, uint pio_sm, V24_RX_POLARITIES_T *polarities) |
| Initialize RX clock/data PIO state machine. | |
| bool | tx_poll (void) |
| Poll TX completion/holdoff state and manage RTS release. | |
| bool | tx_put (uint8_t data) |
| Queue one byte to the TX PIO FIFO. | |
| void | tx_clock_hard_reset (void) |
| Hard-reset TX SM state to discard queued/in-flight bytes. | |
| void | tx_clock_update_settings (V24_CONFIG_T *config) |
| Apply TX runtime settings to an already configured TX PIO SM. Take note that this function relies on tx_clock_init being called before. This is asserted in debug builds but otherwise UB in production. | |
| static void | tx_clock_init_tck (PIO pio, uint pio_sm, V24_CONFIG_T *config) |
| static void | tx_clock_init_xck (PIO pio, uint pio_sm, V24_CONFIG_T *config) |
| void | tx_clock_init (PIO pio, uint pio_sm, V24_CONFIG_T *config) |
| Initialize TX clock/data PIO state machine. | |
Variables | |
| v24_runtime_t | v24_runtime |
| #define LED_MIRROR_PIO pio0 |
Definition at line 112 of file pio_tx_rx_driver.c.
| #define V24_RTS_HOLDOFF_MARGIN 41U |
RTS holdoff multiplier in bit-times. The final holdoff is: tx_rts_holdoff_us = margin * t_bit_us. This value was empirically determined to be the most stable for this system.
Definition at line 51 of file pio_tx_rx_driver.c.
| #define V24_RTS_MIN_HOLDOFF 200U |
Minimum RTS holdoff in microseconds used as a safety floor.
Definition at line 45 of file pio_tx_rx_driver.c.
|
static |
Definition at line 107 of file pio_tx_rx_driver.c.
References TX_PIO_CYCLES_PER_BIT.
Referenced by tx_clock_init_tck(), and tx_clock_update_settings().

|
static |
Definition at line 77 of file pio_tx_rx_driver.c.
References cts_raw_irq_handler(), and V24_CTS.
Referenced by tx_clock_init().


|
static |
Definition at line 66 of file pio_tx_rx_driver.c.
References v24_runtime_t::cts_toggle_seq, V24_CTS, and v24_runtime.
Referenced by cts_irq_init().

| const v24_runtime_t * get_v24_runtime | ( | void | ) |
Returns a pointer to the v24 runtime.
Definition at line 56 of file pio_tx_rx_driver.c.
References v24_runtime.
Referenced by print_status_event().

| void init_v24_config | ( | V24_CONFIG_T * | config, |
| V24_BAUDRATE_T | baudrate | ||
| ) |
Initialize V.24 runtime configuration structure.
| config | Destination configuration object. |
| baudrate | Initial baudrate. |
Definition at line 164 of file pio_tx_rx_driver.c.
References init_polarities(), V24_CONFIG_T::polarities, and reinit_v24_config().
Referenced by init_app().


| void led_mirror_init | ( | void | ) |
Initialize optional LED activity mirror PIO program.
Definition at line 113 of file pio_tx_rx_driver.c.
References LED_MIRROR_PIO, LOG_ERROR, LOG_INFO, V24_RXD, V24_STATUS_LED, and V24_TXD.
|
static |
Definition at line 93 of file pio_tx_rx_driver.c.
| void reinit_v24_config | ( | V24_CONFIG_T * | config, |
| V24_BAUDRATE_T | baudrate | ||
| ) |
Reinitialize V.24 runtime configuration and derived timing values.
| config | Destination configuration object. |
| baudrate | New baudrate. |
Definition at line 152 of file pio_tx_rx_driver.c.
References V24_CONFIG_T::baudrate, v24_runtime_t::rts_set, v24_runtime_t::tx_rts_holdoff_us, US_PER_SECOND, V24_BAUD_1200, V24_RTS_HOLDOFF_MARGIN, V24_RTS_MIN_HOLDOFF, and v24_runtime.
Referenced by ev_set_v24_settings(), init_app(), and init_v24_config().

| void rx_clock_hard_reset | ( | void | ) |
Disable RX Path, clear fifos, restart SMs and CLKDIV and enable again.
Definition at line 213 of file pio_tx_rx_driver.c.
References v24_runtime_t::rx_pio, v24_runtime_t::rx_sm, and v24_runtime.
Referenced by poll_hdlc_no_progress().

| void rx_clock_init | ( | PIO | pio, |
| uint | pio_sm, | ||
| V24_RX_POLARITIES_T * | polarities | ||
| ) |
Initialize RX clock/data PIO state machine.
| pio | PIO instance. |
| pio_sm | State machine index. |
| polarities | RX signal polarity configuration. |
Definition at line 225 of file pio_tx_rx_driver.c.
References LOG_INFO, rx_clock_update_settings(), v24_runtime_t::rx_pio, v24_runtime_t::rx_sm, v24_runtime, V24_RXC, and V24_RXD.
Referenced by main().


| bool rx_clock_poll_stall | ( | void | ) |
Poll RX FIFO stall events and update the provided event counter.
Definition at line 170 of file pio_tx_rx_driver.c.
References v24_runtime_t::rx_pio, v24_runtime_t::rx_sm, and v24_runtime.
Referenced by event_loop().

| void rx_clock_update_settings | ( | V24_RX_POLARITIES_T * | polarities | ) |
Apply RX runtime settings to an already configured RX PIO SM. Take note that this function relies on tx_clock_init being called before. This is asserted in debug builds but otherwise UB in production.
| polarities | RX polarity settings. |
Definition at line 195 of file pio_tx_rx_driver.c.
References V24_RX_POLARITIES_T::dcd_inverted, v24_runtime_t::rx_pio, v24_runtime_t::rx_sm, V24_RX_POLARITIES_T::rxc_inverted, V24_RX_POLARITIES_T::rxd_inverted, V24_DCD, v24_runtime, V24_RXC, and V24_RXD.
Referenced by ev_set_v24_settings(), and rx_clock_init().

| bool rx_get | ( | uint8_t * | data | ) |
Read one received byte from RX PIO FIFO.
| data | Destination pointer for the received byte. |
Definition at line 184 of file pio_tx_rx_driver.c.
References v24_runtime_t::rx_pio, RX_SHIFT_TO_LSB, v24_runtime_t::rx_sm, and v24_runtime.
Referenced by drain_rx_until_empty().

| uint32_t tx_clock_get_cts_toggle_seq | ( | void | ) |
Read current CTS edge sequence counter.
Definition at line 61 of file pio_tx_rx_driver.c.
References v24_runtime_t::cts_toggle_seq, and v24_runtime.
Referenced by tx_queue_drain().

| void tx_clock_hard_reset | ( | void | ) |
Hard-reset TX SM state to discard queued/in-flight bytes.
Definition at line 322 of file pio_tx_rx_driver.c.
References v24_runtime_t::tx_pio, v24_runtime_t::tx_sm, and v24_runtime.
Referenced by tx_queue_drain().

| void tx_clock_init | ( | PIO | pio, |
| uint | pio_sm, | ||
| V24_CONFIG_T * | config | ||
| ) |
Initialize TX clock/data PIO state machine.
| pio | PIO instance. |
| pio_sm | State machine index. |
| config | V.24 configuration. |
Definition at line 453 of file pio_tx_rx_driver.c.
References cts_irq_init(), V24_CONFIG_T::external_clock, tx_clock_init_tck(), and tx_clock_init_xck().
Referenced by main().


|
static |
Definition at line 376 of file pio_tx_rx_driver.c.
References baud_to_clockdiv(), V24_CONFIG_T::baudrate, LOG_DEBUG, LOG_INFO, tx_clock_update_settings(), v24_runtime_t::tx_pio, v24_runtime_t::tx_rts_holdoff_us, v24_runtime_t::tx_sm, V24_CTS, v24_runtime, V24_TXC_DTE, and V24_TXD.
Referenced by tx_clock_init().


|
static |
Definition at line 415 of file pio_tx_rx_driver.c.
References LOG_DEBUG, LOG_INFO, tx_clock_update_settings(), v24_runtime_t::tx_pio, v24_runtime_t::tx_rts_holdoff_us, v24_runtime_t::tx_sm, V24_CTS, v24_runtime, V24_TXC_DCE, and V24_TXD.
Referenced by tx_clock_init().


| void tx_clock_update_settings | ( | V24_CONFIG_T * | config | ) |
Apply TX runtime settings to an already configured TX PIO SM. Take note that this function relies on tx_clock_init being called before. This is asserted in debug builds but otherwise UB in production.
| config | V.24 configuration. |
Definition at line 337 of file pio_tx_rx_driver.c.
References baud_to_clockdiv(), V24_CONFIG_T::baudrate, V24_TX_POLARITIES_T::cts_inverted, V24_TX_POLARITIES_T::dtr_inverted, V24_CONFIG_T::external_clock, V24_CONFIG_T::polarities, V24_TX_POLARITIES_T::rts_inverted, v24_runtime_t::tx_pio, V24_POLARITIES_T::tx_polarities, v24_runtime_t::tx_sm, V24_TX_POLARITIES_T::txc_inverted, V24_TX_POLARITIES_T::txd_inverted, V24_CTS, V24_DTR, V24_RTS, v24_runtime, V24_TXC_DCE, V24_TXC_DTE, and V24_TXD.
Referenced by ev_set_v24_settings(), tx_clock_init_tck(), and tx_clock_init_xck().


| bool tx_poll | ( | void | ) |
Poll TX completion/holdoff state and manage RTS release.
Definition at line 257 of file pio_tx_rx_driver.c.
References v24_runtime_t::rts_set, v24_runtime_t::tx_pio, v24_runtime_t::tx_rts_holdoff_us, v24_runtime_t::tx_sm, V24_RTS, and v24_runtime.
Referenced by poll_tx_pipeline().

| bool tx_put | ( | uint8_t | data | ) |
Queue one byte to the TX PIO FIFO.
| data | Byte to transmit. |
Definition at line 299 of file pio_tx_rx_driver.c.
References v24_runtime_t::rts_set, v24_runtime_t::tx_pio, v24_runtime_t::tx_sm, V24_RTS, and v24_runtime.
Referenced by tx_queue_drain_bytes().

| v24_runtime_t v24_runtime |
Definition at line 54 of file pio_tx_rx_driver.c.
Referenced by cts_raw_irq_handler(), get_v24_runtime(), print_status_event(), reinit_v24_config(), rx_clock_hard_reset(), rx_clock_init(), rx_clock_poll_stall(), rx_clock_update_settings(), rx_get(), tx_clock_get_cts_toggle_seq(), tx_clock_hard_reset(), tx_clock_init_tck(), tx_clock_init_xck(), tx_clock_update_settings(), tx_poll(), and tx_put().