GPIO Event Trigger

Description

Use a single GPIO pin to trigger Event Handler Code

This resource uses a single GPIO pin to trigger an Event Handler Code task code block. Triggering can either occur at high or low level (no transition required) or at rising or falling edge on the GPIO pin.

This can typically be used to:

  • Run the task off an interrupt from an external sensor device or other external activity.
  • Follow up on actions performed by the Execution Code , for example reading results from and powering down an external sensor device when it generates an interrupt.

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.

Note : Enabling this resource will cause the AUX domain to run at 32 kHz (instead of having no clock) when the Sensor Controller and System CPU are in standby mode. The resulting AUX domain clock switching increases slightly the time to enter and exit standby mode for both Sensor Controller and System CPU.

Event Trigger Mapping

The CC13x0/CC26x0 chip family supports up to 1 event trigger 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

If both Sensor Controller and System CPU are in standby mode when the GPIO event trigger occurs, the wake-up is delayed by approximately 400 us. This delay includes:

  • GPIO input signal synchronization (at 32 kHz in standby)
  • Vector fetch + running two instructions to trigger wake-up (at 32 kHz in standby)
  • Wake-up trigger signal propagation (at 32 kHz in standby)
  • AUX domain wake-up

Examples

Sensor Interrupt (Initialization Code)

... Enable the sensor ...

// Set up the first interrupt trigger
evhSetupGpioTrigger(0, AUXIO_I_SENSOR_IRQ, 0, EVH_GPIO_TRIG_ON_EDGE);

Sensor Interrupt (Event Handler Code)

... Read and process sensor data ...

// Set up the next interrupt trigger
evhSetupGpioTrigger(0, AUXIO_I_SENSOR_IRQ, 0, EVH_GPIO_TRIG_ON_EDGE);

Sensor Interrupt (Termination Code)

// 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 …
evhSetupGpioTrigger() Sets up a GPIO pin to generate an Event Handler Code trigger. More …

Constants

Name Description
EVH_GPIO_TRIG_ON_EDGE GPIO trigger type: Generated on transition, edge from inverse level is required
EVH_GPIO_TRIG_ON_MATCH GPIO trigger type: Generated on match, edge from inverse level is not required

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

evhSetupGpioTrigger

Prototype: evhSetupGpioTrigger(#evIndex, #auxio, #level, #type)

Sets up a GPIO pin to generate an Event Handler Code trigger. Event indexes are mapped to event handlers in the task panel. The trigger is one-shot.

The trigger occurs as soon as the GPIO pin matches or transitions to the selected level. The Event Handler Code block that matches the specified event index then starts when the Sensor Controller is idle or in standby mode.

The GPIO pin is sampled at 32 kHz, and must be held active for at least 2 x 32 kHz periods to be captured safely.

Parameter value(s)

  • #evIndex : Event index to be triggered
  • #auxio : The GPIO pin that shall generate the trigger (index of AUX I/O pin)
  • #level : The pin level that shall generate the trigger (1 = high level / rising edge, 0 = low level / falling edge)
  • #type : GPIO trigger type (EVH_GPIO_TRIG_ON_MATCH to trigger immediately on match, or EVH_GPIO_TRIG_ON_EDGE to wait for a transition to the level)