stm32f412g/
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_specs::Stm32f412Specs;
6use stm32f4xx::chip::Stm32f4xxDefaultPeripherals;
7
8use crate::{stm32f412g_nvic, trng_registers};
9
10pub struct Stm32f412gDefaultPeripherals<'a> {
11    pub stm32f4: Stm32f4xxDefaultPeripherals<'a, Stm32f412Specs>,
12    // Once implemented, place Stm32f412g specific peripherals here
13    pub trng: stm32f4xx::trng::Trng<'a>,
14}
15
16impl<'a> Stm32f412gDefaultPeripherals<'a> {
17    pub unsafe fn new(
18        clocks: &'a crate::clocks::Clocks<'a, Stm32f412Specs>,
19        exti: &'a crate::exti::Exti<'a>,
20        dma1: &'a crate::dma::Dma1<'a>,
21        dma2: &'a crate::dma::Dma2<'a>,
22    ) -> Self {
23        Self {
24            stm32f4: Stm32f4xxDefaultPeripherals::new(clocks, exti, dma1, dma2),
25            trng: stm32f4xx::trng::Trng::new(trng_registers::RNG_BASE, clocks),
26        }
27    }
28    // Necessary for setting up circular dependencies & registering deferred calls
29    pub fn init(&'static self) {
30        self.stm32f4.setup_circular_deps();
31    }
32}
33impl kernel::platform::chip::InterruptService for Stm32f412gDefaultPeripherals<'_> {
34    unsafe fn service_interrupt(&self, interrupt: u32) -> bool {
35        match interrupt {
36            // put Stm32f412g specific interrupts here
37            stm32f412g_nvic::RNG => {
38                self.trng.handle_interrupt();
39                true
40            }
41            _ => self.stm32f4.service_interrupt(interrupt),
42        }
43    }
44}