e310_g002/
interrupt_service.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5use crate::chip::E310xDefaultPeripherals;
6use crate::interrupts;
7
8#[repr(transparent)]
9pub struct E310G002DefaultPeripherals<'a> {
10    pub e310x: E310xDefaultPeripherals<'a>,
11}
12
13impl E310G002DefaultPeripherals<'_> {
14    pub unsafe fn new(clock_frequency: u32) -> Self {
15        Self {
16            e310x: E310xDefaultPeripherals::new(clock_frequency),
17        }
18    }
19
20    pub fn init(&'static self) {
21        self.e310x.init();
22    }
23}
24impl kernel::platform::chip::InterruptService for E310G002DefaultPeripherals<'_> {
25    unsafe fn service_interrupt(&self, interrupt: u32) -> bool {
26        match interrupt {
27            interrupts::UART0 => self.e310x.uart0.handle_interrupt(),
28            interrupts::UART1 => self.e310x.uart1.handle_interrupt(),
29            int_pin @ interrupts::GPIO0..=interrupts::GPIO31 => {
30                let pin = &self.e310x.gpio_port[(int_pin - interrupts::GPIO0) as usize];
31                pin.handle_interrupt();
32            }
33
34            // put E310x specific interrupts here
35            _ => return self.e310x.service_interrupt(interrupt),
36        }
37        true
38    }
39}