forked from espressif/esp-idf
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:
@@ -50,6 +50,7 @@
|
|||||||
#include "mbport.h"
|
#include "mbport.h"
|
||||||
#include "driver/timer.h"
|
#include "driver/timer.h"
|
||||||
#include "port_serial_slave.h"
|
#include "port_serial_slave.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#ifdef CONFIG_FMB_TIMER_PORT_ENABLED
|
#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 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 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 -----------------------------*/
|
/* ----------------------- Start implementation -----------------------------*/
|
||||||
static void IRAM_ATTR vTimerGroupIsr(void *param)
|
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).",
|
"failure to set alarm failure, timer_set_alarm_value() returned (0x%x).",
|
||||||
(uint32_t)xErr);
|
(uint32_t)xErr);
|
||||||
// Register ISR for timer
|
// 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,
|
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
|
||||||
"timer set value failure, timer_isr_register() returned (0x%x).",
|
"timer set value failure, timer_isr_register() returned (0x%x).",
|
||||||
(uint32_t)xErr);
|
(uint32_t)xErr);
|
||||||
@@ -142,6 +145,6 @@ void vMBPortTimerClose(void)
|
|||||||
#ifdef CONFIG_FMB_TIMER_PORT_ENABLED
|
#ifdef CONFIG_FMB_TIMER_PORT_ENABLED
|
||||||
ESP_ERROR_CHECK(timer_pause(usTimerGroupIndex, usTimerIndex));
|
ESP_ERROR_CHECK(timer_pause(usTimerGroupIndex, usTimerIndex));
|
||||||
ESP_ERROR_CHECK(timer_disable_intr(usTimerGroupIndex, usTimerIndex));
|
ESP_ERROR_CHECK(timer_disable_intr(usTimerGroupIndex, usTimerIndex));
|
||||||
|
ESP_ERROR_CHECK(esp_intr_free(xTimerIntHandle));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,16 +51,15 @@
|
|||||||
#define MB_TIMER_WITH_RELOAD (1)
|
#define MB_TIMER_WITH_RELOAD (1)
|
||||||
|
|
||||||
// Timer group and timer number to measure time (configurable in KConfig)
|
// Timer group and timer number to measure time (configurable in KConfig)
|
||||||
#define MB_TIMER_INDEX CONFIG_FMB_TIMER_INDEX
|
#define MB_TIMER_INDEX (CONFIG_FMB_TIMER_INDEX)
|
||||||
#define MB_TIMER_GROUP CONFIG_FMB_TIMER_GROUP
|
#define MB_TIMER_GROUP (CONFIG_FMB_TIMER_GROUP)
|
||||||
|
|
||||||
#define MB_TIMER_IO_LED 0
|
|
||||||
|
|
||||||
/* ----------------------- Variables ----------------------------------------*/
|
/* ----------------------- Variables ----------------------------------------*/
|
||||||
static USHORT usT35TimeOut50us;
|
static USHORT usT35TimeOut50us;
|
||||||
|
|
||||||
static const USHORT usTimerIndex = MB_TIMER_INDEX; // Initialize Modbus Timer index used by stack,
|
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 const USHORT usTimerGroupIndex = MB_TIMER_GROUP; // Timer group index used by stack
|
||||||
|
static timer_isr_handle_t xTimerIntHandle; // Timer interrupt handle
|
||||||
|
|
||||||
/* ----------------------- static functions ---------------------------------*/
|
/* ----------------------- static functions ---------------------------------*/
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
|
|||||||
(uint32_t)xErr);
|
(uint32_t)xErr);
|
||||||
// Register ISR for timer
|
// Register ISR for timer
|
||||||
xErr = timer_isr_register(usTimerGroupIndex, usTimerIndex,
|
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,
|
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
|
||||||
"timer set value failure, timer_isr_register() returned (0x%x).",
|
"timer set value failure, timer_isr_register() returned (0x%x).",
|
||||||
(uint32_t)xErr);
|
(uint32_t)xErr);
|
||||||
@@ -146,7 +145,7 @@ static BOOL xMBMasterPortTimersEnable(USHORT usTimerTics50us)
|
|||||||
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
|
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
|
||||||
"timer start failure, timer_start() returned (0x%x).",
|
"timer start failure, timer_start() returned (0x%x).",
|
||||||
(uint32_t)xErr);
|
(uint32_t)xErr);
|
||||||
//ESP_LOGD(MB_PORT_TAG,"%s Init timer.", __func__);
|
ESP_LOGD(MB_PORT_TAG,"%s Init timer.", __func__);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,4 +192,5 @@ void vMBMasterPortTimerClose(void)
|
|||||||
{
|
{
|
||||||
ESP_ERROR_CHECK(timer_pause(usTimerGroupIndex, usTimerIndex));
|
ESP_ERROR_CHECK(timer_pause(usTimerGroupIndex, usTimerIndex));
|
||||||
ESP_ERROR_CHECK(timer_disable_intr(usTimerGroupIndex, usTimerIndex));
|
ESP_ERROR_CHECK(timer_disable_intr(usTimerGroupIndex, usTimerIndex));
|
||||||
}
|
ESP_ERROR_CHECK(esp_intr_free(xTimerIntHandle));
|
||||||
|
}
|
@@ -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_MASTER_CHECK((mb_error == MB_ENOERR), ESP_ERR_INVALID_STATE,
|
||||||
"mb stack close failure returned (0x%x).", (uint32_t)mb_error);
|
"mb stack close failure returned (0x%x).", (uint32_t)mb_error);
|
||||||
free(mbm_interface_ptr); // free the memory allocated for options
|
free(mbm_interface_ptr); // free the memory allocated for options
|
||||||
|
mbm_interface_ptr = NULL;
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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_SLAVE_CHECK((mb_error == MB_ENOERR), ESP_ERR_INVALID_STATE,
|
||||||
"mb stack close failure returned (0x%x).", (uint32_t)mb_error);
|
"mb stack close failure returned (0x%x).", (uint32_t)mb_error);
|
||||||
free(mbs_interface_ptr);
|
free(mbs_interface_ptr);
|
||||||
|
mbs_interface_ptr = NULL;
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,16 +59,16 @@ static void* sense_modbus_get_param_data(const mb_parameter_descriptor_t* param_
|
|||||||
switch(param_descriptor->mb_param_type)
|
switch(param_descriptor->mb_param_type)
|
||||||
{
|
{
|
||||||
case MB_PARAM_HOLDING:
|
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;
|
break;
|
||||||
case MB_PARAM_INPUT:
|
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;
|
break;
|
||||||
case MB_PARAM_COIL:
|
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;
|
break;
|
||||||
case MB_PARAM_DISCRETE:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
instance_ptr = NULL;
|
instance_ptr = NULL;
|
||||||
|
Reference in New Issue
Block a user