struct
events_config config;
events_get_config_defaults(&config);
Use EXAMPLE_EVENT_GENRATOR as event generator
Detect events on rising edge
Use the synchronous event path
Use GCLK Generator 0 as event channel clock source
config.generator = CONF_EVENT_GENERATOR;
config.edge_detect = EVENTS_EDGE_DETECT_RISING;
config.path = EVENTS_PATH_SYNCHRONOUS;
config.clock_source = GCLK_GENERATOR_0;
Allocate and configure the channel using the configuration structure.
events_allocate(resource, &config);
events_attach_user(resource, CONF_EVENT_USER);
struct
tc_config config_tc;
struct
tc_events config_events;
tc_get_config_defaults(&config_tc);
Set counter size to 8-bit
Set wave generation mode to normal frequency generation
Use GCLK generator 1 to as TC module clock source
Prescale the input clock with 64
config_tc.counter_size = TC_COUNTER_SIZE_8BIT;
config_tc.wave_generation = TC_WAVE_GENERATION_NORMAL_FREQ;
config_tc.clock_source = GCLK_GENERATOR_1;
config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV64;
tc_init(tc_instance, CONF_TC_MODULE, &config_tc);
config_events.generate_event_on_overflow =
true;
tc_enable_events(tc_instance, &config_events);
tc_enable(tc_instance);
events_create_hook(hook, event_counter);
events_add_hook(resource, hook);
events_enable_interrupt_source(resource, EVENTS_INTERRUPT_DETECT);
Example interrupt hook code. If the hook was triggered by an event detected interrupt on the event channel this code will toggle the LED on the Xplained PRO board and increase the value of the event_count variable. The interrupt is then acknowledged.
voidevent_counter(
structevents_resource *resource)
{
if
(events_is_interrupt_set(resource, EVENTS_INTERRUPT_DETECT)) {
port_pin_toggle_output_level(LED_0_PIN);
event_count++;
events_ack_interrupt(resource, EVENTS_INTERRUPT_DETECT);
}
}