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

Is this bug in AVR porting?

Posted by mostafa heidary on June 3, 2013
hi
i wrote this program for test:

in port.c:
void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) );
void SIG_OUTPUT_COMPARE1A( void )
{
PORTA++;vPortYieldFromTick();PORTA--;
asm volatile ( "reti" );
}


=================================================================
/* Priority definitions for most of the tasks in the demo application. Some
tasks just use the idle priority. */
#define mainLED_TASK_PRIORITY( tskIDLE_PRIORITY )
void LED1( void *pvParameters )
{
DDRB = 0xff;
while(1)
{
PORTB |= (1<<0);
_delay_us(1);
PORTB &= ~(1<<0);
_delay_us(1);
}
}

void LED2( void *pvParameters )
{
DDRC = 0xff;
while(1)
{
PORTC |= (1<<1);
_delay_us(1);
PORTC &= ~(1<<1);
_delay_us(1);
}
}
portSHORT main(void)
{
DDRA=0xff;
PORTD++;
xTaskCreate( LED1, ( signed char * ) "LED1", 100, NULL, 0, NULL );
xTaskCreate( LED2, ( signed char * ) "LED2", 100, NULL, 0, NULL );

vTaskStartScheduler();
return 0;
}


note that i used PORTA to see timer interrupt flow.
after simulating i got this result on output:


you can see task1 (LED1) runs until first timer interrupt , and after first call of timer interrupt task switched to task2 (LED2) and it runs to ever.

i worked on it many hours and finally i found a way.
if you change timer interrupt in 'port.c' file to this :

void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) );
void SIG_OUTPUT_COMPARE1A( void )
{
asm volatile ( "sei" );
PORTA++;vPortYieldFromTick();PORTA--;
asm volatile ( "reti" );
}


you will see this result :

you can see that the program loops in interrupt handler until next interrupt tick and there are an overlap on firing interrupt.
but both task are working and we have auto switch between tasks.

RE: Is this bug in AVR porting?

Posted by Dave on June 3, 2013
I don't know what you are trying to do, what _delay_us() does (does it call a FreeRTOS function?), or what the "sei" instruction does, but the first thing I notice here is your calling PORTA++; from a naked function. That is probably not a good idea because the naked function will not have a stack frame of any kind, and it will change the MCU context before it has been saved. I would have to check the asm code generated by the compiler to be completely sure, but suspect it will break the scheduler.

RE: Is this bug in AVR porting?

Posted by mostafa heidary on June 3, 2013
thanks for your reply
i made my board and get real test, it works fine and the problem is in my simulator (proteus)


[ 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