大家好,小弟用的是STM8208的单片机,内存64k,为了加快串口工作速度,我发送的时候选择了中断模式发送,现在碰到一个问题
//源码
------ztUart_Transmission_Handle.h-----
#ifndef ztUart_Transmission_Handle_H
#define ztUart_Transmission_Handle_H
#include "stm8s.h"
#define Txbuf_Size 64
extern uint8_t *pInTxbuf;
extern uint8_t *pOutTxbuf;
extern uint8_t TxBuf[Txbuf_Size];
extern void TxBufQueue_Init(void);
extern uint8_t Get_Remainder_Len_of_TxBufQueue(void);
extern void Increase_pInTxbuf(uint8_t Num);
extern void Increase_pOutTxbuf(uint8_t Num);
extern void Copy_data_to_Txbuf(uint8_t *psource,uint8_t len);
extern bool Send_data_to_Uart(uint8_t *pdata,uint8_t len_of_data);
extern void UART1_TX_IRQHandler_CB();
#endif
------ztUart_Transmission_Handle.c-----
uint8_t *pInTxbuf = NULL;
uint8_t *pOutTxbuf = NULL;
uint8_t TxBuf[Txbuf_Size] = {0};
void TxBufQueue_Init(void)
{
pInTxbuf = &TxBuf[0];
pOutTxbuf = pInTxbuf;
}
uint8_t Get_Remainder_Len_of_TxBufQueue(void)
{
disableInterrupts();
if (pInTxbuf <pOutTxbuf)
{
return uint8_t(pOutTxbuf-pInTxbuf );
}
else
{
return uint8_t(Txbuf_Size +pOutTxbuf-pInTxbuf );
}
enableInterrupts();
}
void Increase_pInTxbuf(uint8_t Num)
{
disableInterrupts();
if ((pInTxbuf + Num) >= (&TxBuf[0] + Txbuf_Size))
{
pInTxbuf = (pInTxbuf + Num - Txbuf_Size);
}
else
{
pInTxbuf += Num;
}
enableInterrupts();
}
void Increase_pOutTxbuf(uint8_t Num)
{
disableInterrupts();
if ((pOutTxbuf + Num) >= (&TxBuf[0] + Txbuf_Size))
{
pOutTxbuf = (pOutTxbuf + Num - Txbuf_Size);
}
else
{
pOutTxbuf += Num;
}
enableInterrupts();
}
void Copy_data_to_Txbuf(uint8_t *psource, uint8_t len)
{
if (len <= (&TxBuf[0] + Txbuf_Size - pInTxbuf))
{
//当没有溢出卷积的时候,剩余空间足够的时候
memcpy(pInTxbuf, psource, len);
}
else
{
memcpy(pInTxbuf, psource, &TxBuf[0] + Txbuf_Size - pInTxbuf);