|
为什么在读取数据个数,还有数据拷贝的时候要关掉中断?- /*
- *********************************************************************************************************
- * 函 数 名: UartSend
- * 功能说明: 填写数据到UART发送缓冲区,并启动发送中断。中断处理函数发送完毕后,自动关闭发送中断
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- 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;
- <font color="#ff0000"> DISABLE_INT();
- usCount = _pUart->usTxCount;
- ENABLE_INT();</font>
- if (usCount < _pUart->usTxBufSize)
- {
- break;
- }
- }
- #endif
- /* 将新数据填入发送缓冲区 */
- _pUart->pTxBuf[_pUart->usTxWrite] = _ucaBuf[i];
- <font color="#ff0000"> DISABLE_INT();
- if (++_pUart->usTxWrite >= _pUart->usTxBufSize)
- {
- _pUart->usTxWrite = 0;
- }
- _pUart->usTxCount++;
- ENABLE_INT();</font>
- }
- USART_ITConfig(_pUart->uart, USART_IT_TXE, ENABLE);
- }
复制代码
|
|