Timer 1 Event Trigger

Description

Use Timer 1 to trigger Event Handler Code

This resource uses AUX Timer 1 to trigger an Event Handler Code task code block after a configurable period of time. The timer runs off 4 kHz ticks (4096 Hz) generated by the RTC.

This can typically be used to:

  • Run a Sensor Controller task at irregular intervals, without unnecessary wake-ups from the RTC.
  • Follow up on actions performed by the Execution Code , for reading results from and powering down an external sensor device after a period of time.

There are two options for setting up Timer 1 event triggers:

  • Call evhSetupTimer1Trigger() to generate a single event trigger after the specified delay
  • Use the Timer 1 resource to start (and stop) the timer manually, for example in periodical mode, and then call evhSetupTimer1CustomTrigger()
    • This makes it possible to generate periodical wake-ups with precise timing, or use other tick sources than the 4 kHz from the RTC.
    • In order to operate correctly, Timer 1 must run off a tick source that toggles at less than 32 kHz.

The trigger can be set up from within the Initialization Code , Execution Code or Event Handler Code task code blocks.

The trigger is one-shot. For repeated or periodical triggers, this means that the Event Handler Code must call evhSetupTimer1Trigger() or evhSetupTimer1CustomTrigger() to setup the next trigger.

Event Trigger Mapping

The CC13x2/CC26x2 and CC13x4/CC26x4 chip families support up to 3 event triggers in total per project. The Code Generator Panel displays an error message if this number is exceeded.

Access the Task Panel to map event trigger(s) to Event Handler Code task code blocks:

  • Ensure that one or more event trigger resources are enabled
  • Below these resources, select the number of simultaneous event triggers for the task
  • Map the event index(es) to Event Handler Code task code blocks. The event indexes start at 0 for each task.

While the number of event triggers and mapping of event indexes to task code blocks are static, the event indexes can be reused for different types of event triggers. For example, it is possible to alternate between a timer trigger and a GPIO trigger for one event index.

If a new event trigger is set up using an already active event index, the previously set up event trigger is cancelled.

The Termination Code must call evhCancelTrigger() for each used event index, so that the last set up event triggers do not occur after the task has been stopped.

Trigger Timing

Typical startup delays, from the Timer 1 event trigger to execution of the Event Handler Code task code block, are shown in the tables below.

For startup to low-power mode:

Scenario Typical delay
From standby mode, SCLK_MF clock not running 47 - 77 us
From standby mode, SCLK_MF clock already running 45 - 75 us
Trigger occurs while Sensor Controller runs other code 24 us or more (already running code must finish)

For startup to active mode:

Scenario Typical delay
From standby mode, SCLK_HF clock not running 145 - 215 us
From standby mode, SCLK_HF clock already running 24 - 54 us
Trigger occurs while Sensor Controller runs other code 4 us or more (already running code must finish)

Examples

Variable Wake-Up Interval (Initialization Code)

... Enable the sensor ...

// Set up the first timer trigger ~16 ms from now
evhSetupTimer1Trigger(0, 16, 2);

Variable Wake-Up Interval (Event Handler Code)

... Read and process sensor data ...

// Set up the next timer trigger with delay depending on the current state
U16 delayMs = 16 << state.intervalExp;
evhSetupTimer1Trigger(0, delayMs, 2);

Variable Wake-Up Interval (Termination Code)

// The currently enabled event trigger must be cancelled manually
evhCancelTrigger(0);

Precise Wake-Up Interval (Initialization Code)

... Enable the sensor ...

// Set up Timer 1 to generate events at ~20 Hz
timer1StartWithTickSrc(TIMER1_TICKSRC_AON_RTC_4KHZ, 1, TIMER1_MODE_PERIODICAL, 4096 / 20, 0);

// Setup the first timer trigger
evhSetupTimer1CustomTrigger(0);

Precise Wake-Up Interval (Event Handler Code)

... Read and process sensor data ...

// Set up the next timer trigger (~20 Hz)
evhSetupTimer1CustomTrigger(0);

Precise Wake-Up Interval (Termination Code)

// Stop Timer 1
timer1Stop();

// The currently enabled event trigger must be cancelled manually
evhCancelTrigger(0);

Button Debouncing (Event Handler Code)

// If a button edge has been detected (not yet debounced) ...
if (state.isDebouncing == 0) {

    // Store the state (do not read the pin, as it may have changed since the trigger)
    output.buttonState ^= 1;

    // Alert the System CPU application when the button is pressed
    if (output.buttonState == BUTTON_PRESSED) {

        ... Do something here ...

    }

    // Start ~200 ms debouncing interval
    evhSetupTimer1Trigger(0, 200, 2);

    // Update state
    state.isDebouncing = 1;

// When debouncing has been completed ...
} else {

    // Start listening for the opposite button state
    if (output.buttonState == BUTTON_PRESSED) {
        evhSetupGpioTrigger(0, AUXIO_I_BUTTON, BUTTON_RELEASED, EVH_GPIO_TRIG_ON_MATCH);
    } else {
        evhSetupGpioTrigger(0, AUXIO_I_BUTTON, BUTTON_PRESSED, EVH_GPIO_TRIG_ON_MATCH);
    }

    // Update state
    state.isDebouncing = 0;
}

Procedures Overview

Name Brief description
evhCancelTrigger() Cancels a previous call to an event trigger setup procedure (for example evhSetupGpioTrigger() ) with matching event index, including any pending Event Handler Code execution if the trigger already has occurred. More …
evhGetActiveTrigger() This procedure can be called from event handler code to determine which event index triggered the event handler code. More …
evhSetupTimer1CustomTrigger() Sets up AUX Timer 1 to trigger execution of the Event Handler Code after a specified delay, but does not start Timer 1 in one-shot mode. More …
evhSetupTimer1Trigger() Sets up AUX Timer 1 to trigger execution of the Event Handler Code after a specified delay. More …

Constants

Name Description
TIMER1_TICKSRC_AON_RTC_4KHZ Timer 1 tick source: 4 kHz ticks generated by AON RTC

Global Variables

None.

Procedures

evhCancelTrigger

Prototype: evhCancelTrigger(#evIndex)

Cancels a previous call to an event trigger setup procedure (for example evhSetupGpioTrigger() ) with matching event index, including any pending Event Handler Code execution if the trigger already has occurred.

This procedure should be called from the Termination Code if the task can be stopped by the application while an event trigger is enabled.

Parameter value(s)

  • #evIndex : Event index to be cancelled

evhGetActiveTrigger

Prototype: evhGetActiveTrigger(bvEvent)

This procedure can be called from event handler code to determine which event index triggered the event handler code.

Return value(s)

  • bvEvent : Bit-vector indicating the event index that triggered the event handler code

evhSetupTimer1CustomTrigger

Prototype: evhSetupTimer1CustomTrigger(#evIndex)

Sets up AUX Timer 1 to trigger execution of the Event Handler Code after a specified delay, but does not start Timer 1 in one-shot mode. This allows for example periodical wake-ups at a precise interval.

Use the Timer 1 resource to start and stop the timer manually. In order to operate correctly, Timer 1 must run off a tick source that toggles at less than 32 kHz.

The trigger itself is one-shot. After the trigger occurs, the specified Event Handler Code then starts when the Sensor Controller is idle or in standby.

Parameter value(s)

  • #evIndex : Event index to be triggered

evhSetupTimer1Trigger

Prototype: evhSetupTimer1Trigger(#evIndex, mant, #exp)

Sets up AUX Timer 1 to trigger execution of the Event Handler Code after a specified delay.

The timer runs off 4 kHz ticks (4096 Hz) generated by the RTC. Note the following limitations:

  • The timeout is rounded up to the closest number of 4 kHz ticks
  • The 4 kHz tick rate is matched to the RTC rate, which may be adjusted dynamically if running off RCOSC LF

The trigger occurs after the delay. The specified Event Handler Code then starts when the Sensor Controller is idle or in standby.

Parameter value(s)

  • #evIndex : Event index to be triggered
  • mant : Delay mantissa value (1-65535). Resulting delay is mant * 2^exp [4 kHz ticks].
  • #exp : Delay exponent value (0-15). Resulting delay is mant * 2^exp [4 kHz ticks].