6.5.8. Timer

6.5.8.1. Functions

void PLTFRM_timerA0ExpHndlr(void)

This function is called from the main system loop based on the setting of SYS_GLOBAL_EVT_TIMER_A0_EXPIRY in SYS_globalEvtMsk0. The function handles the tasks following the expiration of timer A0. At the minimum, it will call the callback function associated with the timer.

void PLTFRM_timerA1ExpHndlr(void)

This function is called from the main system loop based on the setting of SYS_GLOBAL_EVT_TIMER_A1_EXPIRY in SYS_globalEvtMsk0. The function handles the tasks following the expiration of timer A1. At the minimum, it will call the callback function associated with the timer.

void PLTFRM_timer1HzPeriodicExpHndlr(void)

This function is called from the main system loop based on the setting of SYS_GLOBAL_EVT_TIMER_1HZ_PERIODIC_EXPIRY in SYS_globalEvtMsk0. The function handles the tasks following the expiration of the watchdog timer. At the minimum, it will call the callback function associated with the timer.

PLTFRM_sts_t msp430g2553_startTimerA0(UINT16_t milliSecs, UINT16_t microSecs, PLTFRM_timerCbFunc_t cbFunc_p)

This is to start the timer A0. It is usually called via the macro PLTFRM_startTimerA0(). This timer is commonly used by the MAC layer. Platform code contains the interrupt handler for this timer, PLTFRM_timerA0IntHndlr(). This sets the event flag SYS_GLOBAL_EVT_TIMER_A0_EXPIRY in SYS_globalEvtMsk0. This in turn triggers the function call PLTFRM_timerA0ExpHndlr() from the main system loop. PLTFRM_timerA0ExpHndlr() will call the callback function given here.

Parameters:
  • milliSecs – Milliseconds part of the timer value.
  • microSecs – Microseconds part of the timer value.
  • cbFunc_p – Points to the callback function that must be called when the timer expires.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_TIMER_ALREADY_ACTIVE and PLTFRM_STS_INV_PARAM.

PLTFRM_sts_t msp430g2553_startTimerA1(UINT16_t secs, UINT16_t milliSecs, PLTFRM_timerCbFunc_t cbFunc_p)

This is to start the timer A1. It is usually called via the macro PLTFRM_startTimerA1(). This timer is commonly used by applications. Platform code contains the interrupt handler for this timer, PLTFRM_timerA1IntHndlr(). This sets the event flag SYS_GLOBAL_EVT_TIMER_A1_EXPIRY in SYS_globalEvtMsk0. This in turn triggers the function call PLTFRM_timerA1ExpHndlr() from the main system loop. PLTFRM_timerA1ExpHndlr() will call the callback function given here.

Parameters:
  • secs – The seconds part of the timer value.
  • milliSecs – Milliseconds part of the timer value.
  • cbFunc_p – Points to the callback function that must be called when the timer expires.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_TIMER_ALREADY_ACTIVE and PLTFRM_STS_INV_PARAM.

PLTFRM_sts_t msp430g2553_startWDTimer(PLTFRM_timerCbFunc_t cbFunc_p)

Watchdog timer is not applicable for RFD devices. By default, watchdog interval is set to one second. The associated interrupt handler in platform code is PLTFRM_watchDogIntHndlr(). Whenever the timer expires, the interrupt handler is called and it sets SYS_GLOBAL_EVT_TIMER_1HZ_PERIODIC_EXPIRY in SYS_globalEvtMsk0. This in turn triggers the function call PLTFRM_timer1HzPeriodicExpHndlr() from the main system loop. PLTFRM_timer1HzPeriodicExpHndlr() will call the callback function given here. The callback function is expected to contain tasks that are to be done periodically by the system.

Function is typically called via the macro PLTFRM_start1HzPeriodicTimer(). Function is called normally during intialization when the system boots up.

Parameters:
  • cbFunc_p – Points to the callback function that must be called from the timer expires.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. One possible error is PLTFRM_STS_TIMER_ALREADY_ACTIVE.

PLTFRM_sts_t PLTFRM_startWakeUpTimer(UINT16_t tmoSecs)

Wakeup timer is applicable only for RFD devices. This timer determines when the RFD has to wakeup from its sleep mode. When the timer expires, event flag SYS_GLOBAL_EVT_WAKEUP_TIMER_EXPIRY_EVT is set in SYS_globalEvtMsk1. This triggers the main system loop to call RFD_APP_wakeUpTimerExpEvt(). Under the hood, this timer is implemented in software based on the watchdog interrupt.

Parameters:
  • tmoSecs – Sleep time in seconds.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_TIMER_ALREADY_ACTIVE and PLTFRM_STS_INV_PARAM.

void msp430g2553_stopTimerA0(void)

Stop timer A0. Event flag SYS_GLOBAL_EVT_TIMER_A0_EXPIRY is cleared in SYS_globalEvtMsk0.

void msp430g2553_stopTimerA1(void)

Stop timer A1. Event flag SYS_GLOBAL_EVT_TIMER_A1_EXPIRY is cleared in SYS_globalEvtMsk0.

void msp430g2553_stopWDTimer(void)

Stop the watchdog timer. Event flag SYS_GLOBAL_EVT_TIMER_1HZ_PERIODIC_EXPIRY is cleared in SYS_globalEvtMsk0.

6.5.8.2. Macros

#define PLTRM_TIMER_A0_ACTIVE_BIT  (1 << 0)
#define PLTRM_TIMER_A1_ACTIVE_BIT  (1 << 1)
#define PLTRM_TIMER_1HZ_PERIODIC_ACTIVE_BIT  (1 << 2)
#define PLTRM_TIMER_WAKEUP_ACTIVE_BIT  (1 << 3)

#define PLTFRM_TIMER_TYPE_PERIODIC  0x1
#define PLTFRM_TIMER_TYPE_ONE_SHOT  0x2

#define PLTFRM_startTimerA0(milliSecs, microSecs, cbFunc_p) \
        msp430g2553_startTimerA0((milliSecs),  \
                                 (microSecs),  \
                                 (PLTFRM_timerCbFunc_t)(cbFunc_p))

#define PLTFRM_startTimerA1(secs, MilliSecs, cbFunc_p) \
        msp430g2553_startTimerA1((secs),  \
                                 (MilliSecs),  \
                                 (PLTFRM_timerCbFunc_t)(cbFunc_p))

#define PLTFRM_start1HzPeriodicTimer(cbFunc_p) \
        msp430g2553_startWDTimer((PLTFRM_timerCbFunc_t)(cbFunc_p))

#define PLTFRM_stopTimerA0(  )  msp430g2553_stopTimerA0( )

#define PLTFRM_stopTimerA1(  )  msp430g2553_stopTimerA1( )

#define PLTFRM_stop1HzPeriodicTimer(  )  msp430g2553_stopWDTimer( )

#define PLTFRM_getTimeStamp(time_p) \
do { \
} while (0)

// CPU_ACTIVE_CLOCK_IN_MHZ is fixed at compile time
// For now, the MSP always runs at a fixed clock rate
// when in active mode.

#define PLTFRM_delay1MicroSecs()  \
        __delay_cycles(1*CPU_ACTIVE_CLOCK_IN_MHZ)

#define PLTFRM_delay5MicroSecs()  \
        __delay_cycles(5*CPU_ACTIVE_CLOCK_IN_MHZ)

#define PLTFRM_delay10MicroSecs()  \
        __delay_cycles(10*CPU_ACTIVE_CLOCK_IN_MHZ)

#define PLTFRM_delay100MicroSecs()  \
        __delay_cycles(100*CPU_ACTIVE_CLOCK_IN_MHZ)

#define PLTFRM_delay1000MicroSecs()  \
        __delay_cycles(1000*CPU_ACTIVE_CLOCK_IN_MHZ)

#define PLTFRM_stopWakeUpTimer()  msp430g2553_stopWDTimer()

6.5.8.3. Type Definitions

typedef UINT32_t PLTFRM_timeStamp_t;

typedef void (*PLTFRM_timerCbFunc_t)(void);