瀏覽代碼

Merge branch 'bugfix/freemodbus_remove_critical_section' into 'master'

freemodbus: Fix remove critical_sections

See merge request idf/esp-idf!4289
Angus Gratton 7 年之前
父節點
當前提交
2f83aea8f3
共有 3 個文件被更改,包括 11 次插入10 次删除
  1. 5 2
      components/freemodbus/port/port.h
  2. 6 6
      components/freemodbus/port/portother.c
  3. 0 2
      components/freemodbus/port/portserial.c

+ 5 - 2
components/freemodbus/port/port.h

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

+ 6 - 6
components/freemodbus/port/portother.c

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

+ 0 - 2
components/freemodbus/port/portserial.c

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