simple application on MPC5516

simfr wrote on Monday, October 06, 2008:


I ported the FreeRTOS to the Freescale MPC5516. FreeRTOS seems to run so far. For a proof-of-concept, I set up an application, where three tasks toggle three LEDs - each tasks toggles "its" LED with a specific frequency.

The problem is, that - when running the application - all three LEDS are toggled exactly the same time with the same frequency. Can somebody help me please? I think I did something wrong in the portTASK_FUNCTION (please see end of message for sourcecode). If not, what could I have done wrong else?

Thank you very much in advance.

Best regards



static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
portTickType xFlashRate, xLastFlashTime;
unsigned portBASE_TYPE uxLED, bit_Mask;

    /* The parameters are not used. */
    ( void ) pvParameters;

    /* Calculate the LED and flash rate. */
        /* See which of the eight LED’s we should use. */
        uxLED = uxFlashTaskNumber;

        /* Update so the next task uses the next LED. */
    /* Determine the Bitmask for each of the three tasks */
    if (uxLED == 0) bit_Mask = 0x80000000;
    else if (uxLED == 1) bit_Mask = 0x40000000;
    else if (uxLED == 2) bit_Mask = 0x20000000;
    /* Determine the Flash rate for each of the three tasks */
    xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( portTickType ) ( uxLED ));
    xFlashRate /= portTICK_RATE_MS;

    /* We will turn the LED on and off again in the delay period, so each
    delay is only half the total period. */
    xFlashRate /= ( portTickType ) 2;

    /* We need to initialise xLastFlashTime prior to the first call to
    vTaskDelayUntil(). */
    xLastFlashTime = xTaskGetTickCount();
    /* Turn LED off for checking reason */
    SIU.PGPDO1.R ^= bit_Mask;

        /* Delay for half the flash period then turn the LED on - specific for each task. */
        vTaskDelayUntil( &xLastFlashTime, xFlashRate );
        SIU.PGPDO1.R ^= bit_Mask;

        /* Delay for half the flash period then turn the LED off - specific for each task. */
        vTaskDelayUntil( &xLastFlashTime, xFlashRate );
        SIU.PGPDO1.R ^= bit_Mask;

woops_ wrote on Monday, October 06, 2008:

Did you try the normal flash tasks that come in the zip? Also step the code to see what values are calculated for the delays.

simfr wrote on Tuesday, October 07, 2008:

Thank you for your answer!

The values, which are calculated for the delays are the right ones for each task.

I saw, that the values for xLastFlashTime are not updated each time vTaskDelayUntil is called. What could be the cause for this problem?

rtel wrote on Wednesday, October 08, 2008:

I think this should only be the case if xFlashRate was set to 0.  Try stepping through the call to vTaskDelayUntil() to see what happens to the value.


simfr wrote on Saturday, October 11, 2008:

Thank you very much for your answer.  I will try stepping through the code.

Best regards,