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

AVR interrupt issue

Posted by Geza Balazs on August 22, 2009
Hi,

I'm using FreeRTOS on an ATmega128 AVR. I have a problematic IRQ routine. Since this routine may cause a task switch, I've put an ASM wrapper around it like this:

SIG_TIMER1_CAPT_Entry:
portSAVE_CONTEXT
call SIG_TIMER1_CAPT
tst r16
breq _no_context_switch
call vTaskSwitchContext
_no_context_switch:
portRESTORE_CONTEXT
reti

In case of a task switch, it does not return with the I flag set, so IRQs remain disabled (in spite of the RETI at the end), neither my timer capture IRQ nor the scheduler IRQ will be triggered anymore.
Anyway, if I modify the code just like it is in the preemptive scheduler call:

SIG_TIMER1_CAPT_Entry:
rcall SIG_TIMER1_CAPT_Proc
reti

SIG_TIMER1_CAPT_Proc:
portSAVE_CONTEXT
call SIG_TIMER1_CAPT
tst r16
breq _no_context_switch
call vTaskSwitchContext
_no_context_switch:
portRESTORE_CONTEXT
ret

It works absolutely fine when calling it via a second stage.
Can you tell me what the problem is here, why it is not working when there's no extra call?

Thanks and best regards,
Geza Balazs

RE: AVR interrupt issue

Posted by Dave on August 22, 2009
I've just taken a quick look at the FreeRTOS WEB pages for the AVR and the source code for the AVR demo and cannot see that either the IAR or GCC ports use assembly wrappers for interrupts. Which compiler are you using? Is there a reason why you cannot write your interrupts as per the serial port example in the demo?

The AVR demos are some of the original demos, so maybe the compiler requires something different now?

Also there was a long explanation of the interrupt flag status during a context switch for the AVR ports on this forum a few months back, you might like to try searching for that.

RE: AVR interrupt issue

Posted by Geza Balazs on August 22, 2009
Dave,

I'm using IAR EWAVR 4.20A. The reason why I'm using an ASM wrapper is that the main IRQ handler may cause a task switch and since this timer capture IRQ needs to be as fast as possible, and the context switch would save and restore all context data anyway, I'd like to get rid of saving and restoring context data at the beginning and the end of the service routine. The main handler function is written in C, with the __task directive. It returns the need of the context switch in R16, and the wrapper handles the request appropriately.

Regarding the IF status I'm gonna look it up right away.

Thanks,
Geza

RE: AVR interrupt issue

Posted by Richard Damon on August 22, 2009
I don't know if this is the problem, but one thing to remember is that vTaskSwitchContext assumes that all paths after it are identical, and may not actually return to your function until the task that was interrupted gets started again.(I think this may depend on the port).


[ 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