FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [March 2017 Threads]
Hi
I run FreeRTOS on an STM32 and inorder to detect if the current executing function is running in an interrupt or non-interrupt context. The following will do the job for me.
~~~
boolean bCalledFromInterrupt(void) {
if ( (SCB->ICSR & SCBICSRVECTACTIVE_Msk) != 0) {
return TRUE;
}
else {
return FALSE;
}
}
~~~
But is still cant distinguish between interrupts that may call FromISR functions and others that dont. I can ofcourse implement a lookuptable, but then I also have to maintain that.
I have looked at vPortValidateInterruptPriority in port.c which does detect the interesting case, but does not allow me to use the functionallity as it uses assert.
How about adding something like this to FreeRTOS that allows the caller to detect the current executing context.
~~~
typedef enum {
UTILRTOSNOCALLS = 0U,
UTILRTOSTASKCALLS = 1U,
UTILRTOSISR_CALLS = 2U,
} teRTOSCallType;
teRTOSCallType teGetRTOSAPIType(void) {
teRTOSCallType retval = UTILRTOSNOCALLS;
BaseTypet schedulerstate = xTaskGetSchedulerState();
if (scheduler_state == taskSCHEDULER_NOT_STARTED) {
// Already set to no_calls
}
else {
boolean from_interrupt = bCalledFromInterrupt();
if (from_interrupt == FALSE) {
ret_val = UTIL_RTOS_TASK_CALLS;
}
else {
boolean safe_isr = bMayCallRTOSISR();
if (safe_isr == TRUE) {
ret_val = UTIL_RTOS_ISR_CALLS;
}
else {
// Already set to no_calls
}
}
}
return ret_val;
}
~~~
where the bMayCallRTOSISR call will use the same statevariables and logic as vPortValidateInterruptPriority.
Best regads
Martin
I run FreeRTOS on an STM32 and inorder to detect if the current
executing function is running in an interrupt or non-interrupt context.
The following will do the job for me.
boolean bCalledFromInterrupt(void) {
if ( (SCB->ICSR & SCBICSRVECTACTIVE_Msk) != 0) {
return TRUE;
}
else {
return FALSE;
}
}
See the function xPortIsInsideInterrupt() in
FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h. Maybe we could
update that function to return the priority of the currently executing
interrupt rather than just pdTRUE.
Wouldnt we also need a way to compare that to the to the ucMaxSysCallPriority and adjust for the interrupt priority depending of the port?
Since an ISR for an interrupt above ucMaxSysCallPriority isn't allowed to call ANY FreeRTOS API routine, there isn't really a need to determine which one they can call, since it is neither.
I can understand somewhat the desire for such a function, if you are writing an API for something, so you don't need to replicate non-ISR and FromISR API points, but I have seen that this is more often an indication that too much is being done in the interrupt.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.