Hey support,
I'm trying to implement a timer interrupt to my Thread application. Would LPTMR be the easiest to use to accomplish the following? Or would something else be easier?
Any pointers or available references would be helpful. Thanks!
Hi johanandrade,
The easiest way is to use TimersManager module (see TimersManager.c, TimersMnager.h) files.
As API the following functions should be used:
- TMR_AllocateTimer - to allocate the timer;
- TMR_StartSingleShotTimer - to start the timer;
- TMR_FreeTimer - to free the timer;
An example of usage is usually presented in each demo application. Please search in your project after "mAppTimerId" or "tmrStartApp".
Regards,
Ovidiu
Thanks Ovi!
After analyzing the example, here's what I was able to get working. I tested it using an LED turning on for 10 seconds before turning off. Posting code for reference.
/*==================================================================================================
Private macros
==================================================================================================*/
.
.
.
#define gLedTimeout_c 10000 /* milliseconds */
/*==================================================================================================
Public global variables declarations
==================================================================================================*/
.
.
.
/* Led timer Id */
tmrTimerID_t mLedTimerId = gTmrInvalidTimerID_c;
/*==================================================================================================
Public functions
==================================================================================================*/
.
.
.
void APP_LightShellEventReceived(void)
{
if(isLedOn)
{
(void)NWKU_SendMsg(APP_SendExtLedOff, NULL, mpAppThreadMsgQueue);
isLedOn = FALSE;
}
else{
(void)NWKU_SendMsg(APP_SendExtLedOn, NULL, mpAppThreadMsgQueue);
isLedOn = TRUE;
if(mLedTimerId == gTmrInvalidTimerID_c)
{
mLedTimerId = TMR_AllocateTimer();
}
/* Validate Led timer Id */
if(mLedTimerId != gTmrInvalidTimerID_c)
{
/* Start the led timer. Wait gLedTimeout_c
to start countdown before turning off led. */
TMR_StartSingleShotTimer(mLedTimerId, gLedTimeout_c, APP_SendExtLedOff, NULL);
}
}