Skip to content

Commit

Permalink
Merge branch 'feature/uart_new_critical_section_api' into 'master'
Browse files Browse the repository at this point in the history
driver: added new critical section API to UART driver

See merge request espressif/esp-idf!19678
  • Loading branch information
0xjakob committed Nov 30, 2022
2 parents cb7686e + fd04374 commit 56acd2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions components/driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/ringbuf.h"
#include "esp_private/critical_section.h"
#include "hal/uart_hal.h"
#include "hal/gpio_hal.h"
#include "hal/clk_tree_ll.h"
Expand Down Expand Up @@ -65,20 +66,20 @@ static const char *UART_TAG = "uart";
#endif


#define UART_ENTER_CRITICAL_SAFE(mux) portENTER_CRITICAL_SAFE(mux)
#define UART_EXIT_CRITICAL_SAFE(mux) portEXIT_CRITICAL_SAFE(mux)
#define UART_ENTER_CRITICAL_ISR(mux) portENTER_CRITICAL_ISR(mux)
#define UART_EXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL_ISR(mux)
#define UART_ENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
#define UART_EXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
#define UART_ENTER_CRITICAL_SAFE(spinlock) esp_os_enter_critical_safe(spinlock)
#define UART_EXIT_CRITICAL_SAFE(spinlock) esp_os_exit_critical_safe(spinlock)
#define UART_ENTER_CRITICAL_ISR(spinlock) esp_os_enter_critical_isr(spinlock)
#define UART_EXIT_CRITICAL_ISR(spinlock) esp_os_exit_critical_isr(spinlock)
#define UART_ENTER_CRITICAL(spinlock) esp_os_enter_critical(spinlock)
#define UART_EXIT_CRITICAL(spinlock) esp_os_exit_critical(spinlock)


// Check actual UART mode set
#define UART_IS_MODE_SET(uart_number, mode) ((p_uart_obj[uart_number]->uart_mode == mode))

#define UART_CONTEX_INIT_DEF(uart_num) {\
.hal.dev = UART_LL_GET_HW(uart_num),\
.spinlock = portMUX_INITIALIZER_UNLOCKED,\
INIT_CRIT_SECTION_LOCK_IN_STRUCT(spinlock)\
.hw_enabled = false,\
}

Expand Down Expand Up @@ -150,7 +151,7 @@ typedef struct {

typedef struct {
uart_hal_context_t hal; /*!< UART hal context*/
portMUX_TYPE spinlock;
DECLARE_CRIT_SECTION_LOCK_IN_STRUCT(spinlock)
bool hw_enabled;
} uart_context_t;

Expand Down
6 changes: 3 additions & 3 deletions components/esp_system/include/esp_private/critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
extern "C" {
#endif

#if CONFIG_FREERTOS_UNICORE && !CONFIG_IDF_TARGET_ESP32S2
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2
/**
* This macro also helps users switching between spinlock declarations/definitions for multi-/single core environments
* if the macros below aren't sufficient.
*/
#define OS_SPINLOCK 0
#else
#define OS_SPINLOCK 1
#else
#define OS_SPINLOCK 0
#endif

#if OS_SPINLOCK == 1
Expand Down

0 comments on commit 56acd2e

Please sign in to comment.