Merge branch 'bugfix/freemodbus_fix_destroy_functions' into 'master'

freemodbus: fix a bug with destroy function of modbus controller and timer port

Closes IDFGH-2056

See merge request espressif/esp-idf!6493
This commit is contained in:
Ivan Grokhotkov
2019-10-31 23:23:24 +08:00
5 changed files with 18 additions and 14 deletions

View File

@@ -50,6 +50,7 @@
#include "mbport.h"
#include "driver/timer.h"
#include "port_serial_slave.h"
#include "sdkconfig.h"
#ifdef CONFIG_FMB_TIMER_PORT_ENABLED
@@ -63,6 +64,7 @@
static const USHORT usTimerIndex = CONFIG_FMB_TIMER_INDEX; // Modbus Timer index used by stack
static const USHORT usTimerGroupIndex = CONFIG_FMB_TIMER_GROUP; // Modbus Timer group index used by stack
static timer_isr_handle_t xTimerIntHandle; // Timer interrupt handle
/* ----------------------- Start implementation -----------------------------*/
static void IRAM_ATTR vTimerGroupIsr(void *param)
@@ -109,7 +111,8 @@ BOOL xMBPortTimersInit(USHORT usTim1Timerout50us)
"failure to set alarm failure, timer_set_alarm_value() returned (0x%x).",
(uint32_t)xErr);
// Register ISR for timer
xErr = timer_isr_register(usTimerGroupIndex, usTimerIndex, vTimerGroupIsr, (void*)(uint32_t)usTimerIndex, ESP_INTR_FLAG_IRAM, NULL);
xErr = timer_isr_register(usTimerGroupIndex, usTimerIndex, vTimerGroupIsr,
(void*)(uint32_t)usTimerIndex, ESP_INTR_FLAG_LOWMED, &xTimerIntHandle);
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
"timer set value failure, timer_isr_register() returned (0x%x).",
(uint32_t)xErr);
@@ -142,6 +145,6 @@ 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(esp_intr_free(xTimerIntHandle));
#endif
}

View File

@@ -51,16 +51,15 @@
#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
#define MB_TIMER_IO_LED 0
#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; // 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
/* ----------------------- static functions ---------------------------------*/
@@ -110,7 +109,7 @@ BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
(uint32_t)xErr);
// Register ISR for timer
xErr = timer_isr_register(usTimerGroupIndex, usTimerIndex,
vTimerGroupIsr, (void*)(uint32_t)usTimerIndex, ESP_INTR_FLAG_IRAM, NULL);
vTimerGroupIsr, (void*)(uint32_t)usTimerIndex, ESP_INTR_FLAG_LOWMED, &xTimerIntHandle);
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
"timer set value failure, timer_isr_register() returned (0x%x).",
(uint32_t)xErr);
@@ -146,7 +145,7 @@ static BOOL xMBMasterPortTimersEnable(USHORT usTimerTics50us)
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
"timer start failure, timer_start() returned (0x%x).",
(uint32_t)xErr);
//ESP_LOGD(MB_PORT_TAG,"%s Init timer.", __func__);
ESP_LOGD(MB_PORT_TAG,"%s Init timer.", __func__);
return TRUE;
}
@@ -193,4 +192,5 @@ void vMBMasterPortTimerClose(void)
{
ESP_ERROR_CHECK(timer_pause(usTimerGroupIndex, usTimerIndex));
ESP_ERROR_CHECK(timer_disable_intr(usTimerGroupIndex, usTimerIndex));
}
ESP_ERROR_CHECK(esp_intr_free(xTimerIntHandle));
}

View File

@@ -140,6 +140,7 @@ static esp_err_t mbc_serial_master_destroy(void)
MB_MASTER_CHECK((mb_error == MB_ENOERR), ESP_ERR_INVALID_STATE,
"mb stack close failure returned (0x%x).", (uint32_t)mb_error);
free(mbm_interface_ptr); // free the memory allocated for options
mbm_interface_ptr = NULL;
return ESP_OK;
}

View File

@@ -133,7 +133,7 @@ static esp_err_t mbc_serial_slave_destroy(void)
MB_SLAVE_CHECK((mb_error == MB_ENOERR), ESP_ERR_INVALID_STATE,
"mb stack close failure returned (0x%x).", (uint32_t)mb_error);
free(mbs_interface_ptr);
mbs_interface_ptr = NULL;
return ESP_OK;
}

View File

@@ -59,16 +59,16 @@ static void* sense_modbus_get_param_data(const mb_parameter_descriptor_t* param_
switch(param_descriptor->mb_param_type)
{
case MB_PARAM_HOLDING:
instance_ptr = (void*)(&holding_reg_params + param_descriptor->param_offset - 1);
instance_ptr = (void*)((uint32_t)&holding_reg_params + param_descriptor->param_offset - 1);
break;
case MB_PARAM_INPUT:
instance_ptr = (void*)(&input_reg_params + param_descriptor->param_offset - 1);
instance_ptr = (void*)((uint32_t)&input_reg_params + param_descriptor->param_offset - 1);
break;
case MB_PARAM_COIL:
instance_ptr = (void*)(&coil_reg_params + param_descriptor->param_offset - 1);
instance_ptr = (void*)((uint32_t)&coil_reg_params + param_descriptor->param_offset - 1);
break;
case MB_PARAM_DISCRETE:
instance_ptr = (void*)(&discrete_reg_params + param_descriptor->param_offset - 1);
instance_ptr = (void*)((uint32_t)&discrete_reg_params + param_descriptor->param_offset - 1);
break;
default:
instance_ptr = NULL;