no crc errors in status; closing the gap?

This commit is contained in:
soypat
2024-01-14 20:08:57 -03:00
parent ace4a8924b
commit d5db138d9a
5 changed files with 348 additions and 275 deletions
-130
View File
@@ -456,136 +456,6 @@ func (t TAAC) AccessTime() (d time.Duration) {
return time.Duration(log10table[t&0b111]) * time.Nanosecond
}
const (
_CMD_TIMEOUT = 100
_R1_IDLE_STATE = 1 << 0
_R1_ERASE_RESET = 1 << 1
_R1_ILLEGAL_COMMAND = 1 << 2
_R1_COM_CRC_ERROR = 1 << 3
_R1_ERASE_SEQUENCE_ERROR = 1 << 4
_R1_ADDRESS_ERROR = 1 << 5
_R1_PARAMETER_ERROR = 1 << 6
)
// Tokens that are sent by card during polling.
// https://github.com/arduino-libraries/SD/blob/master/src/utility/SdInfo.h
const (
tokSTART_BLOCK = 0xfe
tokSTOP_TRAN = 0xfd
tokWRITE_MULT = 0xfc
)
type status uint32
// First status bits.
//
//go:generate stringer -type=status -trimprefix=status -output=status_string.go
const (
statusRsvd0 status = iota
statusRsvd1
statusRsvd2
statusAuthSeqError
statusRsvdSDIO
statusAppCmd
statusFXEvent
statusRsvd7
statusReadyForData
)
// Upper bound status bits.
const (
statusEraseReset status = iota + 13
statusECCDisabled
statusWPEraseSkip
statusCSDOverwrite
_
_
statusGenericError
statusControllerError // internal card controller error
statusECCFailed
statusIllegalCommand
statusComCRCError // CRC check of previous command failed
statusLockUnlockFailed
statusCardIsLocked // Signals that the card is locked by the host.
statusWPViolation // Write protected violation
statusEraseParamError // invalid write block selection for erase
statusEraseSeqError // error in erase sequence
statusBlockLenError // tx block length not allowed
statusAddrError // misaligned address
statusAddrOutOfRange // address out of range
)
// r1 is the normal response to a command.
type r1 struct {
data [48 / 8]byte // 48 bits of response.
}
func (r *r1) RawCopy() [6]byte { return r.data }
func (r *r1) startbit() bool {
return r.data[0]&(1<<7) != 0
}
func (r *r1) txbit() bool {
return r.data[0]&(1<<6) != 0
}
func (r *r1) cmdidx() uint8 {
return r.data[0] & 0b11_1111
}
func (r *r1) cardstatus() status {
return status(binary.BigEndian.Uint32(r.data[1:5]))
}
func (r *r1) CRC7() uint8 { return r.data[5] >> 1 }
func (r *r1) endbit() bool { return r.data[5]&1 != 0 }
func (r *r1) IsValid() bool {
return r.endbit() && CRC7(r.data[:5]) == r.CRC7()
}
type r6 struct {
data [48 / 8]byte
}
func (r *r6) RawCopy() [6]byte { return r.data }
func (r *r6) startbit() bool {
return r.data[0]&(1<<7) != 0
}
func (r *r6) txbit() bool {
return r.data[0]&(1<<6) != 0
}
func (r *r6) cmdidx() uint8 {
return r.data[0] & 0b11_1111
}
func (r *r6) rca() uint16 {
return binary.BigEndian.Uint16(r.data[1:3])
}
func (r *r6) cardstatus() status {
moveBit := func(b status, from, to uint) status {
return (b & (1 << from)) >> from << to
}
// See 4.9.5 R6 (Published RCA response) of the SD Simplified Specification.
s := status(binary.BigEndian.Uint16(r.data[1:5]))
s = moveBit(s, 13, 19)
s = moveBit(s, 14, 22)
s = moveBit(s, 15, 23)
return s
}
func (r *r6) CRC7() uint8 { return r.data[5] >> 1 }
func (r *r6) endbit() bool { return r.data[5]&1 != 0 }
func (r *r6) IsValid() bool {
return r.endbit() && CRC7(r.data[:5]) == r.CRC7()
}
type response1 uint8
func (r response1) IsIdle() bool { return r&_R1_IDLE_STATE != 0 }
func (r response1) IllegalCmdError() bool { return r&_R1_ILLEGAL_COMMAND != 0 }
func (r response1) CRCError() bool { return r&_R1_COM_CRC_ERROR != 0 }
func (r response1) EraseReset() bool { return r&_R1_ERASE_RESET != 0 }
func (r response1) EraseSeqError() bool { return r&_R1_ERASE_SEQUENCE_ERROR != 0 }
func (r response1) AddressError() bool { return r&_R1_ADDRESS_ERROR != 0 }
func (r response1) ParamError() bool { return r&_R1_PARAMETER_ERROR != 0 }
func b2u8(b bool) uint8 {
if b {
return 1