Skip to content

Commit c6e93f7

Browse files
Improved protocol analyzer's error detection and handling
1 parent e03c445 commit c6e93f7

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

CC1101SpiProtocol.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
}
143143

144144

145+
class ProtocolException(Exception):
146+
pass
147+
145148
class ProtocolFrameType:
146149
REGISTER = "register"
147150
COMMAND = "cmd"
@@ -162,10 +165,12 @@ class CC1101SpiProtocol:
162165
"register": None,
163166
"data": None,
164167
"description": None,
168+
"error": None,
165169
}
166170
RESPONSE = {
167171
"status": None,
168172
"data": None,
173+
"error": None,
169174
}
170175
STATUS = {
171176
"chip_rdy": None,
@@ -210,6 +215,7 @@ def interpret_register(self, data_byte):
210215
register = None
211216
address = data_byte & 0x3F
212217
frame_type = None
218+
error = None
213219

214220
if address < 0x30:
215221
frame_type = ProtocolFrameType.REGISTER
@@ -223,11 +229,18 @@ def interpret_register(self, data_byte):
223229
elif self.is_read(data_byte) and self.is_burst(data_byte):
224230
frame_type = ProtocolFrameType.STATUS
225231
register = STATUS_REGISTERS[address]
226-
else:
227-
frame_type = ProtocolFrameType.COMMAND
228-
register = COMMAND_REGISTERS[address]
229-
230-
return frame_type, register["register"], register["description"]
232+
elif address <= 0x3D:
233+
if address != 0x37:
234+
frame_type = ProtocolFrameType.COMMAND
235+
register = COMMAND_REGISTERS[address]
236+
else:
237+
frame_type = ProtocolFrameType.ERROR
238+
error = "Invalid COMMAND"
239+
elif address > 0x3D:
240+
frame_type = ProtocolFrameType.ERROR
241+
error = "Invalid ADDRESS"
242+
243+
return frame_type, register["register"], register["description"], error
231244

232245
def interpret_request(self, data):
233246
request = deepcopy(self.REQUEST)
@@ -237,7 +250,7 @@ def interpret_request(self, data):
237250
request["burst"] = "B" if self.is_burst(data[0]) else ""
238251

239252
# Register address
240-
request["type"], request["register"], request["description"] = self.interpret_register(data[0])
253+
request["type"], request["register"], request["description"], request["error"] = self.interpret_register(data[0])
241254

242255
# Data Byte
243256
if len(data) > 1:

HighLevelAnalyzer.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Hla(HighLevelAnalyzer):
3636
'format': 'Error: {{type}}'
3737
},
3838
ProtocolFrameType.ERROR: {
39-
'format': 'Error: {{type}}'
39+
'format': 'Error: {{type}} | {{data.error_details}}'
4040
},
4141
ProtocolFrameType.REGISTER: {
4242
'format': 'Register: {{data.access}} | {{data.register}} = {{data.focus_data}}'
@@ -157,17 +157,25 @@ def construct_table(self, protocol_msg):
157157
fifo_bytes_available = "" if response is None else "{}".format(response["status"]["fifo_bytes_available"])
158158
read_data = "" if response is None else " ".join(["{:02X}".format(x) for x in response["data"]])
159159
description = protocol_msg["request"]["description"]
160+
focus_data = ""
161+
error_details = ""
160162

161163
# Focus Data is used mainly for the Protocol UI labels
162164
if frame_type == ProtocolFrameType.ERROR:
163-
focus_data = ""
165+
error_details = protocol_msg["request"]["error"]
164166
elif frame_type == ProtocolFrameType.REGISTER:
165167
focus_data = write_data if access == "W" else read_data
166168
elif frame_type == ProtocolFrameType.COMMAND:
167-
focus_data = ""
169+
pass
168170
elif frame_type == ProtocolFrameType.STATUS:
169171
if register == "MARCSTATE":
170-
focus_data = MARC_STATE[response["data"][0]]["state"]
172+
marc_state = response["data"][0]
173+
if marc_state <= 0x16:
174+
focus_data = MARC_STATE[response["data"][0]]["state"]
175+
else:
176+
# See [SWRZ020E] CC1101 Silicon Errata
177+
frame_type = ProtocolFrameType.ERROR
178+
error_details = "Invalid MARCSTATE"
171179
else:
172180
focus_data = read_data
173181
elif frame_type == ProtocolFrameType.PA_TABLE:
@@ -189,7 +197,7 @@ def construct_table(self, protocol_msg):
189197
"read_data": read_data,
190198
"register_description": description,
191199
"focus_data": focus_data,
192-
"error_details": "",
200+
"error_details": error_details,
193201
}
194202
)
195203

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ SPI protocol analyzer for the Texas Instruments CC1101 RF Transceiver
66

77
- TODO
88

9+
# Texas Instruments references
10+
- [CC1101 Product Page](https://www.ti.com/product/CC1101)
11+
- [CC1101 Datasheet](https://www.ti.com/lit/ds/symlink/cc1101.pdf)
12+
- [CC1101 Silicon Errata](https://www.ti.com/lit/er/swrz020e/swrz020e.pdf)
13+
14+

0 commit comments

Comments
 (0)