foc_irqs.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "stm32f3xx_hal.h"
  2. #include "stm32f3xx_ll_tim.h"
  3. #include "stm32f3xx_ll_adc.h"
  4. #include "stm32f3xx_ll_exti.h"
  5. #include "libs/types.h"
  6. __weak void foc_brake_handler(void) {}
  7. __weak void foc_pwm_up_handler(void) {}
  8. __weak void system_tick_handler(void){}
  9. __weak void current_sample_handler(void){}
  10. __weak void hall_sensor_handler(void){}
  11. __weak void uart2_irq_handler(void) {}
  12. __weak void foc_slow_task_handler(void){}
  13. __weak void start_stop_handler(void) {}
  14. void TIM1_BRK_TIM15_IRQHandler(void){
  15. if (LL_TIM_IsActiveFlag_BRK2(TIM1))
  16. {
  17. LL_TIM_ClearFlag_BRK2(TIM1);
  18. TIM1->BDTR |= LL_TIM_OSSI_ENABLE;
  19. foc_brake_handler();
  20. }
  21. }
  22. void TIM1_UP_TIM16_IRQHandler(void){
  23. if (LL_TIM_IsActiveFlag_UPDATE(TIM1))
  24. {
  25. LL_TIM_ClearFlag_UPDATE(TIM1);
  26. foc_pwm_up_handler();
  27. }
  28. }
  29. void ADC1_IRQHandler(void) {
  30. LL_ADC_ClearFlag_JEOS( ADC1 );
  31. current_sample_handler();
  32. }
  33. void TIM6_DAC_IRQHandler(void) {
  34. if (LL_TIM_IsActiveFlag_UPDATE(TIM6))
  35. {
  36. LL_TIM_ClearFlag_UPDATE(TIM6);
  37. foc_slow_task_handler();
  38. }
  39. }
  40. void SysTick_Handler(void)
  41. {
  42. system_tick_handler();
  43. }
  44. void EXTI3_IRQHandler(void) {
  45. if ( LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_3) )
  46. {
  47. LL_EXTI_ClearFlag_0_31 (LL_EXTI_LINE_3);
  48. hall_sensor_handler();
  49. }
  50. }
  51. void EXTI15_10_IRQHandler(void) {
  52. if ( LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_10) )
  53. {
  54. LL_EXTI_ClearFlag_0_31 (LL_EXTI_LINE_10);
  55. hall_sensor_handler();
  56. }
  57. if ( LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_13) )
  58. {
  59. LL_EXTI_ClearFlag_0_31 (LL_EXTI_LINE_13);
  60. start_stop_handler();
  61. }
  62. if ( LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_15) )
  63. {
  64. LL_EXTI_ClearFlag_0_31 (LL_EXTI_LINE_15);
  65. hall_sensor_handler();
  66. }
  67. }
  68. void USART2_IRQHandler(void) {
  69. uart2_irq_handler();
  70. }