本帖最后由 TRUE_ARM 于 2011-7-14 21:06 编辑
专业信号处理学习板例程介绍.pdf
(984.06 KB)
更改思路,使用队列来处理。
更改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) & 0x7F;
usb_buf[usbIdIn] = USART_ReceiveData(USART1) & 0x7F;
}
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 ++;
/*
count_in++;
UserToPMABufferCopy(buffer_in, ENDP1_TXADDR, count_in);
SetEPTxCount(ENDP1, count_in);
SetEPTxValid(ENDP1);
*/
//if usb -in_enp free now? start send?
if(
count_in == 0 )
{//free now? start send...
//j=(usb_len >= VIRTUAL_COM_PORT_DATA_SIZE)?VIRTUAL_COM_PORT_DATA_SIZE:usb_len;
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
} |