forked from espressif/esp-modbus
freemodbus: fix a bug with destroy function of modbus controller and fix port destroy functions
adds timer interrupt handle and free it in vMBXXXPortTimerClose() in master and slave timer port assign modbus controller interface pointer to NULL in destroy function after free * Original commit: espressif/esp-idf@4bac558ab3
This commit is contained in:
@@ -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
|
||||
|
||||
static timg_dev_t *MB_TG[2] = {&TIMERG0, &TIMERG1};
|
||||
|
||||
@@ -121,7 +123,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);
|
||||
@@ -154,6 +157,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
|
||||
}
|
||||
|
||||
|
@@ -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 timg_dev_t *MB_TG[2] = { &TIMERG0, &TIMERG1 };
|
||||
|
||||
@@ -128,7 +127,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);
|
||||
@@ -164,7 +163,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;
|
||||
}
|
||||
|
||||
@@ -211,4 +210,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));
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user