Advertisement
robertbaruch

usb endpoint module documentation

Jul 29th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module usb_serial_ctrl_ep (
  2.   input clk,
  3.   input reset,
  4.   output [6:0] dev_addr,
  5.  
  6.   // For terminology, see https://www.beyondlogic.org/usbnutshell/usb4.shtml.
  7.   //
  8.   // An output control transfer has three stages:
  9.   // 1. Setup (the request from the host)
  10.   // 2. Data (zero or more out packets containing data from the host)
  11.   // 3. Status (a zero-length in packet requesting the endpoint's status of the overall transfer:
  12.   //    done ["ack"], still processing ["nak"], or error ["stall"])
  13.   //
  14.   // An input control transfer has three stages:
  15.   // 1. Setup (the request from the host)
  16.   // 2. Data (zero or more in packets containing data from the endpoint)
  17.   // 3. Status (a zero-length out packet requesting the endpoint's status of the overall transfer:
  18.   //    ready to receive another input request ["ack"], still processing ["nak"], or error
  19.   //    ["stall"])
  20.  
  21.   ////////////////////
  22.   // out endpoint interface
  23.   ////////////////////
  24.  
  25.   // To get data from the out endpoint, the following handshake happens:
  26.   //
  27.   // 1. out_ep_data_avail gets set.  // You've got data!
  28.   // 2. Set out_ep_req.              // Can I have it now?
  29.   // 3. out_ep_grant gets set.       // Yes!
  30.   // 4. Set out_ep_data_get.         // Give me the data.
  31.   // 5. Reset out_ep_data_get.
  32.   // 6. Read out_ep_data.            // Here is the data.
  33.   // (repeat 4-6 while out_ep_data_avail is set)
  34.   //
  35.   // TODO: Is 4-6 the right sequence? In other words, is out_ep_data guaranteed to be valid
  36.   // after out_ep_data_get is reset? And I'm assuming the clocking of out_ep_data_get has a maximum
  37.   // frequency, probably that of clk.
  38.  
  39.   // Set this when data is available (out_ep_data_avail set) in order to request the data.
  40.   output out_ep_req,
  41.   // Set after out_ep_req is set to indicate that the request is granted, and you are now free to
  42.   // get the data by setting out_ep_data_get.
  43.   input out_ep_grant,
  44.   // Set after a DATA0 or DATA1 packet is received for this device and endpoint. If
  45.   // out_ep_setup is high, then this is the data for a setup packet, otherwise this is
  46.   // the data for an out packet.
  47.   input out_ep_data_avail,
  48.   // Set after a SETUP token is received, which indicates that host wants to
  49.   // get a descriptor. Remains high until an OUT token is received. Not applicable to
  50.   // endpoints that are not the control endpoint.
  51.   input out_ep_setup,
  52.   // Set this when the data request has been granted (out_ep_grant set) in order to get the data.
  53.   // A positive transition clocks the next byte into out_ep_data. Continue clocking the data until
  54.   // out_ep_data_avail gets reset.
  55.   output out_ep_data_get,
  56.   // A byte of output data. Only valid if out_ep_grant and out_ep_data_get are set.
  57.   input [7:0] out_ep_data,
  58.   // Set this after receiving the data for an out packet on an output stall condition. During the
  59.   // data stage of a control transfer, a stall happens when the endpoint has had an error and the
  60.   // halt bit is set (TODO: explain this). During the status stage of an output control transfer, a
  61.   // stall happens when the endpoint had an error processing the previous host command (sent via an
  62.   // IN token).
  63.   output out_ep_stall,
  64.   // Set after the host successfully received the input control transfer data.
  65.   //
  66.   // TODO: Is this the out packet for the status stage of an in transfer, or the in packet for
  67.   // the status stage of an out tranfer?
  68.   input out_ep_acked,
  69.  
  70.  
  71.   ////////////////////
  72.   // in endpoint interface
  73.   ////////////////////
  74.  
  75.   // To send data via the in endpoint, the following handshake happens:
  76.   //
  77.   // 1. in_ep_data_free gets set.    // Ready to send.
  78.   // 2. Set in_ep_req.               // I have data to send. Can I send it?
  79.   // 3. in_ep_grant gets set.        // Yes!
  80.   // 4. Set in_ep_data_put.          // This is the data.
  81.   // 5. Set in_ep_data.              //
  82.   // 6. Reset in_ep_data_put.        // Go ahead and send it.
  83.   // (repeat 4-6 until no more data)
  84.   // 7. Set in_ep_data_done.         // I have no more data to send.
  85.   // 8. out_ep_acked gets set.       // Host received the data.
  86.   //
  87.   // TODO: Is 4-6 the right sequence? In other words, is in_ep_data required to be stable
  88.   // when in_ep_data_put is reset? And I'm assuming the clocking of in_ep_data_put has a maximum
  89.   // frequency, probably that of clk.
  90.   //
  91.   // TODO: Does setting in_ep_data_done imply that the endpoint is ready for another input request?
  92.   // If so, does that mean it needs to set in_ep_stall instead of in_ep_data_done?
  93.  
  94.   // Set this when data is ready to send and the line is free (in_ep_data_free set) in order to
  95.   // request permission to send.
  96.   output in_ep_req,
  97.   // Set after in_ep_req is set to indicate that the request is granted, and you are now free to
  98.   // send the data by setting in_ep_data_put.
  99.   input in_ep_grant,
  100.   // Set when the controller is ready to accept a request to send data.
  101.   input in_ep_data_free,
  102.   // Set this when the data send request has been granted (in_ep_grant set) in order to send the
  103.   // data that is in in_ep_data. A negative transition clocks the byte in in_ep_data_put onto the
  104.   // bus. Continue clocking the data until no more data, then set in_ep_data_done.
  105.   output in_ep_data_put,
  106.   // The data to send.
  107.   output reg [7:0] in_ep_data = 0,
  108.   // Set this after final byte is sent.
  109.   output in_ep_data_done,
  110.   // Set this after sending the data for an in packet on an input stall condition. During the
  111.   // data stage of a control transfer, a stall happens when the endpoint has had an error and the
  112.   // halt bit is set (TODO: explain this). During the status stage of an input control transfer, a
  113.   // stall happens when the endpoint had an error processing the previous host data (sent via an OUT
  114.   // token).
  115.   output reg in_ep_stall,
  116.   // Set by the host to acknowledge our completion of processing of the output data sent by the
  117.   // host.
  118.   //
  119.   // TODO: Is this the out packet for the status stage of an in transfer, or the in packet for
  120.   // the status stage of an out tranfer?
  121.   input in_ep_acked
  122. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement