V7.1.0 – non pre-emptive atmega 2560

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

V7.1.0 – non pre-emptive atmega 2560

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.

V7.1.0 – non pre-emptive atmega 2560

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.

V7.1.0 – non pre-emptive atmega 2560

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!