• AVR Freaks

Hot!Determining endpoint number from event callback

Author
cqdx
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2010/11/13 08:41:45
  • Location: 0
  • Status: offline
2019/06/10 11:32:55 (permalink)
0

Determining endpoint number from event callback

Hello Community,
I am developing an application for USB device that uses multiple endpoints, interrupt and bulk. I am using one event handler in app.c to handle all the reading and writing of these endpoints. What I can't seem to find is how the event handler knows which endpoint it is being called for. According to one forum post https://www.microchip.com/forums/m1050956.aspx
the endpoint number is returned as part of eventData structure which is fed to the function as part of the callback. But I can't find where that is. The only data structure passed to the event handler is (void *) eventData. I understand that this void *eventData must be typecasted to the correct type based on the event itself. For an event of ENDPOINT_READ the type is USB_DEVICE_EVENT_DATA_ENDPOINT_READ_COMPLETE. However type: USB_DEVICE_EVENT_DATA_ENDPOINT_READ_COMPLETE does not contain an endpoint field. It only contains the length, status and transferHandle. I searched through to find that transferHandle is just uintptr_t type so no info there.
 
Unless I am missing something here, the only way I can reference the callback event back to the endpoint is to keep a table of transferHandles, updating them with every read or write call. Please tell me there is another way to do this. All of the examples I have found under harmony/2.06/apps use only a single IN and single OUT endpoint. I have not found an example that uses multiple endpoints. I am using MPLAB X 5.20 for Linux, Harmony 2.06 and XC32 2.15, processor is PIC32MZ2064DAG169
 
Many thanks in advance for any help.
 
Kindly,
 
Paul
 
#1

4 Replies Related Threads

    BillP
    Super Member
    • Total Posts : 311
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: offline
    Re: Determining endpoint number from event callback 2019/06/10 15:36:49 (permalink)
    0
    The cdc_com_port_dual demo uses multiple endpoints. All of the generated code is in system_config.h and system_init.c.  Hopefully that should get you what you need to proceed with your own application.
    #2
    cqdx
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2010/11/13 08:41:45
    • Location: 0
    • Status: offline
    Re: Determining endpoint number from event callback 2019/06/11 12:07:38 (permalink)
    0
    Hi BillP, 
     
    Thank you for the quick suggestion.  As I mentioned in my original post, I looked through all of the examples (include CDC dual) and could not find any example in which multiple BULK or INTERRUPT endpoints were used and that the endpoint was passed to the event handler callback function.  While the CDC demo has multiple endpoints, they are being used by the CDC device and not the regular APP callback event handler.   I could not find anything in that project's system_init.c and system_config.h that explains how to determine the endpoint number when a read or write event is fed to the event callback function.  
     
    I'm probably missing something here, this is my first foray into Harmony USB, but not my first time developing for a USB device.   Still, the endpoint number should be available as part of the USB event handler, especially for read/write complete events. 
     
    -Paul
     
     
    #3
    BillP
    Super Member
    • Total Posts : 311
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: offline
    Re: Determining endpoint number from event callback 2019/06/11 14:27:11 (permalink)
    0
    Hi Paul,

    I am not familiar with all the details of a USB stack, so what I have deduced is only based on examining Harmony source code.  The endpoints are defined in the system_config.h file for each cdc "instance".  A callback is registered for each instance, so the callback associates a USB event with the correct instance (endpoint?).  There are read complete and write complete events defined, so you can set flags to show which device was involved.

    Although I see there are Interrupt endpoints defined, I have not used them.  They must be buried in the USB stack.  

    Here is the sequence that I used to configure the USB stack:

    USB_DEVIVE_Open()     // returns a deviceHandle
    USB_DEVICE_EventHandlerSet(handle, device_callback,0)    //registers a device callback
    USBDeviceEventHandler(event,0)    // returns device events

    when a USB_DEVICE_EVENT_CONFIGURED device event occurs, then callbacks are registered for each CDC device (USB_DEVICE_CDC_EventHandlerSet(instance, cdc_callback0, data);

    The cdc_callback responds to CDC events, such as read_complete, etc. and a flag can be set for your applications code to take some action.

    Simple, huh?


    -BillP
    #4
    cqdx
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2010/11/13 08:41:45
    • Location: 0
    • Status: offline
    Re: Determining endpoint number from event callback 2019/06/13 09:28:16 (permalink)
    0
    Hi Bill, 
     
    Ok I see what you are doing/suggesting, to summarize you're essentially creating a separate device for each pair (in/out) of endpoints.  So an IN endpoint plus an OUT endpoint becomes a device and each device has its own event handler.  That is what I have deduced from the Harmony examples.  There is never more than two endpoints per device (in/out).   
     
    Because my application is using a vendor specific protocol, I did not want to create multiple devices.  I want just one device that has multiple endpoints (more than 2).  So what I'm doing now is simply using the transferHandle and tying it to the endpoint.  The only downside is I have to search a short list of transferHandles on each event.   Perhaps in the future I'll do it with multiple devices.  
     
    Thank you for taking the time to answer my question, I very much appreciate your help. 
     
    -Paul
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5