Aug 03, 2021
08:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 03, 2021
08:02 AM
Hi I want to introduce to my code:
something like "enter_critical_section" and "exit_crtical_section".
This function shall disable all interrupt handling and sahll enable interrupt handling afterwards.
The must have is, that the interrupts that occured while disabled, shall be held pending and shall be handled after the call of "exit_critical_section".
I am not quite sure wheter __disable_irq and __enable_irq fullfill this requirement.
In xmc_math.c ther are the functions crtical_section_enter and crtical_section_exit. Do these functions do the job?
I am a bit confused because i expected to find a __enable_irq() in the function critical_section_exit ?
Maybe there is some kind of expert out there who can help me out on this, as the documentation is a bit confusing how to safely catch pending intterupts after re-enabling.
Best regards Sven
__attribute__((always_inline)) __STATIC_INLINE uint32_t critical_section_enter(void)
{
uint32_t status;
status = __get_PRIMASK();
__disable_irq ();
return status;
}
__attribute__((always_inline)) __STATIC_INLINE void critical_section_exit(uint32_t status)
{
__set_PRIMASK(status);
}
something like "enter_critical_section" and "exit_crtical_section".
This function shall disable all interrupt handling and sahll enable interrupt handling afterwards.
The must have is, that the interrupts that occured while disabled, shall be held pending and shall be handled after the call of "exit_critical_section".
I am not quite sure wheter __disable_irq and __enable_irq fullfill this requirement.
In xmc_math.c ther are the functions crtical_section_enter and crtical_section_exit. Do these functions do the job?
I am a bit confused because i expected to find a __enable_irq() in the function critical_section_exit ?
Maybe there is some kind of expert out there who can help me out on this, as the documentation is a bit confusing how to safely catch pending intterupts after re-enabling.
Best regards Sven
__attribute__((always_inline)) __STATIC_INLINE uint32_t critical_section_enter(void)
{
uint32_t status;
status = __get_PRIMASK();
__disable_irq ();
return status;
}
__attribute__((always_inline)) __STATIC_INLINE void critical_section_exit(uint32_t status)
{
__set_PRIMASK(status);
}
Solved! Go to Solution.
- Tags:
- IFX
1 Solution
Aug 04, 2021
09:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 04, 2021
09:49 PM
Hi Sven,
__disable_irq () - Globally disables interrupts and configurable fault handlers.The function disables interrupts and all configurable fault handlers by setting PRIMASK.
Set the Priority Mask bit.
__set_PRIMASK - The function sets the Priority Mask register (PRIMASK) value using the instruction MSR.PRIMASK is a 1-bit-wide interrupt mask register.
When set, it blocks all interrupts apart from the non-maskable interrupt (NMI) and the hard fault exception. The PRIMASK prevents activation of all exceptions with configurable priority.
As both are manipulating one register, __set_PRIMASK call is sufficient. It sets the register to the previous 'status' value( a series critical section will not accidentally turn on the interrupt, but move it to last known state).
The pending interrupts is activated once the the register is unmasked.
Best Regards,
Vasanth
__disable_irq () - Globally disables interrupts and configurable fault handlers.The function disables interrupts and all configurable fault handlers by setting PRIMASK.
Set the Priority Mask bit.
__set_PRIMASK - The function sets the Priority Mask register (PRIMASK) value using the instruction MSR.PRIMASK is a 1-bit-wide interrupt mask register.
When set, it blocks all interrupts apart from the non-maskable interrupt (NMI) and the hard fault exception. The PRIMASK prevents activation of all exceptions with configurable priority.
As both are manipulating one register, __set_PRIMASK call is sufficient. It sets the register to the previous 'status' value( a series critical section will not accidentally turn on the interrupt, but move it to last known state).
The pending interrupts is activated once the the register is unmasked.
Best Regards,
Vasanth
3 Replies
Aug 04, 2021
09:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 04, 2021
09:49 PM
Hi Sven,
__disable_irq () - Globally disables interrupts and configurable fault handlers.The function disables interrupts and all configurable fault handlers by setting PRIMASK.
Set the Priority Mask bit.
__set_PRIMASK - The function sets the Priority Mask register (PRIMASK) value using the instruction MSR.PRIMASK is a 1-bit-wide interrupt mask register.
When set, it blocks all interrupts apart from the non-maskable interrupt (NMI) and the hard fault exception. The PRIMASK prevents activation of all exceptions with configurable priority.
As both are manipulating one register, __set_PRIMASK call is sufficient. It sets the register to the previous 'status' value( a series critical section will not accidentally turn on the interrupt, but move it to last known state).
The pending interrupts is activated once the the register is unmasked.
Best Regards,
Vasanth
__disable_irq () - Globally disables interrupts and configurable fault handlers.The function disables interrupts and all configurable fault handlers by setting PRIMASK.
Set the Priority Mask bit.
__set_PRIMASK - The function sets the Priority Mask register (PRIMASK) value using the instruction MSR.PRIMASK is a 1-bit-wide interrupt mask register.
When set, it blocks all interrupts apart from the non-maskable interrupt (NMI) and the hard fault exception. The PRIMASK prevents activation of all exceptions with configurable priority.
As both are manipulating one register, __set_PRIMASK call is sufficient. It sets the register to the previous 'status' value( a series critical section will not accidentally turn on the interrupt, but move it to last known state).
The pending interrupts is activated once the the register is unmasked.
Best Regards,
Vasanth
Aug 10, 2021
07:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 10, 2021
07:15 AM
crit_sect.h:
*.cpp:
//Critical sections
#define CPU_SR_ALLOCATE() u32 cpu_sr //Allocate storage for CPU status register
#define ENTR_CRT_SECTION() do { cpu_sr = __get_PRIMASK(); __disable_interrupt(); } while (0)
#define EXIT_CRT_SECTION() __set_PRIMASK(cpu_sr)
*.cpp:
void Func()
{
CPU_SR_ALLOCATE();
ENTR_CRT_SECTION();
...
EXIT_CRT_SECTION();
}
Aug 15, 2021
11:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 15, 2021
11:35 PM
Hi,
I think your questions were answered. Let me know if anything was not answered.
Best Regards,
Vasanth
I think your questions were answered. Let me know if anything was not answered.
Best Regards,
Vasanth