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

V7.1.0 - non pre-emptive atmega 2560

Posted by https://www.google.com/accounts on February 20, 2012
I've got v7.1.0 working nicely under an atmega 2560 in pre-emptive mode, but when I switch to non pre-emptive it blows up, even though the tasks are calling vTaskDelayUntil(). Actually it blows up completely so i it isn't that one task is hogging the cpu. looking at some old posts, I found that if I kept pre-emptive enabled but commented out the switch context call, everything still worked.

I want to verify, does this indicate a problem with frame-pointers? should I recompile with -fno-omit-frame-pointer, and then non-premptive will work out of the box? Does this indicate some other deeper issue?

I have a second issue as well. To do with checking max stack use:

When I print the unsigned long output of uxTaskGetStackHighWaterMark( NULL ) in my first task it does not match that which is printed inside the table generated by vTaskLIst ( ). With a 1500 byte stack, it prints 32 bytes, but with a 800 byte stack, it prints a larger number. How can that be? it basically seems to get it wrong, but the vTaskList() table seems correct.

Additionally, the amount printed in vTaskList() table seems to change a little and not always get smaller. I thought that "high water" meant that it could only ever get smaller?

And a hint for anyone looking at FreeRTOS on atmega. Don't use heap_3.c and use the vPortMalloc/Free routines because they just call malloc/free and the avr malloc/free has detection for heap/stack collision which breaks inside a freeRTOS task as the stack is unexpectedly (to AVR) inside the heap! So you must use heap_1 or heap_2, and then ensure all malloc/free calls are converted or #define'd to the FreeRTOS versions that alloc from this fixed heap.

thanks

RE: V7.1.0 - non pre-emptive atmega 2560

Posted by Dave on February 20, 2012
“I've got v7.1.0 working nicely under an atmega 2560 in pre-emptive mode”


Cool. I don't think that is an official port though. Where did it come from? Does it contain the necessary changes to the official base AVR port for the extra addressing register?

“Actually it blows up completely”


Can you give more information on that. If you stop on the debugger, what is being executed, real code or garbage?

“ I found that if I kept pre-emptive enabled but commented out the switch context call, everything still worked”


Looking at the code:

#if configUSE_PREEMPTION == 1

/*
* Tick ISR for preemptive scheduler. We can use a naked attribute as
* the context is saved at the start of vPortYieldFromTick(). The tick
* count is incremented after the context is saved.
*/
void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) );
void SIG_OUTPUT_COMPARE1A( void )
{
vPortYieldFromTick();
asm volatile ( "reti" );
}
#else

/*
* Tick ISR for the cooperative scheduler. All this does is increment the
* tick count. We don't need to switch context, this can only be done by
* manual calls to taskYIELD();
*/
void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal ) );
void SIG_OUTPUT_COMPARE1A( void )
{
vTaskIncrementTick();
}
#endif


it seems that when you are not using pre-emption you are relying instead on the compiler generating the interrupt entry and exit code. Can you see that the SIG_OUTPUT_COMPARE1A function has a reti at the end?

“With a 1500 byte stack, it prints 32 bytes”


There was a post about that recently. It is because the AVR is 8 bits, so portBASE_TYPE is 8 bits and portBASE_TYPE is used to return the water mark value.

RE: V7.1.0 - non pre-emptive atmega 2560

Posted by https://www.google.com/accounts on February 20, 2012
I did the port by piecing together others work, duinos and later ports.
it is pretty standard the 2560 needs to save a couple of extra registers to help with the 256k of flash, the task functions must be located in low memory. I use timer3 for the ticks, pre emptive mode works perfectly, but this being an existing code base not really designed for multi threads I thought changing key hardware polliing to yields would get me tasks without having to lock every global!

I will check the assembler for non premptive isr and post it unfortunately I cannot debug in situ i use blinking LEDs and serial out :)

that's good on the stack free, so perhaps I can get rid of the 8bit overflows just so the numbers add up and I know where it is reliably.


RE: V7.1.0 - non pre-emptive atmega 2560

Posted by https://www.google.com/accounts on February 20, 2012
Well, that was easier than I expected.

One of the ports I used as a starting point had naked ISRs for the non pre-emptive situation, but asm..reti for the pre-emptive ISRs. Adding reti() to the end fixed that issue.

I changed port_basetype from char to int

thanks!


[ 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