Diff: UsbStructures.h
- Revision:
- 1:4461071ed964
- Parent:
- 0:63d45df56584
- Child:
- 2:33e7ce63dd6d
--- a/UsbStructures.h Sun Jul 08 20:18:58 2012 +0000 +++ b/UsbStructures.h Wed Sep 19 16:39:23 2012 +0000 @@ -154,7 +154,20 @@ struct LinkedListItem { LinkedListItem* next; - uint32_t padding[3];//So struct is 16 bytes in size. + uint32_t padding[7];//So struct is 32 bytes in size. +}; + +/** + * Inhert this object and implemet the callback function. + * Then pass this object to the IO functions if you need a callback. + */ +struct TransferCallback +{ + /** + * Called when a transfer has been completed that had a callback ID set. + * Any other transfers without a callback ID will not trigger this. + */ + virtual void onReceive(int deviceID, int endpoint, int status,const uint8_t* data, int length) = 0; }; /** @@ -223,38 +236,52 @@ * ConditionCode field and placed on the done queue. When a * transaction completes without error, ErrorCount is reset to 0. */ - volatile unsigned errorCount:2; + unsigned errorCount:2; /** * This field contains the status of the last attempted transaction. */ - volatile unsigned conditionCode:4; + unsigned conditionCode:4; /** * Contains the physical address of the next memory location that will be * accessed for transfer to/from the endpoint. A value of 0 indicates a zero- * length data packet or that all bytes have been transferred. */ - const volatile uint8_t* CurrentBufferPointer; + const uint8_t* CurrentBufferPointer; /** * his entry points to the next TD on the list of TDs linked to this endpoint - */ - volatile TransferDescriptor *nextTD; + */ + TransferDescriptor *nextTD; /** * Contains physical address of the last byte in the buffer for this TD */ - const volatile uint8_t* bufferEnd; + const uint8_t* bufferEnd; /** * Extra 16 bytes for the callback info. - * - - int callbakID; - const uint8_t* buffer; - int bufferSize; - int padding;*/ + */ + + /** + * If not NULL then called when a transfer is completed. + */ + TransferCallback* transferCallback; + + /** + * The pointer to the start of the data being transfered or recived. + */ + const uint8_t* data; + + /** + * The length of the transfer. + */ + int length; + uint8_t ep; + uint8_t transferType; + uint8_t pad1; + uint8_t pad2; }; /** @@ -286,15 +313,20 @@ */ uint32_t control; - volatile TransferDescriptor* TailTD; //physical pointer to HC_TRANSFER_DESCRIPTOR - volatile TransferDescriptor* HeadTD; //flags + phys ptr to HC_TRANSFER_DESCRIPTOR - EndpointDescriptor* NextED; //phys ptr to HC_ENDPOINT_DESCRIPTOR + unsigned padding0:4; + unsigned TailTD:28; //physical pointer to HC_TRANSFER_DESCRIPTOR + +// TransferDescriptor* HeadTD; //flags + phys ptr to HC_TRANSFER_DESCRIPTOR + unsigned H:1; + unsigned C:1; + unsigned ZERO:2; + unsigned HeadTD:28; + + EndpointDescriptor* NextEP; //phys ptr to HC_ENDPOINT_DESCRIPTOR }; - - /* - * Size is kept to 16 bytes so that I can use the pool of memory in + * Size is kept to no more than 32 bytes so that I can use the pool of memory in * the host controller driver and so not use any of the main 32k of ram. */ struct Device @@ -302,36 +334,43 @@ /** * When we allocated a device with give it an ID and then set the USB device's ID with the set address command. */ - unsigned id:8; + int id; - unsigned lowspeed:1; - unsigned controlTransferDirToHost:1;//LIBUSB_ENDPOINT_IN when set - unsigned controlTransferState:2; //See enum ControlTransferState, the control transfer has several states it can be in. - unsigned padding:4; + uint8_t lowspeed; + uint8_t controlTransferDirToHost;//LIBUSB_ENDPOINT_IN when set + uint8_t controlTransferState; //See enum ControlTransferState, the control transfer has several states it can be in. + uint8_t padding; /** - * This is the packet size of endpoint zero the docs say valid Sizes are 8, 16, 32, 64. Could be out of date. + * This is the packet size of endpoint zero the docs say valid Sizes are 8, 16, 32, 64. This info could be out of date. */ - uint16_t endpointZeroMaxPacketSize; + int endpointZeroMaxPacketSize; /** * This data is used whilst there is a control transfer in progress. * When finished controlTransferDataLength will be the number of bytes recived. */ const uint8_t* controlTransferData; - uint16_t controlTransferDataLength; + int controlTransferDataLength; /** * The first language ID I find from string index zero. Makes life easier. * Used in getting the descriptor strings. */ - uint16_t languageID; + int languageID; + + /* + * If a transfer requires a callback when done then this will have the transfers here. + * If this is the case then the transfer is only free'd after the callback has been called instead of when the interupt is called. + * Because of this it is important that the applicaition calls the Update function of the driver at least once a second. + * Failure to do so whilst issueing many transfers will cause the memory pool to be exhausted. + */ + TransferDescriptor* pendingCallbacks; /** - * Free to be used later. + * When not -1 then will block the transfer until it is -1 again. */ - uint32_t padding2; - + int blockOnEP; }; /** @@ -424,21 +463,20 @@ */ /** - * for some reason the controler does not use a NULL for end of list but an object that does no transfer. Not sure why or if I got that correct. - */ - TransferDescriptor commonTail; - - /** * Device zero is used for enumeration and setup when a usb device is inserted. */ Device deviceZero; /** - * My memory pool of 16 byte objects that MUST be aligned on a 16byte boundry. + * My memory pool of 32 byte objects that MUST be aligned on a 16byte boundry. * So don't move this entry or add stuff before it! + * It is 32 bytes as the transfer descriptor needs an extra 16 bytes for my + * driver so I can do callbacks when a transfer is complete. + * Without it then I would need some kind of horrid lookup table and code that could add bugs. + * This way it is nice, clean, and simple. */ - LinkedListItem memoryPool[64]; - + LinkedListItem memoryPool[32]; + /** * And now some scratch ram to used when I am reciving strings. */