| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- #include "includes.h"
- #include "trace.h"
- #include "Uart.h"
- #include "../APP/command/uart_conf.h"
- #include "../APP/network_mgr/net_proc.h"
- #include "../APP/network/nettimer.h"
- #include "../APP/network/timeout.h"
- #include "../App/network_mgr/net_ctrl.h"
- extern int rs485_send_flag;
- 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==1) return 0;
- while((temp>0)&((uart_def->SR&0X40)==0))
- {
- temp--;
- };//循环发送,直到发送完毕
- //while((USART2->SR & USART_FLAG_TXE) == RESET);
- uart_def->DR = (u8) ch;
- return ch;
- }
- /*测试串口输出4G接收到的数据*/
- void data_dump(const char *name, uint8_t *data, uint16_t length)
- {
- int index = 0;
- if(g_bPrintfDebug == 0) return;
- 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); /*接收新数据,同时清除中断挂起*/
- // USART1->DR = (val & (uint16_t)0x01FF);
- USART_ClearFlag(USARTx, USART_IT_RXNE);
- USART_ClearITPendingBit(USARTx, USART_IT_RXNE);
- // if(USARTx == USART3)
- // {
- // USART_SendData(USART1,val);
- // }
- 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*/
- pinfo->rinfo.rtbuf.buf[index] = 0;
- if(index == pinfo->rinfo.rtbuf.poutput)
- {/*接收的速度大于处理的速度了*/
- pinfo->rinfo.flag.bufof = ENABLE;/*溢出了*/
- }
- else
- {
- pinfo->rinfo.rtbuf.pinput = index;/*更新输入指针长度*/
- }
- }
- }
- 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*/
-
- if(USARTx == RS485_UART)
- {
- if(rs485_send_flag)
- {
- rs485_send_flag = 0;
- rs485_rcv_flag = 1;
- }
- }
- } else {/*没有数据需要发送*/
- USART_ITConfig(USARTx, USART_IT_TXE, DISABLE);
- pinfo->sinfo.sending = FALSE;
- if(rs485_rcv_flag)
- {
- delay_ms(1);
- RS485_RX();
- rs485_rcv_flag = 0;
- }
- }
- }
- 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 *UART;
- switch(uartid)
- {
- case UART1_ID:
- UART = USART1;
- break;
- case UART2_ID:
- UART = USART2;
- break;
- case UART3_ID:
- UART = USART3;
- break;
- case UART4_ID:
- UART = UART4;
- break;
- case UART5_ID:
- UART = UART5;
- break;
- default:
- break;
- }
- return UART;
- }
- int uart_msg_send(u8 uartid, const char *buf, u32 buflen)
- {
- uint32_t t = 0;
- USART_TypeDef* USARTx;
- if(uartid > UART5_ID)
- return -1;
- USARTx = uart_choice(uartid);
- while(buflen--)
- {
- IWDG_ReloadCounter();
- USARTx->DR = (*buf & (uint16_t)0x01FF);
- t = 1000;
- while((t--)&&(USART_GetFlagStatus(USARTx, USART_FLAG_TXE)!=SET)){}
- buf++;
- }
- return 0;
- }
- /*******************************************************************************
- *uart1_msg_send 发送报文处理
- *Input:
- * buf --需要发送的数据指针
- * buflen --发送的数据长度
- *Output:
- * None
- *Return:
- * OK/ERROR,表示执行成功和失败
- */
- int uart_msg_send00(u8 uartid, const char *buf, u32 buflen)
- {
- 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; i<buflen; i++) {
- pinfo->sinfo.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();
- // for(i=0;i<buflen; i++){
- // IWDG_ReloadCounter();
- // while((USARTx->SR & USART_FLAG_TXE) == RESET);
- // USARTx->DR = (buf[i] & (uint16_t)0x01FF);
- // }
- return 0;
- }
- /*******************************************************************************
- *uart_rcv_process 接收报文处理,按照相应的协议,对接收缓冲区的报文进行处理,并调用
- * 注册的rcv处理函数;
- *Input:
- * prt --报文处理使用的协议,根据协议类型进行报文接收;
- * prinfo --接收缓冲区相关信息指针;
- *Output:
- * None
- *Return:
- * OK/ERROR,表示执行成功和失败
- */
- uint8_t u3rcvDaDel[1024] = {0};
- 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;
- char *str = NULL, *str1 = NULL,*str2 = NULL;
- char *msg = NULL;
- int slen;
- // uint8_t cregStatus = 0;
- // static uint16_t datalen = 0,len = 0,index1=0;
- volatile static uint8_t flag = 0,curflag = 0;
- volatile static uint16_t dalen = 0;
- CPU_SR_ALLOC();
-
- 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;
- printf("\r\n in>out\r\n");
- }
- /*看看接收暂存缓冲区当前有没有数据可以接收*/
- 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;
- if(uartid == UART3_ID) {
- if(val == '+'){
- // printf("++++++++ %d = \r\n",index1++);
- // curflag = 1;
- dalen = 0;
- }
- if(dalen>=1023) dalen = 0;
- u3rcvDaDel[dalen++] = val;
- if(dalen>6){
- if(strncmp((char*)u3rcvDaDel,"+MSUB:",6)==0){ // 相同
- // if(curflag == 1 && dalen>240) {
- // uart_msg_send(UART1_ID, (char *)(u3rcvDaDel), 240);
- // curflag = 2;
- // }
- if(u3rcvDaDel[dalen-2] =='\r' && u3rcvDaDel[dalen-1]=='\n'){
- index = (index+1)%UART_RCV_TEMPBUF_LEN;
- ucnt = (ucnt+1)%UART_RCV_PROCBUF_LEN;
- prinfo->rproc.pdata[ucnt] = 0;
- flag = 1;
- break;
- }
- }
- }
- }
- /*处理下一个字符*/
- index = (index+1)%UART_RCV_TEMPBUF_LEN;
- ucnt = (ucnt+1)%UART_RCV_PROCBUF_LEN;
- prinfo->rproc.pdata[ucnt] = 0;
- }
- if(uartid==UART3_ID){
- // printf("index = %d, pinput = %d\r\n",index,prinfo->rtbuf.pinput);
- if(flag == 1) {
- // uart_msg_send(UART1_ID, (char *)(u3rcvDaDel), dalen);
- str = strstr((char*)u3rcvDaDel,"+MSUB:");
- if(str) {
- str1 = strstr((char*)u3rcvDaDel,"byte");
- str2 = strstr(str1,"\r\n");
- if(str1 && str2 ){//&&( ucnt-datalen>=(len+2))
- memset(sys_net.str, 0, sizeof(sys_net.str));
- slen = net_data_copy(str1+5,(uint8_t *)sys_net.str);
- net_rcv_len = net_rcvdata_ch((char *)sys_net.str,net_rcv_data,slen);
- data_dump("NET RECB", net_rcv_data, net_rcv_len);
- msg = (char *)net_queue_mem_calloc_must();
- if(msg) {
- memcpy(msg, net_rcv_data, net_rcv_len);
- net_queue_insert((char *)msg, net_rcv_len); //将数据放到消息队列中
- }
- else
- {
- net_queue_mem_free(msg);
- }
- prinfo->rproc.outcnt = 0;
- memset(str,0xFF,str2-str1);
- }
- }
- dalen = 0;
- flag = 0;
- }
- str = strstr((char*)(prinfo->rproc.pdata),"+CREG:");
- if(str){
- str1 = strstr(str,"\r\n");
- if(str1){
- str2 = strstr(str,",");
- if(str2){
- g_runData.cregStatus = atoi(str2+1);
- printf("\r\n check cregStatus = %d\r\n",g_runData.cregStatus);
- prinfo->rproc.outcnt = 0;
- memset(str,0xFF,str1-str);
- }
- else {
- g_runData.cregStatus = atoi(str+6);
- printf("\r\n auto cregStatus = %d\r\n",g_runData.cregStatus);
- prinfo->rproc.outcnt = 0;
- memset(str,0xFF,str1-str);
- }
- if(g_runData.cregStatus!=1){
- timeout_start(&g_usmTimeOut);
- }
- else {
- timeout_stop(&g_usmTimeOut);
- }
- }
- }
- }
- 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);
- }
- u8 USART3_RX_BUF[128]; //接收缓冲,最大USART_REC_LEN个字节.
- //接收状态
- //bit15, 接收完成标志
- //bit14, 接收到0x0d
- //bit13~0, 接收到的有效字节数目
- u16 USART3_RX_STA=0;
- int rcv_flag = 0;
- void USART3_IRQHandler(void)
- {
- // uint8_t Res;
- // if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
- // {
- // Res =USART_ReceiveData(USART3);//(USART3->DR); //读取接收到的数据
- // USART3_RX_BUF[USART3_RX_STA] = Res;
- // USART3_RX_STA++;
- // if(Res == 16)
- // rcv_flag = 1;
- //
- // }
- uart_interrupt(UART3_ID);
- }
- void UART4_IRQHandler(void)
- {
- uart_interrupt(UART4_ID);
- }
- void UART5_IRQHandler(void)
- {
- uart_interrupt(UART5_ID);
- }
|