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