#include "includes.h" #include "Uart.h" #include "BSP.h" uint8_t UART3_RCV_PROT_BUF[UART_RCV_PROCBUF_LEN];//串口3接收原始数据 uint16_t uart3_prot_index = 0; uart_info g_uart_info[UART_MAX]; uart_config_struct g_uart_cfg[] = { #ifdef GAS_STATION {GPIOA, GPIO_Pin_10,GPIOA, GPIO_Pin_9, 0, USART1_IRQn, USART1, RCC_APB2Periph_USART1, RCC_APB2Periph_GPIOA}, {GPIOA, GPIO_Pin_3, GPIOA, GPIO_Pin_2, 0, USART2_IRQn, USART2, RCC_APB1Periph_USART2, RCC_APB2Periph_GPIOA}, {GPIOD, GPIO_Pin_9, GPIOD, GPIO_Pin_8, GPIO_FullRemap_USART3, USART3_IRQn, USART3, RCC_APB1Periph_USART3, RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO}, {GPIOC, GPIO_Pin_11,GPIOC, GPIO_Pin_10, 0, UART4_IRQn, UART4, RCC_APB1Periph_UART4, RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO}, {GPIOD, GPIO_Pin_2, GPIOC, GPIO_Pin_12, 0, UART5_IRQn, UART5, RCC_APB1Periph_UART5, RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO}, #else #ifdef MSTS_C {GPIOB, GPIO_Pin_7, GPIOB, GPIO_Pin_6, GPIO_Remap_USART1, USART1_IRQn, USART1, RCC_APB2Periph_USART1, RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO}, {GPIOA, GPIO_Pin_3, GPIOA, GPIO_Pin_2, 0, USART2_IRQn, USART2, RCC_APB1Periph_USART2, RCC_APB2Periph_GPIOA},//不可以和me3616链接 {GPIOD, GPIO_Pin_9, GPIOD, GPIO_Pin_8, GPIO_FullRemap_USART3, USART3_IRQn, USART3, RCC_APB1Periph_USART3, RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO}, {GPIOC, GPIO_Pin_11,GPIOC, GPIO_Pin_10, 0, UART4_IRQn, UART4, RCC_APB1Periph_UART4, RCC_APB2Periph_GPIOC}, {GPIOD, GPIO_Pin_2, GPIOC, GPIO_Pin_12, 0, UART5_IRQn, UART5, RCC_APB1Periph_UART5, RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD}, #else {GPIOA, GPIO_Pin_10,GPIOA, GPIO_Pin_9, 0, USART1_IRQn, USART1, RCC_APB2Periph_USART1, RCC_APB2Periph_GPIOA}, {GPIOA, GPIO_Pin_3, GPIOA, GPIO_Pin_2, 0, USART2_IRQn, USART2, RCC_APB1Periph_USART2, RCC_APB2Periph_GPIOA}, {GPIOB, GPIO_Pin_11,GPIOB, GPIO_Pin_10, 0, USART3_IRQn, USART3, RCC_APB1Periph_USART3, RCC_APB2Periph_GPIOB}, {GPIOC, GPIO_Pin_11,GPIOC, GPIO_Pin_10, 0, UART4_IRQn, UART4, RCC_APB1Periph_UART4, RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO}, {GPIOD, GPIO_Pin_2, GPIOC, GPIO_Pin_12, 0, UART5_IRQn, UART5, RCC_APB1Periph_UART5, RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO}, #endif #endif }; int uart_msg_send(u8 uartid, const char *buf, u32 buflen); int fputc(int ch, FILE *f) { uint16_t temp=1000; USART_TypeDef * uart_def = g_uart_cfg[UART_DEBUG].uart_def; if(g_ptTest.bTestStart == PT_OFF) //PT状态关闭 { while((temp>0)&((uart_def->SR&0X40)==0)) { temp--; };//循环发送,直到发送完毕 //while((USART2->SR & USART_FLAG_TXE) == RESET); uart_def->DR = (u8) ch; while((USART_GetFlagStatus(uart_def, USART_FLAG_TXE)!=SET)){} } return ch; } void data_dump(const char *name, uint8_t *data, uint16_t length) { int index = 0; printf("%s Data Info: \r\n ", name); for(index = 0;index < length;index++) { if((index%4 == 0)&&index) { if((index%16 == 0)&&index) { printf("\r\n "); } else { printf(" "); } } printf("%02x ", *(data + index)); } printf("\r\n"); } void uart_init(u8 uartid, u32 baud, u16 wordlen, u16 parity) { uart_config_struct *p_uart = NULL; //GPIO端口设置 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; USART_TypeDef * USARTx = NULL; p_uart = &g_uart_cfg[uartid]; USARTx = (USART_TypeDef *)p_uart->uart_def; RCC_APB2PeriphClockCmd(p_uart->gpio_clk, ENABLE); if(USARTx == USART1) { RCC_APB2PeriphClockCmd(p_uart->uart_clk, ENABLE); } else { RCC_APB1PeriphClockCmd(p_uart->uart_clk, ENABLE); } //USART1_TX GPIOA.9初始化 GPIO_InitStructure.GPIO_Pin = p_uart->tx_pin; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出 GPIO_Init((GPIO_TypeDef* )p_uart->tx_port, &GPIO_InitStructure);//初始化GPIOA.9 //USART1_RX GPIOA.10初始化 GPIO_InitStructure.GPIO_Pin = p_uart->rx_pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入 GPIO_Init((GPIO_TypeDef* )p_uart->rx_port, &GPIO_InitStructure);//初始化GPIOA.10 if(p_uart->remap) { GPIO_PinRemapConfig(p_uart->remap, ENABLE); } //Usart1 NVIC 配置 // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = p_uart->irq_no; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0 ;//抢占优先级3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = uartid; //子优先级3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器 //USART 初始化设置 USART_InitStructure.USART_BaudRate = baud;//串口波特率 USART_InitStructure.USART_WordLength = wordlen;//字长为8位数据格式 USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位 USART_InitStructure.USART_Parity = parity;//无奇偶校验位 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式 USART_Init(USARTx, &USART_InitStructure); //初始化串口1 USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE);//开启串口接受中断 // USART_ITConfig(USARTx, USART_IT_TC, ENABLE);//开启串口发送完成中断 // USART_ITConfig(USARTx, USART_IT_TXE, ENABLE); // USART_ITConfig(USARTx, USART_IT_IDLE, ENABLE);//开启串口空闲中断 USART_Cmd(USARTx, ENABLE); //使能串口1 } /**************************************************************************** * --uart_interrupt() UART0中断服务程序。 * Input: * uid --串口编号 * pinfo --串口信息处理结构指针 *Output: * None *Return: * None */ int rs485_rcv_flag = 0; void uart_interrupt(u8 uartid) { u16 index = 0; u8 val =0; uart_info *pinfo = NULL; uart_config_struct *p_uart = NULL; USART_TypeDef * USARTx = NULL; CPU_SR_ALLOC(); pinfo = &g_uart_info[uartid]; p_uart = &g_uart_cfg[uartid]; USARTx = (USART_TypeDef *)p_uart->uart_def; OSIntEnter(); OS_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */ // OSIntNestingCtr++; if(USART_GetITStatus(USARTx, USART_IT_RXNE) != RESET) {/*有新数据需要接收,不管缓存区是否溢出,数据必须读出*/ val = USART_ReceiveData(USARTx); /*接收新数据,同时清除中断挂起*/ USART_ClearFlag(USARTx, USART_IT_RXNE); USART_ClearITPendingBit(USARTx, USART_IT_RXNE); if(!pinfo->rinfo.flag.bufof) {/*如果接收缓冲没有溢出*/ index = pinfo->rinfo.rtbuf.pinput; pinfo->rinfo.rtbuf.buf[index] = val; index = (index+1)%UART_RCV_TEMPBUF_LEN;/*以datalen为模加index*/ if(index == pinfo->rinfo.rtbuf.poutput) {/*接收的速度大于处理的速度了*/ pinfo->rinfo.flag.bufof = ENABLE;/*溢出了*/ } else { pinfo->rinfo.rtbuf.pinput = index;/*更新输入指针长度*/ } } } #if 0 if(USART_GetITStatus(USARTx, USART_IT_TXE) != RESET) {/*数据发送完成,可以发送新数据*/ if(pinfo->sinfo.poutput != pinfo->sinfo.pinput) {/*如果有数据需要发送*/ index = pinfo->sinfo.poutput; USART_SendData(USARTx, pinfo->sinfo.pdata[index]);/*新数据写入发送缓冲*/ pinfo->sinfo.poutput = (index+1)%pinfo->sinfo.datalen;/*以datalen为模加index*/ } else {/*没有数据需要发送*/ USART_ITConfig(USARTx, USART_IT_TXE, DISABLE); pinfo->sinfo.sending = FALSE; } } #endif OS_CRITICAL_EXIT(); OSIntExit(); return; } /****************************************************************************************** *uart_rs232_init --串口初始化函数 *-- *Input: * prt --协议类型 * rcv --信息接收函数 *Output: * 无 *Return: * OK/ERROR 表示执行成功与否 * */ int uart_rs232_init(u8 uartid, uart_rcv_func rcv) { uart_info *pinfo = NULL; uart_config_struct *p_uart = NULL; pinfo = &g_uart_info[uartid]; p_uart = &g_uart_cfg[uartid]; /*清数据结构*/ memset(pinfo, 0, sizeof(uart_info)); /*记录接收报文处理函数*/ pinfo->rinfo.rproc.rcv = rcv; /*lint -save -e611*/ pinfo->uartid = uartid; pinfo->arg = (void *)p_uart->uart_def; /*lint -restore*/ /*接收和发送指针执行相应的缓冲区*/ //pinfo->rinfo.rproc.pdata = p_rx_data; pinfo->rinfo.rproc.datalen = 1024; //pinfo->sinfo.pdata = p_tx_data; // pinfo->sinfo.datalen = 1024; //trace_otp_trace1(uart_msg_send, uartid, "My Friends, Uart%d!!!\n", uartid+1); return 0; } //u8 uart_msg_send_disable(u8 uartid) //{ // uart_info *pinfo = NULL; // pinfo = &g_uart_info[uartid]; // return (pinfo->sinfo.poutput != pinfo->sinfo.pinput); //} /**********************************************************/ USART_TypeDef* uart_choice(uint8_t uartid) { USART_TypeDef *USARTx; switch(uartid) { case UART1_ID: USARTx = USART1; break; case UART2_ID: USARTx = USART2; break; case UART3_ID: USARTx = USART3; break; case UART4_ID: USARTx = UART4; break; case UART5_ID: USARTx = UART5; break; default: break; } return USARTx; } /**********************************************************/ /******************************************************************************* *uart1_msg_send 发送报文处理 *Input: * buf --需要发送的数据指针 * buflen --发送的数据长度 *Output: * None *Return: * OK/ERROR,表示执行成功和失败 */ int uart_msg_send(u8 uartid, const char *buf, u32 buflen) { #if 1 uint32_t t = 0; USART_TypeDef* USARTx; if(uartid > UART5_ID) return -1; if (uartid == UART_485) RS485_TX(); USARTx = uart_choice(uartid); while(buflen--) { USARTx->DR = (*buf & (uint16_t)0x01FF); t = 5000; while((t--)&&(USART_GetFlagStatus(USARTx, USART_FLAG_TXE)!=SET)){} buf++; } if (uartid == UART_485) { delay_us(120);//极限为210us,大于210us数据接收不完整。 RS485_RX(); } #endif #if 0 u16 i = 0, index = 0; USART_TypeDef* USARTx; uart_info *pinfo = NULL; uart_config_struct *p_uart = NULL; OS_ERR err; CPU_SR_ALLOC(); pinfo = &g_uart_info[uartid]; p_uart = &g_uart_cfg[uartid]; if(pinfo == NULL) { return -1; } USARTx = (USART_TypeDef *)p_uart->uart_def; OS_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */ /*取缓冲区输入指针*/ index = pinfo->sinfo.pinput; /*依次将需要发送的数据放入发送缓冲区*/ for(i=0; isinfo.pdata[index] = buf[i]; /*模加index*/ index = (index+1)%pinfo->sinfo.datalen; while(index == pinfo->sinfo.poutput) {/* 发送太慢了,等一等*/ OS_CRITICAL_EXIT(); OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_DLY, &err); OS_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */ } } /*更新输入指针*/ pinfo->sinfo.pinput = index; /*启动发送*/ if((pinfo->sinfo.pinput != pinfo->sinfo.poutput)) {//&&(!pinfo->sinfo.sending) USART_ITConfig(USARTx, USART_IT_TXE, ENABLE); pinfo->sinfo.sending = TRUE; //index = pinfo->sinfo.poutput; //USART_SendData(USARTx, pinfo->sinfo.pdata[index]);/*新数据写入发送缓冲*/ //pinfo->sinfo.poutput = (index+1)%pinfo->sinfo.datalen;/*以datalen为模加index*/ } OS_CRITICAL_EXIT(); #endif return 0; } /******************************************************************************* *uart_rcv_process 接收报文处理,按照相应的协议,对接收缓冲区的报文进行处理,并调用 * 注册的rcv处理函数; *Input: * prt --报文处理使用的协议,根据协议类型进行报文接收; * prinfo --接收缓冲区相关信息指针; *Output: * None *Return: * OK/ERROR,表示执行成功和失败 */ int uart_rcv_process(u8 uartid) { u8 val = 0; u32 index = 0; u32 ucnt = 0; uart_info *pinfo = NULL; // uart_config_struct *p_uart = NULL; uart_rcv_info *prinfo = NULL; CPU_SR_ALLOC(); // if(uartid == UART3_ID) // return 0; pinfo = &g_uart_info[uartid]; // p_uart = &g_uart_cfg[uartid]; prinfo = &pinfo->rinfo; /*参数检查*/ if(prinfo == NULL) { return -1; } OS_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */ /*20090828modify,szb*/ if(prinfo->flag.bufof==TRUE) { prinfo->flag.bufof=FALSE; prinfo->rtbuf.poutput = prinfo->rtbuf.pinput; prinfo->rproc.outcnt = 0; } /*看看接收暂存缓冲区当前有没有数据可以接收*/ if(prinfo->rtbuf.poutput == prinfo->rtbuf.pinput) {/*没有新数据*/ return 0; } /*记录接收暂存缓冲区开始处理的位置*/ index = prinfo->rtbuf.poutput; ucnt = prinfo->rproc.outcnt; /*处理已经接收完毕但是还没有处理的报文内容*/ while(index != prinfo->rtbuf.pinput) { /*获取接收缓冲区的内容*/ val = prinfo->rtbuf.buf[index]; prinfo->rproc.pdata[ucnt] = val; /*处理下一个字符*/ index = (index+1)%UART_RCV_TEMPBUF_LEN; ucnt = (ucnt+1)%UART_RCV_PROCBUF_LEN; } if(prinfo->rproc.rcv) {/* 注册接收函数 */ prinfo->rproc.rcv(pinfo->uartid, pinfo->arg, prinfo->rproc.pdata, ucnt, NULL); ucnt = 0; } /*更新输出起始指针*/ prinfo->rtbuf.poutput = index; prinfo->rproc.outcnt = ucnt; OS_CRITICAL_EXIT(); return 0; } int uart_blocking_read(char *buffer, u8 uartid, u32 timeout) { OS_ERR err; uart_info *pinfo = NULL; // uart_config_struct *p_uart = NULL; uart_rcv_info *prinfo = NULL; int ret = 1; CPU_SR_ALLOC(); pinfo = &g_uart_info[uartid]; // p_uart = &g_uart_cfg[uartid]; prinfo = &pinfo->rinfo; while(timeout--) { OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_DLY, &err); } OS_CRITICAL_ENTER(); if(prinfo->rproc.outcnt) { memcpy(buffer, prinfo->rproc.pdata, prinfo->rproc.outcnt); ret = prinfo->rproc.outcnt; prinfo->rproc.outcnt = 0; } else { ret = 0; } OS_CRITICAL_EXIT(); return ret; } /***************************************************************************** ** Function name: USART1_IRQHandler ** ** Descriptions: UART1 interrupt handler ** ** parameters: None ** Returned value: None ** *****************************************************************************/ void USART1_IRQHandler(void) { uart_interrupt(UART1_ID); } void USART2_IRQHandler(void) { uart_interrupt(UART2_ID); } void USART3_IRQHandler(void) { uart_interrupt(UART3_ID); // uint8_t cnt = 0; // u16 index = 0; // u8 val =0; // uart_info *pinfo = NULL; // CPU_SR_ALLOC(); // pinfo = &g_uart_info[UART3_ID]; // OSIntEnter(); // OS_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */ // // uart_interrupt(UART3_ID); // if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) // {/*有新数据需要接收,不管缓存区是否溢出,数据必须读出*/ // val = USART_ReceiveData(USART3); /*接收新数据,同时清除中断挂起*/ // USART_ClearFlag(USART3, USART_IT_RXNE); // USART_ClearITPendingBit(USART3, USART_IT_RXNE); // /***********/ // UART3_RCV_PROT_BUF[uart3_prot_index] = val; // // /***********/ // // // if(!pinfo->rinfo.flag.bufof) // {/*如果接收缓冲没有溢出*/ // index = pinfo->rinfo.rtbuf.pinput; // if(val == 0xbb)//接收到首字节 // { // pinfo->irqinfo.head_cnt = index; // pinfo->irqinfo.rcv_over = 0; // pinfo->irqinfo.data_cnt = 0; // pinfo->irqinfo.data_len = 0; // pinfo->irqinfo.code = 0; // // pinfo->irqinfo.head_cnt2 = uart3_prot_index; // pinfo->irqinfo.data_len2 = 0; // } // else if(val == 0xba)//需转义 // { // pinfo->irqinfo.code = 1; // cnt = 1;//不存储 // } // else // { // if(pinfo->irqinfo.code)//转义 // { // pinfo->irqinfo.code = 0; // if(val == 0) // { // val = 0xba; // } // else if (val == 1) // { // val = 0xbb; // } // } // if(index == ((pinfo->irqinfo.head_cnt+1)%UART_RCV_TEMPBUF_LEN))//第二个字节 // { // pinfo->irqinfo.data_len = val; // pinfo->irqinfo.data_cnt = 0; // } // else // { // pinfo->irqinfo.data_cnt = (pinfo->irqinfo.data_cnt+1)%(UART_RCV_TEMPBUF_LEN+1); // if(pinfo->irqinfo.data_cnt == pinfo->irqinfo.data_len) // { // pinfo->irqinfo.rcv_over = 1; // } // } // } // if(cnt == 0) // { // pinfo->rinfo.rtbuf.buf[index] = val; // index = (index+1)%UART_RCV_TEMPBUF_LEN;/*以datalen为模加index*/ // } // pinfo->rinfo.rtbuf.pinput = index;/*更新输入指针长度*/ // // } // // pinfo->irqinfo.data_len2++; // uart3_prot_index = (uart3_prot_index+1)%UART_RCV_TEMPBUF_LEN; // } // OS_CRITICAL_EXIT(); // OSIntExit(); } void UART4_IRQHandler(void) { uart_interrupt(UART4_ID); } void UART5_IRQHandler(void) { uart_interrupt(UART5_ID); } //串口3接收 uint16_t uart_rcv_uart3(uint8_t *buffer) { // OS_ERR err; uint16_t len1 = 0,len2 = 0; uart_info *pinfo = NULL; int ret = 1; CPU_SR_ALLOC(); pinfo = &g_uart_info[UART3_ID]; OS_CRITICAL_ENTER(); if(pinfo->irqinfo.rcv_over && pinfo->irqinfo.data_len) { pinfo->irqinfo.rcv_over = 0; if((pinfo->irqinfo.head_cnt + pinfo->irqinfo.data_len + 2) > UART_RCV_TEMPBUF_LEN) { len1 = UART_RCV_TEMPBUF_LEN - pinfo->irqinfo.head_cnt; len2 = pinfo->irqinfo.head_cnt+pinfo->irqinfo.data_len+2 - UART_RCV_TEMPBUF_LEN; memcpy(buffer,&pinfo->rinfo.rtbuf.buf[pinfo->irqinfo.head_cnt],len1); memcpy(buffer+len1,pinfo->rinfo.rtbuf.buf,len2); } else memcpy(buffer,&pinfo->rinfo.rtbuf.buf[pinfo->irqinfo.head_cnt],pinfo->irqinfo.data_len+2); ret = pinfo->irqinfo.data_len+2; pinfo->irqinfo.data_len = 0; } else { ret = 0; } OS_CRITICAL_EXIT(); return ret; } //串口3接收 uint16_t uart_rcv_uart3_two(uint8_t *buffer1,uint16_t *buf_len1, uint8_t *buffer2, uint16_t *buf_len2) { // OS_ERR err; uint16_t len1 = 0,len2 = 0; uart_info *pinfo = NULL; int ret = 1; CPU_SR_ALLOC(); pinfo = &g_uart_info[UART3_ID]; OS_CRITICAL_ENTER(); if(pinfo->irqinfo.rcv_over && pinfo->irqinfo.data_len) { pinfo->irqinfo.rcv_over = 0; if((pinfo->irqinfo.head_cnt + pinfo->irqinfo.data_len + 2) > UART_RCV_TEMPBUF_LEN) { len1 = UART_RCV_TEMPBUF_LEN - pinfo->irqinfo.head_cnt; len2 = pinfo->irqinfo.head_cnt+pinfo->irqinfo.data_len+2 - UART_RCV_TEMPBUF_LEN; memcpy(buffer1,&pinfo->rinfo.rtbuf.buf[pinfo->irqinfo.head_cnt],len1); memcpy(buffer1+len1,pinfo->rinfo.rtbuf.buf,len2); } else memcpy(buffer1,&pinfo->rinfo.rtbuf.buf[pinfo->irqinfo.head_cnt],pinfo->irqinfo.data_len+2); ret = pinfo->irqinfo.data_len+2; pinfo->irqinfo.data_len = 0; *buf_len1 = ret;//数组1的长度 //原始数据读取 if((pinfo->irqinfo.head_cnt2 + pinfo->irqinfo.data_len2) > UART_RCV_TEMPBUF_LEN) { len1 = UART_RCV_TEMPBUF_LEN - pinfo->irqinfo.head_cnt2; len2 = pinfo->irqinfo.head_cnt2+pinfo->irqinfo.data_len2 - UART_RCV_TEMPBUF_LEN; memcpy(buffer2,&UART3_RCV_PROT_BUF[pinfo->irqinfo.head_cnt2],len1); memcpy(buffer2+len1,UART3_RCV_PROT_BUF,len2); } else memcpy(buffer2,&UART3_RCV_PROT_BUF[pinfo->irqinfo.head_cnt2],pinfo->irqinfo.data_len2); *buf_len2 = pinfo->irqinfo.data_len2; pinfo->irqinfo.data_len2 = 0; } else { ret = 0; } OS_CRITICAL_EXIT(); return ret; }