Skip to content

Commit

Permalink
updates to get it working with current Logic version
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Kostka committed Jul 11, 2020
1 parent b2c2196 commit 94ec4f7
Showing 1 changed file with 33 additions and 51 deletions.
84 changes: 33 additions & 51 deletions hla/sdmmc_from_spi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
High Level Analyzer script for interpreting SDMMC communication.
This is used by Saleae Logic 2.x.
This is supported by Saleae Logic v2.3.1 or later.
For more information, see https://github.com/saleae/logic2-examples
Expand All @@ -11,8 +11,16 @@
This analyzer will only decode the CMD signal. The data signal(s) are not
monitored.
Author: Tim Kostka <[email protected]>
Website: https://github.com/timkostka/saleae_sdmmc_from_spi
"""


from saleae.data.timing import GraphTimeDelta
from saleae.analyzers import HighLevelAnalyzer, AnalyzerFrame


# states (CURRENT_STATE)
CURRENT_STATE = {
0: "IDLE",
Expand Down Expand Up @@ -252,10 +260,7 @@ def __init__(self):
self.expected_response = None
# bits in the expected response
self.expected_response_length = 48
# bits discarded waiting for a command or response
# self.bits_discarded = 0
print("\n\n\n\n\n")
pass

def add_byte(self, value, start_time, end_time):
"""
Expand All @@ -265,17 +270,17 @@ def add_byte(self, value, start_time, end_time):
end is the end time of the byte
"""
if isinstance(value, bytes):
assert len(value) == 1
value = value[0]
assert isinstance(value, int)
# if bus is idle, ignore value
if value == 255 and not self.command_bits:
# self.bits_discarded += 8
# if self.bits_discarded > 20:
# self.expected_response = None
# self.expected_response_length = 48
return None
if not self.first_time:
self.first_time = start_time
new_bits = bits_from_byte(value)
bit_length = (end_time - start_time) / 7.5
bit_length = GraphTimeDelta(float(end_time - start_time) / 7.5)
# self.debug = "t %s to %s" % (start_time, end_time)
self.debug = "start_time:%s, end_time:%s" % (start_time, end_time)
# if we're expecting a response, look for one
Expand All @@ -288,9 +293,8 @@ def add_byte(self, value, start_time, end_time):
count = 0
while new_bits[0]:
count += 1
# self.bits_discarded += 1
del new_bits[0]
self.command_start = start_time + count * bit_length
self.command_start = start_time + GraphTimeDelta(count * float(bit_length))
self.command_bits = new_bits
return None
# add bits to command
Expand All @@ -303,9 +307,9 @@ def add_byte(self, value, start_time, end_time):
this_response_type = self.expected_response
# get end time of this
command_start = self.command_start
command_end = end_time - bit_length * (
command_end = end_time - GraphTimeDelta(float(bit_length) * (
len(self.command_bits) - this_response_length
)
))
bits = self.command_bits[:this_response_length]
print("\n")
print("".join("1" if x else "0" for x in bits))
Expand Down Expand Up @@ -337,16 +341,14 @@ def add_byte(self, value, start_time, end_time):
if all(x for x in self.command_bits):
self.command_bits = None
else:
# self.bits_discarded = 0
while self.command_bits[0]:
del self.command_bits[0]
# self.bits_discarded += 1
self.command_start = end_time
self.command_start -= bit_length * (len(self.command_bits) - 0.5)
self.command_start -= GraphTimeDelta(float(bit_length) * (len(self.command_bits) - 0.5))
print("new command bits =", self.command_bits)
print(info)
print(
"start=%g, duration=%g"
"start=%s, duration=%s"
% (command_start, command_end - command_start)
)
data = {
Expand All @@ -357,44 +359,24 @@ def add_byte(self, value, start_time, end_time):
return data


class SdmmcFromSpiAnalyzer:
def __init__(self):
self.state = SdioState()
class SdmmcFromSpiAnalyzer(HighLevelAnalyzer):

def get_capabilities(self):
return None
return {
"settings": {
"My String Setting": {"type": "string"},
"My Number Setting": {
"type": "number",
"minimum": 0,
"maximum": 100,
},
"My Choices Setting": {
"type": "choices",
"choices": ("A", "B"),
},
}
}
result_types = {
"error": {"format": "ERROR"},
"sdio": {"format": "{{data.info}}"},
}

def set_settings(self, settings):
return {
"result_types": {
"error": {"format": "ERROR"},
"sdio": {"format": "{{data.info}}"},
}
}
def __init__(self):
self.state = SdioState()

def decode(self, data):
info = self.state.add_byte(
data["data"]["mosi"], data["start_time"], data["end_time"]
data.data["mosi"], data.start_time, data.end_time
)
if info:
new_data = {
"type": "sdio",
"start_time": info["start_time"],
"end_time": info["end_time"],
"data": {"info": info["info"]},
}
return new_data
return AnalyzerFrame(
'mytype',
info["start_time"],
info["end_time"],
{"info": info["info"]}
)

0 comments on commit 94ec4f7

Please sign in to comment.