From 09c3e4080e12a8a421e5d4d9d007a6bbd7fda5ed Mon Sep 17 00:00:00 2001 From: aleks Date: Wed, 26 May 2021 13:46:42 +0200 Subject: [PATCH] modbus: add additional timer group options for master --- components/freemodbus/Kconfig | 23 +++++++++++++++++++---- components/freemodbus/port/portother_m.c | 17 ----------------- components/freemodbus/port/porttimer.c | 3 +-- components/freemodbus/port/porttimer_m.c | 14 +++++--------- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/components/freemodbus/Kconfig b/components/freemodbus/Kconfig index d14a64f499..db8ee25976 100644 --- a/components/freemodbus/Kconfig +++ b/components/freemodbus/Kconfig @@ -159,18 +159,33 @@ menu "Modbus configuration" Else the internal UART TOUT timeout is used for 3.5T symbol time measurement. config FMB_TIMER_GROUP - int "Modbus Timer group number" + int "Slave Timer group number" range 0 1 default 0 help - Modbus Timer group number that is used for timeout measurement. + Modbus slave Timer group number that is used for timeout measurement. config FMB_TIMER_INDEX - int "Modbus Timer index in the group" + int "Slave Timer index in the group" range 0 1 default 0 help - Modbus Timer Index in the group that is used for timeout measurement. + Modbus slave Timer Index in the group that is used for timeout measurement. + + config FMB_MASTER_TIMER_GROUP + int "Master Timer group number" + range 0 1 + default FMB_TIMER_GROUP + help + Modbus master Timer group number that is used for timeout measurement. + + config FMB_MASTER_TIMER_INDEX + int "Master Timer index" + range 0 1 + default FMB_TIMER_INDEX + help + Modbus master Timer Index in the group that is used for timeout measurement. + Note: Modbus master and slave should have different timer index to be able to work simultaneously. config FMB_TIMER_ISR_IN_IRAM bool "Place timer interrupt handler into IRAM" diff --git a/components/freemodbus/port/portother_m.c b/components/freemodbus/port/portother_m.c index ffb0238087..bdc471cf70 100644 --- a/components/freemodbus/port/portother_m.c +++ b/components/freemodbus/port/portother_m.c @@ -55,25 +55,9 @@ /* ----------------------- Modbus includes ----------------------------------*/ /* ----------------------- Variables ----------------------------------------*/ -static UCHAR ucPortMode = 0; /* ----------------------- Start implementation -----------------------------*/ -UCHAR -ucMBPortGetMode( void ) -{ - return ucPortMode; -} - -void -vMBPortSetMode( UCHAR ucMode ) -{ - ENTER_CRITICAL_SECTION(); - ucPortMode = ucMode; - EXIT_CRITICAL_SECTION(); -} - - void vMBMasterPortClose( void ) { @@ -84,4 +68,3 @@ vMBMasterPortClose( void ) vMBMasterPortTimerClose( ); vMBMasterPortEventClose( ); } - diff --git a/components/freemodbus/port/porttimer.c b/components/freemodbus/port/porttimer.c index 246ca335da..2e97b3617b 100644 --- a/components/freemodbus/port/porttimer.c +++ b/components/freemodbus/port/porttimer.c @@ -147,8 +147,7 @@ vMBPortTimersDisable(void) void vMBPortTimerClose(void) { #ifdef CONFIG_FMB_TIMER_PORT_ENABLED - ESP_ERROR_CHECK(timer_pause(usTimerGroupIndex, usTimerIndex)); - ESP_ERROR_CHECK(timer_disable_intr(usTimerGroupIndex, usTimerIndex)); + ESP_ERROR_CHECK(timer_deinit(usTimerGroupIndex, usTimerIndex)); ESP_ERROR_CHECK(esp_intr_free(xTimerIntHandle)); #endif } diff --git a/components/freemodbus/port/porttimer_m.c b/components/freemodbus/port/porttimer_m.c index b0a7f93237..b16bc86c19 100644 --- a/components/freemodbus/port/porttimer_m.c +++ b/components/freemodbus/port/porttimer_m.c @@ -50,16 +50,13 @@ #define MB_TIMER_DIVIDER ((TIMER_BASE_CLK / 1000000UL) * MB_TICK_TIME_US - 1) // divider for 50uS #define MB_TIMER_WITH_RELOAD (1) -// Timer group and timer number to measure time (configurable in KConfig) -#define MB_TIMER_INDEX (CONFIG_FMB_TIMER_INDEX) -#define MB_TIMER_GROUP (CONFIG_FMB_TIMER_GROUP) - /* ----------------------- Variables ----------------------------------------*/ static USHORT usT35TimeOut50us; -static const USHORT usTimerIndex = MB_TIMER_INDEX ^ 1; // Initialize Modbus Timer index used by stack, -static const USHORT usTimerGroupIndex = MB_TIMER_GROUP; // Timer group index used by stack -static timer_isr_handle_t xTimerIntHandle; // Timer interrupt handle +// Initialize Modbus Timer group and index used by stack +static const USHORT usTimerIndex = CONFIG_FMB_MASTER_TIMER_INDEX; +static const USHORT usTimerGroupIndex = CONFIG_FMB_MASTER_TIMER_GROUP; +static timer_isr_handle_t xTimerIntHandle; // Timer interrupt handle /* ----------------------- static functions ---------------------------------*/ @@ -194,7 +191,6 @@ vMBMasterPortTimersDisable() void vMBMasterPortTimerClose(void) { - ESP_ERROR_CHECK(timer_pause(usTimerGroupIndex, usTimerIndex)); - ESP_ERROR_CHECK(timer_disable_intr(usTimerGroupIndex, usTimerIndex)); + ESP_ERROR_CHECK(timer_deinit(usTimerGroupIndex, usTimerIndex)); ESP_ERROR_CHECK(esp_intr_free(xTimerIntHandle)); }