Generate exti interrupt handlers
Match interrupts starting with ^EXTI and generate init code and irq handler for them
This commit is contained in:
		
				
					committed by
					
						
						Dario Nieuwenhuis
					
				
			
			
				
	
			
			
			
						parent
						
							8172db6d8e
						
					
				
				
					commit
					0cd3236fa3
				
			@@ -57,6 +57,7 @@ for chip in chips.values():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        af = gpio_afs[chip['gpio_af']]
 | 
					        af = gpio_afs[chip['gpio_af']]
 | 
				
			||||||
        peripheral_names = []  # USART1, PA5, EXTI8
 | 
					        peripheral_names = []  # USART1, PA5, EXTI8
 | 
				
			||||||
 | 
					        exti_interrupts = [] # EXTI IRQs, EXTI0, EXTI4_15 etc.
 | 
				
			||||||
        peripheral_versions = {}  # usart -> v1, syscfg -> f4
 | 
					        peripheral_versions = {}  # usart -> v1, syscfg -> f4
 | 
				
			||||||
        pins = set()  # set of all present pins. PA4, PA5...
 | 
					        pins = set()  # set of all present pins. PA4, PA5...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -177,6 +178,12 @@ for chip in chips.values():
 | 
				
			|||||||
                        if func := funcs.get(f'{name}_D7'):
 | 
					                        if func := funcs.get(f'{name}_D7'):
 | 
				
			||||||
                            f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});')
 | 
					                            f.write(f'impl_sdmmc_pin!({name}, D7Pin, {pin}, {func});')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if block_mod == 'exti':
 | 
				
			||||||
 | 
					                for irq in chip['interrupts']:
 | 
				
			||||||
 | 
					                    if re.match('EXTI', irq):
 | 
				
			||||||
 | 
					                        exti_interrupts.append(irq)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if not custom_singletons:
 | 
					            if not custom_singletons:
 | 
				
			||||||
                peripheral_names.append(name)
 | 
					                peripheral_names.append(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -228,6 +235,15 @@ for chip in chips.values():
 | 
				
			|||||||
                }}
 | 
					                }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                {''.join(irq_declares)}
 | 
					                {''.join(irq_declares)}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                pub mod exti {{
 | 
				
			||||||
 | 
					                    use embassy::interrupt::InterruptExt;
 | 
				
			||||||
 | 
					                    use crate::interrupt;
 | 
				
			||||||
 | 
					                    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    impl_exti_irq!({','.join(exti_interrupts)});
 | 
				
			||||||
 | 
					                    impl_exti_init!({','.join(exti_interrupts)});
 | 
				
			||||||
 | 
					                }}
 | 
				
			||||||
            }}
 | 
					            }}
 | 
				
			||||||
            mod interrupt_vector {{
 | 
					            mod interrupt_vector {{
 | 
				
			||||||
                extern "C" {{
 | 
					                extern "C" {{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,41 +21,6 @@ const EXTI_COUNT: usize = 16;
 | 
				
			|||||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
 | 
					const NEW_AW: AtomicWaker = AtomicWaker::new();
 | 
				
			||||||
static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [NEW_AW; EXTI_COUNT];
 | 
					static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [NEW_AW; EXTI_COUNT];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[interrupt]
 | 
					 | 
				
			||||||
unsafe fn EXTI0() {
 | 
					 | 
				
			||||||
    on_irq()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[interrupt]
 | 
					 | 
				
			||||||
unsafe fn EXTI1() {
 | 
					 | 
				
			||||||
    on_irq()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[interrupt]
 | 
					 | 
				
			||||||
unsafe fn EXTI2() {
 | 
					 | 
				
			||||||
    on_irq()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[interrupt]
 | 
					 | 
				
			||||||
unsafe fn EXTI3() {
 | 
					 | 
				
			||||||
    on_irq()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[interrupt]
 | 
					 | 
				
			||||||
unsafe fn EXTI4() {
 | 
					 | 
				
			||||||
    on_irq()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[interrupt]
 | 
					 | 
				
			||||||
unsafe fn EXTI9_5() {
 | 
					 | 
				
			||||||
    on_irq()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[interrupt]
 | 
					 | 
				
			||||||
unsafe fn EXTI15_10() {
 | 
					 | 
				
			||||||
    on_irq()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub unsafe fn on_irq() {
 | 
					pub unsafe fn on_irq() {
 | 
				
			||||||
    let bits = EXTI.pr().read().0;
 | 
					    let bits = EXTI.pr().read().0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -249,14 +214,30 @@ impl_exti!(EXTI13, 13);
 | 
				
			|||||||
impl_exti!(EXTI14, 14);
 | 
					impl_exti!(EXTI14, 14);
 | 
				
			||||||
impl_exti!(EXTI15, 15);
 | 
					impl_exti!(EXTI15, 15);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// safety: must be called only once
 | 
					macro_rules! impl_exti_irq {
 | 
				
			||||||
pub(crate) unsafe fn init() {
 | 
					    ($e:ident) => {
 | 
				
			||||||
    interrupt::EXTI0::steal().enable();
 | 
					        #[interrupt]
 | 
				
			||||||
    interrupt::EXTI1::steal().enable();
 | 
					        unsafe fn $e() {
 | 
				
			||||||
    interrupt::EXTI2::steal().enable();
 | 
					            crate::exti::on_irq()
 | 
				
			||||||
    interrupt::EXTI3::steal().enable();
 | 
					        }
 | 
				
			||||||
    interrupt::EXTI4::steal().enable();
 | 
					    };
 | 
				
			||||||
    interrupt::EXTI9_5::steal().enable();
 | 
					
 | 
				
			||||||
    interrupt::EXTI15_10::steal().enable();
 | 
					    ($e:ident, $($es:ident),+) => {
 | 
				
			||||||
    interrupt::EXTI15_10::steal().enable();
 | 
					        impl_exti_irq! { $e }
 | 
				
			||||||
 | 
					        impl_exti_irq! { $($es),+ }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					macro_rules! impl_exti_init {
 | 
				
			||||||
 | 
					    ($e:ident) => {
 | 
				
			||||||
 | 
					        crate::interrupt::$e::steal().enable();
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ($e:ident, $($es:ident),+) => {
 | 
				
			||||||
 | 
					        /// safety: must be called only once
 | 
				
			||||||
 | 
					        pub(crate) unsafe fn init() {
 | 
				
			||||||
 | 
					            impl_exti_init! { $e }
 | 
				
			||||||
 | 
					            impl_exti_init! { $($es),+ }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,8 +49,8 @@ pub fn init(_config: Config) -> Peripherals {
 | 
				
			|||||||
    let p = Peripherals::take();
 | 
					    let p = Peripherals::take();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unsafe {
 | 
					    unsafe {
 | 
				
			||||||
        exti::init();
 | 
					 | 
				
			||||||
        dma::init();
 | 
					        dma::init();
 | 
				
			||||||
 | 
					        interrupt::exti::init();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p
 | 
					    p
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user