Modbus Vault v1.0
Loading...
Searching...
No Matches
rs485_driver.c File Reference

Implementation of the rs485 driver. More...

#include "rs485_driver.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "hal/uart_ll.h"
#include "runtime_tasks.h"
Include dependency graph for rs485_driver.c:

Macros

#define RS485_DRIVER_WAIT_ON_RX_QUEUE_MS   (10U)
 

Functions

static void rs485_driver_task (void *parameters_void_ptr)
 RS485 Driver task.
 
static void rs485_driver_stop_task (void)
 Stop event bus task.
 
esp_err_t rs485_driver_init (rs485_driver_t *rs485_drv_ptr, const rs485_driver_config_t *config_ptr)
 Initialize RS485 driver.
 
uint8_t rs485_driver_get_bits_count (rs485_driver_t *rs485_drv_ptr)
 Get frame bits count.
 
void rs485_driver_deinit (rs485_driver_t *rs485_drv_ptr)
 De-initialize RS485 driver.
 

Variables

static const char * TAG = "RS485_DRIVER"
 
static TaskHandle_t rs485_driver_task_handle = NULL
 
runtime_task_config_t rs485_driver_task_config
 

Detailed Description

Implementation of the rs485 driver.

  • Configured as a passive listener, receive only mode
  • Driver event task wait on UART events passing them to callback function

Macro Definition Documentation

◆ RS485_DRIVER_WAIT_ON_RX_QUEUE_MS

#define RS485_DRIVER_WAIT_ON_RX_QUEUE_MS   (10U)

Wait on receiver queue timeout in milli-seconds

Function Documentation

◆ rs485_driver_deinit()

void rs485_driver_deinit ( rs485_driver_t rs485_drv_ptr)

De-initialize RS485 driver.

Parameters
rs485_drv_ptrPointer to RS485 driver structure
Here is the caller graph for this function:

◆ rs485_driver_get_bits_count()

uint8_t rs485_driver_get_bits_count ( rs485_driver_t rs485_drv_ptr)

Get frame bits count.

Parameters
rs485_drv_ptrPointer to RS485 driver structure
Returns
uint8_t Frame bits count
Note
Only call this function after driver initialization otherwise return is unpredictable
Here is the caller graph for this function:

◆ rs485_driver_init()

esp_err_t rs485_driver_init ( rs485_driver_t rs485_drv_ptr,
const rs485_driver_config_t config_ptr 
)

Initialize RS485 driver.

Parameters
rs485_drv_ptrPointer to RS485 driver structure
config_ptrPointer to RS485 driver configuration structure
Returns
esp_err_t Initialize result
Return values
ESP_OKInitialize success
ESP_FAILInitialize fail
ESP_ERR_INVALID_ARGProvided invalid argument(s)
ESP_ERR_NO_MEMNo available memory for resource allocation
Note
  • Driver doesn't use Tx pin as it act as a sniffer only
    • Pin is set as UART_PIN_NO_CHANGE
    • Mode is set to UART_MODE_RS485_APP_CTRL
UART RX FIFO FULL threshold is set to 128. For typical Modbus 8 to 256 Bytes is typical 128 characters is a practical value in-between and less than driver's event data buffer
UART RX timeout threshold is set to 4 closest integer to 3.5 characters Inter-frame timeout of practical Modbus transaction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rs485_driver_task()

static void rs485_driver_task ( void *  parameters_void_ptr)
static

RS485 Driver task.

Parameters
parameters_void_ptrVoid pointer to parameters
Note
Call callback function if available on data/error ready
Old data in queue is dropped in case of overflow
Driver provides raw byte stream only with 4 characters timeout, so, frame boundaries must be reconstructed at higher layers

Variable Documentation

◆ rs485_driver_task_config

runtime_task_config_t rs485_driver_task_config
Initial value:
.arg = NULL,
.stop_func = rs485_driver_stop_task}
static TaskHandle_t rs485_driver_task_handle
Definition rs485_driver.c:24
static void rs485_driver_task(void *parameters_void_ptr)
RS485 Driver task.
Definition rs485_driver.c:38
static void rs485_driver_stop_task(void)
Stop event bus task.
Definition rs485_driver.c:121
#define RS485_DRIVER_TASK_PRIORITY
Definition rs485_driver.h:22
#define RS485_DRIVER_TASK_CPU_AFFINITY
Definition rs485_driver.h:23
#define RS485_DRIVER_TASK_STACK_DEPTH
Definition rs485_driver.h:21
#define RS485_DRIVER_TASK_NAME
Definition rs485_driver.h:20

RS485 Driver task configuration structure

◆ rs485_driver_task_handle

TaskHandle_t rs485_driver_task_handle = NULL
static

RS485 Driver task handle

◆ TAG

const char* TAG = "RS485_DRIVER"
static

RS485 Driver TAG name