Configure EXTINT for fault input
- Create an EXTINT module channel configuration struct, which can be filled out to adjust the configuration of a single external interrupt channel.
struct
extint_chan_conf config;
- Initialize the channel configuration struct with the module's default values.
extint_chan_get_config_defaults(&config);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Adjust the configuration struct to configure the pin MUX (to route the desired physical pin to the logical channel) to the board button, and to configure the channel to detect both rising and falling edges.
config.filter_input_signal =
true
;
config.detection_criteria = EXTINT_DETECT_BOTH;
config.gpio_pin = CONF_FAULT_EIC_PIN;
config.gpio_pin_mux = CONF_FAULT_EIC_PIN_MUX;
- Configure external interrupt channel with the desired channel settings.
extint_chan_set_config(CONF_FAULT_EIC_LINE, &config);
- Create a TXTINT events configuration struct, which can be filled out to enable/disable events. Reset all fields to zero.
struct
extint_events events;
memset(&events, 0,
sizeof
(
struct
extint_events));
- Adjust the configuration struct, set the channels to be enabled to true. Here the channel to the board button is used.
events.generate_event_on_detect[CONF_FAULT_EIC_LINE] =
true
;
- Enable the events.
extint_enable_events(&events);
- Define the EXTINT callback that will be fired when a detection event occurs. For this example, when fault line is released, the TCC fault state is cleared to go on PWM generating.
static
void
eic_callback_to_clear_halt(
void
)
{
if
(port_pin_get_input_level(CONF_FAULT_EIC_PIN)) {
tcc_clear_status(&tcc_instance,
TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR(0));
}
}
- Register a callback function eic_callback_to_clear_halt() to handle detections from the External Interrupt Controller (EIC).
extint_register_callback(eic_callback_to_clear_halt,
CONF_FAULT_EIC_LINE, EXTINT_CALLBACK_TYPE_DETECT);
- Enable the registered callback function for the configured External Interrupt channel, so that it will be called by the module when the channel detects an edge.
extint_chan_enable_callback(CONF_FAULT_EIC_LINE,
EXTINT_CALLBACK_TYPE_DETECT);