summaryrefslogtreecommitdiff
path: root/openpicc
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-02-20 10:58:58 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-02-20 10:58:58 +0000
commit3639a49edf440277793a608b251be4340c750b24 (patch)
tree03ff49721b826755ce39f20d1a4a209184629530 /openpicc
parentdde2f8e09c773518c3a538afe6075a53a8fdacf7 (diff)
Modifications to USB code to allow blocks of more than 1 byte to be more efficiently sent.
Should affect existing byte base code only marginally. (Note: Not compliant with FreeRTOS' braindead coding style) git-svn-id: https://svn.openpcd.org:2342/trunk@416 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'openpicc')
-rw-r--r--openpicc/os/usb/USB-CDC.c40
-rw-r--r--openpicc/os/usb/USB-CDC.h1
2 files changed, 34 insertions, 7 deletions
diff --git a/openpicc/os/usb/USB-CDC.c b/openpicc/os/usb/USB-CDC.c
index 4496c55..13435b4 100644
--- a/openpicc/os/usb/USB-CDC.c
+++ b/openpicc/os/usb/USB-CDC.c
@@ -123,6 +123,8 @@ transmitted. Rx queue must be larger than FIFO size. */
static xQueueHandle xRxCDC;
static xQueueHandle xTxCDC;
+#define CHUNK_SIZE 8
+
/* Line coding - 115,200 baud, N-8-1 */
static const unsigned portCHAR pxLineCoding[] =
{ 0x00, 0xC2, 0x01, 0x00, 0x00, 0x00, 0x08 };
@@ -142,6 +144,8 @@ vUSBCDCTask (void *pvParameters)
unsigned portLONG ulStatus;
unsigned portLONG ulRxBytes;
unsigned portCHAR ucByte;
+ unsigned char chunk[CHUNK_SIZE];
+ portBASE_TYPE i;
portBASE_TYPE xByte;
(void) pvParameters;
@@ -185,16 +189,19 @@ vUSBCDCTask (void *pvParameters)
(AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] & AT91C_UDP_TXPKTRDY))
&& uxQueueMessagesWaiting (xTxCDC))
{
- for (xByte = 0; xByte < 64; xByte++)
+ for (xByte = 0; xByte < 64-CHUNK_SIZE+1; xByte++)
{
- if (!xQueueReceive (xTxCDC, &ucByte, 0))
+ if (!xQueueReceive (xTxCDC, &chunk, 0))
{
/* No data buffered to transmit. */
break;
}
- /* Got a byte to transmit. */
- AT91C_BASE_UDP->UDP_FDR[usbEND_POINT_2] = ucByte;
+ /* Got a byte (or more) to transmit. */
+ for(i=0; i<chunk[0]; i++) {
+ AT91C_BASE_UDP->UDP_FDR[usbEND_POINT_2] = chunk[1+i];
+ xByte++;
+ }
}
AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] |= AT91C_UDP_TXPKTRDY;
}
@@ -255,8 +262,27 @@ vUSBCDCTask (void *pvParameters)
void
vUSBSendByte (portCHAR cByte)
{
+ char chunk[CHUNK_SIZE];
+ chunk[0] = 1;
+ chunk[1] = cByte;
/* Queue the byte to be sent. The USB task will send it. */
- xQueueSend (xTxCDC, &cByte, usbNO_BLOCK);
+ xQueueSend (xTxCDC, &chunk, usbNO_BLOCK);
+}
+
+#define MIN(a,b) ((a)>(b)?(b):(a))
+void
+vUSBSendBuffer (unsigned char *buffer, portBASE_TYPE offset, portBASE_TYPE length)
+{
+ unsigned char chunk[CHUNK_SIZE];
+ while(length > 0) {
+ int next_size = MIN(length, CHUNK_SIZE-1);
+ chunk[0] = next_size;
+ memcpy(chunk+1, buffer+offset, next_size);
+ /* Queue the bytes to be sent. The USB task will send it. */
+ xQueueSend (xTxCDC, &chunk, usbNO_BLOCK);
+ length -= next_size;
+ offset += next_size;
+ }
}
/*------------------------------------------------------------*/
@@ -782,8 +808,8 @@ vInitUSBInterface (void)
xQueueCreate (USB_CDC_QUEUE_SIZE,
(unsigned portCHAR) sizeof (signed portCHAR));
xTxCDC =
- xQueueCreate (USB_CDC_QUEUE_SIZE + 1,
- (unsigned portCHAR) sizeof (signed portCHAR));
+ xQueueCreate ( (USB_CDC_QUEUE_SIZE/CHUNK_SIZE) + 1,
+ (unsigned portCHAR) CHUNK_SIZE * sizeof (signed portCHAR));
if ((!xUSBInterruptQueue) || (!xRxCDC) || (!xTxCDC))
{
diff --git a/openpicc/os/usb/USB-CDC.h b/openpicc/os/usb/USB-CDC.h
index 894ebfb..511c8a8 100644
--- a/openpicc/os/usb/USB-CDC.h
+++ b/openpicc/os/usb/USB-CDC.h
@@ -82,6 +82,7 @@ void vUSBCDCTask (void *pvParameters);
/* Send cByte down the USB port. Characters are simply buffered and not
sent unless the port is connected. */
void vUSBSendByte (portCHAR cByte);
+void vUSBSendBuffer (unsigned char *buffer, portBASE_TYPE offset, portBASE_TYPE length);
portLONG vUSBRecvByte (portCHAR *cByte,portLONG size, portTickType xTicksToWait);
#endif
personal git repositories of Harald Welte. Your mileage may vary