富芮坤 FR8000串口接收 硬件定时器判断超时

#define     UART_LEN_MAX         512   // 最大长度
#define     TIMEOUT_RX_MS        5      // 接收超时时间

volatile uint8_t uart_recving_buffer[UART_LEN_MAX] = {0};
volatile uint16_t  timer_rx_flag = 0,index_uart0 = 0;

volatile uint32_t add_up=0;

// 定时器初始化
void timer_demo(void)
{
	co_printf("%s\r\n",__func__);
    __SYSTEM_TIMER_CLK_ENABLE();
   pmu_set_pin_mux(GPIO_PORT_A, GPIO_BIT_6, PMU_PIN_FUNC_GPIO);
   pmu_set_pin_to_PMU(GPIO_PORT_A, CO_BIT(6));
   pmu_set_pin_dir(GPIO_PORT_A, BIT(6),GPIO_DIR_OUT);
	
    NVIC_ClearPendingIRQ(TIMER0_IRQn);
    NVIC_EnableIRQ(TIMER0_IRQn);
    
    NVIC_SetPriority(TIMER0_IRQn, 2);
    /* timer0 1s */
    timer_init(Timer0, 96000, TIMER_DIV_NONE);
	
    timer_start(Timer0);
}

串口初始化

void uart1_isr_int(UART_HandleTypeDef *huart)
{
	huart->UARTx->IER_DLH.IER.ELSI = 1;
	huart->UARTx->IER_DLH.IER.ERBFI = 1;
}

void uart0_init(void)
{
    system_set_port_pull(GPIO_PD6,GPIO_PULL_UP,true);
    /* set PA2 and PA3 for AT command interface */
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_6, PORTD6_FUNC_UART1_RXD);
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_7, PORTD7_FUNC_UART1_TXD);
    Uart1_handle.UARTx = Uart1;
    Uart1_handle.Init.BaudRate   = gAT_buff_env.uart_param.BaudRate;
    Uart1_handle.Init.DataLength = gAT_buff_env.uart_param.DataLength;
    Uart1_handle.Init.StopBits   = gAT_buff_env.uart_param.StopBits;
    Uart1_handle.Init.Parity     = gAT_buff_env.uart_param.Parity;
    Uart1_handle.Init.FIFO_Mode  = UART_FIFO_ENABLE;

    uart_init_ex(&Uart1_handle);
    NVIC_EnableIRQ(UART1_IRQn);
    NVIC_SetPriority(UART1_IRQn, 4);
	/*enable recv and line status interrupt*/
	uart1_isr_int(&Uart1_handle);

	co_printf("enter at init\r\n");
    gAT_env.at_task_id = os_task_create( at_task_func );
	
	timer_demo();
}


串口接收中断

__attribute__((section("ram_code"))) void uart1_isr(void)
{
	uint32_t isr_id;
    uint8_t rx_char;
	if(gap_get_connect_num()==1)
	{
		volatile struct_UART_t * const uart_reg_ram = (volatile struct_UART_t *)UART1_BASE;
		isr_id = uart_reg_ram->FCR_IID.IID;
		if(((isr_id & 0x04) == 0x04) || ((isr_id & 0x0c) == 0x0c)) //receciver data available or character timeout indication
		{
			while(uart_reg_ram->LSR.LSR_BIT.DR)
			{
				rx_char = uart_reg_ram->DATA_DLL.DATA;
					uart_recving_buffer[index_uart0] = rx_char; //uart_reg_ram->DATA_DLL.DATA;
					index_uart0++;
					timer_rx_flag=1;
					add_up = 1;
					pmu_set_gpio_value(GPIO_PORT_A, BIT(6),1);
				
			}
		}
		else if((isr_id & 0x06) == 0x06)//receiver line status interrupt
		{
			uint32_t tmp = uart_reg_ram->LSR.LSR_DWORD;
			uart_reg_ram->FCR_IID.FCR = isr_id;
			uart_reg_ram->IER_DLH.IER.ELSI = 0;
		}
	}
	else
	{
		void uart1_isr_rom(void);
		uart1_isr_rom();
	}
}

// 定时器中断
__attribute__((section("ram_code"))) void timer0_isr(void)
{
	
		static uint32_t lu32_Count = 0;
		
		timer_int_clear(Timer0);
#if 1
		
		   if(timer_rx_flag >= 1)
		   {
				timer_rx_flag++;
				
				if(timer_rx_flag >= TIMEOUT_RX_MS)
				{
					pmu_set_gpio_value(GPIO_PORT_A, BIT(6),0);
					at_spss_send_data(gAT_ctrl_env.transparent_conidx, uart_recving_buffer, index_uart0);
					timer_rx_flag = 0;
					index_uart0 = 0;
				}
		   
			}
#endif
	

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值