From f526f19661d5e7200441e37b3e907b1291d543a5 Mon Sep 17 00:00:00 2001 From: TomoYamanaka Date: Thu, 14 Dec 2017 20:29:06 +0900 Subject: [PATCH] Change the way of enter/exit of critical section of code I changed disable_irq() / enable_irq() to core_util_critical_section_enter() / core_util_critical_section_exit() by utilizing "mbed_critical" function in the below drivers. - serial_api.c - us_ticker.c --- .../TARGET_RENESAS/TARGET_RZ_A1H/serial_api.c | 101 ++++-------------- .../TARGET_RENESAS/TARGET_RZ_A1H/us_ticker.c | 13 +-- 2 files changed, 24 insertions(+), 90 deletions(-) diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1H/serial_api.c b/targets/TARGET_RENESAS/TARGET_RZ_A1H/serial_api.c index 3dff1c42d8..0d91ccb88d 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1H/serial_api.c +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1H/serial_api.c @@ -26,6 +26,7 @@ #include "scif_iodefine.h" #include "cpg_iodefine.h" +#include "mbed_critical.h" /****************************************************************************** * INITIALIZATION @@ -510,7 +511,7 @@ static void uart_rx_irq(IRQn_Type irq_num, uint32_t index) { static void uart_err_irq(IRQn_Type irq_num, uint32_t index) { serial_t *obj = uart_data[index].receiving_obj; - int was_masked, err_read; + int err_read; if (obj) { serial_irq_err_set(obj, 0); @@ -525,11 +526,7 @@ static void uart_err_irq(IRQn_Type irq_num, uint32_t index) { } serial_rx_abort_asynch(obj); -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); if (obj->serial.uart->SCFSR & 0x93) { err_read = obj->serial.uart->SCFSR; obj->serial.uart->SCFSR = (err_read & ~0x93); @@ -537,9 +534,7 @@ static void uart_err_irq(IRQn_Type irq_num, uint32_t index) { if (obj->serial.uart->SCLSR & 1) { obj->serial.uart->SCLSR = 0; } - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); } } @@ -679,21 +674,14 @@ static void serial_flow_irq_set(serial_t *obj, uint32_t enable) { int serial_getc(serial_t *obj) { uint16_t err_read; int data; - int was_masked; -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); if (obj->serial.uart->SCFSR & 0x93) { err_read = obj->serial.uart->SCFSR; obj->serial.uart->SCFSR = (err_read & ~0x93); } obj->serial.uart->SCSCR |= 0x0040; // Set RIE - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); if (obj->serial.uart->SCLSR & 0x0001) { obj->serial.uart->SCLSR = 0u; // ORER clear @@ -702,16 +690,10 @@ int serial_getc(serial_t *obj) { while (!serial_readable(obj)); data = obj->serial.uart->SCFRDR & 0xff; -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); err_read = obj->serial.uart->SCFSR; obj->serial.uart->SCFSR = (err_read & 0xfffD); // Clear RDF - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); if (err_read & 0x80) { data = -1; //err @@ -727,20 +709,13 @@ void serial_putc(serial_t *obj, int c) { static void serial_put_done(serial_t *obj) { - int was_masked; volatile uint16_t dummy_read; - -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + + core_util_critical_section_enter(); dummy_read = obj->serial.uart->SCFSR; obj->serial.uart->SCFSR = (dummy_read & 0xff9f); // Clear TEND/TDFE obj->serial.uart->SCSCR |= 0x0080; // Set TIE - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); } int serial_readable(serial_t *obj) { @@ -752,20 +727,13 @@ int serial_writable(serial_t *obj) { } void serial_clear(serial_t *obj) { - int was_masked; -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); obj->serial.uart->SCFCR |= 0x06; // TFRST = 1, RFRST = 1 obj->serial.uart->SCFCR &= ~0x06; // TFRST = 0, RFRST = 0 obj->serial.uart->SCFSR &= ~0x0093u; // ER, BRK, RDF, DR = 0 - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); } void serial_pinout_tx(PinName tx) { @@ -773,62 +741,35 @@ void serial_pinout_tx(PinName tx) { } void serial_break_set(serial_t *obj) { - int was_masked; -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); // TxD Output(L) obj->serial.uart->SCSPTR &= ~0x0001u; // SPB2DT = 0 obj->serial.uart->SCSCR &= ~0x0020u; // TE = 0 (Output disable) - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); } void serial_break_clear(serial_t *obj) { - int was_masked; -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); obj->serial.uart->SCSCR |= 0x0020u; // TE = 1 (Output enable) obj->serial.uart->SCSPTR |= 0x0001u; // SPB2DT = 1 - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); } void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) { // determine the UART to use - int was_masked; serial_flow_irq_set(obj, 0); if (type == FlowControlRTSCTS) { -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); obj->serial.uart->SCFCR = 0x0008u; // CTS/RTS enable - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); pinmap_pinout(rxflow, PinMap_UART_RTS); pinmap_pinout(txflow, PinMap_UART_CTS); } else { -#if defined ( __ICCARM__ ) - was_masked = __disable_irq_iar(); -#else - was_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); obj->serial.uart->SCFCR = 0x0000u; // CTS/RTS diable - if (!was_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); } } diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1H/us_ticker.c b/targets/TARGET_RENESAS/TARGET_RZ_A1H/us_ticker.c index 4d10df8a56..83e58dbe43 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1H/us_ticker.c +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1H/us_ticker.c @@ -21,6 +21,7 @@ #include "RZ_A1_Init.h" #include "MBRZA1H.h" #include "vfp_neon_push_pop.h" +#include "mbed_critical.h" #define US_TICKER_TIMER_IRQn (OSTMI1TINT_IRQn) #define CPG_STBCR5_BIT_MSTP50 (0x01u) /* OSTM1 */ @@ -93,21 +94,13 @@ static void us_ticker_read_last(void) { } uint32_t us_ticker_read() { - int check_irq_masked; - -#if defined ( __ICCARM__) - check_irq_masked = __disable_irq_iar(); -#else - check_irq_masked = __disable_irq(); -#endif /* __ICCARM__ */ + core_util_critical_section_enter(); __vfp_neon_push(); us_ticker_read_last(); __vfp_neon_pop(); - if (!check_irq_masked) { - __enable_irq(); - } + core_util_critical_section_exit(); /* clock to us */ return (uint32_t)ticker_us_last64;