Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-214] Add Support for Power Tracing #215

Merged
merged 3 commits into from
Jan 2, 2025

Conversation

hkpeprah
Copy link
Contributor

@hkpeprah hkpeprah commented Dec 2, 2024

[ISSUE-214] Add Support for Power Tracing

Overview

This PR adds support to PyLink for using the Power Trace API. Example usage:

import time

import pylink
import pylink.enums


if __name__ == "__main__":
    jl = pylink.JLink()
    jl.open()

    try:
        channels = jl.power_trace_get_channels()
        print(f"{channels=}")

        channel_caps = jl.power_trace_get_channel_capabilities(channels)
        print(f"{channel_caps=}")

        freq = jl.power_trace_configure(channels, channel_caps.max_sample_freq / 10, pylink.enums.JLinkPowerTraceRef.TIME, True)
        print(f"{freq=}")

        jl.power_trace_start()
        time.sleep(0.1)

        num_items = jl.power_trace_get_num_items()
        print(f"{num_items=}")

        items = jl.power_trace_read(num_items)
        print(f"{items=}")

        jl.power_trace_flush()
        jl.power_trace_stop()
    finally:
        jl.close()

Summary of Changes

  1. Updated pylink/__main__.py to handle old and new six with with_metaclass.
  2. Added power trace enums.
  3. Added power trace API methods.
  4. Added power trace structures.
  5. Updated unit tests.

This patch adds support to PyLink for using the Power Trace API.
bbrown1867
bbrown1867 previously approved these changes Dec 3, 2024
Comment on lines +5281 to +5286
if isinstance(channels, list):
channel_mask = 0x00
for channel in channels:
channel_mask |= (1 << channel)
else:
channel_mask = channels

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test the channel values are in the range of 0-7?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah. Are you thinking of filtering out the values outside of the range, or raising a ValueError? I think either could work here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking along the lines of a ValueError or just an assert.

@diggit
Copy link

diggit commented Dec 4, 2024

Hi,
I can confirm it works with my J-Link Base Compact.

My observations (not relevant to pylink):

channels=[0]
channel_caps=JLinkPowerTraceChannelCaps(SampleFreq=1000Hz, MinDiv=1)
  • 1 kHz maximum sample rate
  • 1 mA resolution, but the quantization step seems to be much larger, possibly around 12 mA (observed only values: 5, 17, 43, 56, 69, 82 - not an extensive test)

@hkpeprah hkpeprah merged commit bab857a into master Jan 2, 2025
5 checks passed
@hkpeprah hkpeprah deleted the ford/ISSUE-214/power-trace branch January 2, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants