|||
更改1:
void USB_To_USART_Send_Data(u8* data_buffer, u8 Nb_bytes)
{
//polling ?
/* 原来官方的例程:这里使用查询的方式把USB 接收到的数据发送出去
u32 i;
for (i = 0; i < Nb_bytes; i++)
{
USART_SendData(USART1, *(data_buffer + i));
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
} */
//int: 改进的处理:使用队列加缓冲加中断来处理USB 接收到的数据
Uart1SendPushBuf(data_buffer, Nb_bytes);
}
更改2:
void USART_To_USB_Send_Data(void) //CALLED by int?
{//write data to END-point
//called by uart_rxe_int:
u16 i,j;
if (linecoding.datatype == 7)
{
//buffer_in[count_in] = USART_ReceiveData(USART1) & 0x
usb_buf[usbIdIn] = USART_ReceiveData(USART1) & 0x
}
else if (linecoding.datatype == 8)
{
//buffer_in[count_in] = USART_ReceiveData(USART1);
usb_buf[usbIdIn] = USART_ReceiveData(USART1);
}
if(++usbIdIn>=2048)usbIdIn=0;
usb_len ++;
//if usb -in_enp free now? start send?
if( count_in == 0 )
{//free now? start send...
// 每次传输不要超过指定的缓冲长度,
if(usb_len > VIRTUAL_COM_PORT_DATA_SIZE)
{
j=VIRTUAL_COM_PORT_DATA_SIZE;
usb_len -=j;
}
else
{
j=usb_len;
usb_len =0;
}
for(i=0;i<j;i++)
{
buffer_in = usb_buf[usbIdOut];
if(++usbIdOut>=2048)usbIdOut=0;
}
count_in = j;
UserToPMABufferCopy(buffer_in, ENDP1_TXADDR, count_in);
SetEPTxCount(ENDP1, count_in);
SetEPTxValid(ENDP1);
}
//else just save to buffer,waiting usb-nak
}