VtaskDelay problem on PIC24

quatoria wrote on Friday, August 23, 2013:

Dear,

I am having problem with Vtaskdelay function its seems to never return, my code is very simple :

void vTaskCode( void * pvParameters )
{
  for( ;; )
  {
      PORTDbits.RD2 = 0;
      vTaskDelay(100);
      PORTDbits.RD2 = 1;
      vTaskDelay(100);
  }
}

int main(int argc, char** argv) {

    vP24Initialise();

   xTaskCreate( vTaskCode, “NAME”, comSTACK_SIZE,NULL, 2,NULL);
 
   vTaskStartScheduler();
  
   while (1);
/* Will only reach here if there is insufficient heap available to start
the scheduler. */
   return 0;

}

Using Freertos 7.5.2 on Pic24FJ256GA106.

Any idea will help.

Thanks

edwards3 wrote on Friday, August 23, 2013:

Is the tick interrupt running? If not time will stand still so the 100 tick delay will not time out.

quatoria wrote on Saturday, August 24, 2013:

In fact any delay is not working, may be I miss some init function for FreeRtos ?

Rgds

quatoria wrote on Saturday, August 24, 2013:

Just for more information, this is an extract of hardwareprofile.h :

#define GetSystemClock()            32000000UL
#define GetPeripheralClock()        (GetSystemClock() / 2)
#define GetInstructionClock()       (GetSystemClock() / 2)
#define MILLISECONDS_PER_TICK       10
#define TIMER_PRESCALER             TIMER_PRESCALER_8 //TIMER_PRESCALER_1
#define TIMER_PERIOD                20000 //40000

and my freertosconfig.h :

#define MPLAB_PIC24_PORT

#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configCPU_CLOCK_HZ ( ( unsigned long ) 16000000 )  /* Fosc / 2 */
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 4 )
#define configMINIMAL_STACK_SIZE ( 115 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) 5120 )
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1

#define configKERNEL_INTERRUPT_PRIORITY 0x01

if anybody has an idea to help me, welcome :slight_smile:

rtel wrote on Saturday, August 24, 2013:

I agree with edwards3 diagnosis in post 2.  Did you check that?  You can do by either setting a break point in the tick interrupt or simply letting the program run for a while then inspecting the xTickCount variable in FreeRTOS/Source/tasks.c

Regards.

quatoria wrote on Saturday, August 24, 2013:

I think the tick interrupt is set correctly, I put an applicationtickhook handler and discovered strange behavior, I entered only one time in vapplicationtickhook or if I follow correctly I should enter each tick time ?

void vApplicationTickHook( void )
{
    ul++;
    if (ul == 2) {PORTDbits.RD2 = 1;} // ul == 1 yes greater never

}

quatoria wrote on Saturday, August 24, 2013:

I discovered strange things the init of tick timer int is done correctly as this : __attribute__(( weak )) void vApplicationSetupTickTimerInterrupt( void )
{
const unsigned long ulCompareMatch = ( ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) / configTICK_RATE_HZ ) - 1;

/* Prescale of 8. */
T1CON = 0;
TMR1 = 0;

PR1 = ( unsigned short ) ulCompareMatch;

/* Setup timer 1 interrupt priority. */
IPC0bits.T1IP = configKERNEL_INTERRUPT_PRIORITY;

/* Clear the interrupt as a starting condition. */
IFS0bits.T1IF = 0;

/* Enable the interrupt. */
IEC0bits.T1IE = 1;

/* Setup the prescale value. */
T1CONbits.TCKPS0 = 1;
T1CONbits.TCKPS1 = 0;

/* Start the timer. */
T1CONbits.TON = 1;

       
}

BUT it never reaches the interrupt routine :

void __attribute__((__interrupt__, auto_psv)) configTICK_INTERRUPT_HANDLER( void )
{
/* Clear the timer interrupt. */
IFS0bits.T1IF = 0;
        LATDbits.LATD2 = ~LATDbits.LATD2;
if( xTaskIncrementTick() != pdFALSE )
{
portYIELD();
}
}

Any idea ?

edwards3 wrote on Saturday, August 24, 2013:

configTICK_INTERRUPT_HANDLER defaults to _T1Interrupt. Is that the name used for the timer 1 interrupt in your build?

quatoria wrote on Saturday, August 24, 2013:

Yes at the begining of port.c ther is :

#ifndef configTICK_INTERRUPT_HANDLER
#define configTICK_INTERRUPT_HANDLER _T1Interrupt
#endif /* configTICK_INTERRUPT_HANDLER */

I am just thinking if there is any problem with my config flag may be ?

_CONFIG2(FNOSC_PRI & POSCMOD_HS & IOL1WAY_OFF ) // Primary HS OSC
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF & ICS_PGx2 ) // JTAG off, watchdog timer off

Regards

woops_ wrote on Saturday, August 24, 2013:

if the tick hook is hit once then the interrupt install must be ok and clearing the interrupt or peripheral seems to be the cause. it can be that the config bits get set in the IDE not the source code, check your project to see which. normally projects should not need any changes to run.

quatoria wrote on Saturday, August 24, 2013:

I can confirm that the interrupt handler :

void __attribute__((__interrupt__, auto_psv)) configTICK_INTERRUPT_HANDLER( void )
{
/* Clear the timer interrupt. */
IFS0bits.T1IF = 0;
        LATDbits.LATD2 = ~LATDbits.LATD2;
if( xTaskIncrementTick() != pdFALSE )
{
portYIELD();
}
}

is NEVER called not at least one time.

quatoria wrote on Sunday, August 25, 2013:

No more progress the interrupt is never called, do I need special things to configure since I am in mplabX latest version ?

rtel wrote on Sunday, August 25, 2013:

I’m not sure which is the latest, but using V1.80 I have just taken a clean download, opened the PIC24 project, set the debugger to use the simulator, built and started a debug session.  The result is that - without having made any changes other than setting the debugger to use the simulator - the timer’s interrupt service routine is being hit and the tick count is being incremented.

Can you try doing the same?

Regards.

rtel wrote on Sunday, August 25, 2013:

….using V1.80 of MPLAB X, if that was not clear in my previous post.

Regards.

quatoria wrote on Monday, August 26, 2013:

Dear Richard,

Many thanks to all for you support I finally solved my problem and I wanted to share the solution with you, after hours and hours of searching I came to the conclusion that the Interrupt was never called due to some bad information during linking.

I have to precise that I am not using same pic of FreeRtos demo which is P24FJ128GA010, my pic with my own hardware is P24FJ256GA106, so  when importing in MPALB X version 1.85 the whole demo I was oblige to tell the linker that GLD file is different and I imported the one provided in microchip library BUT this file is wrong it has bad entry for IVT and alternate IVT, I finally decided to copy and paste all the IVT and alt IVT section from freertos demo and the Interrupt is now working…
I did not contacted yet Microchip for this problem.

Hope it helps future user.

Best Regards