Skip to content

Commit be880a1

Browse files
chinglee-iotaggargActoryOu
authored
Fix portSET_INTERRUPT_MASK_FROM_ISR definition for atomic operation (#940)
* Introduce portHAS_NESTED_INTERRUPTS to identify if port has nested interrupt or not. * Update atomic.h to use portHAS_NESTED_INTERRUPTS instead of portSET_INTERRUPT_MASK_FROM_ISR definition. --------- Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]> Co-authored-by: ActoryOu <[email protected]>
1 parent 75c4044 commit be880a1

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

.github/.cSpellWords.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ brhi
5959
brne
6060
bswtrg
6161
BSWTRG
62+
Bytesto
6263
CANEN
6364
CANRX
6465
CANTX
@@ -89,13 +90,16 @@ CKGR
8990
CKLO
9091
CKPS
9192
CLDIV
93+
CLEARINTENA
9294
CLKA
9395
CLKB
96+
CLKDIS
9497
CLKEN
9598
clki
9699
CLKI
97100
CLKP
98101
CLKS
102+
CLKSOURCE
99103
CLKSTA
100104
CLRB
101105
CLRF
@@ -690,6 +694,7 @@ Rsvd
690694
RTAR
691695
RTCEN
692696
RTCSC
697+
RTICTL
693698
RTIE
694699
RTIF
695700
RTIFRC
@@ -713,6 +718,7 @@ RXRSM
713718
RXSETUP
714719
RXSUSP
715720
RXSYN
721+
RXTDIS
716722
RXTEN
717723
RXUBR
718724
SBYCR
@@ -726,6 +732,7 @@ SECU
726732
SENDA
727733
SETB
728734
SETEN
735+
SETINTENA
729736
SETPSW
730737
SETR
731738
setvect
@@ -849,6 +856,7 @@ TXVC
849856
TXVDIS
850857
UDCP
851858
uncrustify
859+
UNDADD
852860
UNRE
853861
unsuspended
854862
URAD
@@ -867,6 +875,7 @@ VDDCORE
867875
vect
868876
VECT
869877
VECTACTIVE
878+
VECTKEY
870879
visualisation
871880
vldmdbeq
872881
vldmia

include/FreeRTOS.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,36 @@
509509

510510
#endif /* configUSE_TIMERS */
511511

512+
#ifndef portHAS_NESTED_INTERRUPTS
513+
#if defined( portSET_INTERRUPT_MASK_FROM_ISR ) && defined( portCLEAR_INTERRUPT_MASK_FROM_ISR )
514+
#define portHAS_NESTED_INTERRUPTS 1
515+
#else
516+
#define portHAS_NESTED_INTERRUPTS 0
517+
#endif
518+
#endif
519+
512520
#ifndef portSET_INTERRUPT_MASK_FROM_ISR
513-
#define portSET_INTERRUPT_MASK_FROM_ISR() 0
521+
#if ( portHAS_NESTED_INTERRUPTS == 1 )
522+
#error portSET_INTERRUPT_MASK_FROM_ISR must be defined for ports that support nested interrupts (i.e. portHAS_NESTED_INTERRUPTS is set to 1)
523+
#else
524+
#define portSET_INTERRUPT_MASK_FROM_ISR() 0
525+
#endif
526+
#else
527+
#if ( portHAS_NESTED_INTERRUPTS == 0 )
528+
#error portSET_INTERRUPT_MASK_FROM_ISR must not be defined for ports that do not support nested interrupts (i.e. portHAS_NESTED_INTERRUPTS is set to 0)
529+
#endif
514530
#endif
515531

516532
#ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR
517-
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) ( uxSavedStatusValue )
533+
#if ( portHAS_NESTED_INTERRUPTS == 1 )
534+
#error portCLEAR_INTERRUPT_MASK_FROM_ISR must be defined for ports that support nested interrupts (i.e. portHAS_NESTED_INTERRUPTS is set to 1)
535+
#else
536+
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) ( uxSavedStatusValue )
537+
#endif
538+
#else
539+
#if ( portHAS_NESTED_INTERRUPTS == 0 )
540+
#error portCLEAR_INTERRUPT_MASK_FROM_ISR must not be defined for ports that do not support nested interrupts (i.e. portHAS_NESTED_INTERRUPTS is set to 0)
541+
#endif
518542
#endif
519543

520544
#ifndef portCLEAN_UP_TCB

include/atomic.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
* This file implements atomic functions by disabling interrupts globally.
3434
* Implementations with architecture specific atomic instructions can be
3535
* provided under each compiler directory.
36+
*
37+
* The atomic interface can be used in FreeRTOS tasks on all FreeRTOS ports. It
38+
* can also be used in Interrupt Service Routines (ISRs) on FreeRTOS ports that
39+
* support nested interrupts (i.e. portHAS_NESTED_INTERRUPTS is set to 1). The
40+
* atomic interface must not be used in ISRs on FreeRTOS ports that do not
41+
* support nested interrupts (i.e. portHAS_NESTED_INTERRUPTS is set to 0)
42+
* because ISRs on these ports cannot be interrupted and therefore, do not need
43+
* atomics in ISRs.
3644
*/
3745

3846
#ifndef ATOMIC_H
@@ -59,7 +67,7 @@
5967
* ATOMIC_ENTER_CRITICAL().
6068
*
6169
*/
62-
#if defined( portSET_INTERRUPT_MASK_FROM_ISR )
70+
#if ( portHAS_NESTED_INTERRUPTS == 1 )
6371

6472
/* Nested interrupt scheme is supported in this port. */
6573
#define ATOMIC_ENTER_CRITICAL() \

portable/GCC/RISC-V/portmacro.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ extern void vTaskSwitchContext( void );
111111
/* Critical section management. */
112112
#define portCRITICAL_NESTING_IN_TCB 0
113113

114-
#define portSET_INTERRUPT_MASK_FROM_ISR() 0
115-
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue
116-
117114
#define portDISABLE_INTERRUPTS() __asm volatile ( "csrc mstatus, 8" )
118115
#define portENABLE_INTERRUPTS() __asm volatile ( "csrs mstatus, 8" )
119116

portable/IAR/RISC-V/portmacro.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ extern void vTaskSwitchContext( void );
113113
/* Critical section management. */
114114
#define portCRITICAL_NESTING_IN_TCB 0
115115

116-
#define portSET_INTERRUPT_MASK_FROM_ISR() 0
117-
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue
118-
119116
#define portDISABLE_INTERRUPTS() __disable_interrupt()
120117
#define portENABLE_INTERRUPTS() __enable_interrupt()
121118

portable/ThirdParty/xClang/XCOREAI/portmacro.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@
139139
#define portSET_INTERRUPT_MASK() rtos_interrupt_mask_all()
140140
#define portCLEAR_INTERRUPT_MASK( ulState ) rtos_interrupt_mask_set( ulState )
141141

142-
#define portSET_INTERRUPT_MASK_FROM_ISR() ( 0 )
143-
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) ( ( void ) x )
144-
145142
/*
146143
* Will enable interrupts if ulState is non-zero.
147144
*/

0 commit comments

Comments
 (0)