硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3578|回复: 1
收起左侧

[FreeRTOS] static void UartSend(UART_T *_pUart, uint8_t *_ucaBuf, uint16_t _usLen)死机问

[复制链接]

2

主题

8

回帖

14

积分

新手上路

积分
14
发表于 2016-10-18 11:41:32 | 显示全部楼层 |阅读模式
static void UartSend(UART_T *_pUart, uint8_t *_ucaBuf, uint16_t _usLen)
{
        uint16_t i;

        for (i = 0; i < _usLen; i++)
        {
                /* 如果发送缓冲区已经满了,则等待缓冲区空 */
        #if 0
                /*
                        在调试GPRS例程时,下面的代码出现死机,while 死循环
                        原因: 发送第1个字节时 _pUart->usTxWrite = 1;_pUart->usTxRead = 0;
                        将导致while(1) 无法退出
                */
                while (1)
                {
                        uint16_t usRead;

                        DISABLE_INT();
                        usRead = _pUart->usTxRead;
                        ENABLE_INT();

                        if (++usRead >= _pUart->usTxBufSize)
                        {
                                usRead = 0;
                        }

                        if (usRead != _pUart->usTxWrite)
                        {
                                break;
                        }
                }
        #else
                /* 当 _pUart->usTxBufSize == 1 时, 下面的函数会死掉(待完善) */
                while (1)
                {
                        __IO uint16_t usCount;

                        DISABLE_INT();
                        usCount = _pUart->usTxCount;
                        ENABLE_INT();

                        if (usCount < _pUart->usTxBufSize)
                        {
                                break;
                        }
                }
        #endif

                /* 将新数据填入发送缓冲区 */
                _pUart->pTxBuf[_pUart->usTxWrite] = _ucaBuf;

                DISABLE_INT();
                if (++_pUart->usTxWrite >= _pUart->usTxBufSize)
                {
                        _pUart->usTxWrite = 0;
                }
                _pUart->usTxCount++;
                ENABLE_INT();
        }

        USART_ITConfig(_pUart->uart, USART_IT_TXE, ENABLE);
}
这个问题怎么解决,有办法了吗?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107068
QQ
发表于 2016-10-18 12:27:26 | 显示全部楼层
那就别使用我们写的这个函数了,自己实现一个串口的FIFO。


这句话:
/* 当 _pUart->usTxBufSize == 1 时, 下面的函数会死掉(待完善) */
的含义是说,你把发送缓冲区的大小设置为1的时候是有问题的,实际上我们很少将其设置为1,
我们一般都是设置为1024。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-16 09:34 , Processed in 0.144970 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表