This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using Timers on RM46 - xTimerStart and FreeRTOS

Other Parts Discussed in Thread: HALCOGEN

Hi,

I've been trying to set up a timer to call a program function at regular intervals. I'm using HALCoGen to generate my setup parameters, but am new to it and TI microprocessors in general. 

I'm having a compilation error that I can't get around. I think the relevant bits of code are:

#include "FreeRTOS.h"
#include "os_task.h"
#include "os_timer.h"
#include "os_task.h"

void ButtonCallback(xTimerHandle theTimer);

Main:

// TimerHandle_t buttonTimer; //also tried this declaration with no success. Have seen examples implemented both ways
xTimerHandle buttonTimer;

buttonTimer = xTimerCreate("ButtonTimer", 1000, pdTRUE, (void*) 1, ButtonCallback );

xTimerStart(buttonTimer, 0 );

vTaskStartScheduler();

for(;;){...}

I'm finding that the xTimerStart line gives the following error:

#169 argument of type "void *" is incompatible with parameter of type "BaseType_t *"

I'm using FreeRTOS v8.2.0

Halcogen v.04.05.01

CCS V6.1.2.00015

I have to imagine there's something trivial I'm missing here, because I can't find an instance of someone else having the same issue. Any thoughts on why this is happening?

Thanks!

  • Thomas,

    When you call the function the types of the parameters need to match with what they are in the prototype or you'll get at least a warning & sometimes error...

    www.freertos.org/FreeRTOS-timers-xTimerCreate.html

    Shows that the third parameter needs to be of a user defined type, not pointer to void.

    But you could look at the header files you include for the prototype
  • Thanks for the reply Anthony.

    The link directs me to find:
    TimerHandle_t xTimerCreate
    ( const char * const pcTimerName,
    const TickType_t xTimerPeriod,
    const UBaseType_t uxAutoReload,
    void * const pvTimerID,
    TimerCallbackFunction_t pxCallbackFunction );

    In my code I have:
    buttonTimer = xTimerCreate(
    "ButtonTimer",
    1000,
    pdTRUE,
    (void*) 1,
    ButtonCallback
    );

    It looks legitimate to me to have the fourth (I assume this is the third parameter you refer to in your comment) argument be void, since that seems to be what is expected. The example on the link you sent also uses (void *) for the fourth argument. I'm assuming that the user defined type you refer to is the pdTRUE argument. If I've missed the point and you're suggesting that I'm doing something wrong in xTimerCreate that is propagating through and showing up in xTimerStart, please let me know.


    I don't think that my compilation issue resides with the xTimerCreate function, I think it's the xTimerStart function that's causing me problems. If I remove the xTimerStart function, I remove the compilation error.

    Thanks!
  • Hi Paul,

    Ok I missed that - I though it was line 169 not error #169 and looked at the error message to connect the dots.

    xTimerStart is a #define macro in timers.h

    #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )

    So really need to look at xTimerGenericCommand (line 1117 in timers.h)

    BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;

    It looks like this is the likely offender:

    BaseType_t * const pxHigherPriorityTaskWoken

    That's getting a "NULL" it looks like.

    maybe check on what NULL is defined as and compare with how 'BaseType_t' is defined.

    Could be a porting issue or could be that NULL is also defined somewhere else in your code ...
  • Hey Anthony,

    I think you're right about BaseType_t * const pxHigherPriorityTaskWoken getting NULL. I know that I haven't personally defined NULL anywhere. If it's a porting issue or that the FreeRTOS code does something special with NULL, I'm not very enthusiastic about trying to change that.

    For closure, I've decided to use Real Time Interrupts instead, which I didn't previously know existed. It looks like it will work well for my needs. If others come across a similar problem and want to look into RTI as a problem, see rti.h/rti.c. There's a pretty good tutorial in HALCoGen (example_rtiBlinky.c), although there's a spot where the tutorial says to "Map VIM Channel 2 to IRQ", but the accompanying diagram shows it mapped to FIQ. Be sure to follow the written instructions and map to IRQ.

    Thanks again for your help Anthony.

  • Why are you including os_task.h twice?

    The prototype of the xTimerStart() function (www.freertos.org/FreeRTOS-timers-xTimerStart.html) does not have a BaseType_t parameter, but does return a BaseType_t - but your code does not seem to be using the return type. Although, xTimerStart() is in fact a macro that calls the generic command function, which does include a BaseType_t parameter - could it be the macro is not valid (have the source code headers been edited?).

    BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait );