Skip to content

Commit fa0c8e3

Browse files
committed
chore: clean up debug variables
1 parent d8f1d5c commit fa0c8e3

File tree

2 files changed

+0
-160
lines changed

2 files changed

+0
-160
lines changed

src/machine/usb/msc/msc.go

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package msc
22

33
import (
4-
"fmt"
54
"machine"
65
"machine/usb"
76
"machine/usb/descriptor"
@@ -58,21 +57,6 @@ type msc struct {
5857
senseKey scsi.Sense
5958
addlSenseCode scsi.SenseCode
6059
addlSenseQualifier uint8
61-
62-
// TODO: Cleanup
63-
loops uint32 // Number of loops in the current state
64-
prevState mscState
65-
savedState mscState
66-
packetsSent uint32 // Number of packets sent
67-
packetsRecv uint32 // Number of packets received
68-
packetsAcked uint32 // Number of packets acknowledged
69-
packetErrors uint32 // Number of error packets sent
70-
canaryA uint32 // Canaries for debugging
71-
canaryB uint32 // Canaries for debugging
72-
canaryC uint32 // Canaries for debugging
73-
canaryBuf [31]byte // CBW buffer container
74-
cbwLog []CBW // CBW log container
75-
msgLog []MsgLog // TX/RX log container
7660
}
7761

7862
// Port returns the USB Mass Storage port
@@ -168,10 +152,6 @@ func (m *msc) resetBuffer(length int) {
168152

169153
func (m *msc) sendUSBPacket(b []byte) {
170154
if machine.USBDev.InitEndpointComplete {
171-
if len(m.msgLog) > 0 {
172-
m.saveMsgLog(b, true) // FIXME: Cleanup
173-
}
174-
m.packetsSent++ // TODO: Cleanup?
175155
// Send the USB packet
176156
machine.SendUSBInPacket(usb.MSC_ENDPOINT_IN, b)
177157
}
@@ -190,7 +170,6 @@ func (m *msc) sendCSW(status csw.Status) {
190170

191171
func txHandler() {
192172
if MSC != nil {
193-
MSC.packetsAcked++ // TODO: Cleanup?
194173
MSC.txHandler()
195174
}
196175
}
@@ -202,10 +181,6 @@ func (m *msc) txHandler() {
202181
func rxHandler(b []byte) bool {
203182
ack := true
204183
if MSC != nil {
205-
if len(MSC.msgLog) > 0 {
206-
MSC.saveMsgLog(b, false) // FIXME: Cleanup
207-
}
208-
MSC.packetsRecv++ // TODO: Cleanup?
209184
ack = MSC.run(b, true)
210185
}
211186
return ack
@@ -239,14 +214,6 @@ command execution and moves to mscStateStatusSent.
239214
6. The host ACKs the CSW and the MSC moves back to mscStateCmd, waiting for the next CBW.
240215
*/
241216
func (m *msc) run(b []byte, isEpOut bool) bool {
242-
// TODO: Cleanup?
243-
if m.prevState != m.state {
244-
m.savedState = m.prevState
245-
m.loops = 0
246-
m.prevState = m.state
247-
}
248-
m.loops++
249-
250217
ack := true
251218

252219
switch m.state {
@@ -258,11 +225,6 @@ func (m *msc) run(b []byte, isEpOut bool) bool {
258225
return ack
259226
}
260227

261-
// Save debug log of received CBW commands
262-
if len(m.cbwLog) > 0 {
263-
m.saveCBW(b)
264-
}
265-
266228
// Create a temporary CBW wrapper to validate the incoming data. Has to be temporary
267229
// to avoid it escaping into the heap since we're in interrupt context
268230
cbw := CBW{Data: b}
@@ -335,123 +297,3 @@ func (m *msc) run(b []byte, isEpOut bool) bool {
335297

336298
return ack
337299
}
338-
339-
// TODO: Cleanup
340-
func (m *msc) CanaryBuf() string {
341-
if m.canaryA > 0 {
342-
return fmt.Sprintf("% x", m.canaryBuf)
343-
}
344-
return ""
345-
}
346-
347-
func stateToString(state mscState) string {
348-
switch state {
349-
case mscStateCmd:
350-
return "CmdWait"
351-
case mscStateData:
352-
return "Data"
353-
case mscStateStatus:
354-
return "SendStatus"
355-
case mscStateStatusSent:
356-
return "StatusSent"
357-
case mscStateNeedReset:
358-
return "NeedReset"
359-
default:
360-
return "Unknown"
361-
}
362-
}
363-
364-
func (m *msc) State() string {
365-
switch m.state {
366-
case mscStateCmd:
367-
return fmt.Sprintf("(%d/%d/%d) [%d/%d/%d/%d] CmdWait (%d) <- %s", m.canaryA, m.canaryB, m.canaryC, m.packetsRecv, m.packetsSent, m.packetsAcked, m.packetErrors, m.loops, stateToString(m.savedState))
368-
case mscStateData:
369-
return fmt.Sprintf("(%d/%d/%d) [%d/%d/%d/%d] Data [%d/%d/%d] (%d) <- %s", m.canaryA, m.canaryB, m.canaryC, m.packetsRecv, m.packetsSent, m.packetsAcked, m.packetErrors, m.queuedBytes, m.sentBytes, m.totalBytes, m.loops, stateToString(m.savedState))
370-
case mscStateStatus:
371-
return fmt.Sprintf("(%d/%d/%d) [%d/%d/%d/%d] SendStatus (%d) <- %s", m.canaryA, m.canaryB, m.canaryC, m.packetsRecv, m.packetsSent, m.packetsAcked, m.packetErrors, m.loops, stateToString(m.savedState))
372-
case mscStateStatusSent:
373-
return fmt.Sprintf("(%d/%d/%d) [%d/%d/%d/%d] StatusSent (%d) <- %s", m.canaryA, m.canaryB, m.canaryC, m.packetsRecv, m.packetsSent, m.packetsAcked, m.packetErrors, m.loops, stateToString(m.savedState))
374-
case mscStateNeedReset:
375-
return fmt.Sprintf("(%d/%d/%d) [%d/%d/%d/%d] NeedReset (%d) <- %s", m.canaryA, m.canaryB, m.canaryC, m.packetsRecv, m.packetsSent, m.packetsAcked, m.packetErrors, m.loops, stateToString(m.savedState))
376-
default:
377-
return "Unknown"
378-
}
379-
}
380-
381-
func (m *msc) saveCBW(b []byte) {
382-
n := len(m.cbwLog) - 1
383-
// Shift the log entries up to make room for a new entry
384-
for i := 0; i < n; i++ {
385-
copy(m.cbwLog[i].Data, m.cbwLog[i+1].Data)
386-
m.cbwLog[i].HasCmd = m.cbwLog[i+1].HasCmd
387-
}
388-
copy(m.cbwLog[n].Data, b)
389-
m.cbwLog[n].HasCmd = true
390-
}
391-
392-
func (m *msc) SetCBWLogSize(n int) {
393-
// Initialize the CBW log with a fixed size
394-
m.cbwLog = make([]CBW, n)
395-
for i := range m.cbwLog {
396-
m.cbwLog[i].Data = make([]byte, 31)
397-
}
398-
}
399-
400-
func (m *msc) CBWLog() []CBW {
401-
return m.cbwLog
402-
}
403-
404-
type MsgLog struct {
405-
CBW CBW
406-
Data []byte
407-
Length int
408-
Tx bool
409-
Valid bool
410-
}
411-
412-
func (m *msc) saveMsgLog(b []byte, tx bool) {
413-
n := len(m.msgLog) - 1
414-
// Shift the log entries up to make room for a new entry
415-
for i := 0; i < n; i++ {
416-
copy(m.msgLog[i].CBW.Data, m.msgLog[i+1].CBW.Data)
417-
copy(m.msgLog[i].Data, m.msgLog[i+1].Data)
418-
m.msgLog[i].Length = m.msgLog[i+1].Length
419-
m.msgLog[i].Tx = m.msgLog[i+1].Tx
420-
m.msgLog[i].Valid = m.msgLog[i+1].Valid
421-
}
422-
copy(m.msgLog[n].CBW.Data, m.cbw.Data)
423-
copy(m.msgLog[n].Data, b)
424-
m.msgLog[n].Length = len(b)
425-
m.msgLog[n].Tx = tx
426-
m.msgLog[n].Valid = true
427-
}
428-
429-
func (m *msc) SetMsgLogSize(n int) {
430-
// Initialize the TX log with a fixed size
431-
m.msgLog = make([]MsgLog, n)
432-
for i := range m.msgLog {
433-
m.msgLog[i].CBW = CBW{Data: make([]byte, cbwMsgLen)}
434-
m.msgLog[i].Data = make([]byte, m.maxPacketSize)
435-
}
436-
}
437-
438-
func (m *msc) MsgLog() []MsgLog {
439-
return m.msgLog
440-
}
441-
442-
func (m *msc) ClearMsgLog() {
443-
// Clear the TX log
444-
for i := range m.msgLog {
445-
m.msgLog[i].Valid = false
446-
}
447-
}
448-
449-
func allZero(b []byte) bool {
450-
// FIXME: Cleanup
451-
for i := 0; i < len(b); i++ {
452-
if b[i] != 0 {
453-
return false
454-
}
455-
}
456-
return len(b) != 0
457-
}

src/machine/usb/msc/scsi.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ func (m *msc) scsiQueueTask(cmdType scsi.CmdType, b []byte) bool {
278278
}
279279

280280
func (m *msc) sendScsiError(status csw.Status, key scsi.Sense, code scsi.SenseCode) {
281-
m.packetErrors++ // TODO: Cleanup?
282-
283281
// Generate CSW into m.cswBuf
284282
residue := m.totalBytes - m.sentBytes
285283

0 commit comments

Comments
 (0)