Questions about the library code - AM1808 StarterWare 1.00.03.03 example application usb_dev_bulk
Summary
- InternalUSBRegisterTickHandler() is called before USBDCDinit()
- thus, no tick handlers are registered
- why does this still work?? (i.e., is this a "benign" bug, or am I missing something?)
Details
Control flow in StarterWare
- main() invokes usbdbulk.c / USBDBulkInit()
- USBDBulkInit() invokes usbdbulk.c / USBDBulkCompositeInit()
- USBDBulkCompositeInit() invokes usbtick.c / InternalUSBRegisterTickHandler()
- InternalUSBRegisterTickHandler(USB_TICK_HANDLER_DEVICE, BulkTickHandler, psDevice)
- this registers usbdbulk.c / BulkTickHandler() as the device mode tick handler - USBDBulkCompositeInit() returns.
- USBDBulkInit() invokes usbdenum.c / USBDCDInit()
- USBDCDInit() invokes usbtick.c / InternalUSBTickInit()
- InternalUSBTickInit() erases the tick handler table, g_pfTickHandlers!
Why does this code still work correctly?? I am running the USB bulk device with usb_bulk_example.exe, and my PC and development board are communicating correctly...Is the tick handler just required to handle some exceptional cases that I'm not seeing with this simple test? See http://processors.wiki.ti.com/index.php/StarterWare_USB#Running_the_Example_Application
The source code even states (usbdbulk.c / USBDBulkCompositeInit())
//
// Register our tick handler (this must be done after USBDCDInit).
//
InternalUSBRegisterTickHandler(USB_TICK_HANDLER_DEVICE,
BulkTickHandler,
(void *)psDevice);
Further examination of usbdbulk.c / BulkTickHandler(): the only non-trivial operation is to invoke g_sBulkDevice.pfnRxCallback == usbbuffer.c / USBBufferEventCallback() in the event of a "deferred receive". Why is it okay to neglect this? I guess I'm not encountering any deferred receives during testing, but will this remain true in a production scenario?
Thank you!!
Reference
http://processors.wiki.ti.com/index.php/StarterWare_USB#Bulk_Device_Enumeration