Higher priority timer stuck in running state

Hello, Hopefully someone can tell me what Im doing wrong here or suggest a better way of tackling my problem if Im going about this the wrong way. I am trying to uses a timer to break me out of a while loop that is waiting for an EEPROM busy test. The timer is started at function entry and moves to the running state. The timer is at the highest priorty and higher than the task that performs the check. I then sit in a while loop checking the spi eeprom status register. If the timer callback is called i.e. a timeout has occured then its sets a flag.This flag is checked in the while loop to break me out. The code gets stuck in the while loop and the callback never called. Im confident the timer code is correct. Code bones below ( I know this can be tided up somewhat ) Thanks. /////////////// the function in the lower priority task ////////////////// paeepromTimeoutStatus = ERR_NONE; // start the timeout timer if (xTimerStart(PAEEPROMTimer, 0) != pdPASS ) { return ERREXTEEPROMTIMEOUT; }
do
{
    err = eeReadStatusReg(DIO_PA_EEPROM_CS, &status);

    if (paeepromTimeoutStatus == ERR_EXTEEPROM_TIMEOUT)
    {
        err = ERR_EXTEEPROM_TIMEOUT;
        break;
    }

} while( (err == ERR_NONE) && (status & WIP));


///////////// the callback /////////////////

static void timerCallbackPAEEPROM(xTimerHandle pxTimer)
{ // The timer expired, therefore ‘EEPROMTIMEOUTMS’ ms must have passed // Indicate that a timeout occurred paeepromTimeoutStatus = ERREXTEEPROMTIMEOUT; } /////////////// timer creation function ////////////////////// void createtimerEEPROM25AA02E4( void ) { // Create ‘one shot’ timer PAEEPROMTimer = xTimerCreate(“PAEEPROMTimer”, EEPROMTIMEOUTMS / portTICKRATEMS, pdFALSE, NULL, timerCallbackPAEEPROM); if (PAEEPROMTimer != NULL) { xTimerStart(PAEEPROM_Timer, 0); } else …………… }

Higher priority timer stuck in running state

The first obvious question is do you have preemption enabled in FreeRTOSConfig.h ?

Higher priority timer stuck in running state

Hi Richard. Yes I do

Higher priority timer stuck in running state

Sorry Richard I will be more specific #define configUSE_PREEMPTION 1 ~~~

define configUSE_TIMERS 1

define configTIMERTASKPRIORITY 4

~~~ My task that Im stuck in is priority 2

Higher priority timer stuck in running state

Another possible issue is paeepromTimeoutStatus declared volatile? if not the compiler is allowed to read it once and rember the value in the loop.

Higher priority timer stuck in running state

Yes it is. So my approach wasnt completely dumb then and should work?

Higher priority timer stuck in running state

Yes it is. So my approach wasnt completely dumb then and should work?

Higher priority timer stuck in running state

This does seem a bit puzzling. You say the timer callback is not run, I am presuming that means you have tried putting a breakpoint there (or the equivalent) and it doesn’t get hit. Have you confirmed that the system tick is still running? If something has stopped that it will give you issues with the timers. Make sure nothing else can be resetting the timer, if you keep poking it then it won’t expire.

Higher priority timer stuck in running state

The timercallback is hit on code startup when the timer expires. I do have a breakpoint there to verfiy that, so I know it does get called and belived the timer setup was correct. Its a one shot timer and on entry to the function checking the bust status it is my understanding that the xTimerStart resets and restarts the timer. A breakpoint in my Callaback is never hits again . The code is still running but stuck in the do while loop in the lower priorty task, with nothing to break it out. I had assumed with the timer task being higher priority that it would remain running and allow me to break out from the callback. The timer is not started or reset anywhere else in my code. Im puzzled henc emy request for help, incase I had overlooked something obvious.

Higher priority timer stuck in running state

Have you confirmed that the system tick running? If something kills that your timers will stop.

Higher priority timer stuck in running state

Im sorry but its dumb question time because Im not that familiar with FreeRTOS yet. I assume I should be checking the systick timer is running by looking at xPortSysTickHandlerin port.c? If that is the case then its not hitting it when I get stuck it the loop. So thanks for pointing me in the right direction. Just need to find out why now.. Thanks for taking time to assist Richard.

Higher priority timer stuck in running state

All fixed. Had disabled interrupts in the code at somepoint. Not sure how I close the thread.