This commit is contained in:
parent
0b9a30eb0e
commit
b626cbb446
|
@ -22,6 +22,7 @@
|
|||
#include "stm32f4xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "ch438q.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -170,7 +171,7 @@ 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 */
|
||||
}
|
||||
|
||||
|
|
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