kernel/hil/eic.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.
//! Interface for external interrupt controller.
//!
//! The External Interrupt Controller (EIC) allows pins to be configured as
//! external interrupts. Each external interrupt has its own interrupt request
//! and can be individually masked. Each external interrupt can generate an
//! interrupt on rising or falling edge, or high or low level.
//! Every interrupt pin can also be configured to be asynchronous, in order to
//! wake-up the part from sleep modes where the CLK_SYNC clock has been disabled.
//!
//! A basic use case:
//! A user button is configured for falling edge trigger and async mode.
/// Enum for selecting which edge to trigger interrupts on.
#[derive(Debug)]
pub enum InterruptMode {
RisingEdge,
FallingEdge,
HighLevel,
LowLevel,
}
/// Interface for EIC.
pub trait ExternalInterruptController {
/// The chip-dependent type of an EIC line. Number of lines available depends on the chip.
type Line;
/// Enables external interrupt on the given 'line'
/// In asynchronous mode, all edge interrupts will be
/// interpreted as level interrupts and the filter is disabled.
fn line_enable(&self, line: &Self::Line, interrupt_mode: InterruptMode);
/// Disables external interrupt on the given 'line'
fn line_disable(&self, line: &Self::Line);
}
/// Interface for users of EIC. In order
/// to execute interrupts, the user must implement
/// this `Client` interface.
pub trait Client {
/// Called when an interrupt occurs.
fn fired(&self);
}