Skip to content

Commit aa696dc

Browse files
TomoYamanakaadbridge
authored andcommitted
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
1 parent 127b039 commit aa696dc

File tree

2 files changed

+24
-90
lines changed

2 files changed

+24
-90
lines changed

targets/TARGET_RENESAS/TARGET_RZ_A1H/serial_api.c

Lines changed: 21 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "scif_iodefine.h"
2828
#include "cpg_iodefine.h"
29+
#include "mbed_critical.h"
2930

3031
/******************************************************************************
3132
* INITIALIZATION
@@ -510,7 +511,7 @@ static void uart_rx_irq(IRQn_Type irq_num, uint32_t index) {
510511

511512
static void uart_err_irq(IRQn_Type irq_num, uint32_t index) {
512513
serial_t *obj = uart_data[index].receiving_obj;
513-
int was_masked, err_read;
514+
int err_read;
514515

515516
if (obj) {
516517
serial_irq_err_set(obj, 0);
@@ -525,21 +526,15 @@ static void uart_err_irq(IRQn_Type irq_num, uint32_t index) {
525526
}
526527
serial_rx_abort_asynch(obj);
527528

528-
#if defined ( __ICCARM__ )
529-
was_masked = __disable_irq_iar();
530-
#else
531-
was_masked = __disable_irq();
532-
#endif /* __ICCARM__ */
529+
core_util_critical_section_enter();
533530
if (obj->serial.uart->SCFSR & 0x93) {
534531
err_read = obj->serial.uart->SCFSR;
535532
obj->serial.uart->SCFSR = (err_read & ~0x93);
536533
}
537534
if (obj->serial.uart->SCLSR & 1) {
538535
obj->serial.uart->SCLSR = 0;
539536
}
540-
if (!was_masked) {
541-
__enable_irq();
542-
}
537+
core_util_critical_section_exit();
543538
}
544539
}
545540

@@ -679,21 +674,14 @@ static void serial_flow_irq_set(serial_t *obj, uint32_t enable) {
679674
int serial_getc(serial_t *obj) {
680675
uint16_t err_read;
681676
int data;
682-
int was_masked;
683677

684-
#if defined ( __ICCARM__ )
685-
was_masked = __disable_irq_iar();
686-
#else
687-
was_masked = __disable_irq();
688-
#endif /* __ICCARM__ */
678+
core_util_critical_section_enter();
689679
if (obj->serial.uart->SCFSR & 0x93) {
690680
err_read = obj->serial.uart->SCFSR;
691681
obj->serial.uart->SCFSR = (err_read & ~0x93);
692682
}
693683
obj->serial.uart->SCSCR |= 0x0040; // Set RIE
694-
if (!was_masked) {
695-
__enable_irq();
696-
}
684+
core_util_critical_section_exit();
697685

698686
if (obj->serial.uart->SCLSR & 0x0001) {
699687
obj->serial.uart->SCLSR = 0u; // ORER clear
@@ -702,16 +690,10 @@ int serial_getc(serial_t *obj) {
702690
while (!serial_readable(obj));
703691
data = obj->serial.uart->SCFRDR & 0xff;
704692

705-
#if defined ( __ICCARM__ )
706-
was_masked = __disable_irq_iar();
707-
#else
708-
was_masked = __disable_irq();
709-
#endif /* __ICCARM__ */
693+
core_util_critical_section_enter();
710694
err_read = obj->serial.uart->SCFSR;
711695
obj->serial.uart->SCFSR = (err_read & 0xfffD); // Clear RDF
712-
if (!was_masked) {
713-
__enable_irq();
714-
}
696+
core_util_critical_section_exit();
715697

716698
if (err_read & 0x80) {
717699
data = -1; //err
@@ -727,20 +709,13 @@ void serial_putc(serial_t *obj, int c) {
727709

728710
static void serial_put_done(serial_t *obj)
729711
{
730-
int was_masked;
731712
volatile uint16_t dummy_read;
732-
733-
#if defined ( __ICCARM__ )
734-
was_masked = __disable_irq_iar();
735-
#else
736-
was_masked = __disable_irq();
737-
#endif /* __ICCARM__ */
713+
714+
core_util_critical_section_enter();
738715
dummy_read = obj->serial.uart->SCFSR;
739716
obj->serial.uart->SCFSR = (dummy_read & 0xff9f); // Clear TEND/TDFE
740717
obj->serial.uart->SCSCR |= 0x0080; // Set TIE
741-
if (!was_masked) {
742-
__enable_irq();
743-
}
718+
core_util_critical_section_exit();
744719
}
745720

746721
int serial_readable(serial_t *obj) {
@@ -752,83 +727,49 @@ int serial_writable(serial_t *obj) {
752727
}
753728

754729
void serial_clear(serial_t *obj) {
755-
int was_masked;
756-
#if defined ( __ICCARM__ )
757-
was_masked = __disable_irq_iar();
758-
#else
759-
was_masked = __disable_irq();
760-
#endif /* __ICCARM__ */
730+
core_util_critical_section_enter();
761731

762732
obj->serial.uart->SCFCR |= 0x06; // TFRST = 1, RFRST = 1
763733
obj->serial.uart->SCFCR &= ~0x06; // TFRST = 0, RFRST = 0
764734
obj->serial.uart->SCFSR &= ~0x0093u; // ER, BRK, RDF, DR = 0
765735

766-
if (!was_masked) {
767-
__enable_irq();
768-
}
736+
core_util_critical_section_exit();
769737
}
770738

771739
void serial_pinout_tx(PinName tx) {
772740
pinmap_pinout(tx, PinMap_UART_TX);
773741
}
774742

775743
void serial_break_set(serial_t *obj) {
776-
int was_masked;
777-
#if defined ( __ICCARM__ )
778-
was_masked = __disable_irq_iar();
779-
#else
780-
was_masked = __disable_irq();
781-
#endif /* __ICCARM__ */
744+
core_util_critical_section_enter();
782745
// TxD Output(L)
783746
obj->serial.uart->SCSPTR &= ~0x0001u; // SPB2DT = 0
784747
obj->serial.uart->SCSCR &= ~0x0020u; // TE = 0 (Output disable)
785-
if (!was_masked) {
786-
__enable_irq();
787-
}
748+
core_util_critical_section_exit();
788749
}
789750

790751
void serial_break_clear(serial_t *obj) {
791-
int was_masked;
792-
#if defined ( __ICCARM__ )
793-
was_masked = __disable_irq_iar();
794-
#else
795-
was_masked = __disable_irq();
796-
#endif /* __ICCARM__ */
752+
core_util_critical_section_enter();
797753
obj->serial.uart->SCSCR |= 0x0020u; // TE = 1 (Output enable)
798754
obj->serial.uart->SCSPTR |= 0x0001u; // SPB2DT = 1
799-
if (!was_masked) {
800-
__enable_irq();
801-
}
755+
core_util_critical_section_exit();
802756
}
803757

804758
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) {
805759
// determine the UART to use
806-
int was_masked;
807760

808761
serial_flow_irq_set(obj, 0);
809762

810763
if (type == FlowControlRTSCTS) {
811-
#if defined ( __ICCARM__ )
812-
was_masked = __disable_irq_iar();
813-
#else
814-
was_masked = __disable_irq();
815-
#endif /* __ICCARM__ */
764+
core_util_critical_section_enter();
816765
obj->serial.uart->SCFCR = 0x0008u; // CTS/RTS enable
817-
if (!was_masked) {
818-
__enable_irq();
819-
}
766+
core_util_critical_section_exit();
820767
pinmap_pinout(rxflow, PinMap_UART_RTS);
821768
pinmap_pinout(txflow, PinMap_UART_CTS);
822769
} else {
823-
#if defined ( __ICCARM__ )
824-
was_masked = __disable_irq_iar();
825-
#else
826-
was_masked = __disable_irq();
827-
#endif /* __ICCARM__ */
770+
core_util_critical_section_enter();
828771
obj->serial.uart->SCFCR = 0x0000u; // CTS/RTS diable
829-
if (!was_masked) {
830-
__enable_irq();
831-
}
772+
core_util_critical_section_exit();
832773
}
833774
}
834775

targets/TARGET_RENESAS/TARGET_RZ_A1H/us_ticker.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "RZ_A1_Init.h"
2222
#include "MBRZA1H.h"
2323
#include "vfp_neon_push_pop.h"
24+
#include "mbed_critical.h"
2425

2526
#define US_TICKER_TIMER_IRQn (OSTMI1TINT_IRQn)
2627
#define CPG_STBCR5_BIT_MSTP50 (0x01u) /* OSTM1 */
@@ -93,21 +94,13 @@ static void us_ticker_read_last(void) {
9394
}
9495

9596
uint32_t us_ticker_read() {
96-
int check_irq_masked;
97-
98-
#if defined ( __ICCARM__)
99-
check_irq_masked = __disable_irq_iar();
100-
#else
101-
check_irq_masked = __disable_irq();
102-
#endif /* __ICCARM__ */
97+
core_util_critical_section_enter();
10398

10499
__vfp_neon_push();
105100
us_ticker_read_last();
106101
__vfp_neon_pop();
107102

108-
if (!check_irq_masked) {
109-
__enable_irq();
110-
}
103+
core_util_critical_section_exit();
111104

112105
/* clock to us */
113106
return (uint32_t)ticker_us_last64;

0 commit comments

Comments
 (0)