Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists