worked on cleaning up the usb code
diff --git a/gyro_board/src/usb/LPCUSB/USB_SENSOR_STREAM.c b/gyro_board/src/usb/LPCUSB/USB_SENSOR_STREAM.c
index bf360f6..37747d8 100644
--- a/gyro_board/src/usb/LPCUSB/USB_SENSOR_STREAM.c
+++ b/gyro_board/src/usb/LPCUSB/USB_SENSOR_STREAM.c
@@ -44,11 +44,12 @@
#define usbRXBUFFER_LEN ( 80 )
#define usbTXBUFFER_LEN ( 600 )
-#define INT_IN_EP 0x81 //read manual for picking these...
-#define INT_OUT_EP 0x04
+// Read the processor manual for picking these.
+#define INT_IN_EP 0x81
#define BULK_IN_EP 0x82
#define BULK_OUT_EP 0x05
#define ISOC_IN_EP 0x83
+#define NUM_ENDPOINTS 4
#define MAX_PACKET_SIZE 64
@@ -58,8 +59,13 @@
static xQueueHandle xRxedChars = NULL, xCharsForTx = NULL;
-static const unsigned char abDescriptors[] = {
+// This gets cleared each time the ISR is entered and then checked as it's
+// returning so that we can still yield from the ISR to a woken task but not
+// from the middle of the ISR like it would be if this was checked in each
+// endpoint handler that needs it.
+static portBASE_TYPE higher_priority_task_woken;
+static const unsigned char abDescriptors[] = {
// Device descriptor
0x12,
DESC_DEVICE,
@@ -79,7 +85,7 @@
// Configuration descriptor
0x09,
DESC_CONFIGURATION,
- LE_WORD(46), // wTotalLength
+ LE_WORD(9 + 9 + 7 * NUM_ENDPOINTS), // wTotalLength
0x01, // bNumInterfaces
0x01, // bConfigurationValue
0x00, // iConfiguration
@@ -90,7 +96,7 @@
DESC_INTERFACE,
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
- 0x05, // bNumEndPoints
+ NUM_ENDPOINTS, // bNumEndPoints
0x0A, // bInterfaceClass = data
0x00, // bInterfaceSubClass
0x00, // bInterfaceProtocol
@@ -98,7 +104,7 @@
// Debug EP OUT
0x07,
DESC_ENDPOINT,
- BULK_OUT_EP, // bEndpointAddress
+ BULK_OUT_EP, // bEndpointAddress
0x02, // bmAttributes = bulk
LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize
0x00, // bInterval
@@ -109,13 +115,6 @@
0x02, // bmAttributes = bulk
LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize
0x00, // bInterval
-// Data EP OUT
- 0x07,
- DESC_ENDPOINT,
- INT_OUT_EP, // bEndpointAddress
- 0x03, // bmAttributes = intr
- LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize
- 0x01, // bInterval
// Data EP in
0x07,
DESC_ENDPOINT,
@@ -123,14 +122,15 @@
0x03, // bmAttributes = intr
LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize
0x01, // bInterval
-
// isoc data EP IN
0x07,
DESC_ENDPOINT,
ISOC_IN_EP, // bEndpointAddress
0x0D, // bmAttributes = isoc, synchronous, data endpoint
+ // TODO(brians): I think that we can make this 1023 and then send
+ // smaller packets.
LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize
- 0x01, // bInterval
+ 0x01, // bInterval
// string descriptors
0x04,
@@ -162,7 +162,6 @@
*/
static void DebugOut(unsigned char bEP, unsigned char bEPStatus) {
int i, iLen;
- long lHigherPriorityTaskWoken = pdFALSE;
unsigned char abBulkBuf[64];
(void) bEPStatus;
@@ -171,10 +170,8 @@
iLen = USBHwEPRead(bEP, abBulkBuf, sizeof(abBulkBuf));
for (i = 0; i < iLen; i++) {
// put into queue
- xQueueSendFromISR(xRxedChars, &(abBulkBuf[ i ]), &lHigherPriorityTaskWoken);
+ xQueueSendFromISR(xRxedChars, &abBulkBuf[i], &higher_priority_task_woken);
}
-
- portEND_SWITCHING_ISR(lHigherPriorityTaskWoken);
}
@@ -186,7 +183,6 @@
*/
static void DebugIn(unsigned char bEP, unsigned char bEPStatus) {
int i, iLen;
- long lHigherPriorityTaskWoken = pdFALSE;
unsigned char abBulkBuf[64];
(void) bEPStatus;
@@ -199,8 +195,8 @@
// get bytes from transmit FIFO into intermediate buffer
for (i = 0; i < MAX_PACKET_SIZE; i++) {
- if (xQueueReceiveFromISR(xCharsForTx, (&abBulkBuf[i]),
- &lHigherPriorityTaskWoken) != pdPASS) {
+ if (xQueueReceiveFromISR(xCharsForTx, &abBulkBuf[i],
+ &higher_priority_task_woken) != pdPASS) {
break;
}
}
@@ -210,32 +206,14 @@
if (iLen > 0) {
USBHwEPWrite(bEP, abBulkBuf, iLen);
}
-
- portEND_SWITCHING_ISR(lHigherPriorityTaskWoken);
}
-static unsigned char abDataBuf[64];
-int VCOM_putcharFromISR(int c, long *woken);
-static void DataOut(unsigned char bEP, unsigned char bEPStatus) {
- int iLen;
- long lHigherPriorityTaskWoken = pdFALSE;
- /*
- char *a = "hello\n";
- while(*a){
- VCOM_putcharFromISR(*a,&lHigherPriorityTaskWoken);
- a ++;
- }
- */
- iLen = USBHwEPRead(bEP, abDataBuf, sizeof(abDataBuf));
- portEND_SWITCHING_ISR(lHigherPriorityTaskWoken);
-}
-
static void DataIn(unsigned char bEP, unsigned char bEPStatus) {
- long lHigherPriorityTaskWoken = pdFALSE;
- fillSensorPacket(&usbPacket);
- USBHwEPWrite(bEP, (unsigned char *)&usbPacket, sizeof(usbPacket));
- portEND_SWITCHING_ISR(lHigherPriorityTaskWoken);
+ fillSensorPacket(&usbPacket);
+ static uint8_t sequence = 0;
+ usbPacket.sequence = sequence++;
+ USBHwEPWrite(bEP, (unsigned char *)&usbPacket, sizeof(usbPacket));
}
/**
@@ -289,19 +267,24 @@
* Simply calls the USB ISR
*/
void USB_IRQHandler(void) {
+ higher_priority_task_woken = pdFALSE;
USBHwISR();
+ portEND_SWITCHING_ISR(higher_priority_task_woken);
}
static void USBFrameHandler(unsigned short wFrame) {
(void) wFrame;
if (uxQueueMessagesWaitingFromISR(xCharsForTx) > 0) {
- // data available, enable interrupt instead of NAK on bulk in too
+ // Data to send is available so enable interrupt instead of NAK on bulk in
+ // too.
USBHwNakIntEnable(INACK_BI | INACK_II);
} else {
USBHwNakIntEnable(INACK_II);
}
fillSensorPacket(&usbPacket);
+ static uint8_t sequence = 0;
+ usbPacket.sequence = sequence++;
USBHwEPWrite(ISOC_IN_EP, (unsigned char *)&usbPacket, sizeof(usbPacket));
}
@@ -320,7 +303,7 @@
vTaskDelete(NULL);
}
- // initialise stack
+ // Initialise the USB stack.
USBInit();
// register descriptors
@@ -332,16 +315,12 @@
// register endpoint handlers
USBHwRegisterEPIntHandler(INT_IN_EP, DataIn);
- USBHwRegisterEPIntHandler(INT_OUT_EP, DataOut);
USBHwRegisterEPIntHandler(BULK_IN_EP, DebugIn);
USBHwRegisterEPIntHandler(BULK_OUT_EP, DebugOut);
// register frame handler
USBHwRegisterFrameHandler(USBFrameHandler);
- // enable bulk-in interrupts on NAKs
- USBHwNakIntEnable(INACK_BI);
-
DBG("Starting USB communication\n");
NVIC_SetPriority(USB_IRQn, configUSB_INTERRUPT_PRIORITY);
diff --git a/gyro_board/src/usb/LPCUSB/usbhw_lpc.c b/gyro_board/src/usb/LPCUSB/usbhw_lpc.c
index 8229371..2fa038e 100644
--- a/gyro_board/src/usb/LPCUSB/usbhw_lpc.c
+++ b/gyro_board/src/usb/LPCUSB/usbhw_lpc.c
@@ -458,6 +458,8 @@
// endpoint interrupt
if (dwStatus & EP_SLOW) {
// clear EP_SLOW
+ // TODO(brians): The manual says that this should happen after clearing
+ // stuff using USBEpIntClr.
USB->USBDevIntClr = EP_SLOW;
// check all endpoints
for (i = 0; i < 32; i++) {
diff --git a/gyro_board/src/usb/data_struct.h b/gyro_board/src/usb/data_struct.h
index aa0e782..64c9631 100644
--- a/gyro_board/src/usb/data_struct.h
+++ b/gyro_board/src/usb/data_struct.h
@@ -40,6 +40,10 @@
uint16_t header;
};
+ // This is a counter that gets incremented with each packet sent (and wraps
+ // around when it reaches 255).
+ uint8_t sequence;
+
union {
struct {
union {
diff --git a/gyro_board/src/usb/toolchain-build-notes.txt b/gyro_board/src/usb/toolchain-build-notes.txt
index 700a1f3..d81c905 100644
--- a/gyro_board/src/usb/toolchain-build-notes.txt
+++ b/gyro_board/src/usb/toolchain-build-notes.txt
@@ -3,7 +3,7 @@
The flags are from logic, Austin's gcc, and
<http://www.coactionos.com/getting-started/43-building-and-installing-a-cortex-m3-compiler-on-ubuntu.html>
(for some of the newlib flags).
-TODO(brians): make sure that it generates code that works and then update this
+This has been uploaded to our package repository for wheezy as arm-eabi-gcc.
binutils
../binutils-2.23.2/configure --prefix=/opt/cortex-m3 --target=arm-eabi