freemodbus: change critical sections to semaphore mutex

revert changes made in mbrtu.c, mbascii.c
change critical section type to semaphore mutex instead of spin lock

Closes: https://github.com/espressif/esp-idf/issues/3009
This commit is contained in:
aleks 2019-03-07 09:51:25 +01:00
parent e1e82c8949
commit 7342811c37
3 changed files with 11 additions and 10 deletions

View file

@ -60,8 +60,11 @@
#define MB_ENTER_CRITICAL(mux) portENTER_CRITICAL(mux) #define MB_ENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
#define MB_EXIT_CRITICAL(mux) portEXIT_CRITICAL(mux) #define MB_EXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
#define ENTER_CRITICAL_SECTION( ) ( vMBPortEnterCritical() ) #define ENTER_CRITICAL_SECTION( ) { ESP_LOGD(MB_PORT_TAG,"%s: Port enter critical.", __func__); \
#define EXIT_CRITICAL_SECTION( ) ( vMBPortExitCritical() ) vMBPortEnterCritical(); }
#define EXIT_CRITICAL_SECTION( ) { vMBPortExitCritical(); \
ESP_LOGD(MB_PORT_TAG,"%s: Port exit critical", __func__); }
typedef char BOOL; typedef char BOOL;

View file

@ -32,16 +32,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/task.h> #include <freertos/task.h>
#include <freertos/semphr.h>
/* ----------------------- Modbus includes ----------------------------------*/ /* ----------------------- Modbus includes ----------------------------------*/
#include "mb.h" #include "mb.h"
#include "mbport.h" #include "mbport.h"
#include "sys/lock.h"
/* ----------------------- Modbus includes ----------------------------------*/ /* ----------------------- Modbus includes ----------------------------------*/
/* ----------------------- Variables ----------------------------------------*/ /* ----------------------- Variables ----------------------------------------*/
static portMUX_TYPE mb_mutex = portMUX_INITIALIZER_UNLOCKED; static _lock_t s_port_lock;
/* ----------------------- Start implementation -----------------------------*/ /* ----------------------- Start implementation -----------------------------*/
@ -52,16 +52,16 @@ bMBPortIsWithinException( void )
return bIsWithinException; return bIsWithinException;
} }
void inline void
vMBPortEnterCritical( void ) vMBPortEnterCritical( void )
{ {
portENTER_CRITICAL(&mb_mutex); _lock_acquire(&s_port_lock);
} }
void inline void
vMBPortExitCritical( void ) vMBPortExitCritical( void )
{ {
portEXIT_CRITICAL(&mb_mutex); _lock_release(&s_port_lock);
} }
void void

View file

@ -74,7 +74,6 @@ static USHORT uiRxBufferPos = 0; // position in the receiver buffer
void vMBPortSerialEnable(BOOL bRxEnable, BOOL bTxEnable) void vMBPortSerialEnable(BOOL bRxEnable, BOOL bTxEnable)
{ {
// This function can be called from xMBRTUTransmitFSM() of different task // This function can be called from xMBRTUTransmitFSM() of different task
ENTER_CRITICAL_SECTION();
if (bRxEnable) { if (bRxEnable) {
//uart_enable_rx_intr(ucUartNumber); //uart_enable_rx_intr(ucUartNumber);
bRxStateEnabled = TRUE; bRxStateEnabled = TRUE;
@ -88,7 +87,6 @@ void vMBPortSerialEnable(BOOL bRxEnable, BOOL bTxEnable)
} else { } else {
bTxStateEnabled = FALSE; bTxStateEnabled = FALSE;
} }
EXIT_CRITICAL_SECTION();
} }
static void vMBPortSerialRxPoll(size_t xEventSize) static void vMBPortSerialRxPoll(size_t xEventSize)