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

System stack switch sequencing (PIC32)

Posted by Serious on March 15, 2011
Richard & Crew

Could you clarify the sequence of operations for ISRs to use the system stack when the ISR uses the Queue FromISR functions that need that trailing "if (hiPriTaskWaiting)" check?

Until we get our hands on the OpenRTOS USB Device stack, we're using the Microchip device stack, which is a pretty big ISR -- especially as it hooks down into our code which drops the incoming char (or buffer) on a queue in the interrupt context. So we're motivated to switch stacks when it is running to avoid having to have that much room on 10+ other tasks.

It seems that the first step is to "wrap" the ISR from an assembly file like this:

vUSBInterruptHandler:
portSAVE_CONTEXT
jal USBDeviceTasks
nop
portRESTORE_CONTEXT
.end vUSBInterruptHandler


of course with the interrupt mapped in the .C file like this:
#pragma interrupt vUSBInterruptHandler ipl3 vector 45



In the actual C that is called (in this case, the Microchip USB device ISR-not-as-an-ISR function
USBDeviceTasks
), there is no special coding until we do the enqueue.. where we record if a high priority task is waiting.

Here's where it gets interesting. At the end of that C function, we of course add:
portEND_SWITCHING_ISR( xSwitchRequired );


Now, is that really correct? we're calling the yield but we have't "unwrapped" in the assembly wrapper the portRESTORE_CONTEXT, so we're yielding whilst the stack is switched to the system stack.

Are there any issues there? We seem to be getting some odd behaviour when we take this approach and we're trying to ensure we understand the proper flow so as not to chase ghosts.

Thanks
The Serious Team

RE: System stack switch sequencing (PIC32)

Posted by Richard on March 15, 2011
If you follow the instructions in the "interrupt service routines" section of this page:

http://www.freertos.org/port_PIC32_MIPS_MK4.html

and copy the example in the demo that that page documents, then FreeRTOS will automatically handle switching to an interrupt/system stack for you. It is also explained in the FreeRTOS PIC32 tutorial book.

Regards.


[ 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