diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-06-12 21:45:45 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-06-12 21:45:45 +0200 |
commit | a6dc2b0ad2bf5efd2c9f49754ff7057f5c24a929 (patch) | |
tree | 0070f7f79c024a93eaf885fe89d51955da7a3be2 | |
parent | 3db942d06cf22478041921bc570e6c9650b217d0 (diff) |
Added interrupt<>() template.
-rw-r--r-- | SConstruct | 2 | ||||
-rw-r--r-- | interrupt.cpp | 157 | ||||
-rw-r--r-- | interrupt.h | 80 | ||||
-rw-r--r-- | main.cpp | 11 |
4 files changed, 238 insertions, 12 deletions
@@ -34,7 +34,7 @@ sources = \ Glob('chibios/os/hal/platforms/STM32/*.c')
#firmware = env.Program('suzumebachi.elf', Glob('*.cpp') + Glob('*.c') + sources)
-firmware = env.Program('suzumebachi.elf', ['main.cpp', 'entry.cpp', 'rcc.cpp'])
+firmware = env.Program('suzumebachi.elf', ['main.cpp', 'entry.cpp', 'interrupt.cpp', 'rcc.cpp'])
env.Depends(firmware, 'suzumebachi.ld')
env.Command('prog', ['suzumebachi.elf'], 'openocd -f openocd.cfg -c flash_chip')
diff --git a/interrupt.cpp b/interrupt.cpp new file mode 100644 index 0000000..e9e7b24 --- /dev/null +++ b/interrupt.cpp @@ -0,0 +1,157 @@ +#include "interrupt.h" + +void entry(); + +extern "C" void unused_interrupt() { + while(1) {} +} + +template<> void interrupt<Interrupt::NMI>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::HardFault>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::MemManage>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::BusFault>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::UsageFault>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::SVCall>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::PendSV>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::SysTick>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::WWDG>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::PVD>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TAMPER>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::RTC>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::FLASH>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::RCC>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::EXTI0>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::EXTI1>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::EXTI2>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::EXTI3>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::EXTI4>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA1_Channel1>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA1_Channel2>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA1_Channel3>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA1_Channel4>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA1_Channel5>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA1_Channel6>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA1_Channel7>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::ADC1_2>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::USB_HP_CAN_TX>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::USB_LP_CAN_RX0>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::CAN_RX1>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::CAN_SCE>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::EXTI9_5>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM1_BRK>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM1_UP>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM1_TRG_COM>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM1_CC>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM2>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM3>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM4>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::I2C1_EV>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::I2C1_ER>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::I2C2_EV>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::I2C2_ER>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::SPI1>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::SPI2>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::USART1>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::USART2>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::USART3>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::EXTI15_10>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::RTCAlarm>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::USBWakeup>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM8_BRK>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM8_UP>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM8_TRG_COM>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM8_CC>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::ADC3>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::FSMC>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::SDIO>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM5>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::SPI3>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::UART4>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::UART5>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM6>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::TIM7>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA2_Channel1>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA2_Channel2>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA2_Channel3>() __attribute__ ((weak, alias ("unused_interrupt"))); +template<> void interrupt<Interrupt::DMA2_Channel4_5>() __attribute__ ((weak, alias ("unused_interrupt"))); + +typedef void (*vector_t)(); + +vector_t vectors[] __attribute__((section(".vectors"))) = { + (vector_t)0x20004ffc, + entry, + interrupt<Interrupt::NMI>, + interrupt<Interrupt::HardFault>, + interrupt<Interrupt::MemManage>, + interrupt<Interrupt::BusFault>, + interrupt<Interrupt::UsageFault>, + 0, + 0, + 0, + 0, + interrupt<Interrupt::SVCall>, + 0, + 0, + interrupt<Interrupt::PendSV>, + interrupt<Interrupt::SysTick>, + interrupt<Interrupt::WWDG>, + interrupt<Interrupt::PVD>, + interrupt<Interrupt::TAMPER>, + interrupt<Interrupt::RTC>, + interrupt<Interrupt::FLASH>, + interrupt<Interrupt::RCC>, + interrupt<Interrupt::EXTI0>, + interrupt<Interrupt::EXTI1>, + interrupt<Interrupt::EXTI2>, + interrupt<Interrupt::EXTI3>, + interrupt<Interrupt::EXTI4>, + interrupt<Interrupt::DMA1_Channel1>, + interrupt<Interrupt::DMA1_Channel2>, + interrupt<Interrupt::DMA1_Channel3>, + interrupt<Interrupt::DMA1_Channel4>, + interrupt<Interrupt::DMA1_Channel5>, + interrupt<Interrupt::DMA1_Channel6>, + interrupt<Interrupt::DMA1_Channel7>, + interrupt<Interrupt::ADC1_2>, + interrupt<Interrupt::USB_HP_CAN_TX>, + interrupt<Interrupt::USB_LP_CAN_RX0>, + interrupt<Interrupt::CAN_RX1>, + interrupt<Interrupt::CAN_SCE>, + interrupt<Interrupt::EXTI9_5>, + interrupt<Interrupt::TIM1_BRK>, + interrupt<Interrupt::TIM1_UP>, + interrupt<Interrupt::TIM1_TRG_COM>, + interrupt<Interrupt::TIM1_CC>, + interrupt<Interrupt::TIM2>, + interrupt<Interrupt::TIM3>, + interrupt<Interrupt::TIM4>, + interrupt<Interrupt::I2C1_EV>, + interrupt<Interrupt::I2C1_ER>, + interrupt<Interrupt::I2C2_EV>, + interrupt<Interrupt::I2C2_ER>, + interrupt<Interrupt::SPI1>, + interrupt<Interrupt::SPI2>, + interrupt<Interrupt::USART1>, + interrupt<Interrupt::USART2>, + interrupt<Interrupt::USART3>, + interrupt<Interrupt::EXTI15_10>, + interrupt<Interrupt::RTCAlarm>, + interrupt<Interrupt::USBWakeup>, + interrupt<Interrupt::TIM8_BRK>, + interrupt<Interrupt::TIM8_UP>, + interrupt<Interrupt::TIM8_TRG_COM>, + interrupt<Interrupt::TIM8_CC>, + interrupt<Interrupt::ADC3>, + interrupt<Interrupt::FSMC>, + interrupt<Interrupt::SDIO>, + interrupt<Interrupt::TIM5>, + interrupt<Interrupt::SPI3>, + interrupt<Interrupt::UART4>, + interrupt<Interrupt::UART5>, + interrupt<Interrupt::TIM6>, + interrupt<Interrupt::TIM7>, + interrupt<Interrupt::DMA2_Channel1>, + interrupt<Interrupt::DMA2_Channel2>, + interrupt<Interrupt::DMA2_Channel3>, + interrupt<Interrupt::DMA2_Channel4_5>, +}; diff --git a/interrupt.h b/interrupt.h new file mode 100644 index 0000000..cfc187d --- /dev/null +++ b/interrupt.h @@ -0,0 +1,80 @@ +#ifndef INTERRUPT_H +#define INTERRUPT_H + +namespace Interrupt { + enum Interrupt { + NMI, + HardFault, + MemManage, + BusFault, + UsageFault, + SVCall, + PendSV, + SysTick, + WWDG, + PVD, + TAMPER, + RTC, + FLASH, + RCC, + EXTI0, + EXTI1, + EXTI2, + EXTI3, + EXTI4, + DMA1_Channel1, + DMA1_Channel2, + DMA1_Channel3, + DMA1_Channel4, + DMA1_Channel5, + DMA1_Channel6, + DMA1_Channel7, + ADC1_2, + USB_HP_CAN_TX, + USB_LP_CAN_RX0, + CAN_RX1, + CAN_SCE, + EXTI9_5, + TIM1_BRK, + TIM1_UP, + TIM1_TRG_COM, + TIM1_CC, + TIM2, + TIM3, + TIM4, + I2C1_EV, + I2C1_ER, + I2C2_EV, + I2C2_ER, + SPI1, + SPI2, + USART1, + USART2, + USART3, + EXTI15_10, + RTCAlarm, + USBWakeup, + TIM8_BRK, + TIM8_UP, + TIM8_TRG_COM, + TIM8_CC, + ADC3, + FSMC, + SDIO, + TIM5, + SPI3, + UART4, + UART5, + TIM6, + TIM7, + DMA2_Channel1, + DMA2_Channel2, + DMA2_Channel3, + DMA2_Channel4_5 + }; +}; + +template<Interrupt::Interrupt> +void interrupt(); + +#endif @@ -1,16 +1,5 @@ #include "stm32.h" -void entry(); - -void* vectors[4] __attribute__((section(".vectors"))) = { - (void*)0x20004ffc, - (void*)entry - //(unsigned int *) STACK_TOP, // stack pointer - //(unsigned int *) main, // code entry point - //(unsigned int *) nmi_handler, // NMI handler (not really) - //(unsigned int *) hardfault_handler // hard fault handler (let's hope not) -}; - volatile unsigned int cnt; void i2c_write_reg(uint8_t addr, uint8_t reg, uint8_t data) { |