id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
236,000
hazelcast/hazelcast-python-client
hazelcast/cluster.py
ClusterService.remove_listener
def remove_listener(self, registration_id): """ Removes the specified membership listener. :param registration_id: (str), registration id of the listener to be deleted. :return: (bool), if the registration is removed, ``false`` otherwise. """ try: self.listeners.pop(registration_id) return True except KeyError: return False
python
def remove_listener(self, registration_id): """ Removes the specified membership listener. :param registration_id: (str), registration id of the listener to be deleted. :return: (bool), if the registration is removed, ``false`` otherwise. """ try: self.listeners.pop(registration_id) return True except KeyError: return False
[ "def", "remove_listener", "(", "self", ",", "registration_id", ")", ":", "try", ":", "self", ".", "listeners", ".", "pop", "(", "registration_id", ")", "return", "True", "except", "KeyError", ":", "return", "False" ]
Removes the specified membership listener. :param registration_id: (str), registration id of the listener to be deleted. :return: (bool), if the registration is removed, ``false`` otherwise.
[ "Removes", "the", "specified", "membership", "listener", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L84-L95
236,001
hazelcast/hazelcast-python-client
hazelcast/cluster.py
ClusterService.get_member_by_uuid
def get_member_by_uuid(self, member_uuid): """ Returns the member with specified member uuid. :param member_uuid: (int), uuid of the desired member. :return: (:class:`~hazelcast.core.Member`), the corresponding member. """ for member in self.get_member_list(): if member.uuid == member_uuid: return member
python
def get_member_by_uuid(self, member_uuid): """ Returns the member with specified member uuid. :param member_uuid: (int), uuid of the desired member. :return: (:class:`~hazelcast.core.Member`), the corresponding member. """ for member in self.get_member_list(): if member.uuid == member_uuid: return member
[ "def", "get_member_by_uuid", "(", "self", ",", "member_uuid", ")", ":", "for", "member", "in", "self", ".", "get_member_list", "(", ")", ":", "if", "member", ".", "uuid", "==", "member_uuid", ":", "return", "member" ]
Returns the member with specified member uuid. :param member_uuid: (int), uuid of the desired member. :return: (:class:`~hazelcast.core.Member`), the corresponding member.
[ "Returns", "the", "member", "with", "specified", "member", "uuid", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L256-L265
236,002
hazelcast/hazelcast-python-client
hazelcast/cluster.py
ClusterService.get_members
def get_members(self, selector): """ Returns the members that satisfy the given selector. :param selector: (:class:`~hazelcast.core.MemberSelector`), Selector to be applied to the members. :return: (List), List of members. """ members = [] for member in self.get_member_list(): if selector.select(member): members.append(member) return members
python
def get_members(self, selector): """ Returns the members that satisfy the given selector. :param selector: (:class:`~hazelcast.core.MemberSelector`), Selector to be applied to the members. :return: (List), List of members. """ members = [] for member in self.get_member_list(): if selector.select(member): members.append(member) return members
[ "def", "get_members", "(", "self", ",", "selector", ")", ":", "members", "=", "[", "]", "for", "member", "in", "self", ".", "get_member_list", "(", ")", ":", "if", "selector", ".", "select", "(", "member", ")", ":", "members", ".", "append", "(", "member", ")", "return", "members" ]
Returns the members that satisfy the given selector. :param selector: (:class:`~hazelcast.core.MemberSelector`), Selector to be applied to the members. :return: (List), List of members.
[ "Returns", "the", "members", "that", "satisfy", "the", "given", "selector", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L277-L289
236,003
hazelcast/hazelcast-python-client
hazelcast/cluster.py
VectorClock.is_after
def is_after(self, other): """ Returns true if this vector clock is causally strictly after the provided vector clock. This means that it the provided clock is neither equal to, greater than or concurrent to this vector clock. :param other: (:class:`~hazelcast.cluster.VectorClock`), Vector clock to be compared :return: (bool), True if this vector clock is strictly after the other vector clock, False otherwise """ any_timestamp_greater = False for replica_id, other_timestamp in other.entry_set(): local_timestamp = self._replica_timestamps.get(replica_id) if local_timestamp is None or local_timestamp < other_timestamp: return False elif local_timestamp > other_timestamp: any_timestamp_greater = True # there is at least one local timestamp greater or local vector clock has additional timestamps return any_timestamp_greater or other.size() < self.size()
python
def is_after(self, other): """ Returns true if this vector clock is causally strictly after the provided vector clock. This means that it the provided clock is neither equal to, greater than or concurrent to this vector clock. :param other: (:class:`~hazelcast.cluster.VectorClock`), Vector clock to be compared :return: (bool), True if this vector clock is strictly after the other vector clock, False otherwise """ any_timestamp_greater = False for replica_id, other_timestamp in other.entry_set(): local_timestamp = self._replica_timestamps.get(replica_id) if local_timestamp is None or local_timestamp < other_timestamp: return False elif local_timestamp > other_timestamp: any_timestamp_greater = True # there is at least one local timestamp greater or local vector clock has additional timestamps return any_timestamp_greater or other.size() < self.size()
[ "def", "is_after", "(", "self", ",", "other", ")", ":", "any_timestamp_greater", "=", "False", "for", "replica_id", ",", "other_timestamp", "in", "other", ".", "entry_set", "(", ")", ":", "local_timestamp", "=", "self", ".", "_replica_timestamps", ".", "get", "(", "replica_id", ")", "if", "local_timestamp", "is", "None", "or", "local_timestamp", "<", "other_timestamp", ":", "return", "False", "elif", "local_timestamp", ">", "other_timestamp", ":", "any_timestamp_greater", "=", "True", "# there is at least one local timestamp greater or local vector clock has additional timestamps", "return", "any_timestamp_greater", "or", "other", ".", "size", "(", ")", "<", "self", ".", "size", "(", ")" ]
Returns true if this vector clock is causally strictly after the provided vector clock. This means that it the provided clock is neither equal to, greater than or concurrent to this vector clock. :param other: (:class:`~hazelcast.cluster.VectorClock`), Vector clock to be compared :return: (bool), True if this vector clock is strictly after the other vector clock, False otherwise
[ "Returns", "true", "if", "this", "vector", "clock", "is", "causally", "strictly", "after", "the", "provided", "vector", "clock", ".", "This", "means", "that", "it", "the", "provided", "clock", "is", "neither", "equal", "to", "greater", "than", "or", "concurrent", "to", "this", "vector", "clock", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L329-L348
236,004
hazelcast/hazelcast-python-client
hazelcast/proxy/set.py
Set.contains
def contains(self, item): """ Determines whether this set contains the specified item or not. :param item: (object), the specified item to be searched. :return: (bool), ``true`` if the specified item exists in this set, ``false`` otherwise. """ check_not_none(item, "Value can't be None") item_data = self._to_data(item) return self._encode_invoke(set_contains_codec, value=item_data)
python
def contains(self, item): """ Determines whether this set contains the specified item or not. :param item: (object), the specified item to be searched. :return: (bool), ``true`` if the specified item exists in this set, ``false`` otherwise. """ check_not_none(item, "Value can't be None") item_data = self._to_data(item) return self._encode_invoke(set_contains_codec, value=item_data)
[ "def", "contains", "(", "self", ",", "item", ")", ":", "check_not_none", "(", "item", ",", "\"Value can't be None\"", ")", "item_data", "=", "self", ".", "_to_data", "(", "item", ")", "return", "self", ".", "_encode_invoke", "(", "set_contains_codec", ",", "value", "=", "item_data", ")" ]
Determines whether this set contains the specified item or not. :param item: (object), the specified item to be searched. :return: (bool), ``true`` if the specified item exists in this set, ``false`` otherwise.
[ "Determines", "whether", "this", "set", "contains", "the", "specified", "item", "or", "not", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/set.py#L83-L92
236,005
hazelcast/hazelcast-python-client
hazelcast/proxy/set.py
Set.contains_all
def contains_all(self, items): """ Determines whether this set contains all of the items in the specified collection or not. :param items: (Collection), the specified collection which includes the items to be searched. :return: (bool), ``true`` if all of the items in the specified collection exist in this set, ``false`` otherwise. """ check_not_none(items, "Value can't be None") data_items = [] for item in items: check_not_none(item, "Value can't be None") data_items.append(self._to_data(item)) return self._encode_invoke(set_contains_all_codec, items=data_items)
python
def contains_all(self, items): """ Determines whether this set contains all of the items in the specified collection or not. :param items: (Collection), the specified collection which includes the items to be searched. :return: (bool), ``true`` if all of the items in the specified collection exist in this set, ``false`` otherwise. """ check_not_none(items, "Value can't be None") data_items = [] for item in items: check_not_none(item, "Value can't be None") data_items.append(self._to_data(item)) return self._encode_invoke(set_contains_all_codec, items=data_items)
[ "def", "contains_all", "(", "self", ",", "items", ")", ":", "check_not_none", "(", "items", ",", "\"Value can't be None\"", ")", "data_items", "=", "[", "]", "for", "item", "in", "items", ":", "check_not_none", "(", "item", ",", "\"Value can't be None\"", ")", "data_items", ".", "append", "(", "self", ".", "_to_data", "(", "item", ")", ")", "return", "self", ".", "_encode_invoke", "(", "set_contains_all_codec", ",", "items", "=", "data_items", ")" ]
Determines whether this set contains all of the items in the specified collection or not. :param items: (Collection), the specified collection which includes the items to be searched. :return: (bool), ``true`` if all of the items in the specified collection exist in this set, ``false`` otherwise.
[ "Determines", "whether", "this", "set", "contains", "all", "of", "the", "items", "in", "the", "specified", "collection", "or", "not", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/set.py#L94-L106
236,006
hazelcast/hazelcast-python-client
hazelcast/proxy/atomic_long.py
AtomicLong.alter
def alter(self, function): """ Alters the currently stored value by applying a function on it. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. """ check_not_none(function, "function can't be None") return self._encode_invoke(atomic_long_alter_codec, function=self._to_data(function))
python
def alter(self, function): """ Alters the currently stored value by applying a function on it. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. """ check_not_none(function, "function can't be None") return self._encode_invoke(atomic_long_alter_codec, function=self._to_data(function))
[ "def", "alter", "(", "self", ",", "function", ")", ":", "check_not_none", "(", "function", ",", "\"function can't be None\"", ")", "return", "self", ".", "_encode_invoke", "(", "atomic_long_alter_codec", ",", "function", "=", "self", ".", "_to_data", "(", "function", ")", ")" ]
Alters the currently stored value by applying a function on it. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation.
[ "Alters", "the", "currently", "stored", "value", "by", "applying", "a", "function", "on", "it", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/atomic_long.py#L22-L32
236,007
hazelcast/hazelcast-python-client
hazelcast/proxy/atomic_long.py
AtomicLong.alter_and_get
def alter_and_get(self, function): """ Alters the currently stored value by applying a function on it and gets the result. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. :return: (long), the new value. """ check_not_none(function, "function can't be None") return self._encode_invoke(atomic_long_alter_and_get_codec, function=self._to_data(function))
python
def alter_and_get(self, function): """ Alters the currently stored value by applying a function on it and gets the result. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. :return: (long), the new value. """ check_not_none(function, "function can't be None") return self._encode_invoke(atomic_long_alter_and_get_codec, function=self._to_data(function))
[ "def", "alter_and_get", "(", "self", ",", "function", ")", ":", "check_not_none", "(", "function", ",", "\"function can't be None\"", ")", "return", "self", ".", "_encode_invoke", "(", "atomic_long_alter_and_get_codec", ",", "function", "=", "self", ".", "_to_data", "(", "function", ")", ")" ]
Alters the currently stored value by applying a function on it and gets the result. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. :return: (long), the new value.
[ "Alters", "the", "currently", "stored", "value", "by", "applying", "a", "function", "on", "it", "and", "gets", "the", "result", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/atomic_long.py#L34-L45
236,008
hazelcast/hazelcast-python-client
hazelcast/proxy/atomic_long.py
AtomicLong.get_and_alter
def get_and_alter(self, function): """ Alters the currently stored value by applying a function on it on and gets the old value. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. :return: (long), the old value. """ check_not_none(function, "function can't be None") return self._encode_invoke(atomic_long_get_and_alter_codec, function=self._to_data(function))
python
def get_and_alter(self, function): """ Alters the currently stored value by applying a function on it on and gets the old value. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. :return: (long), the old value. """ check_not_none(function, "function can't be None") return self._encode_invoke(atomic_long_get_and_alter_codec, function=self._to_data(function))
[ "def", "get_and_alter", "(", "self", ",", "function", ")", ":", "check_not_none", "(", "function", ",", "\"function can't be None\"", ")", "return", "self", ".", "_encode_invoke", "(", "atomic_long_get_and_alter_codec", ",", "function", "=", "self", ".", "_to_data", "(", "function", ")", ")" ]
Alters the currently stored value by applying a function on it on and gets the old value. :param function: (Function), A stateful serializable object which represents the Function defined on server side. This object must have a serializable Function counter part registered on server side with the actual ``org.hazelcast.core.IFunction`` implementation. :return: (long), the old value.
[ "Alters", "the", "currently", "stored", "value", "by", "applying", "a", "function", "on", "it", "on", "and", "gets", "the", "old", "value", "." ]
3f6639443c23d6d036aa343f8e094f052250d2c1
https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/atomic_long.py#L96-L107
236,009
square/pylink
examples/core.py
main
def main(jlink_serial, device): """Prints the core's information. Args: jlink_serial (str): the J-Link serial number device (str): the target CPU Returns: Always returns ``0``. Raises: JLinkException: on error """ buf = StringIO.StringIO() jlink = pylink.JLink(log=buf.write, detailed_log=buf.write) jlink.open(serial_no=jlink_serial) # Use Serial Wire Debug as the target interface. jlink.set_tif(pylink.enums.JLinkInterfaces.SWD) jlink.connect(device, verbose=True) sys.stdout.write('ARM Id: %d\n' % jlink.core_id()) sys.stdout.write('CPU Id: %d\n' % jlink.core_cpu()) sys.stdout.write('Core Name: %s\n' % jlink.core_name()) sys.stdout.write('Device Family: %d\n' % jlink.device_family())
python
def main(jlink_serial, device): """Prints the core's information. Args: jlink_serial (str): the J-Link serial number device (str): the target CPU Returns: Always returns ``0``. Raises: JLinkException: on error """ buf = StringIO.StringIO() jlink = pylink.JLink(log=buf.write, detailed_log=buf.write) jlink.open(serial_no=jlink_serial) # Use Serial Wire Debug as the target interface. jlink.set_tif(pylink.enums.JLinkInterfaces.SWD) jlink.connect(device, verbose=True) sys.stdout.write('ARM Id: %d\n' % jlink.core_id()) sys.stdout.write('CPU Id: %d\n' % jlink.core_cpu()) sys.stdout.write('Core Name: %s\n' % jlink.core_name()) sys.stdout.write('Device Family: %d\n' % jlink.device_family())
[ "def", "main", "(", "jlink_serial", ",", "device", ")", ":", "buf", "=", "StringIO", ".", "StringIO", "(", ")", "jlink", "=", "pylink", ".", "JLink", "(", "log", "=", "buf", ".", "write", ",", "detailed_log", "=", "buf", ".", "write", ")", "jlink", ".", "open", "(", "serial_no", "=", "jlink_serial", ")", "# Use Serial Wire Debug as the target interface.", "jlink", ".", "set_tif", "(", "pylink", ".", "enums", ".", "JLinkInterfaces", ".", "SWD", ")", "jlink", ".", "connect", "(", "device", ",", "verbose", "=", "True", ")", "sys", ".", "stdout", ".", "write", "(", "'ARM Id: %d\\n'", "%", "jlink", ".", "core_id", "(", ")", ")", "sys", ".", "stdout", ".", "write", "(", "'CPU Id: %d\\n'", "%", "jlink", ".", "core_cpu", "(", ")", ")", "sys", ".", "stdout", ".", "write", "(", "'Core Name: %s\\n'", "%", "jlink", ".", "core_name", "(", ")", ")", "sys", ".", "stdout", ".", "write", "(", "'Device Family: %d\\n'", "%", "jlink", ".", "device_family", "(", ")", ")" ]
Prints the core's information. Args: jlink_serial (str): the J-Link serial number device (str): the target CPU Returns: Always returns ``0``. Raises: JLinkException: on error
[ "Prints", "the", "core", "s", "information", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/examples/core.py#L35-L59
236,010
square/pylink
pylink/jlock.py
JLock.acquire
def acquire(self): """Attempts to acquire a lock for the J-Link lockfile. If the lockfile exists but does not correspond to an active process, the lockfile is first removed, before an attempt is made to acquire it. Args: self (Jlock): the ``JLock`` instance Returns: ``True`` if the lock was acquired, otherwise ``False``. Raises: OSError: on file errors. """ if os.path.exists(self.path): try: pid = None with open(self.path, 'r') as f: line = f.readline().strip() pid = int(line) # In the case that the lockfile exists, but the pid does not # correspond to a valid process, remove the file. if not psutil.pid_exists(pid): os.remove(self.path) except ValueError as e: # Pidfile is invalid, so just delete it. os.remove(self.path) except IOError as e: # Something happened while trying to read/remove the file, so # skip trying to read/remove it. pass try: self.fd = os.open(self.path, os.O_CREAT | os.O_EXCL | os.O_RDWR) # PID is written to the file, so that if a process exits wtihout # cleaning up the lockfile, we can still acquire the lock. to_write = '%s%s' % (os.getpid(), os.linesep) os.write(self.fd, to_write.encode()) except OSError as e: if not os.path.exists(self.path): raise return False self.acquired = True return True
python
def acquire(self): """Attempts to acquire a lock for the J-Link lockfile. If the lockfile exists but does not correspond to an active process, the lockfile is first removed, before an attempt is made to acquire it. Args: self (Jlock): the ``JLock`` instance Returns: ``True`` if the lock was acquired, otherwise ``False``. Raises: OSError: on file errors. """ if os.path.exists(self.path): try: pid = None with open(self.path, 'r') as f: line = f.readline().strip() pid = int(line) # In the case that the lockfile exists, but the pid does not # correspond to a valid process, remove the file. if not psutil.pid_exists(pid): os.remove(self.path) except ValueError as e: # Pidfile is invalid, so just delete it. os.remove(self.path) except IOError as e: # Something happened while trying to read/remove the file, so # skip trying to read/remove it. pass try: self.fd = os.open(self.path, os.O_CREAT | os.O_EXCL | os.O_RDWR) # PID is written to the file, so that if a process exits wtihout # cleaning up the lockfile, we can still acquire the lock. to_write = '%s%s' % (os.getpid(), os.linesep) os.write(self.fd, to_write.encode()) except OSError as e: if not os.path.exists(self.path): raise return False self.acquired = True return True
[ "def", "acquire", "(", "self", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "self", ".", "path", ")", ":", "try", ":", "pid", "=", "None", "with", "open", "(", "self", ".", "path", ",", "'r'", ")", "as", "f", ":", "line", "=", "f", ".", "readline", "(", ")", ".", "strip", "(", ")", "pid", "=", "int", "(", "line", ")", "# In the case that the lockfile exists, but the pid does not", "# correspond to a valid process, remove the file.", "if", "not", "psutil", ".", "pid_exists", "(", "pid", ")", ":", "os", ".", "remove", "(", "self", ".", "path", ")", "except", "ValueError", "as", "e", ":", "# Pidfile is invalid, so just delete it.", "os", ".", "remove", "(", "self", ".", "path", ")", "except", "IOError", "as", "e", ":", "# Something happened while trying to read/remove the file, so", "# skip trying to read/remove it.", "pass", "try", ":", "self", ".", "fd", "=", "os", ".", "open", "(", "self", ".", "path", ",", "os", ".", "O_CREAT", "|", "os", ".", "O_EXCL", "|", "os", ".", "O_RDWR", ")", "# PID is written to the file, so that if a process exits wtihout", "# cleaning up the lockfile, we can still acquire the lock.", "to_write", "=", "'%s%s'", "%", "(", "os", ".", "getpid", "(", ")", ",", "os", ".", "linesep", ")", "os", ".", "write", "(", "self", ".", "fd", ",", "to_write", ".", "encode", "(", ")", ")", "except", "OSError", "as", "e", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "path", ")", ":", "raise", "return", "False", "self", ".", "acquired", "=", "True", "return", "True" ]
Attempts to acquire a lock for the J-Link lockfile. If the lockfile exists but does not correspond to an active process, the lockfile is first removed, before an attempt is made to acquire it. Args: self (Jlock): the ``JLock`` instance Returns: ``True`` if the lock was acquired, otherwise ``False``. Raises: OSError: on file errors.
[ "Attempts", "to", "acquire", "a", "lock", "for", "the", "J", "-", "Link", "lockfile", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlock.py#L81-L132
236,011
square/pylink
pylink/jlock.py
JLock.release
def release(self): """Cleans up the lockfile if it was acquired. Args: self (JLock): the ``JLock`` instance Returns: ``False`` if the lock was not released or the lock is not acquired, otherwise ``True``. """ if not self.acquired: return False os.close(self.fd) if os.path.exists(self.path): os.remove(self.path) self.acquired = False return True
python
def release(self): """Cleans up the lockfile if it was acquired. Args: self (JLock): the ``JLock`` instance Returns: ``False`` if the lock was not released or the lock is not acquired, otherwise ``True``. """ if not self.acquired: return False os.close(self.fd) if os.path.exists(self.path): os.remove(self.path) self.acquired = False return True
[ "def", "release", "(", "self", ")", ":", "if", "not", "self", ".", "acquired", ":", "return", "False", "os", ".", "close", "(", "self", ".", "fd", ")", "if", "os", ".", "path", ".", "exists", "(", "self", ".", "path", ")", ":", "os", ".", "remove", "(", "self", ".", "path", ")", "self", ".", "acquired", "=", "False", "return", "True" ]
Cleans up the lockfile if it was acquired. Args: self (JLock): the ``JLock`` instance Returns: ``False`` if the lock was not released or the lock is not acquired, otherwise ``True``.
[ "Cleans", "up", "the", "lockfile", "if", "it", "was", "acquired", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlock.py#L134-L153
236,012
square/pylink
pylink/util.py
calculate_parity
def calculate_parity(n): """Calculates and returns the parity of a number. The parity of a number is ``1`` if the number has an odd number of ones in its binary representation, otherwise ``0``. Args: n (int): the number whose parity to calculate Returns: ``1`` if the number has an odd number of ones, otherwise ``0``. Raises: ValueError: if ``n`` is less than ``0``. """ if not is_natural(n): raise ValueError('Expected n to be a positive integer.') y = 0 n = abs(n) while n: y += n & 1 n = n >> 1 return y & 1
python
def calculate_parity(n): """Calculates and returns the parity of a number. The parity of a number is ``1`` if the number has an odd number of ones in its binary representation, otherwise ``0``. Args: n (int): the number whose parity to calculate Returns: ``1`` if the number has an odd number of ones, otherwise ``0``. Raises: ValueError: if ``n`` is less than ``0``. """ if not is_natural(n): raise ValueError('Expected n to be a positive integer.') y = 0 n = abs(n) while n: y += n & 1 n = n >> 1 return y & 1
[ "def", "calculate_parity", "(", "n", ")", ":", "if", "not", "is_natural", "(", "n", ")", ":", "raise", "ValueError", "(", "'Expected n to be a positive integer.'", ")", "y", "=", "0", "n", "=", "abs", "(", "n", ")", "while", "n", ":", "y", "+=", "n", "&", "1", "n", "=", "n", ">>", "1", "return", "y", "&", "1" ]
Calculates and returns the parity of a number. The parity of a number is ``1`` if the number has an odd number of ones in its binary representation, otherwise ``0``. Args: n (int): the number whose parity to calculate Returns: ``1`` if the number has an odd number of ones, otherwise ``0``. Raises: ValueError: if ``n`` is less than ``0``.
[ "Calculates", "and", "returns", "the", "parity", "of", "a", "number", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/util.py#L159-L182
236,013
square/pylink
pylink/binpacker.py
pack
def pack(value, nbits=None): """Packs a given value into an array of 8-bit unsigned integers. If ``nbits`` is not present, calculates the minimal number of bits required to represent the given ``value``. The result is little endian. Args: value (int): the integer value to pack nbits (int): optional number of bits to use to represent the value Returns: An array of ``ctypes.c_uint8`` representing the packed ``value``. Raises: ValueError: if ``value < 0`` and ``nbits`` is ``None`` or ``nbits <= 0``. TypeError: if ``nbits`` or ``value`` are not numbers. """ if nbits is None: nbits = pack_size(value) * BITS_PER_BYTE elif nbits <= 0: raise ValueError('Given number of bits must be greater than 0.') buf_size = int(math.ceil(nbits / float(BITS_PER_BYTE))) buf = (ctypes.c_uint8 * buf_size)() for (idx, _) in enumerate(buf): buf[idx] = (value >> (idx * BITS_PER_BYTE)) & 0xFF return buf
python
def pack(value, nbits=None): """Packs a given value into an array of 8-bit unsigned integers. If ``nbits`` is not present, calculates the minimal number of bits required to represent the given ``value``. The result is little endian. Args: value (int): the integer value to pack nbits (int): optional number of bits to use to represent the value Returns: An array of ``ctypes.c_uint8`` representing the packed ``value``. Raises: ValueError: if ``value < 0`` and ``nbits`` is ``None`` or ``nbits <= 0``. TypeError: if ``nbits`` or ``value`` are not numbers. """ if nbits is None: nbits = pack_size(value) * BITS_PER_BYTE elif nbits <= 0: raise ValueError('Given number of bits must be greater than 0.') buf_size = int(math.ceil(nbits / float(BITS_PER_BYTE))) buf = (ctypes.c_uint8 * buf_size)() for (idx, _) in enumerate(buf): buf[idx] = (value >> (idx * BITS_PER_BYTE)) & 0xFF return buf
[ "def", "pack", "(", "value", ",", "nbits", "=", "None", ")", ":", "if", "nbits", "is", "None", ":", "nbits", "=", "pack_size", "(", "value", ")", "*", "BITS_PER_BYTE", "elif", "nbits", "<=", "0", ":", "raise", "ValueError", "(", "'Given number of bits must be greater than 0.'", ")", "buf_size", "=", "int", "(", "math", ".", "ceil", "(", "nbits", "/", "float", "(", "BITS_PER_BYTE", ")", ")", ")", "buf", "=", "(", "ctypes", ".", "c_uint8", "*", "buf_size", ")", "(", ")", "for", "(", "idx", ",", "_", ")", "in", "enumerate", "(", "buf", ")", ":", "buf", "[", "idx", "]", "=", "(", "value", ">>", "(", "idx", "*", "BITS_PER_BYTE", ")", ")", "&", "0xFF", "return", "buf" ]
Packs a given value into an array of 8-bit unsigned integers. If ``nbits`` is not present, calculates the minimal number of bits required to represent the given ``value``. The result is little endian. Args: value (int): the integer value to pack nbits (int): optional number of bits to use to represent the value Returns: An array of ``ctypes.c_uint8`` representing the packed ``value``. Raises: ValueError: if ``value < 0`` and ``nbits`` is ``None`` or ``nbits <= 0``. TypeError: if ``nbits`` or ``value`` are not numbers.
[ "Packs", "a", "given", "value", "into", "an", "array", "of", "8", "-", "bit", "unsigned", "integers", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/binpacker.py#L42-L70
236,014
square/pylink
setup.py
long_description
def long_description(): """Reads and returns the contents of the README. On failure, returns the project long description. Returns: The project's long description. """ cwd = os.path.abspath(os.path.dirname(__file__)) readme_path = os.path.join(cwd, 'README.md') if not os.path.exists(readme_path): return pylink.__long_description__ try: import pypandoc return pypandoc.convert(readme_path, 'rst') except (IOError, ImportError): pass return open(readme_path, 'r').read()
python
def long_description(): """Reads and returns the contents of the README. On failure, returns the project long description. Returns: The project's long description. """ cwd = os.path.abspath(os.path.dirname(__file__)) readme_path = os.path.join(cwd, 'README.md') if not os.path.exists(readme_path): return pylink.__long_description__ try: import pypandoc return pypandoc.convert(readme_path, 'rst') except (IOError, ImportError): pass return open(readme_path, 'r').read()
[ "def", "long_description", "(", ")", ":", "cwd", "=", "os", ".", "path", ".", "abspath", "(", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ")", "readme_path", "=", "os", ".", "path", ".", "join", "(", "cwd", ",", "'README.md'", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "readme_path", ")", ":", "return", "pylink", ".", "__long_description__", "try", ":", "import", "pypandoc", "return", "pypandoc", ".", "convert", "(", "readme_path", ",", "'rst'", ")", "except", "(", "IOError", ",", "ImportError", ")", ":", "pass", "return", "open", "(", "readme_path", ",", "'r'", ")", ".", "read", "(", ")" ]
Reads and returns the contents of the README. On failure, returns the project long description. Returns: The project's long description.
[ "Reads", "and", "returns", "the", "contents", "of", "the", "README", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/setup.py#L209-L228
236,015
square/pylink
setup.py
CleanCommand.finalize_options
def finalize_options(self): """Populate the attributes. Args: self (CleanCommand): the ``CleanCommand`` instance Returns: ``None`` """ self.cwd = os.path.abspath(os.path.dirname(__file__)) self.build_dirs = [ os.path.join(self.cwd, 'build'), os.path.join(self.cwd, 'htmlcov'), os.path.join(self.cwd, 'dist'), os.path.join(self.cwd, 'pylink_square.egg-info') ] self.build_artifacts = ['.pyc', '.o', '.elf', '.bin']
python
def finalize_options(self): """Populate the attributes. Args: self (CleanCommand): the ``CleanCommand`` instance Returns: ``None`` """ self.cwd = os.path.abspath(os.path.dirname(__file__)) self.build_dirs = [ os.path.join(self.cwd, 'build'), os.path.join(self.cwd, 'htmlcov'), os.path.join(self.cwd, 'dist'), os.path.join(self.cwd, 'pylink_square.egg-info') ] self.build_artifacts = ['.pyc', '.o', '.elf', '.bin']
[ "def", "finalize_options", "(", "self", ")", ":", "self", ".", "cwd", "=", "os", ".", "path", ".", "abspath", "(", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ")", "self", ".", "build_dirs", "=", "[", "os", ".", "path", ".", "join", "(", "self", ".", "cwd", ",", "'build'", ")", ",", "os", ".", "path", ".", "join", "(", "self", ".", "cwd", ",", "'htmlcov'", ")", ",", "os", ".", "path", ".", "join", "(", "self", ".", "cwd", ",", "'dist'", ")", ",", "os", ".", "path", ".", "join", "(", "self", ".", "cwd", ",", "'pylink_square.egg-info'", ")", "]", "self", ".", "build_artifacts", "=", "[", "'.pyc'", ",", "'.o'", ",", "'.elf'", ",", "'.bin'", "]" ]
Populate the attributes. Args: self (CleanCommand): the ``CleanCommand`` instance Returns: ``None``
[ "Populate", "the", "attributes", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/setup.py#L52-L68
236,016
square/pylink
setup.py
CoverageCommand.finalize_options
def finalize_options(self): """Finalizes the command's options. Args: self (CoverageCommand): the ``CoverageCommand`` instance Returns: ``None`` """ self.cwd = os.path.abspath(os.path.dirname(__file__)) self.test_dir = os.path.join(self.cwd, 'tests')
python
def finalize_options(self): """Finalizes the command's options. Args: self (CoverageCommand): the ``CoverageCommand`` instance Returns: ``None`` """ self.cwd = os.path.abspath(os.path.dirname(__file__)) self.test_dir = os.path.join(self.cwd, 'tests')
[ "def", "finalize_options", "(", "self", ")", ":", "self", ".", "cwd", "=", "os", ".", "path", ".", "abspath", "(", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ")", "self", ".", "test_dir", "=", "os", ".", "path", ".", "join", "(", "self", ".", "cwd", ",", "'tests'", ")" ]
Finalizes the command's options. Args: self (CoverageCommand): the ``CoverageCommand`` instance Returns: ``None``
[ "Finalizes", "the", "command", "s", "options", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/setup.py#L111-L121
236,017
square/pylink
pylink/unlockers/unlock_kinetis.py
unlock_kinetis_identified
def unlock_kinetis_identified(identity, flags): """Checks whether the given flags are a valid identity. Args: identity (Identity): the identity to validate against flags (register.IDCodeRegisterFlags): the set idcode flags Returns: ``True`` if the given ``flags`` correctly identify the the debug interface, otherwise ``False``. """ if flags.version_code != identity.version_code: return False if flags.part_no != identity.part_no: return False return flags.valid
python
def unlock_kinetis_identified(identity, flags): """Checks whether the given flags are a valid identity. Args: identity (Identity): the identity to validate against flags (register.IDCodeRegisterFlags): the set idcode flags Returns: ``True`` if the given ``flags`` correctly identify the the debug interface, otherwise ``False``. """ if flags.version_code != identity.version_code: return False if flags.part_no != identity.part_no: return False return flags.valid
[ "def", "unlock_kinetis_identified", "(", "identity", ",", "flags", ")", ":", "if", "flags", ".", "version_code", "!=", "identity", ".", "version_code", ":", "return", "False", "if", "flags", ".", "part_no", "!=", "identity", ".", "part_no", ":", "return", "False", "return", "flags", ".", "valid" ]
Checks whether the given flags are a valid identity. Args: identity (Identity): the identity to validate against flags (register.IDCodeRegisterFlags): the set idcode flags Returns: ``True`` if the given ``flags`` correctly identify the the debug interface, otherwise ``False``.
[ "Checks", "whether", "the", "given", "flags", "are", "a", "valid", "identity", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L34-L51
236,018
square/pylink
pylink/unlockers/unlock_kinetis.py
unlock_kinetis_abort_clear
def unlock_kinetis_abort_clear(): """Returns the abort register clear code. Returns: The abort register clear code. """ flags = registers.AbortRegisterFlags() flags.STKCMPCLR = 1 flags.STKERRCLR = 1 flags.WDERRCLR = 1 flags.ORUNERRCLR = 1 return flags.value
python
def unlock_kinetis_abort_clear(): """Returns the abort register clear code. Returns: The abort register clear code. """ flags = registers.AbortRegisterFlags() flags.STKCMPCLR = 1 flags.STKERRCLR = 1 flags.WDERRCLR = 1 flags.ORUNERRCLR = 1 return flags.value
[ "def", "unlock_kinetis_abort_clear", "(", ")", ":", "flags", "=", "registers", ".", "AbortRegisterFlags", "(", ")", "flags", ".", "STKCMPCLR", "=", "1", "flags", ".", "STKERRCLR", "=", "1", "flags", ".", "WDERRCLR", "=", "1", "flags", ".", "ORUNERRCLR", "=", "1", "return", "flags", ".", "value" ]
Returns the abort register clear code. Returns: The abort register clear code.
[ "Returns", "the", "abort", "register", "clear", "code", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L54-L65
236,019
square/pylink
pylink/unlockers/unlock_kinetis.py
unlock_kinetis_read_until_ack
def unlock_kinetis_read_until_ack(jlink, address): """Polls the device until the request is acknowledged. Sends a read request to the connected device to read the register at the given 'address'. Polls indefinitely until either the request is ACK'd or the request ends in a fault. Args: jlink (JLink): the connected J-Link address (int) the address of the register to poll Returns: ``SWDResponse`` object on success. Raises: KinetisException: when read exits with non-ack or non-wait status. Note: This function is required in order to avoid reading corrupt or otherwise invalid data from registers when communicating over SWD. """ request = swd.ReadRequest(address, ap=True) response = None while True: response = request.send(jlink) if response.ack(): break elif response.wait(): continue raise KinetisException('Read exited with status: %s', response.status) return response
python
def unlock_kinetis_read_until_ack(jlink, address): """Polls the device until the request is acknowledged. Sends a read request to the connected device to read the register at the given 'address'. Polls indefinitely until either the request is ACK'd or the request ends in a fault. Args: jlink (JLink): the connected J-Link address (int) the address of the register to poll Returns: ``SWDResponse`` object on success. Raises: KinetisException: when read exits with non-ack or non-wait status. Note: This function is required in order to avoid reading corrupt or otherwise invalid data from registers when communicating over SWD. """ request = swd.ReadRequest(address, ap=True) response = None while True: response = request.send(jlink) if response.ack(): break elif response.wait(): continue raise KinetisException('Read exited with status: %s', response.status) return response
[ "def", "unlock_kinetis_read_until_ack", "(", "jlink", ",", "address", ")", ":", "request", "=", "swd", ".", "ReadRequest", "(", "address", ",", "ap", "=", "True", ")", "response", "=", "None", "while", "True", ":", "response", "=", "request", ".", "send", "(", "jlink", ")", "if", "response", ".", "ack", "(", ")", ":", "break", "elif", "response", ".", "wait", "(", ")", ":", "continue", "raise", "KinetisException", "(", "'Read exited with status: %s'", ",", "response", ".", "status", ")", "return", "response" ]
Polls the device until the request is acknowledged. Sends a read request to the connected device to read the register at the given 'address'. Polls indefinitely until either the request is ACK'd or the request ends in a fault. Args: jlink (JLink): the connected J-Link address (int) the address of the register to poll Returns: ``SWDResponse`` object on success. Raises: KinetisException: when read exits with non-ack or non-wait status. Note: This function is required in order to avoid reading corrupt or otherwise invalid data from registers when communicating over SWD.
[ "Polls", "the", "device", "until", "the", "request", "is", "acknowledged", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L68-L99
236,020
square/pylink
pylink/unlockers/unlock_kinetis.py
unlock_kinetis_swd
def unlock_kinetis_swd(jlink): """Unlocks a Kinetis device over SWD. Steps Involved in Unlocking: 1. Verify that the device is configured to read/write from the CoreSight registers; this is done by reading the Identification Code Register and checking its validity. This register is always at 0x0 on reads. 2. Check for errors in the status register. If there are any errors, they must be cleared by writing to the Abort Register (this is always 0x0 on writes). 3. Turn on the device power and debug power so that the target is powered by the J-Link as more power is required during an unlock. 4. Assert the ``RESET`` pin to force the target to hold in a reset-state as to avoid interrupts and other potentially breaking behaviour. 5. At this point, SWD is configured, so send a request to clear the errors, if any, that may currently be set. 6. Our next SWD request selects the MDM-AP register so that we can start sending unlock instructions. ``SELECT[31:24] = 0x01`` selects it. 7. Poll the MDM-AP Status Register (AP[1] bank 0, register 0) until the flash ready bit is set to indicate we can flash. 8. Write to the MDM-AP Control Register (AP[1] bank 0, register 1) to request a flash mass erase. 9. Poll the system until the flash mass erase bit is acknowledged in the MDM-AP Status Register. 10. Poll the control register until it clears it's mass erase bit to indicate that it finished mass erasing, and therefore the system is now unsecure. Args: jlink (JLink): the connected J-Link Returns: ``True`` if the device was unlocked successfully, otherwise ``False``. Raises: KinetisException: when the device cannot be unlocked or fails to unlock. See Also: `NXP Forum <https://community.nxp.com/thread/317167>`_. See Also: `Kinetis Docs <nxp.com/files/32bit/doc/ref_manual/K12P48M50SF4RM.pdf>` """ SWDIdentity = Identity(0x2, 0xBA01) jlink.power_on() jlink.coresight_configure() # 1. Verify that the device is configured properly. flags = registers.IDCodeRegisterFlags() flags.value = jlink.coresight_read(0x0, False) if not unlock_kinetis_identified(SWDIdentity, flags): return False # 2. Check for errors. flags = registers.ControlStatusRegisterFlags() flags.value = jlink.coresight_read(0x01, False) if flags.STICKYORUN or flags.STICKYCMP or flags.STICKYERR or flags.WDATAERR: jlink.coresight_write(0x0, unlock_kinetis_abort_clear(), False) # 3. Turn on device power and debug. flags = registers.ControlStatusRegisterFlags() flags.value = 0 flags.CSYSPWRUPREQ = 1 # System power-up request flags.CDBGPWRUPREQ = 1 # Debug power-up request jlink.coresight_write(0x01, flags.value, False) # 4. Assert the reset pin. jlink.set_reset_pin_low() time.sleep(1) # 5. Send a SWD Request to clear any errors. request = swd.WriteRequest(0x0, False, unlock_kinetis_abort_clear()) request.send(jlink) # 6. Send a SWD Request to select the MDM-AP register, SELECT[31:24] = 0x01 request = swd.WriteRequest(0x2, False, (1 << 24)) request.send(jlink) try: # 7. Poll until the Flash-ready bit is set in the status register flags. # Have to read first to ensure the data is valid. unlock_kinetis_read_until_ack(jlink, 0x0) flags = registers.MDMAPStatusRegisterFlags() flags.flash_ready = 0 while not flags.flash_ready: flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data # 8. System may still be secure at this point, so request a mass erase. # AP[1] bank 0, register 1 is the MDM-AP Control Register. flags = registers.MDMAPControlRegisterFlags() flags.flash_mass_erase = 1 request = swd.WriteRequest(0x1, True, flags.value) request.send(jlink) # 9. Poll the status register until the mass erase command has been # accepted. unlock_kinetis_read_until_ack(jlink, 0x0) flags = registers.MDMAPStatusRegisterFlags() flags.flash_mass_erase_ack = 0 while not flags.flash_mass_erase_ack: flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data # 10. Poll the control register until the ``flash_mass_erase`` bit is # cleared, which is done automatically when the mass erase # finishes. unlock_kinetis_read_until_ack(jlink, 0x1) flags = registers.MDMAPControlRegisterFlags() flags.flash_mass_erase = 1 while flags.flash_mass_erase: flags.value = unlock_kinetis_read_until_ack(jlink, 0x1).data except KinetisException as e: jlink.set_reset_pin_high() return False jlink.set_reset_pin_high() time.sleep(1) jlink.reset() return True
python
def unlock_kinetis_swd(jlink): """Unlocks a Kinetis device over SWD. Steps Involved in Unlocking: 1. Verify that the device is configured to read/write from the CoreSight registers; this is done by reading the Identification Code Register and checking its validity. This register is always at 0x0 on reads. 2. Check for errors in the status register. If there are any errors, they must be cleared by writing to the Abort Register (this is always 0x0 on writes). 3. Turn on the device power and debug power so that the target is powered by the J-Link as more power is required during an unlock. 4. Assert the ``RESET`` pin to force the target to hold in a reset-state as to avoid interrupts and other potentially breaking behaviour. 5. At this point, SWD is configured, so send a request to clear the errors, if any, that may currently be set. 6. Our next SWD request selects the MDM-AP register so that we can start sending unlock instructions. ``SELECT[31:24] = 0x01`` selects it. 7. Poll the MDM-AP Status Register (AP[1] bank 0, register 0) until the flash ready bit is set to indicate we can flash. 8. Write to the MDM-AP Control Register (AP[1] bank 0, register 1) to request a flash mass erase. 9. Poll the system until the flash mass erase bit is acknowledged in the MDM-AP Status Register. 10. Poll the control register until it clears it's mass erase bit to indicate that it finished mass erasing, and therefore the system is now unsecure. Args: jlink (JLink): the connected J-Link Returns: ``True`` if the device was unlocked successfully, otherwise ``False``. Raises: KinetisException: when the device cannot be unlocked or fails to unlock. See Also: `NXP Forum <https://community.nxp.com/thread/317167>`_. See Also: `Kinetis Docs <nxp.com/files/32bit/doc/ref_manual/K12P48M50SF4RM.pdf>` """ SWDIdentity = Identity(0x2, 0xBA01) jlink.power_on() jlink.coresight_configure() # 1. Verify that the device is configured properly. flags = registers.IDCodeRegisterFlags() flags.value = jlink.coresight_read(0x0, False) if not unlock_kinetis_identified(SWDIdentity, flags): return False # 2. Check for errors. flags = registers.ControlStatusRegisterFlags() flags.value = jlink.coresight_read(0x01, False) if flags.STICKYORUN or flags.STICKYCMP or flags.STICKYERR or flags.WDATAERR: jlink.coresight_write(0x0, unlock_kinetis_abort_clear(), False) # 3. Turn on device power and debug. flags = registers.ControlStatusRegisterFlags() flags.value = 0 flags.CSYSPWRUPREQ = 1 # System power-up request flags.CDBGPWRUPREQ = 1 # Debug power-up request jlink.coresight_write(0x01, flags.value, False) # 4. Assert the reset pin. jlink.set_reset_pin_low() time.sleep(1) # 5. Send a SWD Request to clear any errors. request = swd.WriteRequest(0x0, False, unlock_kinetis_abort_clear()) request.send(jlink) # 6. Send a SWD Request to select the MDM-AP register, SELECT[31:24] = 0x01 request = swd.WriteRequest(0x2, False, (1 << 24)) request.send(jlink) try: # 7. Poll until the Flash-ready bit is set in the status register flags. # Have to read first to ensure the data is valid. unlock_kinetis_read_until_ack(jlink, 0x0) flags = registers.MDMAPStatusRegisterFlags() flags.flash_ready = 0 while not flags.flash_ready: flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data # 8. System may still be secure at this point, so request a mass erase. # AP[1] bank 0, register 1 is the MDM-AP Control Register. flags = registers.MDMAPControlRegisterFlags() flags.flash_mass_erase = 1 request = swd.WriteRequest(0x1, True, flags.value) request.send(jlink) # 9. Poll the status register until the mass erase command has been # accepted. unlock_kinetis_read_until_ack(jlink, 0x0) flags = registers.MDMAPStatusRegisterFlags() flags.flash_mass_erase_ack = 0 while not flags.flash_mass_erase_ack: flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data # 10. Poll the control register until the ``flash_mass_erase`` bit is # cleared, which is done automatically when the mass erase # finishes. unlock_kinetis_read_until_ack(jlink, 0x1) flags = registers.MDMAPControlRegisterFlags() flags.flash_mass_erase = 1 while flags.flash_mass_erase: flags.value = unlock_kinetis_read_until_ack(jlink, 0x1).data except KinetisException as e: jlink.set_reset_pin_high() return False jlink.set_reset_pin_high() time.sleep(1) jlink.reset() return True
[ "def", "unlock_kinetis_swd", "(", "jlink", ")", ":", "SWDIdentity", "=", "Identity", "(", "0x2", ",", "0xBA01", ")", "jlink", ".", "power_on", "(", ")", "jlink", ".", "coresight_configure", "(", ")", "# 1. Verify that the device is configured properly.", "flags", "=", "registers", ".", "IDCodeRegisterFlags", "(", ")", "flags", ".", "value", "=", "jlink", ".", "coresight_read", "(", "0x0", ",", "False", ")", "if", "not", "unlock_kinetis_identified", "(", "SWDIdentity", ",", "flags", ")", ":", "return", "False", "# 2. Check for errors.", "flags", "=", "registers", ".", "ControlStatusRegisterFlags", "(", ")", "flags", ".", "value", "=", "jlink", ".", "coresight_read", "(", "0x01", ",", "False", ")", "if", "flags", ".", "STICKYORUN", "or", "flags", ".", "STICKYCMP", "or", "flags", ".", "STICKYERR", "or", "flags", ".", "WDATAERR", ":", "jlink", ".", "coresight_write", "(", "0x0", ",", "unlock_kinetis_abort_clear", "(", ")", ",", "False", ")", "# 3. Turn on device power and debug.", "flags", "=", "registers", ".", "ControlStatusRegisterFlags", "(", ")", "flags", ".", "value", "=", "0", "flags", ".", "CSYSPWRUPREQ", "=", "1", "# System power-up request", "flags", ".", "CDBGPWRUPREQ", "=", "1", "# Debug power-up request", "jlink", ".", "coresight_write", "(", "0x01", ",", "flags", ".", "value", ",", "False", ")", "# 4. Assert the reset pin.", "jlink", ".", "set_reset_pin_low", "(", ")", "time", ".", "sleep", "(", "1", ")", "# 5. Send a SWD Request to clear any errors.", "request", "=", "swd", ".", "WriteRequest", "(", "0x0", ",", "False", ",", "unlock_kinetis_abort_clear", "(", ")", ")", "request", ".", "send", "(", "jlink", ")", "# 6. Send a SWD Request to select the MDM-AP register, SELECT[31:24] = 0x01", "request", "=", "swd", ".", "WriteRequest", "(", "0x2", ",", "False", ",", "(", "1", "<<", "24", ")", ")", "request", ".", "send", "(", "jlink", ")", "try", ":", "# 7. Poll until the Flash-ready bit is set in the status register flags.", "# Have to read first to ensure the data is valid.", "unlock_kinetis_read_until_ack", "(", "jlink", ",", "0x0", ")", "flags", "=", "registers", ".", "MDMAPStatusRegisterFlags", "(", ")", "flags", ".", "flash_ready", "=", "0", "while", "not", "flags", ".", "flash_ready", ":", "flags", ".", "value", "=", "unlock_kinetis_read_until_ack", "(", "jlink", ",", "0x0", ")", ".", "data", "# 8. System may still be secure at this point, so request a mass erase.", "# AP[1] bank 0, register 1 is the MDM-AP Control Register.", "flags", "=", "registers", ".", "MDMAPControlRegisterFlags", "(", ")", "flags", ".", "flash_mass_erase", "=", "1", "request", "=", "swd", ".", "WriteRequest", "(", "0x1", ",", "True", ",", "flags", ".", "value", ")", "request", ".", "send", "(", "jlink", ")", "# 9. Poll the status register until the mass erase command has been", "# accepted.", "unlock_kinetis_read_until_ack", "(", "jlink", ",", "0x0", ")", "flags", "=", "registers", ".", "MDMAPStatusRegisterFlags", "(", ")", "flags", ".", "flash_mass_erase_ack", "=", "0", "while", "not", "flags", ".", "flash_mass_erase_ack", ":", "flags", ".", "value", "=", "unlock_kinetis_read_until_ack", "(", "jlink", ",", "0x0", ")", ".", "data", "# 10. Poll the control register until the ``flash_mass_erase`` bit is", "# cleared, which is done automatically when the mass erase", "# finishes.", "unlock_kinetis_read_until_ack", "(", "jlink", ",", "0x1", ")", "flags", "=", "registers", ".", "MDMAPControlRegisterFlags", "(", ")", "flags", ".", "flash_mass_erase", "=", "1", "while", "flags", ".", "flash_mass_erase", ":", "flags", ".", "value", "=", "unlock_kinetis_read_until_ack", "(", "jlink", ",", "0x1", ")", ".", "data", "except", "KinetisException", "as", "e", ":", "jlink", ".", "set_reset_pin_high", "(", ")", "return", "False", "jlink", ".", "set_reset_pin_high", "(", ")", "time", ".", "sleep", "(", "1", ")", "jlink", ".", "reset", "(", ")", "return", "True" ]
Unlocks a Kinetis device over SWD. Steps Involved in Unlocking: 1. Verify that the device is configured to read/write from the CoreSight registers; this is done by reading the Identification Code Register and checking its validity. This register is always at 0x0 on reads. 2. Check for errors in the status register. If there are any errors, they must be cleared by writing to the Abort Register (this is always 0x0 on writes). 3. Turn on the device power and debug power so that the target is powered by the J-Link as more power is required during an unlock. 4. Assert the ``RESET`` pin to force the target to hold in a reset-state as to avoid interrupts and other potentially breaking behaviour. 5. At this point, SWD is configured, so send a request to clear the errors, if any, that may currently be set. 6. Our next SWD request selects the MDM-AP register so that we can start sending unlock instructions. ``SELECT[31:24] = 0x01`` selects it. 7. Poll the MDM-AP Status Register (AP[1] bank 0, register 0) until the flash ready bit is set to indicate we can flash. 8. Write to the MDM-AP Control Register (AP[1] bank 0, register 1) to request a flash mass erase. 9. Poll the system until the flash mass erase bit is acknowledged in the MDM-AP Status Register. 10. Poll the control register until it clears it's mass erase bit to indicate that it finished mass erasing, and therefore the system is now unsecure. Args: jlink (JLink): the connected J-Link Returns: ``True`` if the device was unlocked successfully, otherwise ``False``. Raises: KinetisException: when the device cannot be unlocked or fails to unlock. See Also: `NXP Forum <https://community.nxp.com/thread/317167>`_. See Also: `Kinetis Docs <nxp.com/files/32bit/doc/ref_manual/K12P48M50SF4RM.pdf>`
[ "Unlocks", "a", "Kinetis", "device", "over", "SWD", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L102-L222
236,021
square/pylink
pylink/unlockers/unlock_kinetis.py
unlock_kinetis
def unlock_kinetis(jlink): """Unlock for Freescale Kinetis K40 or K60 device. Args: jlink (JLink): an instance of a J-Link that is connected to a target. Returns: ``True`` if the device was successfully unlocked, otherwise ``False``. Raises: ValueError: if the J-Link is not connected to a target. """ if not jlink.connected(): raise ValueError('No target to unlock.') method = UNLOCK_METHODS.get(jlink.tif, None) if method is None: raise NotImplementedError('Unsupported target interface for unlock.') return method(jlink)
python
def unlock_kinetis(jlink): """Unlock for Freescale Kinetis K40 or K60 device. Args: jlink (JLink): an instance of a J-Link that is connected to a target. Returns: ``True`` if the device was successfully unlocked, otherwise ``False``. Raises: ValueError: if the J-Link is not connected to a target. """ if not jlink.connected(): raise ValueError('No target to unlock.') method = UNLOCK_METHODS.get(jlink.tif, None) if method is None: raise NotImplementedError('Unsupported target interface for unlock.') return method(jlink)
[ "def", "unlock_kinetis", "(", "jlink", ")", ":", "if", "not", "jlink", ".", "connected", "(", ")", ":", "raise", "ValueError", "(", "'No target to unlock.'", ")", "method", "=", "UNLOCK_METHODS", ".", "get", "(", "jlink", ".", "tif", ",", "None", ")", "if", "method", "is", "None", ":", "raise", "NotImplementedError", "(", "'Unsupported target interface for unlock.'", ")", "return", "method", "(", "jlink", ")" ]
Unlock for Freescale Kinetis K40 or K60 device. Args: jlink (JLink): an instance of a J-Link that is connected to a target. Returns: ``True`` if the device was successfully unlocked, otherwise ``False``. Raises: ValueError: if the J-Link is not connected to a target.
[ "Unlock", "for", "Freescale", "Kinetis", "K40", "or", "K60", "device", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L251-L270
236,022
square/pylink
pylink/jlink.py
JLink.minimum_required
def minimum_required(version): """Decorator to specify the minimum SDK version required. Args: version (str): valid version string Returns: A decorator function. """ def _minimum_required(func): """Internal decorator that wraps around the given function. Args: func (function): function being decorated Returns: The wrapper unction. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to compare the DLL's SDK version. Args: self (JLink): the ``JLink`` instance args (list): list of arguments to pass to ``func`` kwargs (dict): key-word arguments dict to pass to ``func`` Returns: The return value of the wrapped function. Raises: JLinkException: if the DLL's version is less than ``version``. """ if list(self.version) < list(version): raise errors.JLinkException('Version %s required.' % version) return func(self, *args, **kwargs) return wrapper return _minimum_required
python
def minimum_required(version): """Decorator to specify the minimum SDK version required. Args: version (str): valid version string Returns: A decorator function. """ def _minimum_required(func): """Internal decorator that wraps around the given function. Args: func (function): function being decorated Returns: The wrapper unction. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to compare the DLL's SDK version. Args: self (JLink): the ``JLink`` instance args (list): list of arguments to pass to ``func`` kwargs (dict): key-word arguments dict to pass to ``func`` Returns: The return value of the wrapped function. Raises: JLinkException: if the DLL's version is less than ``version``. """ if list(self.version) < list(version): raise errors.JLinkException('Version %s required.' % version) return func(self, *args, **kwargs) return wrapper return _minimum_required
[ "def", "minimum_required", "(", "version", ")", ":", "def", "_minimum_required", "(", "func", ")", ":", "\"\"\"Internal decorator that wraps around the given function.\n\n Args:\n func (function): function being decorated\n\n Returns:\n The wrapper unction.\n \"\"\"", "@", "functools", ".", "wraps", "(", "func", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Wrapper function to compare the DLL's SDK version.\n\n Args:\n self (JLink): the ``JLink`` instance\n args (list): list of arguments to pass to ``func``\n kwargs (dict): key-word arguments dict to pass to ``func``\n\n Returns:\n The return value of the wrapped function.\n\n Raises:\n JLinkException: if the DLL's version is less than ``version``.\n \"\"\"", "if", "list", "(", "self", ".", "version", ")", "<", "list", "(", "version", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'Version %s required.'", "%", "version", ")", "return", "func", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "return", "wrapper", "return", "_minimum_required" ]
Decorator to specify the minimum SDK version required. Args: version (str): valid version string Returns: A decorator function.
[ "Decorator", "to", "specify", "the", "minimum", "SDK", "version", "required", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L71-L108
236,023
square/pylink
pylink/jlink.py
JLink.open_required
def open_required(func): """Decorator to specify that the J-Link DLL must be opened, and a J-Link connection must be established. Args: func (function): function being decorated Returns: The wrapper function. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to check that the given ``JLink`` has been opened. Args: self (JLink): the ``JLink`` instance args: list of arguments to pass to the wrapped function kwargs: key-word arguments dict to pass to the wrapped function Returns: The return value of the wrapped function. Raises: JLinkException: if the J-Link DLL is not open or the J-Link is disconnected. """ if not self.opened(): raise errors.JLinkException('J-Link DLL is not open.') elif not self.connected(): raise errors.JLinkException('J-Link connection has been lost.') return func(self, *args, **kwargs) return wrapper
python
def open_required(func): """Decorator to specify that the J-Link DLL must be opened, and a J-Link connection must be established. Args: func (function): function being decorated Returns: The wrapper function. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to check that the given ``JLink`` has been opened. Args: self (JLink): the ``JLink`` instance args: list of arguments to pass to the wrapped function kwargs: key-word arguments dict to pass to the wrapped function Returns: The return value of the wrapped function. Raises: JLinkException: if the J-Link DLL is not open or the J-Link is disconnected. """ if not self.opened(): raise errors.JLinkException('J-Link DLL is not open.') elif not self.connected(): raise errors.JLinkException('J-Link connection has been lost.') return func(self, *args, **kwargs) return wrapper
[ "def", "open_required", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Wrapper function to check that the given ``JLink`` has been\n opened.\n\n Args:\n self (JLink): the ``JLink`` instance\n args: list of arguments to pass to the wrapped function\n kwargs: key-word arguments dict to pass to the wrapped function\n\n Returns:\n The return value of the wrapped function.\n\n Raises:\n JLinkException: if the J-Link DLL is not open or the J-Link is\n disconnected.\n \"\"\"", "if", "not", "self", ".", "opened", "(", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'J-Link DLL is not open.'", ")", "elif", "not", "self", ".", "connected", "(", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'J-Link connection has been lost.'", ")", "return", "func", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "return", "wrapper" ]
Decorator to specify that the J-Link DLL must be opened, and a J-Link connection must be established. Args: func (function): function being decorated Returns: The wrapper function.
[ "Decorator", "to", "specify", "that", "the", "J", "-", "Link", "DLL", "must", "be", "opened", "and", "a", "J", "-", "Link", "connection", "must", "be", "established", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L110-L142
236,024
square/pylink
pylink/jlink.py
JLink.connection_required
def connection_required(func): """Decorator to specify that a target connection is required in order for the given method to be used. Args: func (function): function being decorated Returns: The wrapper function. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to check that the given ``JLink`` has been connected to a target. Args: self (JLink): the ``JLink`` instance args: list of arguments to pass to the wrapped function kwargs: key-word arguments dict to pass to the wrapped function Returns: The return value of the wrapped function. Raises: JLinkException: if the JLink's target is not connected. """ if not self.target_connected(): raise errors.JLinkException('Target is not connected.') return func(self, *args, **kwargs) return wrapper
python
def connection_required(func): """Decorator to specify that a target connection is required in order for the given method to be used. Args: func (function): function being decorated Returns: The wrapper function. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to check that the given ``JLink`` has been connected to a target. Args: self (JLink): the ``JLink`` instance args: list of arguments to pass to the wrapped function kwargs: key-word arguments dict to pass to the wrapped function Returns: The return value of the wrapped function. Raises: JLinkException: if the JLink's target is not connected. """ if not self.target_connected(): raise errors.JLinkException('Target is not connected.') return func(self, *args, **kwargs) return wrapper
[ "def", "connection_required", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Wrapper function to check that the given ``JLink`` has been\n connected to a target.\n\n Args:\n self (JLink): the ``JLink`` instance\n args: list of arguments to pass to the wrapped function\n kwargs: key-word arguments dict to pass to the wrapped function\n\n Returns:\n The return value of the wrapped function.\n\n Raises:\n JLinkException: if the JLink's target is not connected.\n \"\"\"", "if", "not", "self", ".", "target_connected", "(", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'Target is not connected.'", ")", "return", "func", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "return", "wrapper" ]
Decorator to specify that a target connection is required in order for the given method to be used. Args: func (function): function being decorated Returns: The wrapper function.
[ "Decorator", "to", "specify", "that", "a", "target", "connection", "is", "required", "in", "order", "for", "the", "given", "method", "to", "be", "used", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L144-L173
236,025
square/pylink
pylink/jlink.py
JLink.interface_required
def interface_required(interface): """Decorator to specify that a particular interface type is required for the given method to be used. Args: interface (int): attribute of ``JLinkInterfaces`` Returns: A decorator function. """ def _interface_required(func): """Internal decorator that wraps around the decorated function. Args: func (function): function being decorated Returns: The wrapper function. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to check that the given ``JLink`` has the same interface as the one specified by the decorator. Args: self (JLink): the ``JLink`` instance args: list of arguments to pass to ``func`` kwargs: key-word arguments dict to pass to ``func`` Returns: The return value of the wrapped function. Raises: JLinkException: if the current interface is not supported by the wrapped method. """ if self.tif != interface: raise errors.JLinkException('Unsupported for current interface.') return func(self, *args, **kwargs) return wrapper return _interface_required
python
def interface_required(interface): """Decorator to specify that a particular interface type is required for the given method to be used. Args: interface (int): attribute of ``JLinkInterfaces`` Returns: A decorator function. """ def _interface_required(func): """Internal decorator that wraps around the decorated function. Args: func (function): function being decorated Returns: The wrapper function. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): """Wrapper function to check that the given ``JLink`` has the same interface as the one specified by the decorator. Args: self (JLink): the ``JLink`` instance args: list of arguments to pass to ``func`` kwargs: key-word arguments dict to pass to ``func`` Returns: The return value of the wrapped function. Raises: JLinkException: if the current interface is not supported by the wrapped method. """ if self.tif != interface: raise errors.JLinkException('Unsupported for current interface.') return func(self, *args, **kwargs) return wrapper return _interface_required
[ "def", "interface_required", "(", "interface", ")", ":", "def", "_interface_required", "(", "func", ")", ":", "\"\"\"Internal decorator that wraps around the decorated function.\n\n Args:\n func (function): function being decorated\n\n Returns:\n The wrapper function.\n \"\"\"", "@", "functools", ".", "wraps", "(", "func", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Wrapper function to check that the given ``JLink`` has the\n same interface as the one specified by the decorator.\n\n Args:\n self (JLink): the ``JLink`` instance\n args: list of arguments to pass to ``func``\n kwargs: key-word arguments dict to pass to ``func``\n\n Returns:\n The return value of the wrapped function.\n\n Raises:\n JLinkException: if the current interface is not supported by\n the wrapped method.\n \"\"\"", "if", "self", ".", "tif", "!=", "interface", ":", "raise", "errors", ".", "JLinkException", "(", "'Unsupported for current interface.'", ")", "return", "func", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "return", "wrapper", "return", "_interface_required" ]
Decorator to specify that a particular interface type is required for the given method to be used. Args: interface (int): attribute of ``JLinkInterfaces`` Returns: A decorator function.
[ "Decorator", "to", "specify", "that", "a", "particular", "interface", "type", "is", "required", "for", "the", "given", "method", "to", "be", "used", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L175-L215
236,026
square/pylink
pylink/jlink.py
JLink.log_handler
def log_handler(self, handler): """Setter for the log handler function. Args: self (JLink): the ``JLink`` instance Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_EnableLog(self._log_handler)
python
def log_handler(self, handler): """Setter for the log handler function. Args: self (JLink): the ``JLink`` instance Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_EnableLog(self._log_handler)
[ "def", "log_handler", "(", "self", ",", "handler", ")", ":", "if", "not", "self", ".", "opened", "(", ")", ":", "handler", "=", "handler", "or", "util", ".", "noop", "self", ".", "_log_handler", "=", "enums", ".", "JLinkFunctions", ".", "LOG_PROTOTYPE", "(", "handler", ")", "self", ".", "_dll", ".", "JLINKARM_EnableLog", "(", "self", ".", "_log_handler", ")" ]
Setter for the log handler function. Args: self (JLink): the ``JLink`` instance Returns: ``None``
[ "Setter", "for", "the", "log", "handler", "function", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L343-L355
236,027
square/pylink
pylink/jlink.py
JLink.detailed_log_handler
def detailed_log_handler(self, handler): """Setter for the detailed log handler function. Args: self (JLink): the ``JLink`` instance Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._detailed_log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_EnableLogCom(self._detailed_log_handler)
python
def detailed_log_handler(self, handler): """Setter for the detailed log handler function. Args: self (JLink): the ``JLink`` instance Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._detailed_log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_EnableLogCom(self._detailed_log_handler)
[ "def", "detailed_log_handler", "(", "self", ",", "handler", ")", ":", "if", "not", "self", ".", "opened", "(", ")", ":", "handler", "=", "handler", "or", "util", ".", "noop", "self", ".", "_detailed_log_handler", "=", "enums", ".", "JLinkFunctions", ".", "LOG_PROTOTYPE", "(", "handler", ")", "self", ".", "_dll", ".", "JLINKARM_EnableLogCom", "(", "self", ".", "_detailed_log_handler", ")" ]
Setter for the detailed log handler function. Args: self (JLink): the ``JLink`` instance Returns: ``None``
[ "Setter", "for", "the", "detailed", "log", "handler", "function", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L371-L383
236,028
square/pylink
pylink/jlink.py
JLink.error_handler
def error_handler(self, handler): """Setter for the error handler function. If the DLL is open, this function is a no-op, so it should be called prior to calling ``open()``. Args: self (JLink): the ``JLink`` instance handler (function): function to call on error messages Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._error_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_SetErrorOutHandler(self._error_handler)
python
def error_handler(self, handler): """Setter for the error handler function. If the DLL is open, this function is a no-op, so it should be called prior to calling ``open()``. Args: self (JLink): the ``JLink`` instance handler (function): function to call on error messages Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._error_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_SetErrorOutHandler(self._error_handler)
[ "def", "error_handler", "(", "self", ",", "handler", ")", ":", "if", "not", "self", ".", "opened", "(", ")", ":", "handler", "=", "handler", "or", "util", ".", "noop", "self", ".", "_error_handler", "=", "enums", ".", "JLinkFunctions", ".", "LOG_PROTOTYPE", "(", "handler", ")", "self", ".", "_dll", ".", "JLINKARM_SetErrorOutHandler", "(", "self", ".", "_error_handler", ")" ]
Setter for the error handler function. If the DLL is open, this function is a no-op, so it should be called prior to calling ``open()``. Args: self (JLink): the ``JLink`` instance handler (function): function to call on error messages Returns: ``None``
[ "Setter", "for", "the", "error", "handler", "function", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L399-L415
236,029
square/pylink
pylink/jlink.py
JLink.warning_handler
def warning_handler(self, handler): """Setter for the warning handler function. If the DLL is open, this function is a no-op, so it should be called prior to calling ``open()``. Args: self (JLink): the ``JLink`` instance handler (function): function to call on warning messages Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._warning_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_SetWarnOutHandler(self._warning_handler)
python
def warning_handler(self, handler): """Setter for the warning handler function. If the DLL is open, this function is a no-op, so it should be called prior to calling ``open()``. Args: self (JLink): the ``JLink`` instance handler (function): function to call on warning messages Returns: ``None`` """ if not self.opened(): handler = handler or util.noop self._warning_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler) self._dll.JLINKARM_SetWarnOutHandler(self._warning_handler)
[ "def", "warning_handler", "(", "self", ",", "handler", ")", ":", "if", "not", "self", ".", "opened", "(", ")", ":", "handler", "=", "handler", "or", "util", ".", "noop", "self", ".", "_warning_handler", "=", "enums", ".", "JLinkFunctions", ".", "LOG_PROTOTYPE", "(", "handler", ")", "self", ".", "_dll", ".", "JLINKARM_SetWarnOutHandler", "(", "self", ".", "_warning_handler", ")" ]
Setter for the warning handler function. If the DLL is open, this function is a no-op, so it should be called prior to calling ``open()``. Args: self (JLink): the ``JLink`` instance handler (function): function to call on warning messages Returns: ``None``
[ "Setter", "for", "the", "warning", "handler", "function", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L431-L447
236,030
square/pylink
pylink/jlink.py
JLink.connected_emulators
def connected_emulators(self, host=enums.JLinkHost.USB): """Returns a list of all the connected emulators. Args: self (JLink): the ``JLink`` instance host (int): host type to search (default: ``JLinkHost.USB``) Returns: List of ``JLinkConnectInfo`` specifying the connected emulators. Raises: JLinkException: if fails to enumerate devices. """ res = self._dll.JLINKARM_EMU_GetList(host, 0, 0) if res < 0: raise errors.JLinkException(res) num_devices = res info = (structs.JLinkConnectInfo * num_devices)() num_found = self._dll.JLINKARM_EMU_GetList(host, info, num_devices) if num_found < 0: raise errors.JLinkException(num_found) return list(info)[:num_found]
python
def connected_emulators(self, host=enums.JLinkHost.USB): """Returns a list of all the connected emulators. Args: self (JLink): the ``JLink`` instance host (int): host type to search (default: ``JLinkHost.USB``) Returns: List of ``JLinkConnectInfo`` specifying the connected emulators. Raises: JLinkException: if fails to enumerate devices. """ res = self._dll.JLINKARM_EMU_GetList(host, 0, 0) if res < 0: raise errors.JLinkException(res) num_devices = res info = (structs.JLinkConnectInfo * num_devices)() num_found = self._dll.JLINKARM_EMU_GetList(host, info, num_devices) if num_found < 0: raise errors.JLinkException(num_found) return list(info)[:num_found]
[ "def", "connected_emulators", "(", "self", ",", "host", "=", "enums", ".", "JLinkHost", ".", "USB", ")", ":", "res", "=", "self", ".", "_dll", ".", "JLINKARM_EMU_GetList", "(", "host", ",", "0", ",", "0", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "num_devices", "=", "res", "info", "=", "(", "structs", ".", "JLinkConnectInfo", "*", "num_devices", ")", "(", ")", "num_found", "=", "self", ".", "_dll", ".", "JLINKARM_EMU_GetList", "(", "host", ",", "info", ",", "num_devices", ")", "if", "num_found", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "num_found", ")", "return", "list", "(", "info", ")", "[", ":", "num_found", "]" ]
Returns a list of all the connected emulators. Args: self (JLink): the ``JLink`` instance host (int): host type to search (default: ``JLinkHost.USB``) Returns: List of ``JLinkConnectInfo`` specifying the connected emulators. Raises: JLinkException: if fails to enumerate devices.
[ "Returns", "a", "list", "of", "all", "the", "connected", "emulators", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L461-L484
236,031
square/pylink
pylink/jlink.py
JLink.supported_device
def supported_device(self, index=0): """Gets the device at the given ``index``. Args: self (JLink): the ``JLink`` instance index (int): the index of the device whose information to get Returns: A ``JLinkDeviceInfo`` describing the requested device. Raises: ValueError: if index is less than 0 or >= supported device count. """ if not util.is_natural(index) or index >= self.num_supported_devices(): raise ValueError('Invalid index.') info = structs.JLinkDeviceInfo() result = self._dll.JLINKARM_DEVICE_GetInfo(index, ctypes.byref(info)) return info
python
def supported_device(self, index=0): """Gets the device at the given ``index``. Args: self (JLink): the ``JLink`` instance index (int): the index of the device whose information to get Returns: A ``JLinkDeviceInfo`` describing the requested device. Raises: ValueError: if index is less than 0 or >= supported device count. """ if not util.is_natural(index) or index >= self.num_supported_devices(): raise ValueError('Invalid index.') info = structs.JLinkDeviceInfo() result = self._dll.JLINKARM_DEVICE_GetInfo(index, ctypes.byref(info)) return info
[ "def", "supported_device", "(", "self", ",", "index", "=", "0", ")", ":", "if", "not", "util", ".", "is_natural", "(", "index", ")", "or", "index", ">=", "self", ".", "num_supported_devices", "(", ")", ":", "raise", "ValueError", "(", "'Invalid index.'", ")", "info", "=", "structs", ".", "JLinkDeviceInfo", "(", ")", "result", "=", "self", ".", "_dll", ".", "JLINKARM_DEVICE_GetInfo", "(", "index", ",", "ctypes", ".", "byref", "(", "info", ")", ")", "return", "info" ]
Gets the device at the given ``index``. Args: self (JLink): the ``JLink`` instance index (int): the index of the device whose information to get Returns: A ``JLinkDeviceInfo`` describing the requested device. Raises: ValueError: if index is less than 0 or >= supported device count.
[ "Gets", "the", "device", "at", "the", "given", "index", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L498-L517
236,032
square/pylink
pylink/jlink.py
JLink.close
def close(self): """Closes the open J-Link. Args: self (JLink): the ``JLink`` instance Returns: ``None`` Raises: JLinkException: if there is no connected JLink. """ self._dll.JLINKARM_Close() if self._lock is not None: del self._lock self._lock = None return None
python
def close(self): """Closes the open J-Link. Args: self (JLink): the ``JLink`` instance Returns: ``None`` Raises: JLinkException: if there is no connected JLink. """ self._dll.JLINKARM_Close() if self._lock is not None: del self._lock self._lock = None return None
[ "def", "close", "(", "self", ")", ":", "self", ".", "_dll", ".", "JLINKARM_Close", "(", ")", "if", "self", ".", "_lock", "is", "not", "None", ":", "del", "self", ".", "_lock", "self", ".", "_lock", "=", "None", "return", "None" ]
Closes the open J-Link. Args: self (JLink): the ``JLink`` instance Returns: ``None`` Raises: JLinkException: if there is no connected JLink.
[ "Closes", "the", "open", "J", "-", "Link", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L606-L624
236,033
square/pylink
pylink/jlink.py
JLink.sync_firmware
def sync_firmware(self): """Syncs the emulator's firmware version and the DLL's firmware. This method is useful for ensuring that the firmware running on the J-Link matches the firmware supported by the DLL. Args: self (JLink): the ``JLink`` instance Returns: ``None`` """ serial_no = self.serial_number if self.firmware_newer(): # The J-Link's firmware is newer than the one compatible with the # DLL (though there are promises of backwards compatibility), so # perform a downgrade. try: # This may throw an exception on older versions of the J-Link # software due to the software timing out after a firmware # upgrade. self.invalidate_firmware() self.update_firmware() except errors.JLinkException as e: pass res = self.open(serial_no=serial_no) if self.firmware_newer(): raise errors.JLinkException('Failed to sync firmware version.') return res elif self.firmware_outdated(): # The J-Link's firmware is older than the one compatible with the # DLL, so perform a firmware upgrade. try: # This may throw an exception on older versions of the J-Link # software due to the software timing out after a firmware # upgrade. self.update_firmware() except errors.JLinkException as e: pass if self.firmware_outdated(): raise errors.JLinkException('Failed to sync firmware version.') return self.open(serial_no=serial_no) return None
python
def sync_firmware(self): """Syncs the emulator's firmware version and the DLL's firmware. This method is useful for ensuring that the firmware running on the J-Link matches the firmware supported by the DLL. Args: self (JLink): the ``JLink`` instance Returns: ``None`` """ serial_no = self.serial_number if self.firmware_newer(): # The J-Link's firmware is newer than the one compatible with the # DLL (though there are promises of backwards compatibility), so # perform a downgrade. try: # This may throw an exception on older versions of the J-Link # software due to the software timing out after a firmware # upgrade. self.invalidate_firmware() self.update_firmware() except errors.JLinkException as e: pass res = self.open(serial_no=serial_no) if self.firmware_newer(): raise errors.JLinkException('Failed to sync firmware version.') return res elif self.firmware_outdated(): # The J-Link's firmware is older than the one compatible with the # DLL, so perform a firmware upgrade. try: # This may throw an exception on older versions of the J-Link # software due to the software timing out after a firmware # upgrade. self.update_firmware() except errors.JLinkException as e: pass if self.firmware_outdated(): raise errors.JLinkException('Failed to sync firmware version.') return self.open(serial_no=serial_no) return None
[ "def", "sync_firmware", "(", "self", ")", ":", "serial_no", "=", "self", ".", "serial_number", "if", "self", ".", "firmware_newer", "(", ")", ":", "# The J-Link's firmware is newer than the one compatible with the", "# DLL (though there are promises of backwards compatibility), so", "# perform a downgrade.", "try", ":", "# This may throw an exception on older versions of the J-Link", "# software due to the software timing out after a firmware", "# upgrade.", "self", ".", "invalidate_firmware", "(", ")", "self", ".", "update_firmware", "(", ")", "except", "errors", ".", "JLinkException", "as", "e", ":", "pass", "res", "=", "self", ".", "open", "(", "serial_no", "=", "serial_no", ")", "if", "self", ".", "firmware_newer", "(", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'Failed to sync firmware version.'", ")", "return", "res", "elif", "self", ".", "firmware_outdated", "(", ")", ":", "# The J-Link's firmware is older than the one compatible with the", "# DLL, so perform a firmware upgrade.", "try", ":", "# This may throw an exception on older versions of the J-Link", "# software due to the software timing out after a firmware", "# upgrade.", "self", ".", "update_firmware", "(", ")", "except", "errors", ".", "JLinkException", "as", "e", ":", "pass", "if", "self", ".", "firmware_outdated", "(", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'Failed to sync firmware version.'", ")", "return", "self", ".", "open", "(", "serial_no", "=", "serial_no", ")", "return", "None" ]
Syncs the emulator's firmware version and the DLL's firmware. This method is useful for ensuring that the firmware running on the J-Link matches the firmware supported by the DLL. Args: self (JLink): the ``JLink`` instance Returns: ``None``
[ "Syncs", "the", "emulator", "s", "firmware", "version", "and", "the", "DLL", "s", "firmware", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L676-L726
236,034
square/pylink
pylink/jlink.py
JLink.exec_command
def exec_command(self, cmd): """Executes the given command. This method executes a command by calling the DLL's exec method. Direct API methods should be prioritized over calling this method. Args: self (JLink): the ``JLink`` instance cmd (str): the command to run Returns: The return code of running the command. Raises: JLinkException: if the command is invalid or fails. See Also: For a full list of the supported commands, please see the SEGGER J-Link documentation, `UM08001 <https://www.segger.com/downloads/jlink>`__. """ err_buf = (ctypes.c_char * self.MAX_BUF_SIZE)() res = self._dll.JLINKARM_ExecCommand(cmd.encode(), err_buf, self.MAX_BUF_SIZE) err_buf = ctypes.string_at(err_buf).decode() if len(err_buf) > 0: # This is how they check for error in the documentation, so check # this way as well. raise errors.JLinkException(err_buf.strip()) return res
python
def exec_command(self, cmd): """Executes the given command. This method executes a command by calling the DLL's exec method. Direct API methods should be prioritized over calling this method. Args: self (JLink): the ``JLink`` instance cmd (str): the command to run Returns: The return code of running the command. Raises: JLinkException: if the command is invalid or fails. See Also: For a full list of the supported commands, please see the SEGGER J-Link documentation, `UM08001 <https://www.segger.com/downloads/jlink>`__. """ err_buf = (ctypes.c_char * self.MAX_BUF_SIZE)() res = self._dll.JLINKARM_ExecCommand(cmd.encode(), err_buf, self.MAX_BUF_SIZE) err_buf = ctypes.string_at(err_buf).decode() if len(err_buf) > 0: # This is how they check for error in the documentation, so check # this way as well. raise errors.JLinkException(err_buf.strip()) return res
[ "def", "exec_command", "(", "self", ",", "cmd", ")", ":", "err_buf", "=", "(", "ctypes", ".", "c_char", "*", "self", ".", "MAX_BUF_SIZE", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_ExecCommand", "(", "cmd", ".", "encode", "(", ")", ",", "err_buf", ",", "self", ".", "MAX_BUF_SIZE", ")", "err_buf", "=", "ctypes", ".", "string_at", "(", "err_buf", ")", ".", "decode", "(", ")", "if", "len", "(", "err_buf", ")", ">", "0", ":", "# This is how they check for error in the documentation, so check", "# this way as well.", "raise", "errors", ".", "JLinkException", "(", "err_buf", ".", "strip", "(", ")", ")", "return", "res" ]
Executes the given command. This method executes a command by calling the DLL's exec method. Direct API methods should be prioritized over calling this method. Args: self (JLink): the ``JLink`` instance cmd (str): the command to run Returns: The return code of running the command. Raises: JLinkException: if the command is invalid or fails. See Also: For a full list of the supported commands, please see the SEGGER J-Link documentation, `UM08001 <https://www.segger.com/downloads/jlink>`__.
[ "Executes", "the", "given", "command", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L728-L758
236,035
square/pylink
pylink/jlink.py
JLink.jtag_configure
def jtag_configure(self, instr_regs=0, data_bits=0): """Configures the JTAG scan chain to determine which CPU to address. Must be called if the J-Link is connected to a JTAG scan chain with multiple devices. Args: self (JLink): the ``JLink`` instance instr_regs (int): length of instruction registers of all devices closer to TD1 then the addressed CPU data_bits (int): total number of data bits closer to TD1 than the addressed CPU Returns: ``None`` Raises: ValueError: if ``instr_regs`` or ``data_bits`` are not natural numbers """ if not util.is_natural(instr_regs): raise ValueError('IR value is not a natural number.') if not util.is_natural(data_bits): raise ValueError('Data bits is not a natural number.') self._dll.JLINKARM_ConfigJTAG(instr_regs, data_bits) return None
python
def jtag_configure(self, instr_regs=0, data_bits=0): """Configures the JTAG scan chain to determine which CPU to address. Must be called if the J-Link is connected to a JTAG scan chain with multiple devices. Args: self (JLink): the ``JLink`` instance instr_regs (int): length of instruction registers of all devices closer to TD1 then the addressed CPU data_bits (int): total number of data bits closer to TD1 than the addressed CPU Returns: ``None`` Raises: ValueError: if ``instr_regs`` or ``data_bits`` are not natural numbers """ if not util.is_natural(instr_regs): raise ValueError('IR value is not a natural number.') if not util.is_natural(data_bits): raise ValueError('Data bits is not a natural number.') self._dll.JLINKARM_ConfigJTAG(instr_regs, data_bits) return None
[ "def", "jtag_configure", "(", "self", ",", "instr_regs", "=", "0", ",", "data_bits", "=", "0", ")", ":", "if", "not", "util", ".", "is_natural", "(", "instr_regs", ")", ":", "raise", "ValueError", "(", "'IR value is not a natural number.'", ")", "if", "not", "util", ".", "is_natural", "(", "data_bits", ")", ":", "raise", "ValueError", "(", "'Data bits is not a natural number.'", ")", "self", ".", "_dll", ".", "JLINKARM_ConfigJTAG", "(", "instr_regs", ",", "data_bits", ")", "return", "None" ]
Configures the JTAG scan chain to determine which CPU to address. Must be called if the J-Link is connected to a JTAG scan chain with multiple devices. Args: self (JLink): the ``JLink`` instance instr_regs (int): length of instruction registers of all devices closer to TD1 then the addressed CPU data_bits (int): total number of data bits closer to TD1 than the addressed CPU Returns: ``None`` Raises: ValueError: if ``instr_regs`` or ``data_bits`` are not natural numbers
[ "Configures", "the", "JTAG", "scan", "chain", "to", "determine", "which", "CPU", "to", "address", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L804-L830
236,036
square/pylink
pylink/jlink.py
JLink.coresight_configure
def coresight_configure(self, ir_pre=0, dr_pre=0, ir_post=0, dr_post=0, ir_len=0, perform_tif_init=True): """Prepares target and J-Link for CoreSight function usage. Args: self (JLink): the ``JLink`` instance ir_pre (int): sum of instruction register length of all JTAG devices in the JTAG chain, close to TDO than the actual one, that J-Link shall communicate with dr_pre (int): number of JTAG devices in the JTAG chain, closer to TDO than the actual one, that J-Link shall communicate with ir_post (int): sum of instruction register length of all JTAG devices in the JTAG chain, following the actual one, that J-Link shall communicate with dr_post (int): Number of JTAG devices in the JTAG chain, following the actual one, J-Link shall communicate with ir_len (int): instruction register length of the actual device that J-Link shall communicate with perform_tif_init (bool): if ``False``, then do not output switching sequence on completion Returns: ``None`` Note: This must be called before calling ``coresight_read()`` or ``coresight_write()``. """ if self.tif == enums.JLinkInterfaces.SWD: # No special setup is needed for SWD, just need to output the # switching sequence. res = self._dll.JLINKARM_CORESIGHT_Configure('') if res < 0: raise errors.JLinkException(res) return None # JTAG requires more setup than SWD. config_string = 'IRPre=%s;DRPre=%s;IRPost=%s;DRPost=%s;IRLenDevice=%s;' config_string = config_string % (ir_pre, dr_pre, ir_post, dr_post, ir_len) if not perform_tif_init: config_string = config_string + ('PerformTIFInit=0;') res = self._dll.JLINKARM_CORESIGHT_Configure(config_string.encode()) if res < 0: raise errors.JLinkException(res) return None
python
def coresight_configure(self, ir_pre=0, dr_pre=0, ir_post=0, dr_post=0, ir_len=0, perform_tif_init=True): """Prepares target and J-Link for CoreSight function usage. Args: self (JLink): the ``JLink`` instance ir_pre (int): sum of instruction register length of all JTAG devices in the JTAG chain, close to TDO than the actual one, that J-Link shall communicate with dr_pre (int): number of JTAG devices in the JTAG chain, closer to TDO than the actual one, that J-Link shall communicate with ir_post (int): sum of instruction register length of all JTAG devices in the JTAG chain, following the actual one, that J-Link shall communicate with dr_post (int): Number of JTAG devices in the JTAG chain, following the actual one, J-Link shall communicate with ir_len (int): instruction register length of the actual device that J-Link shall communicate with perform_tif_init (bool): if ``False``, then do not output switching sequence on completion Returns: ``None`` Note: This must be called before calling ``coresight_read()`` or ``coresight_write()``. """ if self.tif == enums.JLinkInterfaces.SWD: # No special setup is needed for SWD, just need to output the # switching sequence. res = self._dll.JLINKARM_CORESIGHT_Configure('') if res < 0: raise errors.JLinkException(res) return None # JTAG requires more setup than SWD. config_string = 'IRPre=%s;DRPre=%s;IRPost=%s;DRPost=%s;IRLenDevice=%s;' config_string = config_string % (ir_pre, dr_pre, ir_post, dr_post, ir_len) if not perform_tif_init: config_string = config_string + ('PerformTIFInit=0;') res = self._dll.JLINKARM_CORESIGHT_Configure(config_string.encode()) if res < 0: raise errors.JLinkException(res) return None
[ "def", "coresight_configure", "(", "self", ",", "ir_pre", "=", "0", ",", "dr_pre", "=", "0", ",", "ir_post", "=", "0", ",", "dr_post", "=", "0", ",", "ir_len", "=", "0", ",", "perform_tif_init", "=", "True", ")", ":", "if", "self", ".", "tif", "==", "enums", ".", "JLinkInterfaces", ".", "SWD", ":", "# No special setup is needed for SWD, just need to output the", "# switching sequence.", "res", "=", "self", ".", "_dll", ".", "JLINKARM_CORESIGHT_Configure", "(", "''", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "None", "# JTAG requires more setup than SWD.", "config_string", "=", "'IRPre=%s;DRPre=%s;IRPost=%s;DRPost=%s;IRLenDevice=%s;'", "config_string", "=", "config_string", "%", "(", "ir_pre", ",", "dr_pre", ",", "ir_post", ",", "dr_post", ",", "ir_len", ")", "if", "not", "perform_tif_init", ":", "config_string", "=", "config_string", "+", "(", "'PerformTIFInit=0;'", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_CORESIGHT_Configure", "(", "config_string", ".", "encode", "(", ")", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "None" ]
Prepares target and J-Link for CoreSight function usage. Args: self (JLink): the ``JLink`` instance ir_pre (int): sum of instruction register length of all JTAG devices in the JTAG chain, close to TDO than the actual one, that J-Link shall communicate with dr_pre (int): number of JTAG devices in the JTAG chain, closer to TDO than the actual one, that J-Link shall communicate with ir_post (int): sum of instruction register length of all JTAG devices in the JTAG chain, following the actual one, that J-Link shall communicate with dr_post (int): Number of JTAG devices in the JTAG chain, following the actual one, J-Link shall communicate with ir_len (int): instruction register length of the actual device that J-Link shall communicate with perform_tif_init (bool): if ``False``, then do not output switching sequence on completion Returns: ``None`` Note: This must be called before calling ``coresight_read()`` or ``coresight_write()``.
[ "Prepares", "target", "and", "J", "-", "Link", "for", "CoreSight", "function", "usage", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L834-L887
236,037
square/pylink
pylink/jlink.py
JLink.connect
def connect(self, chip_name, speed='auto', verbose=False): """Connects the J-Link to its target. Args: self (JLink): the ``JLink`` instance chip_name (str): target chip name speed (int): connection speed, one of ``{5-12000, 'auto', 'adaptive'}`` verbose (bool): boolean indicating if connection should be verbose in logging Returns: ``None`` Raises: JLinkException: if connection fails to establish. TypeError: if given speed is invalid """ if verbose: self.exec_command('EnableRemarks = 1') # This is weird but is currently the only way to specify what the # target is to the J-Link. self.exec_command('Device = %s' % chip_name) # Need to select target interface speed here, so the J-Link knows what # speed to use to establish target communication. if speed == 'auto': self.set_speed(auto=True) elif speed == 'adaptive': self.set_speed(adaptive=True) else: self.set_speed(speed) result = self._dll.JLINKARM_Connect() if result < 0: raise errors.JLinkException(result) try: # Issue a no-op command after connect. This has to be in a try-catch. self.halted() except errors.JLinkException: pass # Determine which device we are. This is essential for using methods # like 'unlock' or 'lock'. for index in range(self.num_supported_devices()): device = self.supported_device(index) if device.name.lower() == chip_name.lower(): self._device = device break else: raise errors.JLinkException('Unsupported device was connected to.') return None
python
def connect(self, chip_name, speed='auto', verbose=False): """Connects the J-Link to its target. Args: self (JLink): the ``JLink`` instance chip_name (str): target chip name speed (int): connection speed, one of ``{5-12000, 'auto', 'adaptive'}`` verbose (bool): boolean indicating if connection should be verbose in logging Returns: ``None`` Raises: JLinkException: if connection fails to establish. TypeError: if given speed is invalid """ if verbose: self.exec_command('EnableRemarks = 1') # This is weird but is currently the only way to specify what the # target is to the J-Link. self.exec_command('Device = %s' % chip_name) # Need to select target interface speed here, so the J-Link knows what # speed to use to establish target communication. if speed == 'auto': self.set_speed(auto=True) elif speed == 'adaptive': self.set_speed(adaptive=True) else: self.set_speed(speed) result = self._dll.JLINKARM_Connect() if result < 0: raise errors.JLinkException(result) try: # Issue a no-op command after connect. This has to be in a try-catch. self.halted() except errors.JLinkException: pass # Determine which device we are. This is essential for using methods # like 'unlock' or 'lock'. for index in range(self.num_supported_devices()): device = self.supported_device(index) if device.name.lower() == chip_name.lower(): self._device = device break else: raise errors.JLinkException('Unsupported device was connected to.') return None
[ "def", "connect", "(", "self", ",", "chip_name", ",", "speed", "=", "'auto'", ",", "verbose", "=", "False", ")", ":", "if", "verbose", ":", "self", ".", "exec_command", "(", "'EnableRemarks = 1'", ")", "# This is weird but is currently the only way to specify what the", "# target is to the J-Link.", "self", ".", "exec_command", "(", "'Device = %s'", "%", "chip_name", ")", "# Need to select target interface speed here, so the J-Link knows what", "# speed to use to establish target communication.", "if", "speed", "==", "'auto'", ":", "self", ".", "set_speed", "(", "auto", "=", "True", ")", "elif", "speed", "==", "'adaptive'", ":", "self", ".", "set_speed", "(", "adaptive", "=", "True", ")", "else", ":", "self", ".", "set_speed", "(", "speed", ")", "result", "=", "self", ".", "_dll", ".", "JLINKARM_Connect", "(", ")", "if", "result", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "result", ")", "try", ":", "# Issue a no-op command after connect. This has to be in a try-catch.", "self", ".", "halted", "(", ")", "except", "errors", ".", "JLinkException", ":", "pass", "# Determine which device we are. This is essential for using methods", "# like 'unlock' or 'lock'.", "for", "index", "in", "range", "(", "self", ".", "num_supported_devices", "(", ")", ")", ":", "device", "=", "self", ".", "supported_device", "(", "index", ")", "if", "device", ".", "name", ".", "lower", "(", ")", "==", "chip_name", ".", "lower", "(", ")", ":", "self", ".", "_device", "=", "device", "break", "else", ":", "raise", "errors", ".", "JLinkException", "(", "'Unsupported device was connected to.'", ")", "return", "None" ]
Connects the J-Link to its target. Args: self (JLink): the ``JLink`` instance chip_name (str): target chip name speed (int): connection speed, one of ``{5-12000, 'auto', 'adaptive'}`` verbose (bool): boolean indicating if connection should be verbose in logging Returns: ``None`` Raises: JLinkException: if connection fails to establish. TypeError: if given speed is invalid
[ "Connects", "the", "J", "-", "Link", "to", "its", "target", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L890-L943
236,038
square/pylink
pylink/jlink.py
JLink.compile_date
def compile_date(self): """Returns a string specifying the date and time at which the DLL was translated. Args: self (JLink): the ``JLink`` instance Returns: Datetime string. """ result = self._dll.JLINKARM_GetCompileDateTime() return ctypes.cast(result, ctypes.c_char_p).value.decode()
python
def compile_date(self): """Returns a string specifying the date and time at which the DLL was translated. Args: self (JLink): the ``JLink`` instance Returns: Datetime string. """ result = self._dll.JLINKARM_GetCompileDateTime() return ctypes.cast(result, ctypes.c_char_p).value.decode()
[ "def", "compile_date", "(", "self", ")", ":", "result", "=", "self", ".", "_dll", ".", "JLINKARM_GetCompileDateTime", "(", ")", "return", "ctypes", ".", "cast", "(", "result", ",", "ctypes", ".", "c_char_p", ")", ".", "value", ".", "decode", "(", ")" ]
Returns a string specifying the date and time at which the DLL was translated. Args: self (JLink): the ``JLink`` instance Returns: Datetime string.
[ "Returns", "a", "string", "specifying", "the", "date", "and", "time", "at", "which", "the", "DLL", "was", "translated", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L975-L986
236,039
square/pylink
pylink/jlink.py
JLink.version
def version(self): """Returns the device's version. The device's version is returned as a string of the format: M.mr where ``M`` is major number, ``m`` is minor number, and ``r`` is revision character. Args: self (JLink): the ``JLink`` instance Returns: Device version string. """ version = int(self._dll.JLINKARM_GetDLLVersion()) major = version / 10000 minor = (version / 100) % 100 rev = version % 100 rev = '' if rev == 0 else chr(rev + ord('a') - 1) return '%d.%02d%s' % (major, minor, rev)
python
def version(self): """Returns the device's version. The device's version is returned as a string of the format: M.mr where ``M`` is major number, ``m`` is minor number, and ``r`` is revision character. Args: self (JLink): the ``JLink`` instance Returns: Device version string. """ version = int(self._dll.JLINKARM_GetDLLVersion()) major = version / 10000 minor = (version / 100) % 100 rev = version % 100 rev = '' if rev == 0 else chr(rev + ord('a') - 1) return '%d.%02d%s' % (major, minor, rev)
[ "def", "version", "(", "self", ")", ":", "version", "=", "int", "(", "self", ".", "_dll", ".", "JLINKARM_GetDLLVersion", "(", ")", ")", "major", "=", "version", "/", "10000", "minor", "=", "(", "version", "/", "100", ")", "%", "100", "rev", "=", "version", "%", "100", "rev", "=", "''", "if", "rev", "==", "0", "else", "chr", "(", "rev", "+", "ord", "(", "'a'", ")", "-", "1", ")", "return", "'%d.%02d%s'", "%", "(", "major", ",", "minor", ",", "rev", ")" ]
Returns the device's version. The device's version is returned as a string of the format: M.mr where ``M`` is major number, ``m`` is minor number, and ``r`` is revision character. Args: self (JLink): the ``JLink`` instance Returns: Device version string.
[ "Returns", "the", "device", "s", "version", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L989-L1007
236,040
square/pylink
pylink/jlink.py
JLink.compatible_firmware_version
def compatible_firmware_version(self): """Returns the DLL's compatible J-Link firmware version. Args: self (JLink): the ``JLink`` instance Returns: The firmware version of the J-Link that the DLL is compatible with. Raises: JLinkException: on error. """ identifier = self.firmware_version.split('compiled')[0] buf_size = self.MAX_BUF_SIZE buf = (ctypes.c_char * buf_size)() res = self._dll.JLINKARM_GetEmbeddedFWString(identifier.encode(), buf, buf_size) if res < 0: raise errors.JLinkException(res) return ctypes.string_at(buf).decode()
python
def compatible_firmware_version(self): """Returns the DLL's compatible J-Link firmware version. Args: self (JLink): the ``JLink`` instance Returns: The firmware version of the J-Link that the DLL is compatible with. Raises: JLinkException: on error. """ identifier = self.firmware_version.split('compiled')[0] buf_size = self.MAX_BUF_SIZE buf = (ctypes.c_char * buf_size)() res = self._dll.JLINKARM_GetEmbeddedFWString(identifier.encode(), buf, buf_size) if res < 0: raise errors.JLinkException(res) return ctypes.string_at(buf).decode()
[ "def", "compatible_firmware_version", "(", "self", ")", ":", "identifier", "=", "self", ".", "firmware_version", ".", "split", "(", "'compiled'", ")", "[", "0", "]", "buf_size", "=", "self", ".", "MAX_BUF_SIZE", "buf", "=", "(", "ctypes", ".", "c_char", "*", "buf_size", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_GetEmbeddedFWString", "(", "identifier", ".", "encode", "(", ")", ",", "buf", ",", "buf_size", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")" ]
Returns the DLL's compatible J-Link firmware version. Args: self (JLink): the ``JLink`` instance Returns: The firmware version of the J-Link that the DLL is compatible with. Raises: JLinkException: on error.
[ "Returns", "the", "DLL", "s", "compatible", "J", "-", "Link", "firmware", "version", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1011-L1031
236,041
square/pylink
pylink/jlink.py
JLink.firmware_outdated
def firmware_outdated(self): """Returns whether the J-Link's firmware version is older than the one that the DLL is compatible with. Note: This is not the same as calling ``not jlink.firmware_newer()``. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if the J-Link's firmware is older than the one supported by the DLL, otherwise ``False``. """ datefmt = ' %b %d %Y %H:%M:%S' compat_date = self.compatible_firmware_version.split('compiled')[1] compat_date = datetime.datetime.strptime(compat_date, datefmt) fw_date = self.firmware_version.split('compiled')[1] fw_date = datetime.datetime.strptime(fw_date, datefmt) return (compat_date > fw_date)
python
def firmware_outdated(self): """Returns whether the J-Link's firmware version is older than the one that the DLL is compatible with. Note: This is not the same as calling ``not jlink.firmware_newer()``. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if the J-Link's firmware is older than the one supported by the DLL, otherwise ``False``. """ datefmt = ' %b %d %Y %H:%M:%S' compat_date = self.compatible_firmware_version.split('compiled')[1] compat_date = datetime.datetime.strptime(compat_date, datefmt) fw_date = self.firmware_version.split('compiled')[1] fw_date = datetime.datetime.strptime(fw_date, datefmt) return (compat_date > fw_date)
[ "def", "firmware_outdated", "(", "self", ")", ":", "datefmt", "=", "' %b %d %Y %H:%M:%S'", "compat_date", "=", "self", ".", "compatible_firmware_version", ".", "split", "(", "'compiled'", ")", "[", "1", "]", "compat_date", "=", "datetime", ".", "datetime", ".", "strptime", "(", "compat_date", ",", "datefmt", ")", "fw_date", "=", "self", ".", "firmware_version", ".", "split", "(", "'compiled'", ")", "[", "1", "]", "fw_date", "=", "datetime", ".", "datetime", ".", "strptime", "(", "fw_date", ",", "datefmt", ")", "return", "(", "compat_date", ">", "fw_date", ")" ]
Returns whether the J-Link's firmware version is older than the one that the DLL is compatible with. Note: This is not the same as calling ``not jlink.firmware_newer()``. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if the J-Link's firmware is older than the one supported by the DLL, otherwise ``False``.
[ "Returns", "whether", "the", "J", "-", "Link", "s", "firmware", "version", "is", "older", "than", "the", "one", "that", "the", "DLL", "is", "compatible", "with", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1034-L1055
236,042
square/pylink
pylink/jlink.py
JLink.hardware_info
def hardware_info(self, mask=0xFFFFFFFF): """Returns a list of 32 integer values corresponding to the bitfields specifying the power consumption of the target. The values returned by this function only have significance if the J-Link is powering the target. The words, indexed, have the following significance: 0. If ``1``, target is powered via J-Link. 1. Overcurrent bitfield: 0: No overcurrent. 1: Overcurrent happened. 2ms @ 3000mA 2: Overcurrent happened. 10ms @ 1000mA 3: Overcurrent happened. 40ms @ 400mA 2. Power consumption of target (mA). 3. Peak of target power consumption (mA). 4. Peak of target power consumption during J-Link operation (mA). Args: self (JLink): the ``JLink`` instance mask (int): bit mask to decide which hardware information words are returned (defaults to all the words). Returns: List of bitfields specifying different states based on their index within the list and their value. Raises: JLinkException: on hardware error. """ buf = (ctypes.c_uint32 * 32)() res = self._dll.JLINKARM_GetHWInfo(mask, ctypes.byref(buf)) if res != 0: raise errors.JLinkException(res) return list(buf)
python
def hardware_info(self, mask=0xFFFFFFFF): """Returns a list of 32 integer values corresponding to the bitfields specifying the power consumption of the target. The values returned by this function only have significance if the J-Link is powering the target. The words, indexed, have the following significance: 0. If ``1``, target is powered via J-Link. 1. Overcurrent bitfield: 0: No overcurrent. 1: Overcurrent happened. 2ms @ 3000mA 2: Overcurrent happened. 10ms @ 1000mA 3: Overcurrent happened. 40ms @ 400mA 2. Power consumption of target (mA). 3. Peak of target power consumption (mA). 4. Peak of target power consumption during J-Link operation (mA). Args: self (JLink): the ``JLink`` instance mask (int): bit mask to decide which hardware information words are returned (defaults to all the words). Returns: List of bitfields specifying different states based on their index within the list and their value. Raises: JLinkException: on hardware error. """ buf = (ctypes.c_uint32 * 32)() res = self._dll.JLINKARM_GetHWInfo(mask, ctypes.byref(buf)) if res != 0: raise errors.JLinkException(res) return list(buf)
[ "def", "hardware_info", "(", "self", ",", "mask", "=", "0xFFFFFFFF", ")", ":", "buf", "=", "(", "ctypes", ".", "c_uint32", "*", "32", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_GetHWInfo", "(", "mask", ",", "ctypes", ".", "byref", "(", "buf", ")", ")", "if", "res", "!=", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "list", "(", "buf", ")" ]
Returns a list of 32 integer values corresponding to the bitfields specifying the power consumption of the target. The values returned by this function only have significance if the J-Link is powering the target. The words, indexed, have the following significance: 0. If ``1``, target is powered via J-Link. 1. Overcurrent bitfield: 0: No overcurrent. 1: Overcurrent happened. 2ms @ 3000mA 2: Overcurrent happened. 10ms @ 1000mA 3: Overcurrent happened. 40ms @ 400mA 2. Power consumption of target (mA). 3. Peak of target power consumption (mA). 4. Peak of target power consumption during J-Link operation (mA). Args: self (JLink): the ``JLink`` instance mask (int): bit mask to decide which hardware information words are returned (defaults to all the words). Returns: List of bitfields specifying different states based on their index within the list and their value. Raises: JLinkException: on hardware error.
[ "Returns", "a", "list", "of", "32", "integer", "values", "corresponding", "to", "the", "bitfields", "specifying", "the", "power", "consumption", "of", "the", "target", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1078-L1112
236,043
square/pylink
pylink/jlink.py
JLink.hardware_status
def hardware_status(self): """Retrieves and returns the hardware status. Args: self (JLink): the ``JLink`` instance Returns: A ``JLinkHardwareStatus`` describing the J-Link hardware. """ stat = structs.JLinkHardwareStatus() res = self._dll.JLINKARM_GetHWStatus(ctypes.byref(stat)) if res == 1: raise errors.JLinkException('Error in reading hardware status.') return stat
python
def hardware_status(self): """Retrieves and returns the hardware status. Args: self (JLink): the ``JLink`` instance Returns: A ``JLinkHardwareStatus`` describing the J-Link hardware. """ stat = structs.JLinkHardwareStatus() res = self._dll.JLINKARM_GetHWStatus(ctypes.byref(stat)) if res == 1: raise errors.JLinkException('Error in reading hardware status.') return stat
[ "def", "hardware_status", "(", "self", ")", ":", "stat", "=", "structs", ".", "JLinkHardwareStatus", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_GetHWStatus", "(", "ctypes", ".", "byref", "(", "stat", ")", ")", "if", "res", "==", "1", ":", "raise", "errors", ".", "JLinkException", "(", "'Error in reading hardware status.'", ")", "return", "stat" ]
Retrieves and returns the hardware status. Args: self (JLink): the ``JLink`` instance Returns: A ``JLinkHardwareStatus`` describing the J-Link hardware.
[ "Retrieves", "and", "returns", "the", "hardware", "status", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1116-L1129
236,044
square/pylink
pylink/jlink.py
JLink.hardware_version
def hardware_version(self): """Returns the hardware version of the connected J-Link as a major.minor string. Args: self (JLink): the ``JLink`` instance Returns: Hardware version string. """ version = self._dll.JLINKARM_GetHardwareVersion() major = version / 10000 % 100 minor = version / 100 % 100 return '%d.%02d' % (major, minor)
python
def hardware_version(self): """Returns the hardware version of the connected J-Link as a major.minor string. Args: self (JLink): the ``JLink`` instance Returns: Hardware version string. """ version = self._dll.JLINKARM_GetHardwareVersion() major = version / 10000 % 100 minor = version / 100 % 100 return '%d.%02d' % (major, minor)
[ "def", "hardware_version", "(", "self", ")", ":", "version", "=", "self", ".", "_dll", ".", "JLINKARM_GetHardwareVersion", "(", ")", "major", "=", "version", "/", "10000", "%", "100", "minor", "=", "version", "/", "100", "%", "100", "return", "'%d.%02d'", "%", "(", "major", ",", "minor", ")" ]
Returns the hardware version of the connected J-Link as a major.minor string. Args: self (JLink): the ``JLink`` instance Returns: Hardware version string.
[ "Returns", "the", "hardware", "version", "of", "the", "connected", "J", "-", "Link", "as", "a", "major", ".", "minor", "string", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1133-L1146
236,045
square/pylink
pylink/jlink.py
JLink.firmware_version
def firmware_version(self): """Returns a firmware identification string of the connected J-Link. It consists of the following: - Product Name (e.g. J-Link) - The string: compiled - Compile data and time. - Optional additional information. Args: self (JLink): the ``JLink`` instance Returns: Firmware identification string. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() self._dll.JLINKARM_GetFirmwareString(buf, self.MAX_BUF_SIZE) return ctypes.string_at(buf).decode()
python
def firmware_version(self): """Returns a firmware identification string of the connected J-Link. It consists of the following: - Product Name (e.g. J-Link) - The string: compiled - Compile data and time. - Optional additional information. Args: self (JLink): the ``JLink`` instance Returns: Firmware identification string. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() self._dll.JLINKARM_GetFirmwareString(buf, self.MAX_BUF_SIZE) return ctypes.string_at(buf).decode()
[ "def", "firmware_version", "(", "self", ")", ":", "buf", "=", "(", "ctypes", ".", "c_char", "*", "self", ".", "MAX_BUF_SIZE", ")", "(", ")", "self", ".", "_dll", ".", "JLINKARM_GetFirmwareString", "(", "buf", ",", "self", ".", "MAX_BUF_SIZE", ")", "return", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")" ]
Returns a firmware identification string of the connected J-Link. It consists of the following: - Product Name (e.g. J-Link) - The string: compiled - Compile data and time. - Optional additional information. Args: self (JLink): the ``JLink`` instance Returns: Firmware identification string.
[ "Returns", "a", "firmware", "identification", "string", "of", "the", "connected", "J", "-", "Link", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1150-L1167
236,046
square/pylink
pylink/jlink.py
JLink.extended_capabilities
def extended_capabilities(self): """Gets the capabilities of the connected emulator as a list. Args: self (JLink): the ``JLink`` instance Returns: List of 32 integers which define the extended capabilities based on their value and index within the list. """ buf = (ctypes.c_uint8 * 32)() self._dll.JLINKARM_GetEmuCapsEx(buf, 32) return list(buf)
python
def extended_capabilities(self): """Gets the capabilities of the connected emulator as a list. Args: self (JLink): the ``JLink`` instance Returns: List of 32 integers which define the extended capabilities based on their value and index within the list. """ buf = (ctypes.c_uint8 * 32)() self._dll.JLINKARM_GetEmuCapsEx(buf, 32) return list(buf)
[ "def", "extended_capabilities", "(", "self", ")", ":", "buf", "=", "(", "ctypes", ".", "c_uint8", "*", "32", ")", "(", ")", "self", ".", "_dll", ".", "JLINKARM_GetEmuCapsEx", "(", "buf", ",", "32", ")", "return", "list", "(", "buf", ")" ]
Gets the capabilities of the connected emulator as a list. Args: self (JLink): the ``JLink`` instance Returns: List of 32 integers which define the extended capabilities based on their value and index within the list.
[ "Gets", "the", "capabilities", "of", "the", "connected", "emulator", "as", "a", "list", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1184-L1196
236,047
square/pylink
pylink/jlink.py
JLink.features
def features(self): """Returns a list of the J-Link embedded features. Args: self (JLink): the ``JLink`` instance Returns: A list of strings, each a feature. Example: ``[ 'RDI', 'FlashBP', 'FlashDL', 'JFlash', 'GDB' ]`` """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() self._dll.JLINKARM_GetFeatureString(buf) result = ctypes.string_at(buf).decode().strip() if len(result) == 0: return list() return result.split(', ')
python
def features(self): """Returns a list of the J-Link embedded features. Args: self (JLink): the ``JLink`` instance Returns: A list of strings, each a feature. Example: ``[ 'RDI', 'FlashBP', 'FlashDL', 'JFlash', 'GDB' ]`` """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() self._dll.JLINKARM_GetFeatureString(buf) result = ctypes.string_at(buf).decode().strip() if len(result) == 0: return list() return result.split(', ')
[ "def", "features", "(", "self", ")", ":", "buf", "=", "(", "ctypes", ".", "c_char", "*", "self", ".", "MAX_BUF_SIZE", ")", "(", ")", "self", ".", "_dll", ".", "JLINKARM_GetFeatureString", "(", "buf", ")", "result", "=", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")", ".", "strip", "(", ")", "if", "len", "(", "result", ")", "==", "0", ":", "return", "list", "(", ")", "return", "result", ".", "split", "(", "', '", ")" ]
Returns a list of the J-Link embedded features. Args: self (JLink): the ``JLink`` instance Returns: A list of strings, each a feature. Example: ``[ 'RDI', 'FlashBP', 'FlashDL', 'JFlash', 'GDB' ]``
[ "Returns", "a", "list", "of", "the", "J", "-", "Link", "embedded", "features", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1215-L1232
236,048
square/pylink
pylink/jlink.py
JLink.product_name
def product_name(self): """Returns the product name of the connected J-Link. Args: self (JLink): the ``JLink`` instance Returns: Product name. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() self._dll.JLINKARM_EMU_GetProductName(buf, self.MAX_BUF_SIZE) return ctypes.string_at(buf).decode()
python
def product_name(self): """Returns the product name of the connected J-Link. Args: self (JLink): the ``JLink`` instance Returns: Product name. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() self._dll.JLINKARM_EMU_GetProductName(buf, self.MAX_BUF_SIZE) return ctypes.string_at(buf).decode()
[ "def", "product_name", "(", "self", ")", ":", "buf", "=", "(", "ctypes", ".", "c_char", "*", "self", ".", "MAX_BUF_SIZE", ")", "(", ")", "self", ".", "_dll", ".", "JLINKARM_EMU_GetProductName", "(", "buf", ",", "self", ".", "MAX_BUF_SIZE", ")", "return", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")" ]
Returns the product name of the connected J-Link. Args: self (JLink): the ``JLink`` instance Returns: Product name.
[ "Returns", "the", "product", "name", "of", "the", "connected", "J", "-", "Link", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1236-L1247
236,049
square/pylink
pylink/jlink.py
JLink.oem
def oem(self): """Retrieves and returns the OEM string of the connected J-Link. Args: self (JLink): the ``JLink`` instance Returns: The string of the OEM. If this is an original SEGGER product, then ``None`` is returned instead. Raises: JLinkException: on hardware error. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() res = self._dll.JLINKARM_GetOEMString(ctypes.byref(buf)) if res != 0: raise errors.JLinkException('Failed to grab OEM string.') oem = ctypes.string_at(buf).decode() if len(oem) == 0: # In the case that the product is an original SEGGER product, then # the OEM string is the empty string, so there is no OEM. return None return oem
python
def oem(self): """Retrieves and returns the OEM string of the connected J-Link. Args: self (JLink): the ``JLink`` instance Returns: The string of the OEM. If this is an original SEGGER product, then ``None`` is returned instead. Raises: JLinkException: on hardware error. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() res = self._dll.JLINKARM_GetOEMString(ctypes.byref(buf)) if res != 0: raise errors.JLinkException('Failed to grab OEM string.') oem = ctypes.string_at(buf).decode() if len(oem) == 0: # In the case that the product is an original SEGGER product, then # the OEM string is the empty string, so there is no OEM. return None return oem
[ "def", "oem", "(", "self", ")", ":", "buf", "=", "(", "ctypes", ".", "c_char", "*", "self", ".", "MAX_BUF_SIZE", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_GetOEMString", "(", "ctypes", ".", "byref", "(", "buf", ")", ")", "if", "res", "!=", "0", ":", "raise", "errors", ".", "JLinkException", "(", "'Failed to grab OEM string.'", ")", "oem", "=", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")", "if", "len", "(", "oem", ")", "==", "0", ":", "# In the case that the product is an original SEGGER product, then", "# the OEM string is the empty string, so there is no OEM.", "return", "None", "return", "oem" ]
Retrieves and returns the OEM string of the connected J-Link. Args: self (JLink): the ``JLink`` instance Returns: The string of the OEM. If this is an original SEGGER product, then ``None`` is returned instead. Raises: JLinkException: on hardware error.
[ "Retrieves", "and", "returns", "the", "OEM", "string", "of", "the", "connected", "J", "-", "Link", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1264-L1288
236,050
square/pylink
pylink/jlink.py
JLink.set_speed
def set_speed(self, speed=None, auto=False, adaptive=False): """Sets the speed of the JTAG communication with the ARM core. If no arguments are present, automatically detects speed. If a ``speed`` is provided, the speed must be no larger than ``JLink.MAX_JTAG_SPEED`` and no smaller than ``JLink.MIN_JTAG_SPEED``. The given ``speed`` can also not be ``JLink.INVALID_JTAG_SPEED``. Args: self (JLink): the ``JLink`` instance speed (int): the speed in kHz to set the communication at auto (bool): automatically detect correct speed adaptive (bool): select adaptive clocking as JTAG speed Returns: ``None`` Raises: TypeError: if given speed is not a natural number. ValueError: if given speed is too high, too low, or invalid. """ if speed is None: speed = 0 elif not util.is_natural(speed): raise TypeError('Expected positive number for speed, given %s.' % speed) elif speed > self.MAX_JTAG_SPEED: raise ValueError('Given speed exceeds max speed of %d.' % self.MAX_JTAG_SPEED) elif speed < self.MIN_JTAG_SPEED: raise ValueError('Given speed is too slow. Minimum is %d.' % self.MIN_JTAG_SPEED) if auto: speed = speed | self.AUTO_JTAG_SPEED if adaptive: speed = speed | self.ADAPTIVE_JTAG_SPEED self._dll.JLINKARM_SetSpeed(speed) return None
python
def set_speed(self, speed=None, auto=False, adaptive=False): """Sets the speed of the JTAG communication with the ARM core. If no arguments are present, automatically detects speed. If a ``speed`` is provided, the speed must be no larger than ``JLink.MAX_JTAG_SPEED`` and no smaller than ``JLink.MIN_JTAG_SPEED``. The given ``speed`` can also not be ``JLink.INVALID_JTAG_SPEED``. Args: self (JLink): the ``JLink`` instance speed (int): the speed in kHz to set the communication at auto (bool): automatically detect correct speed adaptive (bool): select adaptive clocking as JTAG speed Returns: ``None`` Raises: TypeError: if given speed is not a natural number. ValueError: if given speed is too high, too low, or invalid. """ if speed is None: speed = 0 elif not util.is_natural(speed): raise TypeError('Expected positive number for speed, given %s.' % speed) elif speed > self.MAX_JTAG_SPEED: raise ValueError('Given speed exceeds max speed of %d.' % self.MAX_JTAG_SPEED) elif speed < self.MIN_JTAG_SPEED: raise ValueError('Given speed is too slow. Minimum is %d.' % self.MIN_JTAG_SPEED) if auto: speed = speed | self.AUTO_JTAG_SPEED if adaptive: speed = speed | self.ADAPTIVE_JTAG_SPEED self._dll.JLINKARM_SetSpeed(speed) return None
[ "def", "set_speed", "(", "self", ",", "speed", "=", "None", ",", "auto", "=", "False", ",", "adaptive", "=", "False", ")", ":", "if", "speed", "is", "None", ":", "speed", "=", "0", "elif", "not", "util", ".", "is_natural", "(", "speed", ")", ":", "raise", "TypeError", "(", "'Expected positive number for speed, given %s.'", "%", "speed", ")", "elif", "speed", ">", "self", ".", "MAX_JTAG_SPEED", ":", "raise", "ValueError", "(", "'Given speed exceeds max speed of %d.'", "%", "self", ".", "MAX_JTAG_SPEED", ")", "elif", "speed", "<", "self", ".", "MIN_JTAG_SPEED", ":", "raise", "ValueError", "(", "'Given speed is too slow. Minimum is %d.'", "%", "self", ".", "MIN_JTAG_SPEED", ")", "if", "auto", ":", "speed", "=", "speed", "|", "self", ".", "AUTO_JTAG_SPEED", "if", "adaptive", ":", "speed", "=", "speed", "|", "self", ".", "ADAPTIVE_JTAG_SPEED", "self", ".", "_dll", ".", "JLINKARM_SetSpeed", "(", "speed", ")", "return", "None" ]
Sets the speed of the JTAG communication with the ARM core. If no arguments are present, automatically detects speed. If a ``speed`` is provided, the speed must be no larger than ``JLink.MAX_JTAG_SPEED`` and no smaller than ``JLink.MIN_JTAG_SPEED``. The given ``speed`` can also not be ``JLink.INVALID_JTAG_SPEED``. Args: self (JLink): the ``JLink`` instance speed (int): the speed in kHz to set the communication at auto (bool): automatically detect correct speed adaptive (bool): select adaptive clocking as JTAG speed Returns: ``None`` Raises: TypeError: if given speed is not a natural number. ValueError: if given speed is too high, too low, or invalid.
[ "Sets", "the", "speed", "of", "the", "JTAG", "communication", "with", "the", "ARM", "core", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1318-L1357
236,051
square/pylink
pylink/jlink.py
JLink.speed_info
def speed_info(self): """Retrieves information about supported target interface speeds. Args: self (JLink): the ``JLink`` instance Returns: The ``JLinkSpeedInfo`` instance describing the supported target interface speeds. """ speed_info = structs.JLinkSpeedInfo() self._dll.JLINKARM_GetSpeedInfo(ctypes.byref(speed_info)) return speed_info
python
def speed_info(self): """Retrieves information about supported target interface speeds. Args: self (JLink): the ``JLink`` instance Returns: The ``JLinkSpeedInfo`` instance describing the supported target interface speeds. """ speed_info = structs.JLinkSpeedInfo() self._dll.JLINKARM_GetSpeedInfo(ctypes.byref(speed_info)) return speed_info
[ "def", "speed_info", "(", "self", ")", ":", "speed_info", "=", "structs", ".", "JLinkSpeedInfo", "(", ")", "self", ".", "_dll", ".", "JLINKARM_GetSpeedInfo", "(", "ctypes", ".", "byref", "(", "speed_info", ")", ")", "return", "speed_info" ]
Retrieves information about supported target interface speeds. Args: self (JLink): the ``JLink`` instance Returns: The ``JLinkSpeedInfo`` instance describing the supported target interface speeds.
[ "Retrieves", "information", "about", "supported", "target", "interface", "speeds", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1374-L1386
236,052
square/pylink
pylink/jlink.py
JLink.licenses
def licenses(self): """Returns a string of the built-in licenses the J-Link has. Args: self (JLink): the ``JLink`` instance Returns: String of the contents of the built-in licenses the J-Link has. """ buf_size = self.MAX_BUF_SIZE buf = (ctypes.c_char * buf_size)() res = self._dll.JLINK_GetAvailableLicense(buf, buf_size) if res < 0: raise errors.JLinkException(res) return ctypes.string_at(buf).decode()
python
def licenses(self): """Returns a string of the built-in licenses the J-Link has. Args: self (JLink): the ``JLink`` instance Returns: String of the contents of the built-in licenses the J-Link has. """ buf_size = self.MAX_BUF_SIZE buf = (ctypes.c_char * buf_size)() res = self._dll.JLINK_GetAvailableLicense(buf, buf_size) if res < 0: raise errors.JLinkException(res) return ctypes.string_at(buf).decode()
[ "def", "licenses", "(", "self", ")", ":", "buf_size", "=", "self", ".", "MAX_BUF_SIZE", "buf", "=", "(", "ctypes", ".", "c_char", "*", "buf_size", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINK_GetAvailableLicense", "(", "buf", ",", "buf_size", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")" ]
Returns a string of the built-in licenses the J-Link has. Args: self (JLink): the ``JLink`` instance Returns: String of the contents of the built-in licenses the J-Link has.
[ "Returns", "a", "string", "of", "the", "built", "-", "in", "licenses", "the", "J", "-", "Link", "has", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1390-L1404
236,053
square/pylink
pylink/jlink.py
JLink.custom_licenses
def custom_licenses(self): """Returns a string of the installed licenses the J-Link has. Args: self (JLink): the ``JLink`` instance Returns: String of the contents of the custom licenses the J-Link has. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() result = self._dll.JLINK_EMU_GetLicenses(buf, self.MAX_BUF_SIZE) if result < 0: raise errors.JLinkException(result) return ctypes.string_at(buf).decode()
python
def custom_licenses(self): """Returns a string of the installed licenses the J-Link has. Args: self (JLink): the ``JLink`` instance Returns: String of the contents of the custom licenses the J-Link has. """ buf = (ctypes.c_char * self.MAX_BUF_SIZE)() result = self._dll.JLINK_EMU_GetLicenses(buf, self.MAX_BUF_SIZE) if result < 0: raise errors.JLinkException(result) return ctypes.string_at(buf).decode()
[ "def", "custom_licenses", "(", "self", ")", ":", "buf", "=", "(", "ctypes", ".", "c_char", "*", "self", ".", "MAX_BUF_SIZE", ")", "(", ")", "result", "=", "self", ".", "_dll", ".", "JLINK_EMU_GetLicenses", "(", "buf", ",", "self", ".", "MAX_BUF_SIZE", ")", "if", "result", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "result", ")", "return", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")" ]
Returns a string of the installed licenses the J-Link has. Args: self (JLink): the ``JLink`` instance Returns: String of the contents of the custom licenses the J-Link has.
[ "Returns", "a", "string", "of", "the", "installed", "licenses", "the", "J", "-", "Link", "has", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1409-L1422
236,054
square/pylink
pylink/jlink.py
JLink.add_license
def add_license(self, contents): """Adds the given ``contents`` as a new custom license to the J-Link. Args: self (JLink): the ``JLink`` instance contents: the string contents of the new custom license Returns: ``True`` if license was added, ``False`` if license already existed. Raises: JLinkException: if the write fails. Note: J-Link V9 and J-Link ULTRA/PRO V4 have 336 Bytes of memory for licenses, while older versions of 80 bytes. """ buf_size = len(contents) buf = (ctypes.c_char * (buf_size + 1))(*contents.encode()) res = self._dll.JLINK_EMU_AddLicense(buf) if res == -1: raise errors.JLinkException('Unspecified error.') elif res == -2: raise errors.JLinkException('Failed to read/write license area.') elif res == -3: raise errors.JLinkException('J-Link out of space.') return (res == 0)
python
def add_license(self, contents): """Adds the given ``contents`` as a new custom license to the J-Link. Args: self (JLink): the ``JLink`` instance contents: the string contents of the new custom license Returns: ``True`` if license was added, ``False`` if license already existed. Raises: JLinkException: if the write fails. Note: J-Link V9 and J-Link ULTRA/PRO V4 have 336 Bytes of memory for licenses, while older versions of 80 bytes. """ buf_size = len(contents) buf = (ctypes.c_char * (buf_size + 1))(*contents.encode()) res = self._dll.JLINK_EMU_AddLicense(buf) if res == -1: raise errors.JLinkException('Unspecified error.') elif res == -2: raise errors.JLinkException('Failed to read/write license area.') elif res == -3: raise errors.JLinkException('J-Link out of space.') return (res == 0)
[ "def", "add_license", "(", "self", ",", "contents", ")", ":", "buf_size", "=", "len", "(", "contents", ")", "buf", "=", "(", "ctypes", ".", "c_char", "*", "(", "buf_size", "+", "1", ")", ")", "(", "*", "contents", ".", "encode", "(", ")", ")", "res", "=", "self", ".", "_dll", ".", "JLINK_EMU_AddLicense", "(", "buf", ")", "if", "res", "==", "-", "1", ":", "raise", "errors", ".", "JLinkException", "(", "'Unspecified error.'", ")", "elif", "res", "==", "-", "2", ":", "raise", "errors", ".", "JLinkException", "(", "'Failed to read/write license area.'", ")", "elif", "res", "==", "-", "3", ":", "raise", "errors", ".", "JLinkException", "(", "'J-Link out of space.'", ")", "return", "(", "res", "==", "0", ")" ]
Adds the given ``contents`` as a new custom license to the J-Link. Args: self (JLink): the ``JLink`` instance contents: the string contents of the new custom license Returns: ``True`` if license was added, ``False`` if license already existed. Raises: JLinkException: if the write fails. Note: J-Link V9 and J-Link ULTRA/PRO V4 have 336 Bytes of memory for licenses, while older versions of 80 bytes.
[ "Adds", "the", "given", "contents", "as", "a", "new", "custom", "license", "to", "the", "J", "-", "Link", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1426-L1455
236,055
square/pylink
pylink/jlink.py
JLink.supported_tifs
def supported_tifs(self): """Returns a bitmask of the supported target interfaces. Args: self (JLink): the ``JLink`` instance Returns: Bitfield specifying which target interfaces are supported. """ buf = ctypes.c_uint32() self._dll.JLINKARM_TIF_GetAvailable(ctypes.byref(buf)) return buf.value
python
def supported_tifs(self): """Returns a bitmask of the supported target interfaces. Args: self (JLink): the ``JLink`` instance Returns: Bitfield specifying which target interfaces are supported. """ buf = ctypes.c_uint32() self._dll.JLINKARM_TIF_GetAvailable(ctypes.byref(buf)) return buf.value
[ "def", "supported_tifs", "(", "self", ")", ":", "buf", "=", "ctypes", ".", "c_uint32", "(", ")", "self", ".", "_dll", ".", "JLINKARM_TIF_GetAvailable", "(", "ctypes", ".", "byref", "(", "buf", ")", ")", "return", "buf", ".", "value" ]
Returns a bitmask of the supported target interfaces. Args: self (JLink): the ``JLink`` instance Returns: Bitfield specifying which target interfaces are supported.
[ "Returns", "a", "bitmask", "of", "the", "supported", "target", "interfaces", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1488-L1499
236,056
square/pylink
pylink/jlink.py
JLink.set_tif
def set_tif(self, interface): """Selects the specified target interface. Note that a restart must be triggered for this to take effect. Args: self (Jlink): the ``JLink`` instance interface (int): integer identifier of the interface Returns: ``True`` if target was updated, otherwise ``False``. Raises: JLinkException: if the given interface is invalid or unsupported. """ if not ((1 << interface) & self.supported_tifs()): raise errors.JLinkException('Unsupported target interface: %s' % interface) # The return code here is actually *NOT* the previous set interface, it # is ``0`` on success, otherwise ``1``. res = self._dll.JLINKARM_TIF_Select(interface) if res != 0: return False self._tif = interface return True
python
def set_tif(self, interface): """Selects the specified target interface. Note that a restart must be triggered for this to take effect. Args: self (Jlink): the ``JLink`` instance interface (int): integer identifier of the interface Returns: ``True`` if target was updated, otherwise ``False``. Raises: JLinkException: if the given interface is invalid or unsupported. """ if not ((1 << interface) & self.supported_tifs()): raise errors.JLinkException('Unsupported target interface: %s' % interface) # The return code here is actually *NOT* the previous set interface, it # is ``0`` on success, otherwise ``1``. res = self._dll.JLINKARM_TIF_Select(interface) if res != 0: return False self._tif = interface return True
[ "def", "set_tif", "(", "self", ",", "interface", ")", ":", "if", "not", "(", "(", "1", "<<", "interface", ")", "&", "self", ".", "supported_tifs", "(", ")", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'Unsupported target interface: %s'", "%", "interface", ")", "# The return code here is actually *NOT* the previous set interface, it", "# is ``0`` on success, otherwise ``1``.", "res", "=", "self", ".", "_dll", ".", "JLINKARM_TIF_Select", "(", "interface", ")", "if", "res", "!=", "0", ":", "return", "False", "self", ".", "_tif", "=", "interface", "return", "True" ]
Selects the specified target interface. Note that a restart must be triggered for this to take effect. Args: self (Jlink): the ``JLink`` instance interface (int): integer identifier of the interface Returns: ``True`` if target was updated, otherwise ``False``. Raises: JLinkException: if the given interface is invalid or unsupported.
[ "Selects", "the", "specified", "target", "interface", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1502-L1527
236,057
square/pylink
pylink/jlink.py
JLink.gpio_properties
def gpio_properties(self): """Returns the properties of the user-controllable GPIOs. Provided the device supports user-controllable GPIOs, they will be returned by this method. Args: self (JLink): the ``JLink`` instance Returns: A list of ``JLinkGPIODescriptor`` instances totalling the number of requested properties. Raises: JLinkException: on error. """ res = self._dll.JLINK_EMU_GPIO_GetProps(0, 0) if res < 0: raise errors.JLinkException(res) num_props = res buf = (structs.JLinkGPIODescriptor * num_props)() res = self._dll.JLINK_EMU_GPIO_GetProps(ctypes.byref(buf), num_props) if res < 0: raise errors.JLinkException(res) return list(buf)
python
def gpio_properties(self): """Returns the properties of the user-controllable GPIOs. Provided the device supports user-controllable GPIOs, they will be returned by this method. Args: self (JLink): the ``JLink`` instance Returns: A list of ``JLinkGPIODescriptor`` instances totalling the number of requested properties. Raises: JLinkException: on error. """ res = self._dll.JLINK_EMU_GPIO_GetProps(0, 0) if res < 0: raise errors.JLinkException(res) num_props = res buf = (structs.JLinkGPIODescriptor * num_props)() res = self._dll.JLINK_EMU_GPIO_GetProps(ctypes.byref(buf), num_props) if res < 0: raise errors.JLinkException(res) return list(buf)
[ "def", "gpio_properties", "(", "self", ")", ":", "res", "=", "self", ".", "_dll", ".", "JLINK_EMU_GPIO_GetProps", "(", "0", ",", "0", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "num_props", "=", "res", "buf", "=", "(", "structs", ".", "JLinkGPIODescriptor", "*", "num_props", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINK_EMU_GPIO_GetProps", "(", "ctypes", ".", "byref", "(", "buf", ")", ",", "num_props", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "list", "(", "buf", ")" ]
Returns the properties of the user-controllable GPIOs. Provided the device supports user-controllable GPIOs, they will be returned by this method. Args: self (JLink): the ``JLink`` instance Returns: A list of ``JLinkGPIODescriptor`` instances totalling the number of requested properties. Raises: JLinkException: on error.
[ "Returns", "the", "properties", "of", "the", "user", "-", "controllable", "GPIOs", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1530-L1556
236,058
square/pylink
pylink/jlink.py
JLink.gpio_get
def gpio_get(self, pins=None): """Returns a list of states for the given pins. Defaults to the first four pins if an argument is not given. Args: self (JLink): the ``JLink`` instance pins (list): indices of the GPIO pins whose states are requested Returns: A list of states. Raises: JLinkException: on error. """ if pins is None: pins = range(4) size = len(pins) indices = (ctypes.c_uint8 * size)(*pins) statuses = (ctypes.c_uint8 * size)() result = self._dll.JLINK_EMU_GPIO_GetState(ctypes.byref(indices), ctypes.byref(statuses), size) if result < 0: raise errors.JLinkException(result) return list(statuses)
python
def gpio_get(self, pins=None): """Returns a list of states for the given pins. Defaults to the first four pins if an argument is not given. Args: self (JLink): the ``JLink`` instance pins (list): indices of the GPIO pins whose states are requested Returns: A list of states. Raises: JLinkException: on error. """ if pins is None: pins = range(4) size = len(pins) indices = (ctypes.c_uint8 * size)(*pins) statuses = (ctypes.c_uint8 * size)() result = self._dll.JLINK_EMU_GPIO_GetState(ctypes.byref(indices), ctypes.byref(statuses), size) if result < 0: raise errors.JLinkException(result) return list(statuses)
[ "def", "gpio_get", "(", "self", ",", "pins", "=", "None", ")", ":", "if", "pins", "is", "None", ":", "pins", "=", "range", "(", "4", ")", "size", "=", "len", "(", "pins", ")", "indices", "=", "(", "ctypes", ".", "c_uint8", "*", "size", ")", "(", "*", "pins", ")", "statuses", "=", "(", "ctypes", ".", "c_uint8", "*", "size", ")", "(", ")", "result", "=", "self", ".", "_dll", ".", "JLINK_EMU_GPIO_GetState", "(", "ctypes", ".", "byref", "(", "indices", ")", ",", "ctypes", ".", "byref", "(", "statuses", ")", ",", "size", ")", "if", "result", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "result", ")", "return", "list", "(", "statuses", ")" ]
Returns a list of states for the given pins. Defaults to the first four pins if an argument is not given. Args: self (JLink): the ``JLink`` instance pins (list): indices of the GPIO pins whose states are requested Returns: A list of states. Raises: JLinkException: on error.
[ "Returns", "a", "list", "of", "states", "for", "the", "given", "pins", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1559-L1586
236,059
square/pylink
pylink/jlink.py
JLink.gpio_set
def gpio_set(self, pins, states): """Sets the state for one or more user-controllable GPIOs. For each of the given pins, sets the the corresponding state based on the index. Args: self (JLink): the ``JLink`` instance pins (list): list of GPIO indices states (list): list of states to set Returns: A list of updated states. Raises: JLinkException: on error. ValueError: if ``len(pins) != len(states)`` """ if len(pins) != len(states): raise ValueError('Length mismatch between pins and states.') size = len(pins) indices = (ctypes.c_uint8 * size)(*pins) states = (ctypes.c_uint8 * size)(*states) result_states = (ctypes.c_uint8 * size)() result = self._dll.JLINK_EMU_GPIO_SetState(ctypes.byref(indices), ctypes.byref(states), ctypes.byref(result_states), size) if result < 0: raise errors.JLinkException(result) return list(result_states)
python
def gpio_set(self, pins, states): """Sets the state for one or more user-controllable GPIOs. For each of the given pins, sets the the corresponding state based on the index. Args: self (JLink): the ``JLink`` instance pins (list): list of GPIO indices states (list): list of states to set Returns: A list of updated states. Raises: JLinkException: on error. ValueError: if ``len(pins) != len(states)`` """ if len(pins) != len(states): raise ValueError('Length mismatch between pins and states.') size = len(pins) indices = (ctypes.c_uint8 * size)(*pins) states = (ctypes.c_uint8 * size)(*states) result_states = (ctypes.c_uint8 * size)() result = self._dll.JLINK_EMU_GPIO_SetState(ctypes.byref(indices), ctypes.byref(states), ctypes.byref(result_states), size) if result < 0: raise errors.JLinkException(result) return list(result_states)
[ "def", "gpio_set", "(", "self", ",", "pins", ",", "states", ")", ":", "if", "len", "(", "pins", ")", "!=", "len", "(", "states", ")", ":", "raise", "ValueError", "(", "'Length mismatch between pins and states.'", ")", "size", "=", "len", "(", "pins", ")", "indices", "=", "(", "ctypes", ".", "c_uint8", "*", "size", ")", "(", "*", "pins", ")", "states", "=", "(", "ctypes", ".", "c_uint8", "*", "size", ")", "(", "*", "states", ")", "result_states", "=", "(", "ctypes", ".", "c_uint8", "*", "size", ")", "(", ")", "result", "=", "self", ".", "_dll", ".", "JLINK_EMU_GPIO_SetState", "(", "ctypes", ".", "byref", "(", "indices", ")", ",", "ctypes", ".", "byref", "(", "states", ")", ",", "ctypes", ".", "byref", "(", "result_states", ")", ",", "size", ")", "if", "result", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "result", ")", "return", "list", "(", "result_states", ")" ]
Sets the state for one or more user-controllable GPIOs. For each of the given pins, sets the the corresponding state based on the index. Args: self (JLink): the ``JLink`` instance pins (list): list of GPIO indices states (list): list of states to set Returns: A list of updated states. Raises: JLinkException: on error. ValueError: if ``len(pins) != len(states)``
[ "Sets", "the", "state", "for", "one", "or", "more", "user", "-", "controllable", "GPIOs", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1589-L1621
236,060
square/pylink
pylink/jlink.py
JLink.unlock
def unlock(self): """Unlocks the device connected to the J-Link. Unlocking a device allows for access to read/writing memory, as well as flash programming. Note: Unlock is not supported on all devices. Supported Devices: Kinetis Returns: ``True``. Raises: JLinkException: if the device fails to unlock. """ if not unlockers.unlock(self, self._device.manufacturer): raise errors.JLinkException('Failed to unlock device.') return True
python
def unlock(self): """Unlocks the device connected to the J-Link. Unlocking a device allows for access to read/writing memory, as well as flash programming. Note: Unlock is not supported on all devices. Supported Devices: Kinetis Returns: ``True``. Raises: JLinkException: if the device fails to unlock. """ if not unlockers.unlock(self, self._device.manufacturer): raise errors.JLinkException('Failed to unlock device.') return True
[ "def", "unlock", "(", "self", ")", ":", "if", "not", "unlockers", ".", "unlock", "(", "self", ",", "self", ".", "_device", ".", "manufacturer", ")", ":", "raise", "errors", ".", "JLinkException", "(", "'Failed to unlock device.'", ")", "return", "True" ]
Unlocks the device connected to the J-Link. Unlocking a device allows for access to read/writing memory, as well as flash programming. Note: Unlock is not supported on all devices. Supported Devices: Kinetis Returns: ``True``. Raises: JLinkException: if the device fails to unlock.
[ "Unlocks", "the", "device", "connected", "to", "the", "J", "-", "Link", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1680-L1701
236,061
square/pylink
pylink/jlink.py
JLink.erase
def erase(self): """Erases the flash contents of the device. This erases the flash memory of the target device. If this method fails, the device may be left in an inoperable state. Args: self (JLink): the ``JLink`` instance Returns: Number of bytes erased. """ try: # This has to be in a try-catch, as the device may not be in a # state where it can halt, but we still want to try and erase. if not self.halted(): self.halt() except errors.JLinkException: # Can't halt, so just continue to erasing. pass res = self._dll.JLINK_EraseChip() if res < 0: raise errors.JLinkEraseException(res) return res
python
def erase(self): """Erases the flash contents of the device. This erases the flash memory of the target device. If this method fails, the device may be left in an inoperable state. Args: self (JLink): the ``JLink`` instance Returns: Number of bytes erased. """ try: # This has to be in a try-catch, as the device may not be in a # state where it can halt, but we still want to try and erase. if not self.halted(): self.halt() except errors.JLinkException: # Can't halt, so just continue to erasing. pass res = self._dll.JLINK_EraseChip() if res < 0: raise errors.JLinkEraseException(res) return res
[ "def", "erase", "(", "self", ")", ":", "try", ":", "# This has to be in a try-catch, as the device may not be in a", "# state where it can halt, but we still want to try and erase.", "if", "not", "self", ".", "halted", "(", ")", ":", "self", ".", "halt", "(", ")", "except", "errors", ".", "JLinkException", ":", "# Can't halt, so just continue to erasing.", "pass", "res", "=", "self", ".", "_dll", ".", "JLINK_EraseChip", "(", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkEraseException", "(", "res", ")", "return", "res" ]
Erases the flash contents of the device. This erases the flash memory of the target device. If this method fails, the device may be left in an inoperable state. Args: self (JLink): the ``JLink`` instance Returns: Number of bytes erased.
[ "Erases", "the", "flash", "contents", "of", "the", "device", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1920-L1945
236,062
square/pylink
pylink/jlink.py
JLink.reset
def reset(self, ms=0, halt=True): """Resets the target. This method resets the target, and by default toggles the RESET and TRST pins. Args: self (JLink): the ``JLink`` instance ms (int): Amount of milliseconds to delay after reset (default: 0) halt (bool): if the CPU should halt after reset (default: True) Returns: Number of bytes read. """ self._dll.JLINKARM_SetResetDelay(ms) res = self._dll.JLINKARM_Reset() if res < 0: raise errors.JLinkException(res) elif not halt: self._dll.JLINKARM_Go() return res
python
def reset(self, ms=0, halt=True): """Resets the target. This method resets the target, and by default toggles the RESET and TRST pins. Args: self (JLink): the ``JLink`` instance ms (int): Amount of milliseconds to delay after reset (default: 0) halt (bool): if the CPU should halt after reset (default: True) Returns: Number of bytes read. """ self._dll.JLINKARM_SetResetDelay(ms) res = self._dll.JLINKARM_Reset() if res < 0: raise errors.JLinkException(res) elif not halt: self._dll.JLINKARM_Go() return res
[ "def", "reset", "(", "self", ",", "ms", "=", "0", ",", "halt", "=", "True", ")", ":", "self", ".", "_dll", ".", "JLINKARM_SetResetDelay", "(", "ms", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_Reset", "(", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "elif", "not", "halt", ":", "self", ".", "_dll", ".", "JLINKARM_Go", "(", ")", "return", "res" ]
Resets the target. This method resets the target, and by default toggles the RESET and TRST pins. Args: self (JLink): the ``JLink`` instance ms (int): Amount of milliseconds to delay after reset (default: 0) halt (bool): if the CPU should halt after reset (default: True) Returns: Number of bytes read.
[ "Resets", "the", "target", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2046-L2068
236,063
square/pylink
pylink/jlink.py
JLink.halt
def halt(self): """Halts the CPU Core. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if halted, ``False`` otherwise. """ res = int(self._dll.JLINKARM_Halt()) if res == 0: time.sleep(1) return True return False
python
def halt(self): """Halts the CPU Core. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if halted, ``False`` otherwise. """ res = int(self._dll.JLINKARM_Halt()) if res == 0: time.sleep(1) return True return False
[ "def", "halt", "(", "self", ")", ":", "res", "=", "int", "(", "self", ".", "_dll", ".", "JLINKARM_Halt", "(", ")", ")", "if", "res", "==", "0", ":", "time", ".", "sleep", "(", "1", ")", "return", "True", "return", "False" ]
Halts the CPU Core. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if halted, ``False`` otherwise.
[ "Halts", "the", "CPU", "Core", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2121-L2134
236,064
square/pylink
pylink/jlink.py
JLink.halted
def halted(self): """Returns whether the CPU core was halted. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if the CPU core is halted, otherwise ``False``. Raises: JLinkException: on device errors. """ result = int(self._dll.JLINKARM_IsHalted()) if result < 0: raise errors.JLinkException(result) return (result > 0)
python
def halted(self): """Returns whether the CPU core was halted. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if the CPU core is halted, otherwise ``False``. Raises: JLinkException: on device errors. """ result = int(self._dll.JLINKARM_IsHalted()) if result < 0: raise errors.JLinkException(result) return (result > 0)
[ "def", "halted", "(", "self", ")", ":", "result", "=", "int", "(", "self", ".", "_dll", ".", "JLINKARM_IsHalted", "(", ")", ")", "if", "result", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "result", ")", "return", "(", "result", ">", "0", ")" ]
Returns whether the CPU core was halted. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if the CPU core is halted, otherwise ``False``. Raises: JLinkException: on device errors.
[ "Returns", "whether", "the", "CPU", "core", "was", "halted", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2137-L2153
236,065
square/pylink
pylink/jlink.py
JLink.core_name
def core_name(self): """Returns the name of the target ARM core. Args: self (JLink): the ``JLink`` instance Returns: The target core's name. """ buf_size = self.MAX_BUF_SIZE buf = (ctypes.c_char * buf_size)() self._dll.JLINKARM_Core2CoreName(self.core_cpu(), buf, buf_size) return ctypes.string_at(buf).decode()
python
def core_name(self): """Returns the name of the target ARM core. Args: self (JLink): the ``JLink`` instance Returns: The target core's name. """ buf_size = self.MAX_BUF_SIZE buf = (ctypes.c_char * buf_size)() self._dll.JLINKARM_Core2CoreName(self.core_cpu(), buf, buf_size) return ctypes.string_at(buf).decode()
[ "def", "core_name", "(", "self", ")", ":", "buf_size", "=", "self", ".", "MAX_BUF_SIZE", "buf", "=", "(", "ctypes", ".", "c_char", "*", "buf_size", ")", "(", ")", "self", ".", "_dll", ".", "JLINKARM_Core2CoreName", "(", "self", ".", "core_cpu", "(", ")", ",", "buf", ",", "buf_size", ")", "return", "ctypes", ".", "string_at", "(", "buf", ")", ".", "decode", "(", ")" ]
Returns the name of the target ARM core. Args: self (JLink): the ``JLink`` instance Returns: The target core's name.
[ "Returns", "the", "name", "of", "the", "target", "ARM", "core", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2184-L2196
236,066
square/pylink
pylink/jlink.py
JLink.scan_chain_len
def scan_chain_len(self, scan_chain): """Retrieves and returns the number of bits in the scan chain. Args: self (JLink): the ``JLink`` instance scan_chain (int): scan chain to be measured Returns: Number of bits in the specified scan chain. Raises: JLinkException: on error. """ res = self._dll.JLINKARM_MeasureSCLen(scan_chain) if res < 0: raise errors.JLinkException(res) return res
python
def scan_chain_len(self, scan_chain): """Retrieves and returns the number of bits in the scan chain. Args: self (JLink): the ``JLink`` instance scan_chain (int): scan chain to be measured Returns: Number of bits in the specified scan chain. Raises: JLinkException: on error. """ res = self._dll.JLINKARM_MeasureSCLen(scan_chain) if res < 0: raise errors.JLinkException(res) return res
[ "def", "scan_chain_len", "(", "self", ",", "scan_chain", ")", ":", "res", "=", "self", ".", "_dll", ".", "JLINKARM_MeasureSCLen", "(", "scan_chain", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "res" ]
Retrieves and returns the number of bits in the scan chain. Args: self (JLink): the ``JLink`` instance scan_chain (int): scan chain to be measured Returns: Number of bits in the specified scan chain. Raises: JLinkException: on error.
[ "Retrieves", "and", "returns", "the", "number", "of", "bits", "in", "the", "scan", "chain", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2224-L2240
236,067
square/pylink
pylink/jlink.py
JLink.register_list
def register_list(self): """Returns a list of the indices for the CPU registers. The returned indices can be used to read the register content or grab the register name. Args: self (JLink): the ``JLink`` instance Returns: List of registers. """ num_items = self.MAX_NUM_CPU_REGISTERS buf = (ctypes.c_uint32 * num_items)() num_regs = self._dll.JLINKARM_GetRegisterList(buf, num_items) return buf[:num_regs]
python
def register_list(self): """Returns a list of the indices for the CPU registers. The returned indices can be used to read the register content or grab the register name. Args: self (JLink): the ``JLink`` instance Returns: List of registers. """ num_items = self.MAX_NUM_CPU_REGISTERS buf = (ctypes.c_uint32 * num_items)() num_regs = self._dll.JLINKARM_GetRegisterList(buf, num_items) return buf[:num_regs]
[ "def", "register_list", "(", "self", ")", ":", "num_items", "=", "self", ".", "MAX_NUM_CPU_REGISTERS", "buf", "=", "(", "ctypes", ".", "c_uint32", "*", "num_items", ")", "(", ")", "num_regs", "=", "self", ".", "_dll", ".", "JLINKARM_GetRegisterList", "(", "buf", ",", "num_items", ")", "return", "buf", "[", ":", "num_regs", "]" ]
Returns a list of the indices for the CPU registers. The returned indices can be used to read the register content or grab the register name. Args: self (JLink): the ``JLink`` instance Returns: List of registers.
[ "Returns", "a", "list", "of", "the", "indices", "for", "the", "CPU", "registers", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2255-L2270
236,068
square/pylink
pylink/jlink.py
JLink.register_name
def register_name(self, register_index): """Retrives and returns the name of an ARM CPU register. Args: self (JLink): the ``JLink`` instance register_index (int): index of the register whose name to retrieve Returns: Name of the register. """ result = self._dll.JLINKARM_GetRegisterName(register_index) return ctypes.cast(result, ctypes.c_char_p).value.decode()
python
def register_name(self, register_index): """Retrives and returns the name of an ARM CPU register. Args: self (JLink): the ``JLink`` instance register_index (int): index of the register whose name to retrieve Returns: Name of the register. """ result = self._dll.JLINKARM_GetRegisterName(register_index) return ctypes.cast(result, ctypes.c_char_p).value.decode()
[ "def", "register_name", "(", "self", ",", "register_index", ")", ":", "result", "=", "self", ".", "_dll", ".", "JLINKARM_GetRegisterName", "(", "register_index", ")", "return", "ctypes", ".", "cast", "(", "result", ",", "ctypes", ".", "c_char_p", ")", ".", "value", ".", "decode", "(", ")" ]
Retrives and returns the name of an ARM CPU register. Args: self (JLink): the ``JLink`` instance register_index (int): index of the register whose name to retrieve Returns: Name of the register.
[ "Retrives", "and", "returns", "the", "name", "of", "an", "ARM", "CPU", "register", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2273-L2284
236,069
square/pylink
pylink/jlink.py
JLink.cpu_speed
def cpu_speed(self, silent=False): """Retrieves the CPU speed of the target. If the target does not support CPU frequency detection, this function will return ``0``. Args: self (JLink): the ``JLink`` instance silent (bool): ``True`` if the CPU detection should not report errors to the error handler on failure. Returns: The measured CPU frequency on success, otherwise ``0`` if the core does not support CPU frequency detection. Raises: JLinkException: on hardware error. """ res = self._dll.JLINKARM_MeasureCPUSpeedEx(-1, 1, int(silent)) if res < 0: raise errors.JLinkException(res) return res
python
def cpu_speed(self, silent=False): """Retrieves the CPU speed of the target. If the target does not support CPU frequency detection, this function will return ``0``. Args: self (JLink): the ``JLink`` instance silent (bool): ``True`` if the CPU detection should not report errors to the error handler on failure. Returns: The measured CPU frequency on success, otherwise ``0`` if the core does not support CPU frequency detection. Raises: JLinkException: on hardware error. """ res = self._dll.JLINKARM_MeasureCPUSpeedEx(-1, 1, int(silent)) if res < 0: raise errors.JLinkException(res) return res
[ "def", "cpu_speed", "(", "self", ",", "silent", "=", "False", ")", ":", "res", "=", "self", ".", "_dll", ".", "JLINKARM_MeasureCPUSpeedEx", "(", "-", "1", ",", "1", ",", "int", "(", "silent", ")", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "res" ]
Retrieves the CPU speed of the target. If the target does not support CPU frequency detection, this function will return ``0``. Args: self (JLink): the ``JLink`` instance silent (bool): ``True`` if the CPU detection should not report errors to the error handler on failure. Returns: The measured CPU frequency on success, otherwise ``0`` if the core does not support CPU frequency detection. Raises: JLinkException: on hardware error.
[ "Retrieves", "the", "CPU", "speed", "of", "the", "target", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2287-L2308
236,070
square/pylink
pylink/jlink.py
JLink.cpu_halt_reasons
def cpu_halt_reasons(self): """Retrives the reasons that the CPU was halted. Args: self (JLink): the ``JLink`` instance Returns: A list of ``JLInkMOEInfo`` instances specifying the reasons for which the CPU was halted. This list may be empty in the case that the CPU is not halted. Raises: JLinkException: on hardware error. """ buf_size = self.MAX_NUM_MOES buf = (structs.JLinkMOEInfo * buf_size)() num_reasons = self._dll.JLINKARM_GetMOEs(buf, buf_size) if num_reasons < 0: raise errors.JLinkException(num_reasons) return list(buf)[:num_reasons]
python
def cpu_halt_reasons(self): """Retrives the reasons that the CPU was halted. Args: self (JLink): the ``JLink`` instance Returns: A list of ``JLInkMOEInfo`` instances specifying the reasons for which the CPU was halted. This list may be empty in the case that the CPU is not halted. Raises: JLinkException: on hardware error. """ buf_size = self.MAX_NUM_MOES buf = (structs.JLinkMOEInfo * buf_size)() num_reasons = self._dll.JLINKARM_GetMOEs(buf, buf_size) if num_reasons < 0: raise errors.JLinkException(num_reasons) return list(buf)[:num_reasons]
[ "def", "cpu_halt_reasons", "(", "self", ")", ":", "buf_size", "=", "self", ".", "MAX_NUM_MOES", "buf", "=", "(", "structs", ".", "JLinkMOEInfo", "*", "buf_size", ")", "(", ")", "num_reasons", "=", "self", ".", "_dll", ".", "JLINKARM_GetMOEs", "(", "buf", ",", "buf_size", ")", "if", "num_reasons", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "num_reasons", ")", "return", "list", "(", "buf", ")", "[", ":", "num_reasons", "]" ]
Retrives the reasons that the CPU was halted. Args: self (JLink): the ``JLink`` instance Returns: A list of ``JLInkMOEInfo`` instances specifying the reasons for which the CPU was halted. This list may be empty in the case that the CPU is not halted. Raises: JLinkException: on hardware error.
[ "Retrives", "the", "reasons", "that", "the", "CPU", "was", "halted", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2311-L2331
236,071
square/pylink
pylink/jlink.py
JLink.jtag_send
def jtag_send(self, tms, tdi, num_bits): """Sends data via JTAG. Sends data via JTAG on the rising clock edge, TCK. At on each rising clock edge, on bit is transferred in from TDI and out to TDO. The clock uses the TMS to step through the standard JTAG state machine. Args: self (JLink): the ``JLink`` instance tms (int): used to determine the state transitions for the Test Access Port (TAP) controller from its current state tdi (int): input data to be transferred in from TDI to TDO num_bits (int): a number in the range ``[1, 32]`` inclusively specifying the number of meaningful bits in the ``tms`` and ``tdi`` parameters for the purpose of extracting state and data information Returns: ``None`` Raises: ValueError: if ``num_bits < 1`` or ``num_bits > 32``. See Also: `JTAG Technical Overview <https://www.xjtag.com/about-jtag/jtag-a-technical-overview>`_. """ if not util.is_natural(num_bits) or num_bits <= 0 or num_bits > 32: raise ValueError('Number of bits must be >= 1 and <= 32.') self._dll.JLINKARM_StoreBits(tms, tdi, num_bits) return None
python
def jtag_send(self, tms, tdi, num_bits): """Sends data via JTAG. Sends data via JTAG on the rising clock edge, TCK. At on each rising clock edge, on bit is transferred in from TDI and out to TDO. The clock uses the TMS to step through the standard JTAG state machine. Args: self (JLink): the ``JLink`` instance tms (int): used to determine the state transitions for the Test Access Port (TAP) controller from its current state tdi (int): input data to be transferred in from TDI to TDO num_bits (int): a number in the range ``[1, 32]`` inclusively specifying the number of meaningful bits in the ``tms`` and ``tdi`` parameters for the purpose of extracting state and data information Returns: ``None`` Raises: ValueError: if ``num_bits < 1`` or ``num_bits > 32``. See Also: `JTAG Technical Overview <https://www.xjtag.com/about-jtag/jtag-a-technical-overview>`_. """ if not util.is_natural(num_bits) or num_bits <= 0 or num_bits > 32: raise ValueError('Number of bits must be >= 1 and <= 32.') self._dll.JLINKARM_StoreBits(tms, tdi, num_bits) return None
[ "def", "jtag_send", "(", "self", ",", "tms", ",", "tdi", ",", "num_bits", ")", ":", "if", "not", "util", ".", "is_natural", "(", "num_bits", ")", "or", "num_bits", "<=", "0", "or", "num_bits", ">", "32", ":", "raise", "ValueError", "(", "'Number of bits must be >= 1 and <= 32.'", ")", "self", ".", "_dll", ".", "JLINKARM_StoreBits", "(", "tms", ",", "tdi", ",", "num_bits", ")", "return", "None" ]
Sends data via JTAG. Sends data via JTAG on the rising clock edge, TCK. At on each rising clock edge, on bit is transferred in from TDI and out to TDO. The clock uses the TMS to step through the standard JTAG state machine. Args: self (JLink): the ``JLink`` instance tms (int): used to determine the state transitions for the Test Access Port (TAP) controller from its current state tdi (int): input data to be transferred in from TDI to TDO num_bits (int): a number in the range ``[1, 32]`` inclusively specifying the number of meaningful bits in the ``tms`` and ``tdi`` parameters for the purpose of extracting state and data information Returns: ``None`` Raises: ValueError: if ``num_bits < 1`` or ``num_bits > 32``. See Also: `JTAG Technical Overview <https://www.xjtag.com/about-jtag/jtag-a-technical-overview>`_.
[ "Sends", "data", "via", "JTAG", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2349-L2378
236,072
square/pylink
pylink/jlink.py
JLink.swd_read8
def swd_read8(self, offset): """Gets a unit of ``8`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer. """ value = self._dll.JLINK_SWD_GetU8(offset) return ctypes.c_uint8(value).value
python
def swd_read8(self, offset): """Gets a unit of ``8`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer. """ value = self._dll.JLINK_SWD_GetU8(offset) return ctypes.c_uint8(value).value
[ "def", "swd_read8", "(", "self", ",", "offset", ")", ":", "value", "=", "self", ".", "_dll", ".", "JLINK_SWD_GetU8", "(", "offset", ")", "return", "ctypes", ".", "c_uint8", "(", "value", ")", ".", "value" ]
Gets a unit of ``8`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer.
[ "Gets", "a", "unit", "of", "8", "bits", "from", "the", "input", "buffer", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2399-L2410
236,073
square/pylink
pylink/jlink.py
JLink.swd_read16
def swd_read16(self, offset): """Gets a unit of ``16`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer. """ value = self._dll.JLINK_SWD_GetU16(offset) return ctypes.c_uint16(value).value
python
def swd_read16(self, offset): """Gets a unit of ``16`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer. """ value = self._dll.JLINK_SWD_GetU16(offset) return ctypes.c_uint16(value).value
[ "def", "swd_read16", "(", "self", ",", "offset", ")", ":", "value", "=", "self", ".", "_dll", ".", "JLINK_SWD_GetU16", "(", "offset", ")", "return", "ctypes", ".", "c_uint16", "(", "value", ")", ".", "value" ]
Gets a unit of ``16`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer.
[ "Gets", "a", "unit", "of", "16", "bits", "from", "the", "input", "buffer", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2414-L2425
236,074
square/pylink
pylink/jlink.py
JLink.swd_read32
def swd_read32(self, offset): """Gets a unit of ``32`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer. """ value = self._dll.JLINK_SWD_GetU32(offset) return ctypes.c_uint32(value).value
python
def swd_read32(self, offset): """Gets a unit of ``32`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer. """ value = self._dll.JLINK_SWD_GetU32(offset) return ctypes.c_uint32(value).value
[ "def", "swd_read32", "(", "self", ",", "offset", ")", ":", "value", "=", "self", ".", "_dll", ".", "JLINK_SWD_GetU32", "(", "offset", ")", "return", "ctypes", ".", "c_uint32", "(", "value", ")", ".", "value" ]
Gets a unit of ``32`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer.
[ "Gets", "a", "unit", "of", "32", "bits", "from", "the", "input", "buffer", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2429-L2440
236,075
square/pylink
pylink/jlink.py
JLink.swd_sync
def swd_sync(self, pad=False): """Causes a flush to write all data remaining in output buffers to SWD device. Args: self (JLink): the ``JLink`` instance pad (bool): ``True`` if should pad the data to full byte size Returns: ``None`` """ if pad: self._dll.JLINK_SWD_SyncBytes() else: self._dll.JLINK_SWD_SyncBits() return None
python
def swd_sync(self, pad=False): """Causes a flush to write all data remaining in output buffers to SWD device. Args: self (JLink): the ``JLink`` instance pad (bool): ``True`` if should pad the data to full byte size Returns: ``None`` """ if pad: self._dll.JLINK_SWD_SyncBytes() else: self._dll.JLINK_SWD_SyncBits() return None
[ "def", "swd_sync", "(", "self", ",", "pad", "=", "False", ")", ":", "if", "pad", ":", "self", ".", "_dll", ".", "JLINK_SWD_SyncBytes", "(", ")", "else", ":", "self", ".", "_dll", ".", "JLINK_SWD_SyncBits", "(", ")", "return", "None" ]
Causes a flush to write all data remaining in output buffers to SWD device. Args: self (JLink): the ``JLink`` instance pad (bool): ``True`` if should pad the data to full byte size Returns: ``None``
[ "Causes", "a", "flush", "to", "write", "all", "data", "remaining", "in", "output", "buffers", "to", "SWD", "device", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2512-L2527
236,076
square/pylink
pylink/jlink.py
JLink.flash_write
def flash_write(self, addr, data, nbits=None, flags=0): """Writes data to the flash region of a device. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. Args: self (JLink): the ``JLink`` instance addr (int): starting flash address to write to data (list): list of data units to write nbits (int): number of bits to use for each unit Returns: Number of bytes written to flash. """ # This indicates that all data written from this point on will go into # the buffer of the flashloader of the DLL. self._dll.JLINKARM_BeginDownload(flags) self.memory_write(addr, data, nbits=nbits) # Start downloading the data into the flash memory. bytes_flashed = self._dll.JLINKARM_EndDownload() if bytes_flashed < 0: raise errors.JLinkFlashException(bytes_flashed) return bytes_flashed
python
def flash_write(self, addr, data, nbits=None, flags=0): """Writes data to the flash region of a device. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. Args: self (JLink): the ``JLink`` instance addr (int): starting flash address to write to data (list): list of data units to write nbits (int): number of bits to use for each unit Returns: Number of bytes written to flash. """ # This indicates that all data written from this point on will go into # the buffer of the flashloader of the DLL. self._dll.JLINKARM_BeginDownload(flags) self.memory_write(addr, data, nbits=nbits) # Start downloading the data into the flash memory. bytes_flashed = self._dll.JLINKARM_EndDownload() if bytes_flashed < 0: raise errors.JLinkFlashException(bytes_flashed) return bytes_flashed
[ "def", "flash_write", "(", "self", ",", "addr", ",", "data", ",", "nbits", "=", "None", ",", "flags", "=", "0", ")", ":", "# This indicates that all data written from this point on will go into", "# the buffer of the flashloader of the DLL.", "self", ".", "_dll", ".", "JLINKARM_BeginDownload", "(", "flags", ")", "self", ".", "memory_write", "(", "addr", ",", "data", ",", "nbits", "=", "nbits", ")", "# Start downloading the data into the flash memory.", "bytes_flashed", "=", "self", ".", "_dll", ".", "JLINKARM_EndDownload", "(", ")", "if", "bytes_flashed", "<", "0", ":", "raise", "errors", ".", "JLinkFlashException", "(", "bytes_flashed", ")", "return", "bytes_flashed" ]
Writes data to the flash region of a device. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. Args: self (JLink): the ``JLink`` instance addr (int): starting flash address to write to data (list): list of data units to write nbits (int): number of bits to use for each unit Returns: Number of bytes written to flash.
[ "Writes", "data", "to", "the", "flash", "region", "of", "a", "device", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2530-L2556
236,077
square/pylink
pylink/jlink.py
JLink.code_memory_read
def code_memory_read(self, addr, num_bytes): """Reads bytes from code memory. Note: This is similar to calling ``memory_read`` or ``memory_read8``, except that this uses a cache and reads ahead. This should be used in instances where you want to read a small amount of bytes at a time, and expect to always read ahead. Args: self (JLink): the ``JLink`` instance addr (int): starting address from which to read num_bytes (int): number of bytes to read Returns: A list of bytes read from the target. Raises: JLinkException: if memory could not be read. """ buf_size = num_bytes buf = (ctypes.c_uint8 * buf_size)() res = self._dll.JLINKARM_ReadCodeMem(addr, buf_size, buf) if res < 0: raise errors.JLinkException(res) return list(buf)[:res]
python
def code_memory_read(self, addr, num_bytes): """Reads bytes from code memory. Note: This is similar to calling ``memory_read`` or ``memory_read8``, except that this uses a cache and reads ahead. This should be used in instances where you want to read a small amount of bytes at a time, and expect to always read ahead. Args: self (JLink): the ``JLink`` instance addr (int): starting address from which to read num_bytes (int): number of bytes to read Returns: A list of bytes read from the target. Raises: JLinkException: if memory could not be read. """ buf_size = num_bytes buf = (ctypes.c_uint8 * buf_size)() res = self._dll.JLINKARM_ReadCodeMem(addr, buf_size, buf) if res < 0: raise errors.JLinkException(res) return list(buf)[:res]
[ "def", "code_memory_read", "(", "self", ",", "addr", ",", "num_bytes", ")", ":", "buf_size", "=", "num_bytes", "buf", "=", "(", "ctypes", ".", "c_uint8", "*", "buf_size", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_ReadCodeMem", "(", "addr", ",", "buf_size", ",", "buf", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "list", "(", "buf", ")", "[", ":", "res", "]" ]
Reads bytes from code memory. Note: This is similar to calling ``memory_read`` or ``memory_read8``, except that this uses a cache and reads ahead. This should be used in instances where you want to read a small amount of bytes at a time, and expect to always read ahead. Args: self (JLink): the ``JLink`` instance addr (int): starting address from which to read num_bytes (int): number of bytes to read Returns: A list of bytes read from the target. Raises: JLinkException: if memory could not be read.
[ "Reads", "bytes", "from", "code", "memory", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2601-L2626
236,078
square/pylink
pylink/jlink.py
JLink.num_memory_zones
def num_memory_zones(self): """Returns the number of memory zones supported by the target. Args: self (JLink): the ``JLink`` instance Returns: An integer count of the number of memory zones supported by the target. Raises: JLinkException: on error. """ count = self._dll.JLINK_GetMemZones(0, 0) if count < 0: raise errors.JLinkException(count) return count
python
def num_memory_zones(self): """Returns the number of memory zones supported by the target. Args: self (JLink): the ``JLink`` instance Returns: An integer count of the number of memory zones supported by the target. Raises: JLinkException: on error. """ count = self._dll.JLINK_GetMemZones(0, 0) if count < 0: raise errors.JLinkException(count) return count
[ "def", "num_memory_zones", "(", "self", ")", ":", "count", "=", "self", ".", "_dll", ".", "JLINK_GetMemZones", "(", "0", ",", "0", ")", "if", "count", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "count", ")", "return", "count" ]
Returns the number of memory zones supported by the target. Args: self (JLink): the ``JLink`` instance Returns: An integer count of the number of memory zones supported by the target. Raises: JLinkException: on error.
[ "Returns", "the", "number", "of", "memory", "zones", "supported", "by", "the", "target", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2629-L2645
236,079
square/pylink
pylink/jlink.py
JLink.memory_zones
def memory_zones(self): """Gets all memory zones supported by the current target. Some targets support multiple memory zones. This function provides the ability to get a list of all the memory zones to facilate using the memory zone routing functions. Args: self (JLink): the ``JLink`` instance Returns: A list of all the memory zones as ``JLinkMemoryZone`` structures. Raises: JLinkException: on hardware errors. """ count = self.num_memory_zones() if count == 0: return list() buf = (structs.JLinkMemoryZone * count)() res = self._dll.JLINK_GetMemZones(buf, count) if res < 0: raise errors.JLinkException(res) return list(buf)
python
def memory_zones(self): """Gets all memory zones supported by the current target. Some targets support multiple memory zones. This function provides the ability to get a list of all the memory zones to facilate using the memory zone routing functions. Args: self (JLink): the ``JLink`` instance Returns: A list of all the memory zones as ``JLinkMemoryZone`` structures. Raises: JLinkException: on hardware errors. """ count = self.num_memory_zones() if count == 0: return list() buf = (structs.JLinkMemoryZone * count)() res = self._dll.JLINK_GetMemZones(buf, count) if res < 0: raise errors.JLinkException(res) return list(buf)
[ "def", "memory_zones", "(", "self", ")", ":", "count", "=", "self", ".", "num_memory_zones", "(", ")", "if", "count", "==", "0", ":", "return", "list", "(", ")", "buf", "=", "(", "structs", ".", "JLinkMemoryZone", "*", "count", ")", "(", ")", "res", "=", "self", ".", "_dll", ".", "JLINK_GetMemZones", "(", "buf", ",", "count", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "list", "(", "buf", ")" ]
Gets all memory zones supported by the current target. Some targets support multiple memory zones. This function provides the ability to get a list of all the memory zones to facilate using the memory zone routing functions. Args: self (JLink): the ``JLink`` instance Returns: A list of all the memory zones as ``JLinkMemoryZone`` structures. Raises: JLinkException: on hardware errors.
[ "Gets", "all", "memory", "zones", "supported", "by", "the", "current", "target", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2648-L2673
236,080
square/pylink
pylink/jlink.py
JLink.memory_read
def memory_read(self, addr, num_units, zone=None, nbits=None): """Reads memory from a target system or specific memory zone. The optional ``zone`` specifies a memory zone to access to read from, e.g. ``IDATA``, ``DDATA``, or ``CODE``. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. If not provided, always reads ``num_units`` bytes. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_units (int): number of units to read zone (str): optional memory zone name to access nbits (int): number of bits to use for each unit Returns: List of units read from the target system. Raises: JLinkException: if memory could not be read. ValueError: if ``nbits`` is not ``None``, and not in ``8``, ``16``, or ``32``. """ buf_size = num_units buf = None access = 0 if nbits is None: buf = (ctypes.c_uint8 * buf_size)() access = 0 elif nbits == 8: buf = (ctypes.c_uint8 * buf_size)() access = 1 elif nbits == 16: buf = (ctypes.c_uint16 * buf_size)() access = 2 buf_size = buf_size * access elif nbits == 32: buf = (ctypes.c_uint32 * buf_size)() access = 4 buf_size = buf_size * access else: raise ValueError('Given bit size is invalid: %s' % nbits) args = [addr, buf_size, buf, access] method = self._dll.JLINKARM_ReadMemEx if zone is not None: method = self._dll.JLINKARM_ReadMemZonedEx args.append(zone.encode()) units_read = method(*args) if units_read < 0: raise errors.JLinkReadException(units_read) return buf[:units_read]
python
def memory_read(self, addr, num_units, zone=None, nbits=None): """Reads memory from a target system or specific memory zone. The optional ``zone`` specifies a memory zone to access to read from, e.g. ``IDATA``, ``DDATA``, or ``CODE``. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. If not provided, always reads ``num_units`` bytes. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_units (int): number of units to read zone (str): optional memory zone name to access nbits (int): number of bits to use for each unit Returns: List of units read from the target system. Raises: JLinkException: if memory could not be read. ValueError: if ``nbits`` is not ``None``, and not in ``8``, ``16``, or ``32``. """ buf_size = num_units buf = None access = 0 if nbits is None: buf = (ctypes.c_uint8 * buf_size)() access = 0 elif nbits == 8: buf = (ctypes.c_uint8 * buf_size)() access = 1 elif nbits == 16: buf = (ctypes.c_uint16 * buf_size)() access = 2 buf_size = buf_size * access elif nbits == 32: buf = (ctypes.c_uint32 * buf_size)() access = 4 buf_size = buf_size * access else: raise ValueError('Given bit size is invalid: %s' % nbits) args = [addr, buf_size, buf, access] method = self._dll.JLINKARM_ReadMemEx if zone is not None: method = self._dll.JLINKARM_ReadMemZonedEx args.append(zone.encode()) units_read = method(*args) if units_read < 0: raise errors.JLinkReadException(units_read) return buf[:units_read]
[ "def", "memory_read", "(", "self", ",", "addr", ",", "num_units", ",", "zone", "=", "None", ",", "nbits", "=", "None", ")", ":", "buf_size", "=", "num_units", "buf", "=", "None", "access", "=", "0", "if", "nbits", "is", "None", ":", "buf", "=", "(", "ctypes", ".", "c_uint8", "*", "buf_size", ")", "(", ")", "access", "=", "0", "elif", "nbits", "==", "8", ":", "buf", "=", "(", "ctypes", ".", "c_uint8", "*", "buf_size", ")", "(", ")", "access", "=", "1", "elif", "nbits", "==", "16", ":", "buf", "=", "(", "ctypes", ".", "c_uint16", "*", "buf_size", ")", "(", ")", "access", "=", "2", "buf_size", "=", "buf_size", "*", "access", "elif", "nbits", "==", "32", ":", "buf", "=", "(", "ctypes", ".", "c_uint32", "*", "buf_size", ")", "(", ")", "access", "=", "4", "buf_size", "=", "buf_size", "*", "access", "else", ":", "raise", "ValueError", "(", "'Given bit size is invalid: %s'", "%", "nbits", ")", "args", "=", "[", "addr", ",", "buf_size", ",", "buf", ",", "access", "]", "method", "=", "self", ".", "_dll", ".", "JLINKARM_ReadMemEx", "if", "zone", "is", "not", "None", ":", "method", "=", "self", ".", "_dll", ".", "JLINKARM_ReadMemZonedEx", "args", ".", "append", "(", "zone", ".", "encode", "(", ")", ")", "units_read", "=", "method", "(", "*", "args", ")", "if", "units_read", "<", "0", ":", "raise", "errors", ".", "JLinkReadException", "(", "units_read", ")", "return", "buf", "[", ":", "units_read", "]" ]
Reads memory from a target system or specific memory zone. The optional ``zone`` specifies a memory zone to access to read from, e.g. ``IDATA``, ``DDATA``, or ``CODE``. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. If not provided, always reads ``num_units`` bytes. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_units (int): number of units to read zone (str): optional memory zone name to access nbits (int): number of bits to use for each unit Returns: List of units read from the target system. Raises: JLinkException: if memory could not be read. ValueError: if ``nbits`` is not ``None``, and not in ``8``, ``16``, or ``32``.
[ "Reads", "memory", "from", "a", "target", "system", "or", "specific", "memory", "zone", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2676-L2732
236,081
square/pylink
pylink/jlink.py
JLink.memory_read8
def memory_read8(self, addr, num_bytes, zone=None): """Reads memory from the target system in units of bytes. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_bytes (int): number of bytes to read zone (str): memory zone to read from Returns: List of bytes read from the target system. Raises: JLinkException: if memory could not be read. """ return self.memory_read(addr, num_bytes, zone=zone, nbits=8)
python
def memory_read8(self, addr, num_bytes, zone=None): """Reads memory from the target system in units of bytes. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_bytes (int): number of bytes to read zone (str): memory zone to read from Returns: List of bytes read from the target system. Raises: JLinkException: if memory could not be read. """ return self.memory_read(addr, num_bytes, zone=zone, nbits=8)
[ "def", "memory_read8", "(", "self", ",", "addr", ",", "num_bytes", ",", "zone", "=", "None", ")", ":", "return", "self", ".", "memory_read", "(", "addr", ",", "num_bytes", ",", "zone", "=", "zone", ",", "nbits", "=", "8", ")" ]
Reads memory from the target system in units of bytes. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_bytes (int): number of bytes to read zone (str): memory zone to read from Returns: List of bytes read from the target system. Raises: JLinkException: if memory could not be read.
[ "Reads", "memory", "from", "the", "target", "system", "in", "units", "of", "bytes", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2735-L2750
236,082
square/pylink
pylink/jlink.py
JLink.memory_read16
def memory_read16(self, addr, num_halfwords, zone=None): """Reads memory from the target system in units of 16-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_halfwords (int): number of half words to read zone (str): memory zone to read from Returns: List of halfwords read from the target system. Raises: JLinkException: if memory could not be read """ return self.memory_read(addr, num_halfwords, zone=zone, nbits=16)
python
def memory_read16(self, addr, num_halfwords, zone=None): """Reads memory from the target system in units of 16-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_halfwords (int): number of half words to read zone (str): memory zone to read from Returns: List of halfwords read from the target system. Raises: JLinkException: if memory could not be read """ return self.memory_read(addr, num_halfwords, zone=zone, nbits=16)
[ "def", "memory_read16", "(", "self", ",", "addr", ",", "num_halfwords", ",", "zone", "=", "None", ")", ":", "return", "self", ".", "memory_read", "(", "addr", ",", "num_halfwords", ",", "zone", "=", "zone", ",", "nbits", "=", "16", ")" ]
Reads memory from the target system in units of 16-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_halfwords (int): number of half words to read zone (str): memory zone to read from Returns: List of halfwords read from the target system. Raises: JLinkException: if memory could not be read
[ "Reads", "memory", "from", "the", "target", "system", "in", "units", "of", "16", "-", "bits", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2753-L2768
236,083
square/pylink
pylink/jlink.py
JLink.memory_read32
def memory_read32(self, addr, num_words, zone=None): """Reads memory from the target system in units of 32-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_words (int): number of words to read zone (str): memory zone to read from Returns: List of words read from the target system. Raises: JLinkException: if memory could not be read """ return self.memory_read(addr, num_words, zone=zone, nbits=32)
python
def memory_read32(self, addr, num_words, zone=None): """Reads memory from the target system in units of 32-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_words (int): number of words to read zone (str): memory zone to read from Returns: List of words read from the target system. Raises: JLinkException: if memory could not be read """ return self.memory_read(addr, num_words, zone=zone, nbits=32)
[ "def", "memory_read32", "(", "self", ",", "addr", ",", "num_words", ",", "zone", "=", "None", ")", ":", "return", "self", ".", "memory_read", "(", "addr", ",", "num_words", ",", "zone", "=", "zone", ",", "nbits", "=", "32", ")" ]
Reads memory from the target system in units of 32-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_words (int): number of words to read zone (str): memory zone to read from Returns: List of words read from the target system. Raises: JLinkException: if memory could not be read
[ "Reads", "memory", "from", "the", "target", "system", "in", "units", "of", "32", "-", "bits", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2771-L2786
236,084
square/pylink
pylink/jlink.py
JLink.memory_read64
def memory_read64(self, addr, num_long_words): """Reads memory from the target system in units of 64-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_long_words (int): number of long words to read Returns: List of long words read from the target system. Raises: JLinkException: if memory could not be read """ buf_size = num_long_words buf = (ctypes.c_ulonglong * buf_size)() units_read = self._dll.JLINKARM_ReadMemU64(addr, buf_size, buf, 0) if units_read < 0: raise errors.JLinkException(units_read) return buf[:units_read]
python
def memory_read64(self, addr, num_long_words): """Reads memory from the target system in units of 64-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_long_words (int): number of long words to read Returns: List of long words read from the target system. Raises: JLinkException: if memory could not be read """ buf_size = num_long_words buf = (ctypes.c_ulonglong * buf_size)() units_read = self._dll.JLINKARM_ReadMemU64(addr, buf_size, buf, 0) if units_read < 0: raise errors.JLinkException(units_read) return buf[:units_read]
[ "def", "memory_read64", "(", "self", ",", "addr", ",", "num_long_words", ")", ":", "buf_size", "=", "num_long_words", "buf", "=", "(", "ctypes", ".", "c_ulonglong", "*", "buf_size", ")", "(", ")", "units_read", "=", "self", ".", "_dll", ".", "JLINKARM_ReadMemU64", "(", "addr", ",", "buf_size", ",", "buf", ",", "0", ")", "if", "units_read", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "units_read", ")", "return", "buf", "[", ":", "units_read", "]" ]
Reads memory from the target system in units of 64-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_long_words (int): number of long words to read Returns: List of long words read from the target system. Raises: JLinkException: if memory could not be read
[ "Reads", "memory", "from", "the", "target", "system", "in", "units", "of", "64", "-", "bits", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2789-L2809
236,085
square/pylink
pylink/jlink.py
JLink.memory_write
def memory_write(self, addr, data, zone=None, nbits=None): """Writes memory to a target system or specific memory zone. The optional ``zone`` specifies a memory zone to access to write to, e.g. ``IDATA``, ``DDATA``, or ``CODE``. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of data units to write zone (str): optional memory zone name to access nbits (int): number of bits to use for each unit Returns: Number of units written. Raises: JLinkException: on write hardware failure. ValueError: if ``nbits`` is not ``None``, and not in ``8``, ``16`` or ``32``. """ buf_size = len(data) buf = None access = 0 if nbits is None: # Pack the given data into an array of 8-bit unsigned integers in # order to write it successfully packed_data = map(lambda d: reversed(binpacker.pack(d)), data) packed_data = list(itertools.chain(*packed_data)) buf_size = len(packed_data) buf = (ctypes.c_uint8 * buf_size)(*packed_data) # Allow the access width to be chosen for us. access = 0 elif nbits == 8: buf = (ctypes.c_uint8 * buf_size)(*data) access = 1 elif nbits == 16: buf = (ctypes.c_uint16 * buf_size)(*data) access = 2 buf_size = buf_size * access elif nbits == 32: buf = (ctypes.c_uint32 * buf_size)(*data) access = 4 buf_size = buf_size * access else: raise ValueError('Given bit size is invalid: %s' % nbits) args = [addr, buf_size, buf, access] method = self._dll.JLINKARM_WriteMemEx if zone is not None: method = self._dll.JLINKARM_WriteMemZonedEx args.append(zone.encode()) units_written = method(*args) if units_written < 0: raise errors.JLinkWriteException(units_written) return units_written
python
def memory_write(self, addr, data, zone=None, nbits=None): """Writes memory to a target system or specific memory zone. The optional ``zone`` specifies a memory zone to access to write to, e.g. ``IDATA``, ``DDATA``, or ``CODE``. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of data units to write zone (str): optional memory zone name to access nbits (int): number of bits to use for each unit Returns: Number of units written. Raises: JLinkException: on write hardware failure. ValueError: if ``nbits`` is not ``None``, and not in ``8``, ``16`` or ``32``. """ buf_size = len(data) buf = None access = 0 if nbits is None: # Pack the given data into an array of 8-bit unsigned integers in # order to write it successfully packed_data = map(lambda d: reversed(binpacker.pack(d)), data) packed_data = list(itertools.chain(*packed_data)) buf_size = len(packed_data) buf = (ctypes.c_uint8 * buf_size)(*packed_data) # Allow the access width to be chosen for us. access = 0 elif nbits == 8: buf = (ctypes.c_uint8 * buf_size)(*data) access = 1 elif nbits == 16: buf = (ctypes.c_uint16 * buf_size)(*data) access = 2 buf_size = buf_size * access elif nbits == 32: buf = (ctypes.c_uint32 * buf_size)(*data) access = 4 buf_size = buf_size * access else: raise ValueError('Given bit size is invalid: %s' % nbits) args = [addr, buf_size, buf, access] method = self._dll.JLINKARM_WriteMemEx if zone is not None: method = self._dll.JLINKARM_WriteMemZonedEx args.append(zone.encode()) units_written = method(*args) if units_written < 0: raise errors.JLinkWriteException(units_written) return units_written
[ "def", "memory_write", "(", "self", ",", "addr", ",", "data", ",", "zone", "=", "None", ",", "nbits", "=", "None", ")", ":", "buf_size", "=", "len", "(", "data", ")", "buf", "=", "None", "access", "=", "0", "if", "nbits", "is", "None", ":", "# Pack the given data into an array of 8-bit unsigned integers in", "# order to write it successfully", "packed_data", "=", "map", "(", "lambda", "d", ":", "reversed", "(", "binpacker", ".", "pack", "(", "d", ")", ")", ",", "data", ")", "packed_data", "=", "list", "(", "itertools", ".", "chain", "(", "*", "packed_data", ")", ")", "buf_size", "=", "len", "(", "packed_data", ")", "buf", "=", "(", "ctypes", ".", "c_uint8", "*", "buf_size", ")", "(", "*", "packed_data", ")", "# Allow the access width to be chosen for us.", "access", "=", "0", "elif", "nbits", "==", "8", ":", "buf", "=", "(", "ctypes", ".", "c_uint8", "*", "buf_size", ")", "(", "*", "data", ")", "access", "=", "1", "elif", "nbits", "==", "16", ":", "buf", "=", "(", "ctypes", ".", "c_uint16", "*", "buf_size", ")", "(", "*", "data", ")", "access", "=", "2", "buf_size", "=", "buf_size", "*", "access", "elif", "nbits", "==", "32", ":", "buf", "=", "(", "ctypes", ".", "c_uint32", "*", "buf_size", ")", "(", "*", "data", ")", "access", "=", "4", "buf_size", "=", "buf_size", "*", "access", "else", ":", "raise", "ValueError", "(", "'Given bit size is invalid: %s'", "%", "nbits", ")", "args", "=", "[", "addr", ",", "buf_size", ",", "buf", ",", "access", "]", "method", "=", "self", ".", "_dll", ".", "JLINKARM_WriteMemEx", "if", "zone", "is", "not", "None", ":", "method", "=", "self", ".", "_dll", ".", "JLINKARM_WriteMemZonedEx", "args", ".", "append", "(", "zone", ".", "encode", "(", ")", ")", "units_written", "=", "method", "(", "*", "args", ")", "if", "units_written", "<", "0", ":", "raise", "errors", ".", "JLinkWriteException", "(", "units_written", ")", "return", "units_written" ]
Writes memory to a target system or specific memory zone. The optional ``zone`` specifies a memory zone to access to write to, e.g. ``IDATA``, ``DDATA``, or ``CODE``. The given number of bits, if provided, must be either ``8``, ``16``, or ``32``. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of data units to write zone (str): optional memory zone name to access nbits (int): number of bits to use for each unit Returns: Number of units written. Raises: JLinkException: on write hardware failure. ValueError: if ``nbits`` is not ``None``, and not in ``8``, ``16`` or ``32``.
[ "Writes", "memory", "to", "a", "target", "system", "or", "specific", "memory", "zone", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2812-L2876
236,086
square/pylink
pylink/jlink.py
JLink.memory_write8
def memory_write8(self, addr, data, zone=None): """Writes bytes to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of bytes to write zone (str): optional memory zone to access Returns: Number of bytes written to target. Raises: JLinkException: on memory access error. """ return self.memory_write(addr, data, zone, 8)
python
def memory_write8(self, addr, data, zone=None): """Writes bytes to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of bytes to write zone (str): optional memory zone to access Returns: Number of bytes written to target. Raises: JLinkException: on memory access error. """ return self.memory_write(addr, data, zone, 8)
[ "def", "memory_write8", "(", "self", ",", "addr", ",", "data", ",", "zone", "=", "None", ")", ":", "return", "self", ".", "memory_write", "(", "addr", ",", "data", ",", "zone", ",", "8", ")" ]
Writes bytes to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of bytes to write zone (str): optional memory zone to access Returns: Number of bytes written to target. Raises: JLinkException: on memory access error.
[ "Writes", "bytes", "to", "memory", "of", "a", "target", "system", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2879-L2894
236,087
square/pylink
pylink/jlink.py
JLink.memory_write16
def memory_write16(self, addr, data, zone=None): """Writes half-words to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of half-words to write zone (str): optional memory zone to access Returns: Number of half-words written to target. Raises: JLinkException: on memory access error. """ return self.memory_write(addr, data, zone, 16)
python
def memory_write16(self, addr, data, zone=None): """Writes half-words to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of half-words to write zone (str): optional memory zone to access Returns: Number of half-words written to target. Raises: JLinkException: on memory access error. """ return self.memory_write(addr, data, zone, 16)
[ "def", "memory_write16", "(", "self", ",", "addr", ",", "data", ",", "zone", "=", "None", ")", ":", "return", "self", ".", "memory_write", "(", "addr", ",", "data", ",", "zone", ",", "16", ")" ]
Writes half-words to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of half-words to write zone (str): optional memory zone to access Returns: Number of half-words written to target. Raises: JLinkException: on memory access error.
[ "Writes", "half", "-", "words", "to", "memory", "of", "a", "target", "system", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2897-L2912
236,088
square/pylink
pylink/jlink.py
JLink.memory_write32
def memory_write32(self, addr, data, zone=None): """Writes words to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of words to write zone (str): optional memory zone to access Returns: Number of words written to target. Raises: JLinkException: on memory access error. """ return self.memory_write(addr, data, zone, 32)
python
def memory_write32(self, addr, data, zone=None): """Writes words to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of words to write zone (str): optional memory zone to access Returns: Number of words written to target. Raises: JLinkException: on memory access error. """ return self.memory_write(addr, data, zone, 32)
[ "def", "memory_write32", "(", "self", ",", "addr", ",", "data", ",", "zone", "=", "None", ")", ":", "return", "self", ".", "memory_write", "(", "addr", ",", "data", ",", "zone", ",", "32", ")" ]
Writes words to memory of a target system. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of words to write zone (str): optional memory zone to access Returns: Number of words written to target. Raises: JLinkException: on memory access error.
[ "Writes", "words", "to", "memory", "of", "a", "target", "system", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2915-L2930
236,089
square/pylink
pylink/jlink.py
JLink.memory_write64
def memory_write64(self, addr, data, zone=None): """Writes long words to memory of a target system. Note: This is little-endian. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of long words to write zone (str): optional memory zone to access Returns: Number of long words written to target. Raises: JLinkException: on memory access error. """ words = [] bitmask = 0xFFFFFFFF for long_word in data: words.append(long_word & bitmask) # Last 32-bits words.append((long_word >> 32) & bitmask) # First 32-bits return self.memory_write32(addr, words, zone=zone)
python
def memory_write64(self, addr, data, zone=None): """Writes long words to memory of a target system. Note: This is little-endian. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of long words to write zone (str): optional memory zone to access Returns: Number of long words written to target. Raises: JLinkException: on memory access error. """ words = [] bitmask = 0xFFFFFFFF for long_word in data: words.append(long_word & bitmask) # Last 32-bits words.append((long_word >> 32) & bitmask) # First 32-bits return self.memory_write32(addr, words, zone=zone)
[ "def", "memory_write64", "(", "self", ",", "addr", ",", "data", ",", "zone", "=", "None", ")", ":", "words", "=", "[", "]", "bitmask", "=", "0xFFFFFFFF", "for", "long_word", "in", "data", ":", "words", ".", "append", "(", "long_word", "&", "bitmask", ")", "# Last 32-bits", "words", ".", "append", "(", "(", "long_word", ">>", "32", ")", "&", "bitmask", ")", "# First 32-bits", "return", "self", ".", "memory_write32", "(", "addr", ",", "words", ",", "zone", "=", "zone", ")" ]
Writes long words to memory of a target system. Note: This is little-endian. Args: self (JLink): the ``JLink`` instance addr (int): start address to write to data (list): list of long words to write zone (str): optional memory zone to access Returns: Number of long words written to target. Raises: JLinkException: on memory access error.
[ "Writes", "long", "words", "to", "memory", "of", "a", "target", "system", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2933-L2956
236,090
square/pylink
pylink/jlink.py
JLink.register_read_multiple
def register_read_multiple(self, register_indices): """Retrieves the values from the registers specified. Args: self (JLink): the ``JLink`` instance register_indices (list): list of registers to read Returns: A list of values corresponding one-to-one for each of the given register indices. The returned list of values are the values in order of which the indices were specified. Raises: JLinkException: if a given register is invalid or an error occurs. """ num_regs = len(register_indices) buf = (ctypes.c_uint32 * num_regs)(*register_indices) data = (ctypes.c_uint32 * num_regs)(0) # TODO: For some reason, these statuses are wonky, not sure why, might # be bad documentation, but they cannot be trusted at all. statuses = (ctypes.c_uint8 * num_regs)(0) res = self._dll.JLINKARM_ReadRegs(buf, data, statuses, num_regs) if res < 0: raise errors.JLinkException(res) return list(data)
python
def register_read_multiple(self, register_indices): """Retrieves the values from the registers specified. Args: self (JLink): the ``JLink`` instance register_indices (list): list of registers to read Returns: A list of values corresponding one-to-one for each of the given register indices. The returned list of values are the values in order of which the indices were specified. Raises: JLinkException: if a given register is invalid or an error occurs. """ num_regs = len(register_indices) buf = (ctypes.c_uint32 * num_regs)(*register_indices) data = (ctypes.c_uint32 * num_regs)(0) # TODO: For some reason, these statuses are wonky, not sure why, might # be bad documentation, but they cannot be trusted at all. statuses = (ctypes.c_uint8 * num_regs)(0) res = self._dll.JLINKARM_ReadRegs(buf, data, statuses, num_regs) if res < 0: raise errors.JLinkException(res) return list(data)
[ "def", "register_read_multiple", "(", "self", ",", "register_indices", ")", ":", "num_regs", "=", "len", "(", "register_indices", ")", "buf", "=", "(", "ctypes", ".", "c_uint32", "*", "num_regs", ")", "(", "*", "register_indices", ")", "data", "=", "(", "ctypes", ".", "c_uint32", "*", "num_regs", ")", "(", "0", ")", "# TODO: For some reason, these statuses are wonky, not sure why, might", "# be bad documentation, but they cannot be trusted at all.", "statuses", "=", "(", "ctypes", ".", "c_uint8", "*", "num_regs", ")", "(", "0", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_ReadRegs", "(", "buf", ",", "data", ",", "statuses", ",", "num_regs", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "list", "(", "data", ")" ]
Retrieves the values from the registers specified. Args: self (JLink): the ``JLink`` instance register_indices (list): list of registers to read Returns: A list of values corresponding one-to-one for each of the given register indices. The returned list of values are the values in order of which the indices were specified. Raises: JLinkException: if a given register is invalid or an error occurs.
[ "Retrieves", "the", "values", "from", "the", "registers", "specified", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L2972-L2999
236,091
square/pylink
pylink/jlink.py
JLink.register_write
def register_write(self, reg_index, value): """Writes into an ARM register. Note: The data is not immediately written, but is cached before being transferred to the CPU on CPU start. Args: self (JLink): the ``JLink`` instance reg_index (int): the ARM register to write to value (int): the value to write to the register Returns: The value written to the ARM register. Raises: JLinkException: on write error. """ res = self._dll.JLINKARM_WriteReg(reg_index, value) if res != 0: raise errors.JLinkException('Error writing to register %d' % reg_index) return value
python
def register_write(self, reg_index, value): """Writes into an ARM register. Note: The data is not immediately written, but is cached before being transferred to the CPU on CPU start. Args: self (JLink): the ``JLink`` instance reg_index (int): the ARM register to write to value (int): the value to write to the register Returns: The value written to the ARM register. Raises: JLinkException: on write error. """ res = self._dll.JLINKARM_WriteReg(reg_index, value) if res != 0: raise errors.JLinkException('Error writing to register %d' % reg_index) return value
[ "def", "register_write", "(", "self", ",", "reg_index", ",", "value", ")", ":", "res", "=", "self", ".", "_dll", ".", "JLINKARM_WriteReg", "(", "reg_index", ",", "value", ")", "if", "res", "!=", "0", ":", "raise", "errors", ".", "JLinkException", "(", "'Error writing to register %d'", "%", "reg_index", ")", "return", "value" ]
Writes into an ARM register. Note: The data is not immediately written, but is cached before being transferred to the CPU on CPU start. Args: self (JLink): the ``JLink`` instance reg_index (int): the ARM register to write to value (int): the value to write to the register Returns: The value written to the ARM register. Raises: JLinkException: on write error.
[ "Writes", "into", "an", "ARM", "register", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3002-L3023
236,092
square/pylink
pylink/jlink.py
JLink.register_write_multiple
def register_write_multiple(self, register_indices, values): """Writes to multiple CPU registers. Writes the values to the given registers in order. There must be a one-to-one correspondence between the values and the registers specified. Args: self (JLink): the ``JLink`` instance register_indices (list): list of registers to write to values (list): list of values to write to the registers Returns: ``None`` Raises: ValueError: if ``len(register_indices) != len(values)`` JLinkException: if a register could not be written to or on error """ if len(register_indices) != len(values): raise ValueError('Must be an equal number of registers and values') num_regs = len(register_indices) buf = (ctypes.c_uint32 * num_regs)(*register_indices) data = (ctypes.c_uint32 * num_regs)(*values) # TODO: For some reason, these statuses are wonky, not sure why, might # be bad documentation, but they cannot be trusted at all. statuses = (ctypes.c_uint8 * num_regs)(0) res = self._dll.JLINKARM_WriteRegs(buf, data, statuses, num_regs) if res != 0: raise errors.JLinkException(res) return None
python
def register_write_multiple(self, register_indices, values): """Writes to multiple CPU registers. Writes the values to the given registers in order. There must be a one-to-one correspondence between the values and the registers specified. Args: self (JLink): the ``JLink`` instance register_indices (list): list of registers to write to values (list): list of values to write to the registers Returns: ``None`` Raises: ValueError: if ``len(register_indices) != len(values)`` JLinkException: if a register could not be written to or on error """ if len(register_indices) != len(values): raise ValueError('Must be an equal number of registers and values') num_regs = len(register_indices) buf = (ctypes.c_uint32 * num_regs)(*register_indices) data = (ctypes.c_uint32 * num_regs)(*values) # TODO: For some reason, these statuses are wonky, not sure why, might # be bad documentation, but they cannot be trusted at all. statuses = (ctypes.c_uint8 * num_regs)(0) res = self._dll.JLINKARM_WriteRegs(buf, data, statuses, num_regs) if res != 0: raise errors.JLinkException(res) return None
[ "def", "register_write_multiple", "(", "self", ",", "register_indices", ",", "values", ")", ":", "if", "len", "(", "register_indices", ")", "!=", "len", "(", "values", ")", ":", "raise", "ValueError", "(", "'Must be an equal number of registers and values'", ")", "num_regs", "=", "len", "(", "register_indices", ")", "buf", "=", "(", "ctypes", ".", "c_uint32", "*", "num_regs", ")", "(", "*", "register_indices", ")", "data", "=", "(", "ctypes", ".", "c_uint32", "*", "num_regs", ")", "(", "*", "values", ")", "# TODO: For some reason, these statuses are wonky, not sure why, might", "# be bad documentation, but they cannot be trusted at all.", "statuses", "=", "(", "ctypes", ".", "c_uint8", "*", "num_regs", ")", "(", "0", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_WriteRegs", "(", "buf", ",", "data", ",", "statuses", ",", "num_regs", ")", "if", "res", "!=", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "None" ]
Writes to multiple CPU registers. Writes the values to the given registers in order. There must be a one-to-one correspondence between the values and the registers specified. Args: self (JLink): the ``JLink`` instance register_indices (list): list of registers to write to values (list): list of values to write to the registers Returns: ``None`` Raises: ValueError: if ``len(register_indices) != len(values)`` JLinkException: if a register could not be written to or on error
[ "Writes", "to", "multiple", "CPU", "registers", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3026-L3060
236,093
square/pylink
pylink/jlink.py
JLink.ice_register_write
def ice_register_write(self, register_index, value, delay=False): """Writes a value to an ARM ICE register. Args: self (JLink): the ``JLink`` instance register_index (int): the ICE register to write to value (int): the value to write to the ICE register delay (bool): boolean specifying if the write should be delayed Returns: ``None`` """ self._dll.JLINKARM_WriteICEReg(register_index, int(value), int(delay)) return None
python
def ice_register_write(self, register_index, value, delay=False): """Writes a value to an ARM ICE register. Args: self (JLink): the ``JLink`` instance register_index (int): the ICE register to write to value (int): the value to write to the ICE register delay (bool): boolean specifying if the write should be delayed Returns: ``None`` """ self._dll.JLINKARM_WriteICEReg(register_index, int(value), int(delay)) return None
[ "def", "ice_register_write", "(", "self", ",", "register_index", ",", "value", ",", "delay", "=", "False", ")", ":", "self", ".", "_dll", ".", "JLINKARM_WriteICEReg", "(", "register_index", ",", "int", "(", "value", ")", ",", "int", "(", "delay", ")", ")", "return", "None" ]
Writes a value to an ARM ICE register. Args: self (JLink): the ``JLink`` instance register_index (int): the ICE register to write to value (int): the value to write to the ICE register delay (bool): boolean specifying if the write should be delayed Returns: ``None``
[ "Writes", "a", "value", "to", "an", "ARM", "ICE", "register", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3076-L3089
236,094
square/pylink
pylink/jlink.py
JLink.etm_supported
def etm_supported(self): """Returns if the CPU core supports ETM. Args: self (JLink): the ``JLink`` instance. Returns: ``True`` if the CPU has the ETM unit, otherwise ``False``. """ res = self._dll.JLINKARM_ETM_IsPresent() if (res == 1): return True # JLINKARM_ETM_IsPresent() only works on ARM 7/9 devices. This # fallback checks if ETM is present by checking the Cortex ROM table # for debugging information for ETM. info = ctypes.c_uint32(0) index = enums.JLinkROMTable.ETM res = self._dll.JLINKARM_GetDebugInfo(index, ctypes.byref(info)) if (res == 1): return False return True
python
def etm_supported(self): """Returns if the CPU core supports ETM. Args: self (JLink): the ``JLink`` instance. Returns: ``True`` if the CPU has the ETM unit, otherwise ``False``. """ res = self._dll.JLINKARM_ETM_IsPresent() if (res == 1): return True # JLINKARM_ETM_IsPresent() only works on ARM 7/9 devices. This # fallback checks if ETM is present by checking the Cortex ROM table # for debugging information for ETM. info = ctypes.c_uint32(0) index = enums.JLinkROMTable.ETM res = self._dll.JLINKARM_GetDebugInfo(index, ctypes.byref(info)) if (res == 1): return False return True
[ "def", "etm_supported", "(", "self", ")", ":", "res", "=", "self", ".", "_dll", ".", "JLINKARM_ETM_IsPresent", "(", ")", "if", "(", "res", "==", "1", ")", ":", "return", "True", "# JLINKARM_ETM_IsPresent() only works on ARM 7/9 devices. This", "# fallback checks if ETM is present by checking the Cortex ROM table", "# for debugging information for ETM.", "info", "=", "ctypes", ".", "c_uint32", "(", "0", ")", "index", "=", "enums", ".", "JLinkROMTable", ".", "ETM", "res", "=", "self", ".", "_dll", ".", "JLINKARM_GetDebugInfo", "(", "index", ",", "ctypes", ".", "byref", "(", "info", ")", ")", "if", "(", "res", "==", "1", ")", ":", "return", "False", "return", "True" ]
Returns if the CPU core supports ETM. Args: self (JLink): the ``JLink`` instance. Returns: ``True`` if the CPU has the ETM unit, otherwise ``False``.
[ "Returns", "if", "the", "CPU", "core", "supports", "ETM", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3092-L3114
236,095
square/pylink
pylink/jlink.py
JLink.etm_register_write
def etm_register_write(self, register_index, value, delay=False): """Writes a value to an ETM register. Args: self (JLink): the ``JLink`` instance. register_index (int): the register to write to. value (int): the value to write to the register. delay (bool): boolean specifying if the write should be buffered. Returns: ``None`` """ self._dll.JLINKARM_ETM_WriteReg(int(register_index), int(value), int(delay)) return None
python
def etm_register_write(self, register_index, value, delay=False): """Writes a value to an ETM register. Args: self (JLink): the ``JLink`` instance. register_index (int): the register to write to. value (int): the value to write to the register. delay (bool): boolean specifying if the write should be buffered. Returns: ``None`` """ self._dll.JLINKARM_ETM_WriteReg(int(register_index), int(value), int(delay)) return None
[ "def", "etm_register_write", "(", "self", ",", "register_index", ",", "value", ",", "delay", "=", "False", ")", ":", "self", ".", "_dll", ".", "JLINKARM_ETM_WriteReg", "(", "int", "(", "register_index", ")", ",", "int", "(", "value", ")", ",", "int", "(", "delay", ")", ")", "return", "None" ]
Writes a value to an ETM register. Args: self (JLink): the ``JLink`` instance. register_index (int): the register to write to. value (int): the value to write to the register. delay (bool): boolean specifying if the write should be buffered. Returns: ``None``
[ "Writes", "a", "value", "to", "an", "ETM", "register", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3130-L3143
236,096
square/pylink
pylink/jlink.py
JLink.set_vector_catch
def set_vector_catch(self, flags): """Sets vector catch bits of the processor. The CPU will jump to a vector if the given vector catch is active, and will enter a debug state. This has the effect of halting the CPU as well, meaning the CPU must be explicitly restarted. Args: self (JLink): the ``JLink`` instance Returns: ``None`` Raises: JLinkException: on error. """ res = self._dll.JLINKARM_WriteVectorCatch(flags) if res < 0: raise errors.JLinkException(res) return None
python
def set_vector_catch(self, flags): """Sets vector catch bits of the processor. The CPU will jump to a vector if the given vector catch is active, and will enter a debug state. This has the effect of halting the CPU as well, meaning the CPU must be explicitly restarted. Args: self (JLink): the ``JLink`` instance Returns: ``None`` Raises: JLinkException: on error. """ res = self._dll.JLINKARM_WriteVectorCatch(flags) if res < 0: raise errors.JLinkException(res) return None
[ "def", "set_vector_catch", "(", "self", ",", "flags", ")", ":", "res", "=", "self", ".", "_dll", ".", "JLINKARM_WriteVectorCatch", "(", "flags", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "res", ")", "return", "None" ]
Sets vector catch bits of the processor. The CPU will jump to a vector if the given vector catch is active, and will enter a debug state. This has the effect of halting the CPU as well, meaning the CPU must be explicitly restarted. Args: self (JLink): the ``JLink`` instance Returns: ``None`` Raises: JLinkException: on error.
[ "Sets", "vector", "catch", "bits", "of", "the", "processor", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3320-L3339
236,097
square/pylink
pylink/jlink.py
JLink.step
def step(self, thumb=False): """Executes a single step. Steps even if there is a breakpoint. Args: self (JLink): the ``JLink`` instance thumb (bool): boolean indicating if to step in thumb mode Returns: ``None`` Raises: JLinkException: on error """ method = self._dll.JLINKARM_Step if thumb: method = self._dll.JLINKARM_StepComposite res = method() if res != 0: raise errors.JLinkException("Failed to step over instruction.") return None
python
def step(self, thumb=False): """Executes a single step. Steps even if there is a breakpoint. Args: self (JLink): the ``JLink`` instance thumb (bool): boolean indicating if to step in thumb mode Returns: ``None`` Raises: JLinkException: on error """ method = self._dll.JLINKARM_Step if thumb: method = self._dll.JLINKARM_StepComposite res = method() if res != 0: raise errors.JLinkException("Failed to step over instruction.") return None
[ "def", "step", "(", "self", ",", "thumb", "=", "False", ")", ":", "method", "=", "self", ".", "_dll", ".", "JLINKARM_Step", "if", "thumb", ":", "method", "=", "self", ".", "_dll", ".", "JLINKARM_StepComposite", "res", "=", "method", "(", ")", "if", "res", "!=", "0", ":", "raise", "errors", ".", "JLinkException", "(", "\"Failed to step over instruction.\"", ")", "return", "None" ]
Executes a single step. Steps even if there is a breakpoint. Args: self (JLink): the ``JLink`` instance thumb (bool): boolean indicating if to step in thumb mode Returns: ``None`` Raises: JLinkException: on error
[ "Executes", "a", "single", "step", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3342-L3365
236,098
square/pylink
pylink/jlink.py
JLink.num_available_breakpoints
def num_available_breakpoints(self, arm=False, thumb=False, ram=False, flash=False, hw=False): """Returns the number of available breakpoints of the specified type. If ``arm`` is set, gets the number of available ARM breakpoint units. If ``thumb`` is set, gets the number of available THUMB breakpoint units. If ``ram`` is set, gets the number of available software RAM breakpoint units. If ``flash`` is set, gets the number of available software flash breakpoint units. If ``hw`` is set, gets the number of available hardware breakpoint units. If a combination of the flags is given, then ``num_available_breakpoints()`` returns the number of breakpoints specified by the given flags. If no flags are specified, then the count of available breakpoint units is returned. Args: self (JLink): the ``JLink`` instance arm (bool): Boolean indicating to get number of ARM breakpoints. thumb (bool): Boolean indicating to get number of THUMB breakpoints. ram (bool): Boolean indicating to get number of SW RAM breakpoints. flash (bool): Boolean indicating to get number of Flash breakpoints. hw (bool): Boolean indicating to get number of Hardware breakpoints. Returns: The number of available breakpoint units of the specified type. """ flags = [ enums.JLinkBreakpoint.ARM, enums.JLinkBreakpoint.THUMB, enums.JLinkBreakpoint.SW_RAM, enums.JLinkBreakpoint.SW_FLASH, enums.JLinkBreakpoint.HW ] set_flags = [ arm, thumb, ram, flash, hw ] if not any(set_flags): flags = enums.JLinkBreakpoint.ANY else: flags = list(f for i, f in enumerate(flags) if set_flags[i]) flags = functools.reduce(operator.__or__, flags, 0) return self._dll.JLINKARM_GetNumBPUnits(flags)
python
def num_available_breakpoints(self, arm=False, thumb=False, ram=False, flash=False, hw=False): """Returns the number of available breakpoints of the specified type. If ``arm`` is set, gets the number of available ARM breakpoint units. If ``thumb`` is set, gets the number of available THUMB breakpoint units. If ``ram`` is set, gets the number of available software RAM breakpoint units. If ``flash`` is set, gets the number of available software flash breakpoint units. If ``hw`` is set, gets the number of available hardware breakpoint units. If a combination of the flags is given, then ``num_available_breakpoints()`` returns the number of breakpoints specified by the given flags. If no flags are specified, then the count of available breakpoint units is returned. Args: self (JLink): the ``JLink`` instance arm (bool): Boolean indicating to get number of ARM breakpoints. thumb (bool): Boolean indicating to get number of THUMB breakpoints. ram (bool): Boolean indicating to get number of SW RAM breakpoints. flash (bool): Boolean indicating to get number of Flash breakpoints. hw (bool): Boolean indicating to get number of Hardware breakpoints. Returns: The number of available breakpoint units of the specified type. """ flags = [ enums.JLinkBreakpoint.ARM, enums.JLinkBreakpoint.THUMB, enums.JLinkBreakpoint.SW_RAM, enums.JLinkBreakpoint.SW_FLASH, enums.JLinkBreakpoint.HW ] set_flags = [ arm, thumb, ram, flash, hw ] if not any(set_flags): flags = enums.JLinkBreakpoint.ANY else: flags = list(f for i, f in enumerate(flags) if set_flags[i]) flags = functools.reduce(operator.__or__, flags, 0) return self._dll.JLINKARM_GetNumBPUnits(flags)
[ "def", "num_available_breakpoints", "(", "self", ",", "arm", "=", "False", ",", "thumb", "=", "False", ",", "ram", "=", "False", ",", "flash", "=", "False", ",", "hw", "=", "False", ")", ":", "flags", "=", "[", "enums", ".", "JLinkBreakpoint", ".", "ARM", ",", "enums", ".", "JLinkBreakpoint", ".", "THUMB", ",", "enums", ".", "JLinkBreakpoint", ".", "SW_RAM", ",", "enums", ".", "JLinkBreakpoint", ".", "SW_FLASH", ",", "enums", ".", "JLinkBreakpoint", ".", "HW", "]", "set_flags", "=", "[", "arm", ",", "thumb", ",", "ram", ",", "flash", ",", "hw", "]", "if", "not", "any", "(", "set_flags", ")", ":", "flags", "=", "enums", ".", "JLinkBreakpoint", ".", "ANY", "else", ":", "flags", "=", "list", "(", "f", "for", "i", ",", "f", "in", "enumerate", "(", "flags", ")", "if", "set_flags", "[", "i", "]", ")", "flags", "=", "functools", ".", "reduce", "(", "operator", ".", "__or__", ",", "flags", ",", "0", ")", "return", "self", ".", "_dll", ".", "JLINKARM_GetNumBPUnits", "(", "flags", ")" ]
Returns the number of available breakpoints of the specified type. If ``arm`` is set, gets the number of available ARM breakpoint units. If ``thumb`` is set, gets the number of available THUMB breakpoint units. If ``ram`` is set, gets the number of available software RAM breakpoint units. If ``flash`` is set, gets the number of available software flash breakpoint units. If ``hw`` is set, gets the number of available hardware breakpoint units. If a combination of the flags is given, then ``num_available_breakpoints()`` returns the number of breakpoints specified by the given flags. If no flags are specified, then the count of available breakpoint units is returned. Args: self (JLink): the ``JLink`` instance arm (bool): Boolean indicating to get number of ARM breakpoints. thumb (bool): Boolean indicating to get number of THUMB breakpoints. ram (bool): Boolean indicating to get number of SW RAM breakpoints. flash (bool): Boolean indicating to get number of Flash breakpoints. hw (bool): Boolean indicating to get number of Hardware breakpoints. Returns: The number of available breakpoint units of the specified type.
[ "Returns", "the", "number", "of", "available", "breakpoints", "of", "the", "specified", "type", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3411-L3459
236,099
square/pylink
pylink/jlink.py
JLink.breakpoint_info
def breakpoint_info(self, handle=0, index=-1): """Returns the information about a set breakpoint. Note: Either ``handle`` or ``index`` can be specified. If the ``index`` is not provided, the ``handle`` must be set, and vice-versa. If both ``index`` and ``handle`` are provided, the ``index`` overrides the provided ``handle``. Args: self (JLink): the ``JLink`` instance handle (int): option handle of a valid breakpoint index (int): optional index of the breakpoint. Returns: An instance of ``JLinkBreakpointInfo`` specifying information about the breakpoint. Raises: JLinkException: on error. ValueError: if both the handle and index are invalid. """ if index < 0 and handle == 0: raise ValueError('Handle must be provided if index is not set.') bp = structs.JLinkBreakpointInfo() bp.Handle = int(handle) res = self._dll.JLINKARM_GetBPInfoEx(index, ctypes.byref(bp)) if res < 0: raise errors.JLinkException('Failed to get breakpoint info.') return bp
python
def breakpoint_info(self, handle=0, index=-1): """Returns the information about a set breakpoint. Note: Either ``handle`` or ``index`` can be specified. If the ``index`` is not provided, the ``handle`` must be set, and vice-versa. If both ``index`` and ``handle`` are provided, the ``index`` overrides the provided ``handle``. Args: self (JLink): the ``JLink`` instance handle (int): option handle of a valid breakpoint index (int): optional index of the breakpoint. Returns: An instance of ``JLinkBreakpointInfo`` specifying information about the breakpoint. Raises: JLinkException: on error. ValueError: if both the handle and index are invalid. """ if index < 0 and handle == 0: raise ValueError('Handle must be provided if index is not set.') bp = structs.JLinkBreakpointInfo() bp.Handle = int(handle) res = self._dll.JLINKARM_GetBPInfoEx(index, ctypes.byref(bp)) if res < 0: raise errors.JLinkException('Failed to get breakpoint info.') return bp
[ "def", "breakpoint_info", "(", "self", ",", "handle", "=", "0", ",", "index", "=", "-", "1", ")", ":", "if", "index", "<", "0", "and", "handle", "==", "0", ":", "raise", "ValueError", "(", "'Handle must be provided if index is not set.'", ")", "bp", "=", "structs", ".", "JLinkBreakpointInfo", "(", ")", "bp", ".", "Handle", "=", "int", "(", "handle", ")", "res", "=", "self", ".", "_dll", ".", "JLINKARM_GetBPInfoEx", "(", "index", ",", "ctypes", ".", "byref", "(", "bp", ")", ")", "if", "res", "<", "0", ":", "raise", "errors", ".", "JLinkException", "(", "'Failed to get breakpoint info.'", ")", "return", "bp" ]
Returns the information about a set breakpoint. Note: Either ``handle`` or ``index`` can be specified. If the ``index`` is not provided, the ``handle`` must be set, and vice-versa. If both ``index`` and ``handle`` are provided, the ``index`` overrides the provided ``handle``. Args: self (JLink): the ``JLink`` instance handle (int): option handle of a valid breakpoint index (int): optional index of the breakpoint. Returns: An instance of ``JLinkBreakpointInfo`` specifying information about the breakpoint. Raises: JLinkException: on error. ValueError: if both the handle and index are invalid.
[ "Returns", "the", "information", "about", "a", "set", "breakpoint", "." ]
81dda0a191d923a8b2627c52cb778aba24d279d7
https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L3462-L3493