Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Detecting the current executing context

Posted by dreamsters on March 29, 2017

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


Detecting the current executing context

Posted by rtel on March 29, 2017

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.


Detecting the current executing context

Posted by dreamsters on March 30, 2017

Wouldnt we also need a way to compare that to the to the ucMaxSysCallPriority and adjust for the interrupt priority depending of the port?


Detecting the current executing context

Posted by richard_damon on March 30, 2017

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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS