This commit is contained in:
parent
0b9a30eb0e
commit
b626cbb446
|
@ -1,20 +1,20 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file stm32f4xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
@ -22,6 +22,7 @@
|
|||
#include "stm32f4xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "ch438q.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -66,8 +67,8 @@ extern TIM_HandleTypeDef htim4;
|
|||
/* Cortex-M4 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
@ -81,8 +82,8 @@ void NMI_Handler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
@ -96,8 +97,8 @@ void HardFault_Handler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
@ -111,8 +112,8 @@ void MemManage_Handler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pre-fetch fault, memory access fault.
|
||||
*/
|
||||
* @brief This function handles Pre-fetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
@ -126,8 +127,8 @@ void BusFault_Handler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
@ -141,8 +142,8 @@ void UsageFault_Handler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
@ -161,8 +162,8 @@ void DebugMon_Handler(void)
|
|||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line2 interrupt.
|
||||
*/
|
||||
* @brief This function handles EXTI line2 interrupt.
|
||||
*/
|
||||
void EXTI2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI2_IRQn 0 */
|
||||
|
@ -170,13 +171,13 @@ void EXTI2_IRQHandler(void)
|
|||
/* USER CODE END EXTI2_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(CH438_INT_Pin);
|
||||
/* USER CODE BEGIN EXTI2_IRQn 1 */
|
||||
|
||||
ch438_interrupt_handler();
|
||||
/* USER CODE END EXTI2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM4 global interrupt.
|
||||
*/
|
||||
* @brief This function handles TIM4 global interrupt.
|
||||
*/
|
||||
void TIM4_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_IRQn 0 */
|
||||
|
@ -189,8 +190,8 @@ void TIM4_IRQHandler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Ethernet global interrupt.
|
||||
*/
|
||||
* @brief This function handles Ethernet global interrupt.
|
||||
*/
|
||||
void ETH_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN ETH_IRQn 0 */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -24,6 +24,9 @@ const uint8_t Interruptnum[] = {
|
|||
0x80,
|
||||
}; /* SSR寄存器中断号对应值 */
|
||||
|
||||
uint8_t receive_data_buff[256];
|
||||
uint8_t receive_data_len;
|
||||
|
||||
static void ch438_tranconfig(uint8_t uart_num);
|
||||
static void ch438_set_baudrate(uint8_t uart_num, uint32_t baudrate);
|
||||
|
||||
|
@ -208,8 +211,16 @@ uint8_t ch438_recv_data(uint8_t uart_num, uint8_t *data)
|
|||
uint8_t data_len = 0;
|
||||
uint8_t *receive_data;
|
||||
receive_data = data;
|
||||
uint16_t time_out = 1000;
|
||||
// 等待数据准备好
|
||||
while ((ch438_read_reg(offsetadd[uart_num] | REG_LSR_ADDR, 1) & BIT_LSR_DATARDY) == 0)
|
||||
; // 等待数据准备好
|
||||
{
|
||||
time_out--;
|
||||
if (time_out == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ((ch438_read_reg(offsetadd[uart_num] | REG_LSR_ADDR, 1) & BIT_LSR_DATARDY))
|
||||
{
|
||||
*receive_data = ch438_read_reg(offsetadd[uart_num] | REG_RBR_ADDR, 1);
|
||||
|
@ -223,3 +234,48 @@ uint8_t ch438_recv_data(uint8_t uart_num, uint8_t *data)
|
|||
return data_len;
|
||||
}
|
||||
|
||||
void ch438_interrupt_handler(void)
|
||||
{
|
||||
uint8_t gInterruptStatus; /* 全局中断状态 */
|
||||
uint8_t InterruptStatus; /* 独立串口中断状态 */
|
||||
uint8_t i;
|
||||
|
||||
gInterruptStatus = ch438_read_reg(REG_SSR_ADDR, 1);
|
||||
|
||||
if (!gInterruptStatus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
if (gInterruptStatus & Interruptnum[i]) /* 检测哪个串口发生中断 */
|
||||
{
|
||||
InterruptStatus = ch438_read_reg(offsetadd[i] | REG_IIR_ADDR, 1) & 0x0f; /* 读串口的中断状态 */
|
||||
|
||||
switch (InterruptStatus)
|
||||
{
|
||||
case INT_NOINT: /* 没有中断 */
|
||||
break;
|
||||
case INT_THR_EMPTY: /* THR空中断 */
|
||||
break;
|
||||
case INT_RCV_OVERTIME: /* 接收超时中断 */
|
||||
receive_data_len = ch438_recv_data(i, receive_data_buff);
|
||||
ch438_send_data(i, receive_data_buff, receive_data_len);
|
||||
break;
|
||||
case INT_RCV_SUCCESS: /* 接收数据可用中断 */
|
||||
receive_data_len = ch438_recv_data(i, receive_data_buff);
|
||||
ch438_send_data(i, receive_data_buff, receive_data_len);
|
||||
break;
|
||||
case INT_RCV_LINES: /* 接收线路状态中断 */
|
||||
ch438_read_reg(offsetadd[i] | REG_LSR_ADDR, 1);
|
||||
break;
|
||||
case INT_MODEM_CHANGE: /* MODEM输入变化中断 */
|
||||
ch438_read_reg(offsetadd[i] | REG_MSR_ADDR, 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,4 +132,5 @@ uint8_t ch438_check_iir_reg(uint8_t uart_num);
|
|||
void ch438_init_config(uint8_t uart_num);
|
||||
void ch438_send_data(uint8_t uart_num, uint8_t *data, uint16_t len);
|
||||
uint8_t ch438_recv_data(uint8_t uart_num, uint8_t *data);
|
||||
void ch438_interrupt_handler(void);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue