@@ -2629,6 +2629,196 @@ def jtag_flush(self):
26292629 """
26302630 self ._dll .JLINKARM_WriteBits ()
26312631
2632+ @interface_required (enums .JLinkInterfaces .JTAG )
2633+ @open_required
2634+ def jtag_store_instruction (self , instr , num_bits ):
2635+ """Stores the specified JTAG instruction in the internal output buffer to
2636+ be written to the instruction register of the JTAG device.
2637+
2638+ The necessary bits to place the TAP controller into the Shift-IR state
2639+ are automatically added in order to form the complete command
2640+ sequence for the given instruction.
2641+
2642+ Data in the output buffer is not flushed until TDO data is required, or
2643+ ``jtag_sync_bits()`` or ``jtag_sync_bytes()`` is called.
2644+
2645+ Args:
2646+ self (JLink): the ``JLink`` instance.
2647+ instr (int): JTAG protocol command bits.
2648+ num_bits (int): Number of bits in the given instruction.
2649+
2650+ Returns:
2651+ Bit position in input buffer after instruction transmission.
2652+ """
2653+ buf = ctypes .c_uint8 (instr )
2654+ return self ._dll .JLINKARM_JTAG_StoreInst (ctypes .byref (buf ), num_bits )
2655+
2656+ @interface_required (enums .JLinkInterfaces .JTAG )
2657+ @open_required
2658+ def jtag_store_data (self , data , num_bits ):
2659+ """Stores the specified JTAG data in the internal output buffer to be
2660+ written to the data register of the JTAG device.
2661+
2662+ The necessary bits to place the TAP controller into the Shift-DR state
2663+ are automatically added in order to form a complete data transmission.
2664+
2665+ Data in the output buffer is not flushed until TDO data is required, or
2666+ ``jtag_sync_bits()`` or ``jtag_sync_bytes()`` is called.
2667+
2668+ Args:
2669+ self (JLink): the ``JLink`` instance.
2670+ data (list): list of bits to transfer.
2671+ num_bits (int): number of bits to to transfer per integer in ``data``.
2672+
2673+ Returns:
2674+ Bit position in input buffer after instruction transmission.
2675+ """
2676+ buf = data
2677+ if isinstance (buf , list ):
2678+ buf = bytes (buf )
2679+
2680+ return self ._dll .JLINKARM_JTAG_StoreData (buf , len (data ) * num_bits )
2681+
2682+ @interface_required (enums .JLinkInterfaces .JTAG )
2683+ @open_required
2684+ def jtag_get_device_info (self , index = 0 ):
2685+ """Retrieves the JTAG related information for the JTAG device on the scan chain.
2686+
2687+ Args:
2688+ self (JLink): the ``JLink`` instance.
2689+ index (int): index of the device on the scan chain.
2690+
2691+ Returns:
2692+ A ``JLinkJTAGDeviceInfo`` describing the requested device.
2693+
2694+ Raises:
2695+ ValueError: if index is less than 0 or >= number of devices on the scan chain.
2696+ """
2697+ if index < 0 :
2698+ raise ValueError ('Invalid index provided, must be > 0.' )
2699+
2700+ info = structs .JLinkJTAGDeviceInfo ()
2701+ res = self ._dll .JLINKARM_JTAG_GetDeviceInfo (index , ctypes .byref (info ))
2702+ if res == - 1 :
2703+ raise ValueError ('Invalid index provided, no device found.' )
2704+
2705+ info .DeviceId = self ._dll .JLINKARM_JTAG_GetDeviceId (index )
2706+ return info
2707+
2708+ @interface_required (enums .JLinkInterfaces .JTAG )
2709+ @open_required
2710+ def jtag_read (self , offset , num_bits ):
2711+ """Reads the specified number of bits from the JTAG input buffer.
2712+
2713+ Note:
2714+ If there is data in the output buffer, then ``num_bits`` of data will
2715+ be transmitted.
2716+
2717+ Args:
2718+ self (JLink): the ``JLink`` instance.
2719+ offset (int): bit position within the input buffer to read from.
2720+ num_bits (int): total number of bits to read.
2721+
2722+ Returns:
2723+ List of bytes containing the TDO data. This function may return more
2724+ bytes than expected due to no context around the data size. The
2725+ caller should pull bits as appopriate starting from the first returned
2726+ byte.
2727+ """
2728+ # The smallest data length is 4 bits, so we use that as a divider. If
2729+ # the data length is actually 7 and the user specifies 7, we will
2730+ # return two integers, but that is fine, so the caller ultimately knows
2731+ # the data length they need.
2732+ buf_size = num_bits // 4
2733+ if (buf_size % 4 ) > 0 :
2734+ buf_size += 1
2735+ buf = (ctypes .c_uint8 * buf_size )()
2736+ self ._dll .JLINKARM_JTAG_GetData (ctypes .byref (buf ), offset , num_bits )
2737+ return list (buf )
2738+
2739+ @interface_required (enums .JLinkInterfaces .JTAG )
2740+ @open_required
2741+ def jtag_read8 (self , offset ):
2742+ """Reads a 8-bit integer from the JTAG input buffer.
2743+
2744+ Note:
2745+ If there is data in the output buffer, this function will force a
2746+ transmission.
2747+
2748+ Args:
2749+ self (JLink): the ``JLink`` instance.
2750+ offset (int): bit position within the input buffer to read from.
2751+
2752+ Returns:
2753+ The read 8-bit integer from the input buffer.
2754+ """
2755+ return self ._dll .JLINKARM_JTAG_GetU8 (offset )
2756+
2757+ @interface_required (enums .JLinkInterfaces .JTAG )
2758+ @open_required
2759+ def jtag_read16 (self , offset ):
2760+ """Reads a 16-bit integer from the JTAG input buffer.
2761+
2762+ Note:
2763+ If there is data in the output buffer, this function will force a
2764+ transmission.
2765+
2766+ Args:
2767+ self (JLink): the ``JLink`` instance.
2768+ offset (int): bit position within the input buffer to read from.
2769+
2770+ Returns:
2771+ The read 16-bit integer from the input buffer.
2772+ """
2773+ return self ._dll .JLINKARM_JTAG_GetU16 (offset )
2774+
2775+ @interface_required (enums .JLinkInterfaces .JTAG )
2776+ @open_required
2777+ def jtag_read32 (self , offset ):
2778+ """Reads a 32-bit integer from the JTAG input buffer.
2779+
2780+ Note:
2781+ If there is data in the output buffer, this function will force a
2782+ transmission.
2783+
2784+ Args:
2785+ self (JLink): the ``JLink`` instance.
2786+ offset (int): bit position within the input buffer to read from.
2787+
2788+ Returns:
2789+ The read 32-bit integer from the input buffer.
2790+ """
2791+ return self ._dll .JLINKARM_JTAG_GetU32 (offset )
2792+
2793+ @interface_required (enums .JLinkInterfaces .JTAG )
2794+ @open_required
2795+ def jtag_sync_bits (self ):
2796+ """Flushes the internal output buffer to the JTAG device.
2797+
2798+ Args:
2799+ self (JLink): the ``JLink`` instance.
2800+
2801+ Returns:
2802+ ``None``
2803+ """
2804+ self ._dll .JLINKARM_JTAG_SyncBits ()
2805+
2806+ @interface_required (enums .JLinkInterfaces .JTAG )
2807+ @open_required
2808+ def jtag_sync_bytes (self ):
2809+ """Flushes the data content in the internal output buffer to the JTAG device.
2810+
2811+ This function will add the necessary bits to ensure the transmitted
2812+ data is byte-aligned.
2813+
2814+ Args:
2815+ self (JLink): the ``JLink`` instance.
2816+
2817+ Returns:
2818+ ``None``
2819+ """
2820+ self ._dll .JLINKARM_JTAG_SyncBytes ()
2821+
26322822 @interface_required (enums .JLinkInterfaces .SWD )
26332823 @connection_required
26342824 def swd_read8 (self , offset ):
0 commit comments