RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
Classes | Namespaces | Macros | Functions | Variables
half_duplex_uart.cpp File Reference
#include <string.h>
#include "esp_types.h"
#include "esp_attr.h"
#include "esp_intr_alloc.h"
#include "esp_log.h"
#include "esp_err.h"
#include "esp_clk.h"
#include "malloc.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/xtensa_api.h"
#include "freertos/task.h"
#include "freertos/ringbuf.h"
#include "soc/dport_reg.h"
#include "soc/uart_struct.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "driver/uart_select.h"
#include "half_duplex_uart.h"

Classes

struct  rb::half_duplex::uart_tx_data_t
 
struct  rb::half_duplex::uart_pat_rb_t
 
struct  rb::half_duplex::uart_obj_t
 

Namespaces

 rb
 The base namespace. Contains some logging functions, too.
 
 rb::half_duplex
 

Macros

#define XOFF   (char)0x13
 
#define XON   (char)0x11
 
#define UART_CHECK(a, str, ret_val)
 
#define UART_EMPTY_THRESH_DEFAULT   (10)
 
#define UART_FULL_THRESH_DEFAULT   (120)
 
#define UART_TOUT_THRESH_DEFAULT   (10)
 
#define UART_CLKDIV_FRAG_BIT_WIDTH   (3)
 
#define UART_TOUT_REF_FACTOR_DEFAULT   (UART_CLK_FREQ/(REF_CLK_FREQ<<UART_CLKDIV_FRAG_BIT_WIDTH))
 
#define UART_TX_IDLE_NUM_DEFAULT   (0)
 
#define UART_PATTERN_DET_QLEN_DEFAULT   (10)
 
#define UART_MIN_WAKEUP_THRESH   (2)
 
#define UART_ENTER_CRITICAL_ISR(mux)   portENTER_CRITICAL_ISR(mux)
 
#define UART_EXIT_CRITICAL_ISR(mux)   portEXIT_CRITICAL_ISR(mux)
 
#define UART_ENTER_CRITICAL(mux)   portENTER_CRITICAL(mux)
 
#define UART_EXIT_CRITICAL(mux)   portEXIT_CRITICAL(mux)
 
#define UART_IS_MODE_SET(uart_number, mode)   ((p_uart_obj[uart_number]->uart_mode == mode))
 

Functions

esp_err_t rb::half_duplex::uart_set_word_length (uart_port_t uart_num, uart_word_length_t data_bit)
 Set UART data bits. More...
 
esp_err_t rb::half_duplex::uart_get_word_length (uart_port_t uart_num, uart_word_length_t *data_bit)
 Get UART data bits. More...
 
esp_err_t rb::half_duplex::uart_set_stop_bits (uart_port_t uart_num, uart_stop_bits_t stop_bits)
 Set UART stop bits. More...
 
esp_err_t rb::half_duplex::uart_get_stop_bits (uart_port_t uart_num, uart_stop_bits_t *stop_bits)
 Get UART stop bits. More...
 
esp_err_t rb::half_duplex::uart_set_parity (uart_port_t uart_num, uart_parity_t parity_mode)
 Set UART parity mode. More...
 
esp_err_t rb::half_duplex::uart_get_parity (uart_port_t uart_num, uart_parity_t *parity_mode)
 Get UART parity mode. More...
 
esp_err_t rb::half_duplex::uart_set_baudrate (uart_port_t uart_num, uint32_t baudrate)
 Set UART baud rate. More...
 
esp_err_t rb::half_duplex::uart_get_baudrate (uart_port_t uart_num, uint32_t *baudrate)
 Get UART baud rate. More...
 
esp_err_t rb::half_duplex::uart_set_line_inverse (uart_port_t uart_num, uint32_t inverse_mask)
 Set UART line inverse mode. More...
 
esp_err_t rb::half_duplex::uart_set_sw_flow_ctrl (uart_port_t uart_num, bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff)
 Set software flow control. More...
 
esp_err_t rb::half_duplex::uart_set_hw_flow_ctrl (uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh)
 Set hardware flow control. More...
 
esp_err_t rb::half_duplex::uart_get_hw_flow_ctrl (uart_port_t uart_num, uart_hw_flowcontrol_t *flow_ctrl)
 Get hardware flow control mode. More...
 
static esp_err_t IRAM_ATTR rb::half_duplex::uart_reset_rx_fifo (uart_port_t uart_num)
 
esp_err_t IRAM_ATTR rb::half_duplex::uart_clear_intr_status (uart_port_t uart_num, uint32_t clr_mask)
 Clear UART interrupt status. More...
 
esp_err_t rb::half_duplex::uart_enable_intr_mask (uart_port_t uart_num, uint32_t enable_mask)
 Set UART interrupt enable. More...
 
esp_err_t rb::half_duplex::uart_disable_intr_mask (uart_port_t uart_num, uint32_t disable_mask)
 Clear UART interrupt enable bits. More...
 
static void IRAM_ATTR rb::half_duplex::uart_disable_intr_mask_from_isr (uart_port_t uart_num, uint32_t disable_mask)
 
static void IRAM_ATTR rb::half_duplex::uart_enable_intr_mask_from_isr (uart_port_t uart_num, uint32_t enable_mask)
 
static esp_err_t rb::half_duplex::uart_pattern_link_free (uart_port_t uart_num)
 
static esp_err_t IRAM_ATTR rb::half_duplex::uart_pattern_enqueue (uart_port_t uart_num, int pos)
 
static esp_err_t rb::half_duplex::uart_pattern_dequeue (uart_port_t uart_num)
 
static esp_err_t rb::half_duplex::uart_pattern_queue_update (uart_port_t uart_num, int diff_len)
 
int rb::half_duplex::uart_pattern_pop_pos (uart_port_t uart_num)
 Return the nearest detected pattern position in buffer. The positions of the detected pattern are saved in a queue, this function will dequeue the first pattern position and move the pointer to next pattern position. More...
 
int rb::half_duplex::uart_pattern_get_pos (uart_port_t uart_num)
 Return the nearest detected pattern position in buffer. The positions of the detected pattern are saved in a queue, This function do nothing to the queue. More...
 
esp_err_t rb::half_duplex::uart_pattern_queue_reset (uart_port_t uart_num, int queue_length)
 Allocate a new memory with the given length to save record the detected pattern position in rx buffer. More...
 
esp_err_t rb::half_duplex::uart_enable_pattern_det_intr (uart_port_t uart_num, char pattern_chr, uint8_t chr_num, int chr_tout, int post_idle, int pre_idle)
 UART enable pattern detect function. Designed for applications like 'AT commands'. When the hardware detect a series of one same character, the interrupt will be triggered. More...
 
esp_err_t rb::half_duplex::uart_disable_pattern_det_intr (uart_port_t uart_num)
 UART disable pattern detect function. Designed for applications like 'AT commands'. When the hardware detects a series of one same character, the interrupt will be triggered. More...
 
esp_err_t rb::half_duplex::uart_enable_rx_intr (uart_port_t uart_num)
 Enable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT) More...
 
esp_err_t rb::half_duplex::uart_disable_rx_intr (uart_port_t uart_num)
 Disable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT) More...
 
esp_err_t rb::half_duplex::uart_disable_tx_intr (uart_port_t uart_num)
 Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT) More...
 
esp_err_t rb::half_duplex::uart_enable_tx_intr (uart_port_t uart_num, int enable, int thresh)
 Enable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT) More...
 
esp_err_t rb::half_duplex::uart_isr_register (uart_port_t uart_num, void(*fn)(void *), void *arg, int intr_alloc_flags, uart_isr_handle_t *handle)
 Register UART interrupt handler (ISR). More...
 
esp_err_t rb::half_duplex::uart_isr_free (uart_port_t uart_num)
 Free UART interrupt handler registered by uart_isr_register. Must be called on the same core as uart_isr_register was called. More...
 
esp_err_t rb::half_duplex::uart_set_pin (uart_port_t uart_num, int tx_io_num, int rx_io_num, int rts_io_num, int cts_io_num)
 Set UART pin number. More...
 
esp_err_t rb::half_duplex::uart_set_rts (uart_port_t uart_num, int level)
 Manually set the UART RTS pin level. More...
 
esp_err_t rb::half_duplex::uart_set_dtr (uart_port_t uart_num, int level)
 Manually set the UART DTR pin level. More...
 
esp_err_t rb::half_duplex::uart_set_tx_idle_num (uart_port_t uart_num, uint16_t idle_num)
 Set UART idle interval after tx FIFO is empty. More...
 
esp_err_t rb::half_duplex::uart_param_config (uart_port_t uart_num, const uart_config_t *uart_config)
 Set UART configuration parameters. More...
 
esp_err_t rb::half_duplex::uart_intr_config (uart_port_t uart_num, const uart_intr_config_t *intr_conf)
 Configure UART interrupts. More...
 
static int rb::half_duplex::uart_find_pattern_from_last (uint8_t *buf, int length, uint8_t pat_chr, int pat_num)
 
static void IRAM_ATTR rb::half_duplex::uart_rx_intr_handler_default (void *param)
 
static int rb::half_duplex::uart_fill_fifo (uart_port_t uart_num, const char *buffer, uint32_t len)
 
int rb::half_duplex::uart_tx_chars (uart_port_t uart_num, const char *buffer, uint32_t len)
 Send data to the UART port from a given buffer and length. More...
 
static bool rb::half_duplex::uart_check_buf_full (uart_port_t uart_num)
 
int rb::half_duplex::uart_read_bytes (uart_port_t uart_num, uint8_t *buf, uint32_t length, TickType_t ticks_to_wait)
 UART read bytes from UART buffer. More...
 
esp_err_t rb::half_duplex::uart_get_buffered_data_len (uart_port_t uart_num, size_t *size)
 UART get RX ring buffer cached data length. More...
 
esp_err_t rb::half_duplex::uart_flush_input (uart_port_t uart_num)
 Clear input buffer, discard all the data is in the ring-buffer. More...
 
esp_err_t rb::half_duplex::uart_flush (uart_port_t uart_num)
 Alias of uart_flush_input. UART ring buffer flush. This will discard all data in the UART RX buffer. More...
 
esp_err_t rb::half_duplex::uart_driver_install (uart_port_t uart_num, int rx_buffer_size, int tx_buffer_size, int queue_size, QueueHandle_t *uart_queue, int intr_alloc_flags)
 Install UART driver. More...
 
esp_err_t rb::half_duplex::uart_driver_delete (uart_port_t uart_num)
 Uninstall UART driver. More...
 
void rb::half_duplex::uart_set_select_notif_callback (uart_port_t uart_num, uart_select_notif_callback_t uart_select_notif_callback)
 
portMUX_TYPE * rb::half_duplex::uart_get_selectlock ()
 
esp_err_t rb::half_duplex::uart_set_mode (uart_port_t uart_num, uart_mode_t mode)
 UART set communication mode. More...
 
esp_err_t rb::half_duplex::uart_set_rx_timeout (uart_port_t uart_num, const uint8_t tout_thresh)
 UART set threshold timeout for TOUT feature. More...
 
esp_err_t rb::half_duplex::uart_get_collision_flag (uart_port_t uart_num, bool *collision_flag)
 Returns collision detection flag for RS485 mode Function returns the collision detection flag into variable pointed by collision_flag. *collision_flag = true, if collision detected else it is equal to false. This function should be executed when actual transmission is completed (after uart_write_bytes()). More...
 
esp_err_t rb::half_duplex::uart_set_wakeup_threshold (uart_port_t uart_num, int wakeup_threshold)
 Set the number of RX pin signal edges for light sleep wakeup. More...
 
esp_err_t rb::half_duplex::uart_get_wakeup_threshold (uart_port_t uart_num, int *out_wakeup_threshold)
 Get the number of RX pin signal edges for light sleep wakeup. More...
 
void rb::half_duplex::uart_set_half_duplex_pin (uart_port_t uart_num, gpio_num_t pin)
 

Variables

static const char * rb::half_duplex::UART_TAG = "uart"
 
static uart_obj_t * rb::half_duplex::p_uart_obj [UART_NUM_MAX] = {0}
 
static DRAM_ATTR uart_dev_t *const rb::half_duplex::UART [UART_NUM_MAX] = {&UART0, &UART1, &UART2}
 
static portMUX_TYPE rb::half_duplex::uart_spinlock [UART_NUM_MAX] = {portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED}
 
static portMUX_TYPE rb::half_duplex::uart_selectlock = portMUX_INITIALIZER_UNLOCKED
 

Macro Definition Documentation

◆ UART_CHECK

#define UART_CHECK (   a,
  str,
  ret_val 
)
Value:
if (!(a)) { \
ESP_LOGE(UART_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
return (ret_val); \
}
static const char * UART_TAG
Definition: half_duplex_uart.cpp:59

◆ UART_CLKDIV_FRAG_BIT_WIDTH

#define UART_CLKDIV_FRAG_BIT_WIDTH   (3)

◆ UART_EMPTY_THRESH_DEFAULT

#define UART_EMPTY_THRESH_DEFAULT   (10)

◆ UART_ENTER_CRITICAL

#define UART_ENTER_CRITICAL (   mux)    portENTER_CRITICAL(mux)

◆ UART_ENTER_CRITICAL_ISR

#define UART_ENTER_CRITICAL_ISR (   mux)    portENTER_CRITICAL_ISR(mux)

◆ UART_EXIT_CRITICAL

#define UART_EXIT_CRITICAL (   mux)    portEXIT_CRITICAL(mux)

◆ UART_EXIT_CRITICAL_ISR

#define UART_EXIT_CRITICAL_ISR (   mux)    portEXIT_CRITICAL_ISR(mux)

◆ UART_FULL_THRESH_DEFAULT

#define UART_FULL_THRESH_DEFAULT   (120)

◆ UART_IS_MODE_SET

#define UART_IS_MODE_SET (   uart_number,
  mode 
)    ((p_uart_obj[uart_number]->uart_mode == mode))

◆ UART_MIN_WAKEUP_THRESH

#define UART_MIN_WAKEUP_THRESH   (2)

◆ UART_PATTERN_DET_QLEN_DEFAULT

#define UART_PATTERN_DET_QLEN_DEFAULT   (10)

◆ UART_TOUT_REF_FACTOR_DEFAULT

#define UART_TOUT_REF_FACTOR_DEFAULT   (UART_CLK_FREQ/(REF_CLK_FREQ<<UART_CLKDIV_FRAG_BIT_WIDTH))

◆ UART_TOUT_THRESH_DEFAULT

#define UART_TOUT_THRESH_DEFAULT   (10)

◆ UART_TX_IDLE_NUM_DEFAULT

#define UART_TX_IDLE_NUM_DEFAULT   (0)

◆ XOFF

#define XOFF   (char)0x13

◆ XON

#define XON   (char)0x11