427 lines
10 KiB
C
427 lines
10 KiB
C
/**
|
||
******************************************************************************
|
||
* @file : stm32f0xx_it.c
|
||
* @author : zsq
|
||
* @version : V1.0
|
||
* @date : 2019-06-27
|
||
* @brief : it body
|
||
******************************************************************************
|
||
* @attention
|
||
*
|
||
* Copyright (c) 2019 YUNHORN(Shenzhen YunHorn Technology Co., Ltd
|
||
* All rights reserved.
|
||
*
|
||
******************************************************************************
|
||
*/
|
||
|
||
/* Includes ------------------------------------------------------------------*/
|
||
#include "stm32f0xx_it.h"
|
||
#include "bsp_usart.h"
|
||
#include "main.h"
|
||
|
||
#include "fifo.h"
|
||
|
||
#include <string.h>
|
||
/** @addtogroup Template_Project
|
||
* @{
|
||
*/
|
||
|
||
/* Private typedef -----------------------------------------------------------*/
|
||
/* Private define ------------------------------------------------------------*/
|
||
/* Private macro -------------------------------------------------------------*/
|
||
/* Private variables ---------------------------------------------------------*/
|
||
/* Private function prototypes -----------------------------------------------*/
|
||
/* Private functions ---------------------------------------------------------*/
|
||
|
||
/******************************************************************************/
|
||
/* Cortex-M0 Processor Exceptions Handlers */
|
||
/******************************************************************************/
|
||
#include "user_sensor.h"
|
||
extern SensorDataTypeDef sensorData;
|
||
extern uint8_t CO2_Buffer[CO2_BUF_LEN];
|
||
//loraNode receive Buffer
|
||
extern uint8_t loraNode_Buffer[LoraNode_BUF_LEN];
|
||
|
||
|
||
|
||
extern volatile uint8_t WifiConfigState;
|
||
|
||
|
||
#ifdef DEBUG
|
||
__IO uint8_t LORA_STATE = LORA_JOINED;
|
||
#else
|
||
__IO uint8_t LORA_STATE = LORA_NOT_JOIN;
|
||
#endif
|
||
|
||
__IO uint8_t TIMER_COUNTER = STATE;
|
||
|
||
|
||
#ifdef DEBUG
|
||
__IO uint8_t WORK_STATE = ENABLE;
|
||
#else
|
||
__IO uint8_t WORK_STATE = DISABLE;
|
||
#endif
|
||
|
||
uint8_t CO2_Rx = 0; //Uart6_Buffer下标
|
||
uint8_t CO2_head1; //帧头1
|
||
uint8_t CO2_head2; //帧头2
|
||
uint8_t CO2_Sta; //数据帧正确标志
|
||
|
||
extern RingBuff_t ringBuff;
|
||
/**
|
||
* @brief This function handles NMI exception.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void NMI_Handler(void)
|
||
{
|
||
}
|
||
|
||
/**
|
||
* @brief This function handles Hard Fault exception.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void HardFault_Handler(void)
|
||
{
|
||
/* Go to infinite loop when Hard Fault exception occurs */
|
||
while (1)
|
||
{
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief This function handles SVCall exception.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void SVC_Handler(void)
|
||
{
|
||
}
|
||
|
||
/**
|
||
* @brief This function handles PendSVC exception.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void PendSV_Handler(void)
|
||
{
|
||
|
||
}
|
||
|
||
/**
|
||
* @brief This function handles SysTick Handler.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
//void SysTick_Handler(void)
|
||
//{
|
||
//}
|
||
|
||
/******************************************************************************/
|
||
/* STM32F0xx Peripherals Interrupt Handlers */
|
||
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
|
||
/* available peripheral interrupt handler's name please refer to the startup */
|
||
/* file (startup_stm32f0xx.s). */
|
||
/******************************************************************************/
|
||
|
||
/**
|
||
* @brief This function handles PPP interrupt request.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
/*void PPP_IRQHandler(void)
|
||
{
|
||
}*/
|
||
|
||
/**
|
||
* @brief DMA1_Ch1 interrupt Handler.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler(void)
|
||
{
|
||
DMA_GetITStatus(DMA1_IT_TC3);
|
||
{
|
||
DMA_ClearFlag(DMA1_IT_TC3);
|
||
}
|
||
}
|
||
void DDMA1_Ch4_7_DMA2_Ch3_5_IRQHandler(void)
|
||
{
|
||
DMA_GetITStatus(DMA1_IT_TC5);
|
||
{
|
||
DMA_ClearFlag(DMA1_IT_TC5);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief DEBUG_USART_IRQHandler interrupt Handler.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void DEBUG_USART_IRQHandler(void)
|
||
{
|
||
uint8_t Res;
|
||
if(USART_GetITStatus(DEBUG_USART,USART_IT_RXNE)!=RESET)
|
||
{
|
||
Res = USART_ReceiveData(DEBUG_USART);
|
||
// USART_SendData(WIFI_USART,Res);
|
||
// while(USART_GetFlagStatus(WIFI_USART,USART_FLAG_TXE)==RESET);
|
||
// USART_ClearITPendingBit(DEBUG_USART,USART_IT_RXNE);
|
||
|
||
// Res = USART_ReceiveData(DEBUG_USART);
|
||
// Write_RingBuff(Res);
|
||
USART_ClearITPendingBit(DEBUG_USART,USART_IT_RXNE);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief NH3_USART_IRQHandler interrupt Handler.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void NH3_USART_IRQHandler(void)
|
||
{
|
||
if(USART_GetITStatus(NH3_USART,USART_IT_IDLE)!=RESET)
|
||
{
|
||
USART_ClearITPendingBit(NH3_USART,USART_IT_IDLE);
|
||
DMA_Cmd(NH3_USART_DMA_CHANNEL,DISABLE);
|
||
NH3_USART_DMA_CHANNEL->CNDTR=NH3_BUF_LEN;
|
||
DMA_Cmd(NH3_USART_DMA_CHANNEL,ENABLE);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief USART3_8 interrupt Handler.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void USART3_8_IRQHandler()
|
||
{
|
||
|
||
if(USART_GetITStatus(CH2O_USART,USART_IT_IDLE)!=RESET)
|
||
{
|
||
// for(int i = 0;i<100-DMA_GetCurrDataCounter(DMA1_Channel3);i++)
|
||
// {
|
||
// USART_SendData(USART1,CH2O_Buffer[i]);
|
||
// while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
|
||
// }
|
||
USART_ClearITPendingBit(CH2O_USART,USART_IT_IDLE);
|
||
DMA_Cmd(CH2O_USART_DMA_CHANNEL,DISABLE);
|
||
CH2O_USART_DMA_CHANNEL->CNDTR=CH2O_BUF_LEN;
|
||
DMA_Cmd(CH2O_USART_DMA_CHANNEL,ENABLE);
|
||
}
|
||
|
||
if(USART_GetITStatus(PM25_USART,USART_IT_IDLE)!=RESET)
|
||
{
|
||
USART_ClearITPendingBit(PM25_USART,USART_IT_IDLE);
|
||
DMA_Cmd(PM25_USART_DMA_CHANNEL,DISABLE);
|
||
PM25_USART_DMA_CHANNEL->CNDTR=PM25_BUF_LEN;
|
||
DMA_Cmd(PM25_USART_DMA_CHANNEL,ENABLE);
|
||
}
|
||
|
||
if(USART_GetITStatus(H2S_USART,USART_IT_IDLE)!=RESET)
|
||
{
|
||
USART_ClearITPendingBit(H2S_USART,USART_IT_IDLE);
|
||
DMA_Cmd(H2S_USART_DMA_CHANNEL,DISABLE);
|
||
H2S_USART_DMA_CHANNEL->CNDTR=H2S_BUF_LEN;
|
||
DMA_Cmd(H2S_USART_DMA_CHANNEL,ENABLE);
|
||
}
|
||
|
||
//CO2中断处理函数
|
||
if(USART_GetITStatus(CO2_USART,USART_IT_RXNE)!=RESET)
|
||
{
|
||
CO2_Buffer[CO2_Rx] =USART_ReceiveData(CO2_USART);
|
||
CO2_Rx++;
|
||
CO2_Rx &= 0xFF;
|
||
USART_ClearITPendingBit(CO2_USART,USART_IT_RXNE);
|
||
}
|
||
if(CO2_Buffer[CO2_Rx-1] == 0xFF)
|
||
{
|
||
CO2_head1 = CO2_Rx-1;
|
||
}
|
||
else if((CO2_Rx-1 == CO2_head1+1)&&(CO2_Buffer[CO2_Rx-1] == 0x86))
|
||
{
|
||
CO2_head2 = CO2_Rx-1;
|
||
}
|
||
|
||
else if(CO2_Rx-1 == CO2_head2+7)
|
||
{
|
||
uint8_t CO2_temp = 0x00;
|
||
for(int i = CO2_head2; i<CO2_head2+7; i++)
|
||
{
|
||
CO2_temp += CO2_Buffer[i];
|
||
}
|
||
CO2_temp = (~CO2_temp)+1;
|
||
if(((CO2_temp&0xFF) == CO2_Buffer[CO2_head2+7]) && (CO2_Buffer[CO2_head2] == 0x86))
|
||
{
|
||
sensorData.co2 = (CO2_Buffer[CO2_head2+1]*256+CO2_Buffer[CO2_head2+2]);
|
||
#ifdef DEBUG
|
||
printf("co2: %d\r\n",sensorData.co2);
|
||
#endif
|
||
}
|
||
CO2_Sta = 0;
|
||
CO2_Rx = 0;
|
||
}
|
||
|
||
// //二氧化碳传感器目前DMA有问题,暂时使用中断处理
|
||
// if(USART_GetITStatus(CO2_USART,USART_IT_IDLE)!=RESET)
|
||
// {
|
||
//// USART_SendData(DEBUG_USART,'A');
|
||
//// while(USART_GetFlagStatus(DEBUG_USART,USART_FLAG_TXE)==RESET);
|
||
//// for(int i = 0;i<64-DMA_GetCurrDataCounter(DMA1_Channel6);i++)
|
||
//// {
|
||
//// USART_SendData(DEBUG_USART,CO2_Buffer[i]);
|
||
//// while(USART_GetFlagStatus(DEBUG_USART,USART_FLAG_TXE)==RESET);
|
||
//// }
|
||
// USART_ClearITPendingBit(CO2_USART,USART_IT_IDLE);
|
||
// DMA_Cmd(CO2_USART_DMA_CHANNEL,DISABLE);
|
||
// CO2_USART_DMA_CHANNEL->CNDTR=CO2_BUF_LEN;
|
||
// DMA_Cmd(CO2_USART_DMA_CHANNEL,ENABLE);
|
||
//
|
||
// //CO2数据校验
|
||
// uint8_t CO2_temp = 0x00;
|
||
// for(int i = 1; i<8; i++)
|
||
// {
|
||
// CO2_temp += CO2_Buffer[i];
|
||
// }
|
||
// CO2_temp = (~CO2_temp)+1;
|
||
// if(((CO2_temp&0xFF) == CO2_Buffer[8]) && (CO2_Buffer[1] == 0x86))
|
||
// {
|
||
// sensorData.co2 = (CO2_Buffer[2]*256+CO2_Buffer[3]);
|
||
// }
|
||
// }
|
||
|
||
//WIFI
|
||
if(USART_GetITStatus(WIFI_USART,USART_IT_RXNE)!=RESET)
|
||
{
|
||
uint8_t Res;
|
||
if(USART_GetITStatus(WIFI_USART,USART_IT_RXNE)!=RESET)
|
||
{
|
||
Res = USART_ReceiveData(WIFI_USART);
|
||
while(USART_GetFlagStatus(DEBUG_USART,USART_FLAG_TXE)==RESET);
|
||
USART_ClearITPendingBit(WIFI_USART,USART_IT_RXNE);
|
||
}
|
||
}
|
||
|
||
if(USART_GetITStatus(LORA_USART,USART_IT_IDLE)!=RESET)
|
||
{
|
||
USART_ClearITPendingBit(LORA_USART,USART_IT_IDLE);
|
||
DMA_Cmd(LORA_USART_DMA_CHANNEL,DISABLE);
|
||
LORA_USART_DMA_CHANNEL->CNDTR=LoraNode_BUF_LEN;
|
||
DMA_Cmd(LORA_USART_DMA_CHANNEL,ENABLE);
|
||
|
||
if(strncmp("\r\n+STATUS:",(const char *)loraNode_Buffer,10) == 0)
|
||
{
|
||
switch(loraNode_Buffer[10]-0x30)
|
||
{
|
||
case LORA_RESET:
|
||
LORA_STATE = LORA_RESET;
|
||
break;
|
||
case LORA_P2P:
|
||
LORA_STATE = LORA_P2P;
|
||
break;
|
||
case LORA_NOT_JOIN:
|
||
LORA_STATE = LORA_NOT_JOIN;
|
||
break;
|
||
case LORA_JOINED:
|
||
LORA_STATE = LORA_JOINED;
|
||
break;
|
||
}
|
||
// printf("LORA_STATE is : %d!\r\n",LORA_STATE);
|
||
}
|
||
if(strncmp("\r\n^STATUS:",(const char *)loraNode_Buffer,10) == 0)
|
||
{
|
||
switch(loraNode_Buffer[10]-0x30)
|
||
{
|
||
case LORA_RESET:
|
||
LORA_STATE = LORA_RESET;
|
||
break;
|
||
case LORA_P2P:
|
||
LORA_STATE = LORA_P2P;
|
||
break;
|
||
case LORA_NOT_JOIN:
|
||
LORA_STATE = LORA_NOT_JOIN;
|
||
break;
|
||
case LORA_JOINED:
|
||
LORA_STATE = LORA_JOINED;
|
||
break;
|
||
}
|
||
// printf("LORA_STATE is : %d!\r\n",LORA_STATE);
|
||
}
|
||
if(strncmp("^STATUS:",(const char *)loraNode_Buffer,8) == 0)
|
||
{
|
||
switch(loraNode_Buffer[8]-0x30)
|
||
{
|
||
case LORA_RESET:
|
||
LORA_STATE = LORA_RESET;
|
||
break;
|
||
case LORA_P2P:
|
||
LORA_STATE = LORA_P2P;
|
||
break;
|
||
case LORA_NOT_JOIN:
|
||
LORA_STATE = LORA_NOT_JOIN;
|
||
break;
|
||
case LORA_JOINED:
|
||
LORA_STATE = LORA_JOINED;
|
||
break;
|
||
}
|
||
// printf("LORA_STATE is : %d!\r\n",LORA_STATE);
|
||
}
|
||
}
|
||
}
|
||
|
||
void BUTTON0_IRQHandler()
|
||
{
|
||
if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
|
||
{
|
||
WifiConfigState = ENABLE;
|
||
|
||
EXTI_ClearITPendingBit(EXTI_Line0);
|
||
#ifdef DEBUG
|
||
printf("BUTTON0_IRQHandler\r\n");
|
||
#endif
|
||
}
|
||
else
|
||
{
|
||
EXTI->PR = 0x0003;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief This function handles TIM interrupt request.
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void TIM6_DAC_IRQHandler (void)
|
||
{
|
||
if(TIM_GetITStatus(TIM6,TIM_IT_Update) != RESET )
|
||
{
|
||
|
||
TIM_ClearITPendingBit(TIM6,TIM_IT_Update);
|
||
|
||
switch(TIMER_COUNTER)
|
||
{
|
||
case SEND:
|
||
TIMER_COUNTER = STATE;
|
||
WORK_STATE = ENABLE;
|
||
break;
|
||
case CONFIG:
|
||
TIMER_COUNTER = SEND;
|
||
WORK_STATE = ENABLE;
|
||
break;
|
||
case STATE:
|
||
TIMER_COUNTER = CONFIG;
|
||
WORK_STATE = ENABLE;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @}
|
||
*/
|
||
|
||
|
||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|