-
Notifications
You must be signed in to change notification settings - Fork 963
machine/rp2: expose usb endpoint stall handling #4850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,26 +21,33 @@ func initEndpoint(ep, config uint32) { | |
offset := ep*2*usbBufferLen + 0x100 | ||
val |= offset | ||
|
||
// Bulk and interrupt endpoints must have their Packet ID reset to DATA0 when un-stalled. | ||
epXPIDReset[ep] = false // Default to false in case an endpoint is re-initialized. | ||
|
||
switch config { | ||
case usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn: | ||
val |= usbEpControlEndpointTypeInterrupt | ||
_usbDPSRAM.EPxControl[ep].In.Set(val) | ||
epXPIDReset[ep] = true | ||
|
||
case usb.ENDPOINT_TYPE_BULK | usb.EndpointOut: | ||
val |= usbEpControlEndpointTypeBulk | ||
_usbDPSRAM.EPxControl[ep].Out.Set(val) | ||
_usbDPSRAM.EPxBufferControl[ep].Out.Set(usbBufferLen & usbBuf0CtrlLenMask) | ||
_usbDPSRAM.EPxBufferControl[ep].Out.SetBits(usbBuf0CtrlAvail) | ||
epXPIDReset[ep] = true | ||
|
||
case usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointOut: | ||
val |= usbEpControlEndpointTypeInterrupt | ||
_usbDPSRAM.EPxControl[ep].Out.Set(val) | ||
_usbDPSRAM.EPxBufferControl[ep].Out.Set(usbBufferLen & usbBuf0CtrlLenMask) | ||
_usbDPSRAM.EPxBufferControl[ep].Out.SetBits(usbBuf0CtrlAvail) | ||
epXPIDReset[ep] = true | ||
|
||
case usb.ENDPOINT_TYPE_BULK | usb.EndpointIn: | ||
val |= usbEpControlEndpointTypeBulk | ||
_usbDPSRAM.EPxControl[ep].In.Set(val) | ||
epXPIDReset[ep] = true | ||
|
||
case usb.ENDPOINT_TYPE_CONTROL: | ||
val |= usbEpControlEndpointTypeControl | ||
|
@@ -109,7 +116,12 @@ func handleEndpointRx(ep uint32) []byte { | |
} | ||
|
||
func handleEndpointRxComplete(ep uint32) { | ||
epXdata0[ep] = !epXdata0[ep] | ||
setEPDataPID(ep, !epXdata0[ep]) | ||
} | ||
|
||
// Set the USB endpoint Packet ID to DATA0 or DATA1. | ||
func setEPDataPID(ep uint32, dataOne bool) { | ||
epXdata0[ep] = dataOne | ||
if epXdata0[ep] || ep == 0 { | ||
_usbDPSRAM.EPxBufferControl[ep].Out.SetBits(usbBuf0CtrlData1Pid) | ||
} | ||
|
@@ -138,7 +150,8 @@ func sendViaEPIn(ep uint32, data []byte, count int) { | |
_usbDPSRAM.EPxBufferControl[ep&0x7F].In.Set(val) | ||
} | ||
|
||
func sendStallViaEPIn(ep uint32) { | ||
// Set ENDPOINT_HALT/stall status on a USB IN endpoint. | ||
func (dev *USBDevice) SetStallEPIn(ep uint32) { | ||
// Prepare buffer control register value | ||
if ep == 0 { | ||
armEPZeroStall() | ||
|
@@ -149,6 +162,37 @@ func sendStallViaEPIn(ep uint32) { | |
_usbDPSRAM.EPxBufferControl[ep&0x7F].In.Set(val) | ||
} | ||
|
||
// Set ENDPOINT_HALT/stall status on a USB OUT endpoint. | ||
func (dev *USBDevice) SetStallEPOut(ep uint32) { | ||
if ep == 0 { | ||
panic("SetStallEPOut: EP0 OUT not valid") | ||
} | ||
val := uint32(usbBuf0CtrlStall) | ||
_usbDPSRAM.EPxBufferControl[ep&0x7F].Out.Set(val) | ||
} | ||
|
||
// Clear the ENDPOINT_HALT/stall on a USB IN endpoint. | ||
func (dev *USBDevice) ClearStallEPIn(ep uint32) { | ||
ep = ep & 0x7F | ||
val := uint32(usbBuf0CtrlStall) | ||
_usbDPSRAM.EPxBufferControl[ep].In.ClearBits(val) | ||
if epXPIDReset[ep] { | ||
// Reset the PID to DATA0 | ||
setEPDataPID(ep&0x7F, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the masking is redundant here. |
||
} | ||
} | ||
|
||
// Clear the ENDPOINT_HALT/stall on a USB OUT endpoint. | ||
func (dev *USBDevice) ClearStallEPOut(ep uint32) { | ||
ep = ep & 0x7F | ||
val := uint32(usbBuf0CtrlStall) | ||
_usbDPSRAM.EPxBufferControl[ep].Out.ClearBits(val) | ||
if epXPIDReset[ep] { | ||
// Reset the PID to DATA0 | ||
setEPDataPID(ep, false) | ||
} | ||
} | ||
|
||
type usbDPSRAM struct { | ||
// Note that EPxControl[0] is not EP0Control but 8-byte setup data. | ||
EPxControl [16]usbEndpointControlRegister | ||
|
@@ -173,9 +217,10 @@ type usbBuffer struct { | |
} | ||
|
||
var ( | ||
_usbDPSRAM = (*usbDPSRAM)(unsafe.Pointer(uintptr(0x50100000))) | ||
epXdata0 [16]bool | ||
setupBytes [8]byte | ||
_usbDPSRAM = (*usbDPSRAM)(unsafe.Pointer(uintptr(0x50100000))) | ||
epXdata0 [16]bool | ||
epXPIDReset [16]bool | ||
setupBytes [8]byte | ||
) | ||
|
||
func (d *usbDPSRAM) setupBytes() []byte { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
ep
be masked before comparing with 0?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 0 endpoint is a special case. It's both an in and out endpoint in one so there's no direction bit applied for it, but couldn't hurt