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

PIC32 configISR_STACK_SIZE setting

Posted by Peter on February 5, 2010
Hi Folks,
i have two questions - probably someone can help me a little. I've read already the whole pdf documention but i could not find a proper answer (that does not mean, that this is not in the documentation).

1) Parameter configISR_STACK_SIZE.
For what is this setting exactly for?

2) Stack question:
In my application the kernel runs at priority 1, MAX_SYSCALL_ISR_PRIO is by default 3. All tasks (6 in total) run on prio 1 either. I have several interrupts that runs on prio >= 4..7, so they are out of reach from FreeRTOS (thats what i've understood from the manual). If one of the interrupts is being called, which stack is being used then.

For example: If task 2 is currently active and an interrupt >= 4..7 is being raised - will the stack of task 2 will be used?


Thanks in advance,
Peter

RE: PIC32 configISR_STACK_SIZE setting

Posted by Dave on February 5, 2010
Which port and compiler are you using?

RE: PIC32 configISR_STACK_SIZE setting

Posted by Peter on February 5, 2010
Iam running FreeRTOS v6.0.2 on a PIC32MX360F512L and using the Microchip C32 compiler v1.10b.

RE: PIC32 configISR_STACK_SIZE setting

Posted by Richard on February 5, 2010
“1) Parameter configISR_STACK_SIZE.
For what is this setting exactly for?”


This sets the size of the stack that is used when an interrupt occurs. The PIC32 port implements multiple stacks in software (whereas other hardware platforms do this in hardware). When an interrupt occurs the stack is switched to the ISR stack to prevent each and every task having to allocate enough stack for interrupts that may nest deeply.

“2) Stack question:
In my application the kernel runs at priority 1, MAX_SYSCALL_ISR_PRIO is by default 3. All tasks (6 in total) run on prio 1 either. I have several interrupts that runs on prio >= 4..7, so they are out of reach from FreeRTOS (thats what i've understood from the manual). If one of the interrupts is being called, which stack is being used then.

For example: If task 2 is currently active and an interrupt >= 4..7 is being raised - will the stack of task 2 will be used?”


That depends on how you have implemented the interrupt handler. If you just use the compiler to generate the interrupt entry and exit code then the task stack will be used - but this is not recommended as it wastes RAM. If you use the FreeRTOS provided interrupt entry and exit code then the separate ISR stack will be used.

Regards.


RE: PIC32 configISR_STACK_SIZE setting

Posted by Peter on February 8, 2010
Hi Richard,
thank you for the detailed informations.

Regarding that answer i have some more questions. Sorry about that.

1) Regarding my implementation of the interrupts and the stack usage. Iam using the compiler generated interrupt routines ->
void __ISR(_UART_1_VECTOR) UART1_ISR(void).
That means that i can set the parameter configISR_STACK_SIZE to 0, because the stack which is needed to process the interrupt is being nested in the currently active task. Even if this solution is wasting RAM. Correct?

2) If i want to use the FreeRTOS provided interrupt entry and exit code, i have to create my own interrupt service routine(provided with the demos in assembly). So the routine should look something like this:

File: UART1_ISR.S - This creates my own ISR entry and exit code.

.section .FreeRTOS, "ax", @progbits
.setnoreorder
.set noat
.entUART1_ISR_WRAPPER

UART1_ISR_WRAPPER:
portSAVE_CONTEXT
jal UART1_ISR_HANDLER
nop
portRESTORE_CONTEXT
.end UART1_ISR_WRAPPER

File: UART1.c
void __attribute__( (interrupt(ipl2), vector(_UART1_VECTOR))) UART1_ISR_WRAPPER(void);

void UART1_ISR_HANDLER(void)
{
... whithin this i can handle my code as i did before.
... I can also access my static defined buffer to read and write to it without the need of using the Queue-Functions and the
... fromISR / toISR functions. Correct?
}

3) Am i right if i say that this interrupt (FreeRTOS provided entry/exit code) is being handled like a "normal" interrupt, that means:
An interrupt with a higher priority can interrupt the currently running interrupt?

4) How to check the stack usage within an interrupt (FreeRTOS provided entry/exit code)? Is that being done with a call to
uxTaskGetStackHighWaterMark( NULL );
within the interrupt?

Thanks very very much for all the answers in advance!

Kind regards,
Peter

RE: PIC32 configISR_STACK_SIZE setting

Posted by Richard on February 8, 2010
“1) Regarding my implementation of the interrupts and the stack usage. Iam using the compiler generated interrupt routines ->
void __ISR(_UART_1_VECTOR) UART1_ISR(void).
That means that i can set the parameter configISR_STACK_SIZE to 0, because the stack which is needed to process the interrupt is being nested in the currently active task. Even if this solution is wasting RAM. Correct?”


No, because if nothing else the scheduler interrupts will still expect there to be a separate stack.



“2) If i want to use the FreeRTOS provided interrupt entry and exit code, i have to create my own interrupt service routine(provided with the demos in assembly). So the routine should look something like this:”


[code snipped]

If the snipped code is as per the online documentation and provided examples, then yes, otherwise no. Just do the same as the examples then you will be ok.


“3) Am i right if i say that this interrupt (FreeRTOS provided entry/exit code) is being handled like a "normal" interrupt, that means:
An interrupt with a higher priority can interrupt the currently running interrupt?”



Yes. The entry/exit code is designed to allow interrupt nesting while preserving the RAM required.

“4) How to check the stack usage within an interrupt (FreeRTOS provided entry/exit code)? Is that being done with a call to
uxTaskGetStackHighWaterMark( NULL );
within the interrupt?”


No! You cannot call functions that don't end in FromISR or FROM_ISR from an interrupt.

uxTaskGetStackHighWaterMark() will only check the high water mark of the task stack, not the interrupt stack. You can however fill the interrupt stack with a known pattern before calling main(), then write a utility to see how much has been overwritten, or just view it in the debugger. Be careful not to corrupt the stack that is being used by the currently executing code, which is why I say do it before main() is called. Alternatively you could just write the pattern at the far end of the stack.

Regards.

RE: PIC32 configISR_STACK_SIZE setting

Posted by Peter on February 8, 2010
Hello Richard,
regarding that issue below.

“1) Regarding my implementation of the interrupts and the stack usage. Iam using the compiler generated interrupt routines ->
void __ISR(_UART_1_VECTOR) UART1_ISR(void).
That means that i can set the parameter configISR_STACK_SIZE to 0, because the stack which is needed to process the interrupt is being nested in the currently active task. Even if this solution is wasting RAM. Correct?

No, because if nothing else the scheduler interrupts will still expect there to be a separate stack.”


“Checking fill level of ISR stack: You can however fill the interrupt stack with a known pattern before calling main(), then write a utility to see how much has been overwritten, or just view it in the debugger. Be careful not to corrupt the stack that is being used by the currently executing code, which is why I say do it before main() is called. Alternatively you could just write the pattern at the far end of the stack.”


1) Is the ISR stack stored in the structure xISRStack[ configISR_STACK_SIZE ]?
2) The stack is being filled from the end of the structure to be beginning?
3) This stack is also being used for the context-switch vPortYieldISR (so thats the reason, why its not to be allowed to configure configISR_STACK_SIZE == 0)?

Thanks in advance,
Peter


[ 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