Skip to content

Fix portSET_INTERRUPT_MASK_FROM_ISR definition for atomic operation #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,36 @@

#endif /* configUSE_TIMERS */

#ifndef portHAS_NESTED_INTERRUPTS
#if defined( portSET_INTERRUPT_MASK_FROM_ISR ) && defined( portCLEAR_INTERRUPT_MASK_FROM_ISR )
#define portHAS_NESTED_INTERRUPTS 1
#else
#define portHAS_NESTED_INTERRUPTS 0
#endif
#endif

#ifndef portSET_INTERRUPT_MASK_FROM_ISR
#define portSET_INTERRUPT_MASK_FROM_ISR() 0
#if ( portHAS_NESTED_INTERRUPTS == 1 )
#error portSET_INTERRUPT_MASK_FROM_ISR has to be defined for port supports nested interrupts
#else
#define portSET_INTERRUPT_MASK_FROM_ISR() 0
#endif
#else
#if ( portHAS_NESTED_INTERRUPTS == 0 )
#error portSET_INTERRUPT_MASK_FROM_ISR should not be defined when portHAS_NESTED_INTERRUPTS is set to 0
#endif
#endif

#ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) ( uxSavedStatusValue )
#if ( portHAS_NESTED_INTERRUPTS == 1 )
#error portCLEAR_INTERRUPT_MASK_FROM_ISR has to be defined for port supports nested interrupts
#else
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) ( uxSavedStatusValue )
#endif
#else
#if ( portHAS_NESTED_INTERRUPTS == 0 )
#error portCLEAR_INTERRUPT_MASK_FROM_ISR should not be defined when portHAS_NESTED_INTERRUPTS is set to 0
#endif
#endif

#ifndef portCLEAN_UP_TCB
Expand Down
7 changes: 6 additions & 1 deletion include/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
* This file implements atomic functions by disabling interrupts globally.
* Implementations with architecture specific atomic instructions can be
* provided under each compiler directory.
*
* The atomic interface is intended for use outside of ISRs, on all ports, and
* also for use inside ISRs on ports that support nested interrupts. However, the
* atomic interface must not be used from ISRs on ports without support for nested
* interrupts. ISR code on these ports is already atomic.
*/

#ifndef ATOMIC_H
Expand All @@ -59,7 +64,7 @@
* ATOMIC_ENTER_CRITICAL().
*
*/
#if defined( portSET_INTERRUPT_MASK_FROM_ISR )
#if ( portHAS_NESTED_INTERRUPTS == 1 )

/* Nested interrupt scheme is supported in this port. */
#define ATOMIC_ENTER_CRITICAL() \
Expand Down
3 changes: 0 additions & 3 deletions portable/GCC/RISC-V/portmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ extern void vTaskSwitchContext( void );
/* Critical section management. */
#define portCRITICAL_NESTING_IN_TCB 0

#define portSET_INTERRUPT_MASK_FROM_ISR() 0
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue

#define portDISABLE_INTERRUPTS() __asm volatile ( "csrc mstatus, 8" )
#define portENABLE_INTERRUPTS() __asm volatile ( "csrs mstatus, 8" )

Expand Down
3 changes: 0 additions & 3 deletions portable/IAR/RISC-V/portmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ extern void vTaskSwitchContext( void );
/* Critical section management. */
#define portCRITICAL_NESTING_IN_TCB 0

#define portSET_INTERRUPT_MASK_FROM_ISR() 0
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue

#define portDISABLE_INTERRUPTS() __disable_interrupt()
#define portENABLE_INTERRUPTS() __enable_interrupt()

Expand Down
3 changes: 0 additions & 3 deletions portable/ThirdParty/xClang/XCOREAI/portmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@
#define portSET_INTERRUPT_MASK() rtos_interrupt_mask_all()
#define portCLEAR_INTERRUPT_MASK( ulState ) rtos_interrupt_mask_set( ulState )

#define portSET_INTERRUPT_MASK_FROM_ISR() ( 0 )
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) ( ( void ) x )

/*
* Will enable interrupts if ulState is non-zero.
*/
Expand Down