Microchip® Advanced Software Framework

Quick Start Guide for EVENTS - Basic

In this use case, the EVENT module is configured for:

  • Synchronous event path with rising edge detection on the input
  • One user attached to the configured event channel
  • No hardware event generator attached to the channel

This use case allocates an event channel. This channel is not connected to any hardware event generator, events are software triggered. One user is connected to the allocated and configured event channel.

Setup

Prerequisites

There are no special setup requirements for this use-case.

Code

Add to the main application source file, before any functions, according to the kit used:

  • SAM D20 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_TC4_MCX_0
    #define CONF_EVENT_USER EVSYS_ID_USER_TC3_EVU
  • SAM D21 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_TC4_MCX_0
    #define CONF_EVENT_USER EVSYS_ID_USER_TC3_EVU
  • SAM R21 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_TC4_MCX_0
    #define CONF_EVENT_USER EVSYS_ID_USER_TC3_EVU
  • SAM D11 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_TC2_MCX_0
    #define CONF_EVENT_USER EVSYS_ID_USER_TC1_EVU
  • SAM L21 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_NONE
    #define CONF_EVENT_USER EVSYS_ID_USER_PORT_EV_0
  • SAM L22 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_NONE
    #define CONF_EVENT_USER EVSYS_ID_USER_PORT_EV_0
  • SAM DA1 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_TC4_MCX_0
    #define CONF_EVENT_USER EVSYS_ID_USER_TC3_EVU
  • SAM C21 Xplained Pro:
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_NONE
    #define CONF_EVENT_USER EVSYS_ID_USER_PORT_EV_0
  • SAM HA1G16A Xplained Pro
    #define CONF_EVENT_GENERATOR EVSYS_ID_GEN_TC4_MCX_0
    #define CONF_EVENT_USER EVSYS_ID_USER_TC3_EVU
    Copy-paste the following setup code to your user application:
    static void configure_event_channel(struct events_resource *resource)
    {
    struct events_config config;
    config.generator = CONF_EVENT_GENERATOR;
    config.edge_detect = EVENTS_EDGE_DETECT_RISING;
    config.path = EVENTS_PATH_SYNCHRONOUS;
    config.clock_source = GCLK_GENERATOR_0;
    events_allocate(resource, &config);
    }
    static void configure_event_user(struct events_resource *resource)
    {
    events_attach_user(resource, CONF_EVENT_USER);
    }
    Create an event resource struct and add to user application (typically the start of main()):
    struct events_resource example_event;
    Add to user application initialization (typically the start of main()):
    configure_event_channel(&example_event);
    configure_event_user(&example_event);

Workflow

  1. Create an event channel configuration struct, which can be filled out to adjust the configuration of a single event channel.
    struct events_config config;
  2. Initialize the event channel configuration struct with the module's default values.
    Note
    This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  3. Adjust the configuration struct to request that the channel is to be attached to the specified event generator, that rising edges of the event signal is to be detected on the channel, and that the synchronous event path is to be used.
    config.generator = CONF_EVENT_GENERATOR;
    config.edge_detect = EVENTS_EDGE_DETECT_RISING;
    config.path = EVENTS_PATH_SYNCHRONOUS;
    config.clock_source = GCLK_GENERATOR_0;
  4. Allocate and configure the channel using the configuration structure.
    events_allocate(resource, &config);
    Note
    The existing configuration struct may be re-used, as long as any values that have been altered from the default settings are taken into account by the user application.
  5. Attach a user to the channel.
    events_attach_user(resource, CONF_EVENT_USER);

Use Case

Code

Copy-paste the following code to your user application:

while (events_is_busy(&example_event)) {
/* Wait for channel */
};
events_trigger(&example_event);
while (true) {
/* Nothing to do */
}

Workflow

  1. Wait for the event channel to become ready to accept a new event trigger.
    while (events_is_busy(&example_event)) {
    /* Wait for channel */
    };
  2. Perform a software event trigger on the configured event channel.
    events_trigger(&example_event);