From ce545fa88cdd68741f72b822d34bf39b6a39e6bf Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Vauboin Date: Mon, 15 Feb 2021 18:45:14 +0100 Subject: [PATCH] Decoder sdcard: trigger the decoding on clock raising edge This improves the decoding speed a lot (~8x faster), especially when using a high sampling rate. --- libsigrokdecode4DSL/decoders/sdcard_sd/pd.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libsigrokdecode4DSL/decoders/sdcard_sd/pd.py b/libsigrokdecode4DSL/decoders/sdcard_sd/pd.py index 2b4f8c7a..24c3fba5 100755 --- a/libsigrokdecode4DSL/decoders/sdcard_sd/pd.py +++ b/libsigrokdecode4DSL/decoders/sdcard_sd/pd.py @@ -525,15 +525,19 @@ class Decoder(srd.Decoder): def decode(self): while True: + conds = {Pin.CLK: 'r'} + + # Wait for start bit (CMD = 0). + if ((self.state == St.GET_COMMAND_TOKEN or + self.state.value.startswith('GET_RESPONSE')) and + (len(self.token) == 0)): + conds.update({Pin.CMD: 'l'}) + # Wait for a rising CLK edge. - (cmd_pin, clk, dat0, dat1, dat2, dat3) = self.wait({Pin.CLK: 'r'}) + (cmd_pin, clk, dat0, dat1, dat2, dat3) = self.wait(conds) # State machine. if self.state == St.GET_COMMAND_TOKEN: - if len(self.token) == 0: - # Wait for start bit (CMD = 0). - if cmd_pin != 0: - continue self.get_command_token(cmd_pin) elif self.state.value.startswith('HANDLE_CMD'): # Call the respective handler method for the command. @@ -544,12 +548,7 @@ class Decoder(srd.Decoder): if self.is_acmd and cmdstr not in ('55', '63'): self.is_acmd = False elif self.state.value.startswith('GET_RESPONSE'): - if len(self.token) == 0: - # Wait for start bit (CMD = 0). - if cmd_pin != 0: - continue # Call the respective handler method for the response. s = 'handle_response_%s' % self.state.value[13:].lower() handle_response = getattr(self, s) handle_response(cmd_pin) -