/**
  ******************************************************************************
  * @file    stm32l1xx_it.c
  * @brief   Interrupt Service Routines.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */

#include "main.h"
#include "stm32l1xx_it.h"

extern DMA_HandleTypeDef hdma_usart1_tx;
extern DMA_HandleTypeDef hdma_usart3_tx;
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart3;
extern RTC_HandleTypeDef hrtc;
extern I2C_HandleTypeDef hi2c1;
extern uint8_t usb_recv_data[11];

volatile uint8_t FatFsCnt = 0;
volatile uint8_t Timer1, Timer2;

void EXTI15_10_IRQHandler(void)
{
	HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
}

void USART1_IRQHandler(void)
{
	HAL_UART_IRQHandler(&huart1);
	//HAL_UART_Receive_IT(&huart1, usb_recv_data, 11);
}

void USART3_IRQHandler(void)
{
	HAL_UART_IRQHandler(&huart3);
}

void RTC_Alarm_IRQHandler(void)
{
	HAL_RTC_AlarmIRQHandler(&hrtc);
}

void I2C1_IRQHandler(void)
{
	HAL_I2C_EV_IRQHandler(&hi2c1);
}

void SDTimer_Handler(void)
{
	if(Timer1 > 0)
		Timer1--;

	if(Timer2 > 0)
		Timer2--;
}

void NMI_Handler(void)
{

}


void HardFault_Handler(void)
{
  while (1)
  {

  }
}

void MemManage_Handler(void)
{
  while (1)
  {

  }
}

void BusFault_Handler(void)
{
  while (1)
  {

  }
}

void UsageFault_Handler(void)
{
  while (1)
  {

  }
}

void SVC_Handler(void)
{

}

void DebugMon_Handler(void)
{

}

void PendSV_Handler(void)
{

}

/*void SysTick_Handler(void)
{
  HAL_IncTick();

}*/

void SysTick_Handler(void)
{
	FatFsCnt++;
	if(FatFsCnt >= 10)
	{
		FatFsCnt = 0;
		SDTimer_Handler();
	}

	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
}

void DMA1_Channel2_IRQHandler(void)
{
  HAL_DMA_IRQHandler(&hdma_usart3_tx);
}

void DMA1_Channel4_IRQHandler(void)
{
  HAL_DMA_IRQHandler(&hdma_usart1_tx);
}

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
