mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
machine: implement usb receive message throttling
This commit is contained in:
@@ -194,10 +194,9 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
|
||||
setEPINTFLAG(i, epFlags)
|
||||
if (epFlags & sam.USB_DEVICE_EPINTFLAG_TRCPT0) > 0 {
|
||||
buf := handleEndpointRx(i)
|
||||
if usbRxHandler[i] != nil {
|
||||
usbRxHandler[i](buf)
|
||||
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
|
||||
AckUsbOutTransfer(i)
|
||||
}
|
||||
handleEndpointRxComplete(i)
|
||||
} else if (epFlags & sam.USB_DEVICE_EPINTFLAG_TRCPT1) > 0 {
|
||||
if usbTxHandler[i] != nil {
|
||||
usbTxHandler[i]()
|
||||
@@ -417,7 +416,8 @@ func handleEndpointRx(ep uint32) []byte {
|
||||
return udd_ep_out_cache_buffer[ep][:count]
|
||||
}
|
||||
|
||||
func handleEndpointRxComplete(ep uint32) {
|
||||
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
|
||||
func AckUsbOutTransfer(ep uint32) {
|
||||
// set byte count to zero
|
||||
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos)
|
||||
|
||||
|
||||
@@ -197,10 +197,9 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
|
||||
setEPINTFLAG(i, epFlags)
|
||||
if (epFlags & sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT0) > 0 {
|
||||
buf := handleEndpointRx(i)
|
||||
if usbRxHandler[i] != nil {
|
||||
usbRxHandler[i](buf)
|
||||
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
|
||||
AckUsbOutTransfer(i)
|
||||
}
|
||||
handleEndpointRxComplete(i)
|
||||
} else if (epFlags & sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT1) > 0 {
|
||||
if usbTxHandler[i] != nil {
|
||||
usbTxHandler[i]()
|
||||
@@ -420,7 +419,8 @@ func handleEndpointRx(ep uint32) []byte {
|
||||
return udd_ep_out_cache_buffer[ep][:count]
|
||||
}
|
||||
|
||||
func handleEndpointRxComplete(ep uint32) {
|
||||
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
|
||||
func AckUsbOutTransfer(ep uint32) {
|
||||
// set byte count to zero
|
||||
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos)
|
||||
|
||||
|
||||
@@ -206,10 +206,9 @@ func handleUSBIRQ(interrupt.Interrupt) {
|
||||
if nrf.USBD.EVENTS_ENDEPOUT[i].Get() > 0 {
|
||||
nrf.USBD.EVENTS_ENDEPOUT[i].Set(0)
|
||||
buf := handleEndpointRx(uint32(i))
|
||||
if usbRxHandler[i] != nil {
|
||||
usbRxHandler[i](buf)
|
||||
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
|
||||
AckUsbOutTransfer(uint32(i))
|
||||
}
|
||||
handleEndpointRxComplete(uint32(i))
|
||||
exitCriticalSection()
|
||||
}
|
||||
}
|
||||
@@ -304,7 +303,8 @@ func handleEndpointRx(ep uint32) []byte {
|
||||
return udd_ep_out_cache_buffer[ep][:count]
|
||||
}
|
||||
|
||||
func handleEndpointRxComplete(ep uint32) {
|
||||
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
|
||||
func AckUsbOutTransfer(ep uint32) {
|
||||
// set ready for next data
|
||||
nrf.USBD.SIZE.EPOUT[ep].Set(0)
|
||||
}
|
||||
|
||||
@@ -95,10 +95,9 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
|
||||
for i := 0; i < 16; i++ {
|
||||
if s2&(1<<(i*2+1)) > 0 {
|
||||
buf := handleEndpointRx(uint32(i))
|
||||
if usbRxHandler[i] != nil {
|
||||
usbRxHandler[i](buf)
|
||||
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
|
||||
AckUsbOutTransfer(uint32(i))
|
||||
}
|
||||
handleEndpointRxComplete(uint32(i))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,10 +98,9 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
|
||||
for i := 0; i < 16; i++ {
|
||||
if s2&(1<<(i*2+1)) > 0 {
|
||||
buf := handleEndpointRx(uint32(i))
|
||||
if usbRxHandler[i] != nil {
|
||||
usbRxHandler[i](buf)
|
||||
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
|
||||
AckUsbOutTransfer(uint32(i))
|
||||
}
|
||||
handleEndpointRxComplete(uint32(i))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,8 @@ func handleEndpointRx(ep uint32) []byte {
|
||||
return _usbDPSRAM.EPxBuffer[ep].Buffer0[:sz]
|
||||
}
|
||||
|
||||
func handleEndpointRxComplete(ep uint32) {
|
||||
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
|
||||
func AckUsbOutTransfer(ep uint32) {
|
||||
ep = ep & 0x7F
|
||||
setEPDataPID(ep, !epXdata0[ep])
|
||||
}
|
||||
|
||||
+6
-1
@@ -319,7 +319,12 @@ func ConfigureUSBEndpoint(desc descriptor.Descriptor, epSettings []usb.EndpointC
|
||||
} else {
|
||||
endPoints[ep.Index] = uint32(ep.Type | usb.EndpointOut)
|
||||
if ep.RxHandler != nil {
|
||||
usbRxHandler[ep.Index] = ep.RxHandler
|
||||
usbRxHandler[ep.Index] = func(b []byte) bool {
|
||||
ep.RxHandler(b)
|
||||
return true
|
||||
}
|
||||
} else if ep.DelayRxHandler != nil {
|
||||
usbRxHandler[ep.Index] = ep.DelayRxHandler
|
||||
}
|
||||
}
|
||||
if ep.StallHandler != nil {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package usb
|
||||
|
||||
type EndpointConfig struct {
|
||||
Index uint8
|
||||
IsIn bool
|
||||
TxHandler func()
|
||||
RxHandler func([]byte)
|
||||
StallHandler func(Setup) bool
|
||||
Type uint8
|
||||
Index uint8
|
||||
IsIn bool
|
||||
TxHandler func()
|
||||
RxHandler func([]byte)
|
||||
DelayRxHandler func([]byte) bool
|
||||
StallHandler func(Setup) bool
|
||||
Type uint8
|
||||
}
|
||||
|
||||
type SetupConfig struct {
|
||||
|
||||
Reference in New Issue
Block a user