Skip to content

Commit

Permalink
Change max response length to 17 bytes
Browse files Browse the repository at this point in the history
Setting sink.data size to 16 bytes results in missing 2 bytes in LONG
response.
  • Loading branch information
kamilrakoczy committed Apr 7, 2020
1 parent 019b1ee commit ada2405
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions litesdcard/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, phy, csr_data_width=32):
if csr_data_width == 8:
self.issue_cmd = CSRStorage(1)

self.response = CSRStatus(120)
self.response = CSRStatus(136)

self.cmdevt = CSRStatus(32)
self.dataevt = CSRStatus(32)
Expand All @@ -44,7 +44,7 @@ def __init__(self, phy, csr_data_width=32):

argument = Signal(32)
command = Signal(32)
response = Signal(120)
response = Signal(136)
cmdevt = Signal(32)
dataevt = Signal(32)
blocksize = Signal(16)
Expand All @@ -63,7 +63,7 @@ def __init__(self, phy, csr_data_width=32):
]

# sd to sys cdc
response_cdc = BusSynchronizer(120, "sd", "sys")
response_cdc = BusSynchronizer(136, "sd", "sys")
cmdevt_cdc = BusSynchronizer(32, "sd", "sys")
dataevt_cdc = BusSynchronizer(32, "sd", "sys")
self.submodules += response_cdc, cmdevt_cdc, dataevt_cdc
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(self, phy, csr_data_width=32):
]

self.submodules.crc7inserter = ClockDomainsRenamer("sd")(CRC(9, 7, 40))
self.submodules.crc7checker = ClockDomainsRenamer("sd")(CRCChecker(9, 7, 120))
self.submodules.crc7checker = ClockDomainsRenamer("sd")(CRCChecker(9, 7, 136))
self.submodules.crc16inserter = ClockDomainsRenamer("sd")(CRCUpstreamInserter())
self.submodules.crc16checker = ClockDomainsRenamer("sd")(CRCDownstreamChecker())

Expand Down Expand Up @@ -212,7 +212,10 @@ def __init__(self, phy, csr_data_width=32):
If(waitresp == SDCARD_CTRL_RESPONSE_SHORT,
phy.sink.data.eq(5) # (5+1)*8 == 48bits
).Elif(waitresp == SDCARD_CTRL_RESPONSE_LONG,
phy.sink.data.eq(16) # (16+1)*8 == 136bits
phy.sink.data.eq(17) # (17+1)*8 == 144bits
#FIXME: Setting sink data width to 16 here, results in missing 2 last bytes in LONG response
#Before this, example response is: 0x 000e00325b590000734f7f800a40001b
#After this, example response is : 0x0000003f400e00325b590000734f7f800a40001b
),

If(phy.source.valid, # Wait for resp or timeout coming from phy
Expand All @@ -236,8 +239,7 @@ def __init__(self, phy, csr_data_width=32):
NextState("IDLE")
),
).Else(
NextValue(response,
Cat(phy.source.data, response[0:112]))
NextValue(response, Cat(phy.source.data, response[:-len(phy.source.data)]))
)
)
)
Expand Down

0 comments on commit ada2405

Please sign in to comment.