Skip to content

Commit cf325c4

Browse files
committed
ISSUE-232: Address Co-Pilot review.
1 parent 1904f31 commit cf325c4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

pylink/jlink.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,7 +2631,7 @@ def jtag_flush(self):
26312631

26322632
@interface_required(enums.JLinkInterfaces.JTAG)
26332633
@open_required
2634-
def jtag_store_instruction(self, instr, num_bits):
2634+
def jtag_store_instruction(self, instr, ir_len):
26352635
"""Stores the specified JTAG instruction in the internal output buffer to
26362636
be written to the instruction register of the JTAG device.
26372637
@@ -2645,17 +2645,17 @@ def jtag_store_instruction(self, instr, num_bits):
26452645
Args:
26462646
self (JLink): the ``JLink`` instance.
26472647
instr (int): JTAG protocol command bits.
2648-
num_bits (int): Number of bits in the given instruction.
2648+
ir_len (int): instruction register length.
26492649
26502650
Returns:
26512651
Bit position in input buffer after instruction transmission.
26522652
"""
26532653
buf = ctypes.c_uint8(instr)
2654-
return self._dll.JLINKARM_JTAG_StoreInst(ctypes.byref(buf), num_bits)
2654+
return self._dll.JLINKARM_JTAG_StoreInst(ctypes.byref(buf), ir_len)
26552655

26562656
@interface_required(enums.JLinkInterfaces.JTAG)
26572657
@open_required
2658-
def jtag_store_data(self, data, num_bits):
2658+
def jtag_store_data(self, data, dr_len):
26592659
"""Stores the specified JTAG data in the internal output buffer to be
26602660
written to the data register of the JTAG device.
26612661
@@ -2668,16 +2668,21 @@ def jtag_store_data(self, data, num_bits):
26682668
Args:
26692669
self (JLink): the ``JLink`` instance.
26702670
data (list): list of bits to transfer.
2671-
num_bits (int): number of bits to to transfer per integer in ``data``.
2671+
dr_len (int): data register length.
26722672
26732673
Returns:
26742674
Bit position in input buffer after instruction transmission.
2675+
2676+
Raises:
2677+
TypeError: If passed data is not bytes or a list of integers.
26752678
"""
26762679
buf = data
26772680
if isinstance(buf, list):
26782681
buf = bytes(buf)
2682+
elif not any(isinstance(buf, t) for t in [bytes, bytearray]):
2683+
raise TypeError('Expected to be given bytes / list: given %s' % type(buf))
26792684

2680-
return self._dll.JLINKARM_JTAG_StoreData(buf, len(data) * num_bits)
2685+
return self._dll.JLINKARM_JTAG_StoreData(buf, len(data) * dr_len)
26812686

26822687
@interface_required(enums.JLinkInterfaces.JTAG)
26832688
@open_required
@@ -2730,7 +2735,7 @@ def jtag_read(self, offset, num_bits):
27302735
# return two integers, but that is fine, so the caller ultimately knows
27312736
# the data length they need.
27322737
buf_size = num_bits // 4
2733-
if (buf_size % 4) > 0:
2738+
if (num_bits % 4) > 0:
27342739
buf_size += 1
27352740
buf = (ctypes.c_uint8 * buf_size)()
27362741
self._dll.JLINKARM_JTAG_GetData(ctypes.byref(buf), offset, num_bits)

tests/unit/test_jlink.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,7 @@ def test_jlink_jtag_flush(self):
32973297
self.jlink.jtag_flush()
32983298
self.dll.JLINKARM_WriteBits.assert_called_once()
32993299

3300-
def test_jlijnk_jtag_store_instruction(self):
3300+
def test_jlink_jtag_store_instruction(self):
33013301
"""Tests the J-Link JTAG method for storing a JTAG instruction.
33023302
33033303
Args:
@@ -3328,7 +3328,8 @@ def test_jlink_jtag_store_data(self):
33283328
self.jlink.jtag_store_data(tdi, 5)
33293329

33303330
buf, num_bits = self.dll.JLINKARM_JTAG_StoreData.call_args[0]
3331-
self.assertEqual(10, num_bits)
3331+
expected_num_bits = len(tdi) * 5
3332+
self.assertEqual(expected_num_bits, num_bits)
33323333
self.assertEqual(b'\x0A\x03', bytearray(buf))
33333334

33343335
def test_jlink_jtag_get_device_info(self):

0 commit comments

Comments
 (0)