Higher priority timer stuck in running state

cliver47 wrote on Thursday, July 26, 2018:

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(PA_EEPROM_Timer, 0) != pdPASS )
{
return ERR_EXTEEPROM_TIMEOUT;
}

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 ‘EEPROM_TIMEOUT_MS’ ms must have passed
// Indicate that a timeout occurred
paeepromTimeoutStatus = ERR_EXTEEPROM_TIMEOUT;
}

/////////////// timer creation function //////////////////////

void createtimerEEPROM_25AA02E4( void )
{
// Create ‘one shot’ timer
PA_EEPROM_Timer = xTimerCreate(“PA_EEPROM_Timer”, EEPROM_TIMEOUT_MS / portTICK_RATE_MS, pdFALSE, NULL, timerCallbackPAEEPROM);
if (PA_EEPROM_Timer != NULL)
{
xTimerStart(PA_EEPROM_Timer, 0);
}
else

}

richarddamon wrote on Thursday, July 26, 2018:

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

cliver47 wrote on Thursday, July 26, 2018:

Hi Richard. Yes I do

cliver47 wrote on Thursday, July 26, 2018:

Sorry Richard I will be more specific

#define configUSE_PREEMPTION 1

#define configUSE_TIMERS                    1
#define configTIMER_TASK_PRIORITY           4

My task that Im stuck in is priority 2

richard_damon wrote on Thursday, July 26, 2018:

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

cliver47 wrote on Thursday, July 26, 2018:

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

cliver47 wrote on Thursday, July 26, 2018:

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

richarddamon wrote on Thursday, July 26, 2018:

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.

cliver47 wrote on Thursday, July 26, 2018:

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.

richard_damon wrote on Thursday, July 26, 2018:

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

cliver47 wrote on Friday, July 27, 2018:

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.

cliver47 wrote on Friday, July 27, 2018:

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