Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

Committer:
Pawel Zarembski
Date:
Tue Apr 07 12:55:42 2020 +0200
Revision:
0:01f31e923fe2
hani: DAPLink with reset workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 #
Pawel Zarembski 0:01f31e923fe2 2 # DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 3 # Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 4 # SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 5 #
Pawel Zarembski 0:01f31e923fe2 6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 7 # not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 8 # You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 9 #
Pawel Zarembski 0:01f31e923fe2 10 # http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 11 #
Pawel Zarembski 0:01f31e923fe2 12 # Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 15 # See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 16 # limitations under the License.
Pawel Zarembski 0:01f31e923fe2 17 #
Pawel Zarembski 0:01f31e923fe2 18
Pawel Zarembski 0:01f31e923fe2 19 from __future__ import absolute_import
Pawel Zarembski 0:01f31e923fe2 20 from __future__ import print_function
Pawel Zarembski 0:01f31e923fe2 21 import six
Pawel Zarembski 0:01f31e923fe2 22 import sys
Pawel Zarembski 0:01f31e923fe2 23 import time
Pawel Zarembski 0:01f31e923fe2 24
Pawel Zarembski 0:01f31e923fe2 25
Pawel Zarembski 0:01f31e923fe2 26 class TestInfo(object):
Pawel Zarembski 0:01f31e923fe2 27 # Higher number = more severe
Pawel Zarembski 0:01f31e923fe2 28 SUBTEST = 0
Pawel Zarembski 0:01f31e923fe2 29 INFO = 1
Pawel Zarembski 0:01f31e923fe2 30 WARNING = 2
Pawel Zarembski 0:01f31e923fe2 31 FAILURE = 3
Pawel Zarembski 0:01f31e923fe2 32
Pawel Zarembski 0:01f31e923fe2 33 _MSG_TYPES = set((INFO, WARNING, FAILURE))
Pawel Zarembski 0:01f31e923fe2 34 _MSG_LEVEL_TO_FMT_STR = {
Pawel Zarembski 0:01f31e923fe2 35 INFO: "Info: %s",
Pawel Zarembski 0:01f31e923fe2 36 WARNING: "Warning: %s",
Pawel Zarembski 0:01f31e923fe2 37 FAILURE: "Failure: %s",
Pawel Zarembski 0:01f31e923fe2 38 }
Pawel Zarembski 0:01f31e923fe2 39
Pawel Zarembski 0:01f31e923fe2 40 def __init__(self, name, init_print=True):
Pawel Zarembski 0:01f31e923fe2 41 self._all = []
Pawel Zarembski 0:01f31e923fe2 42 self.failures = 0
Pawel Zarembski 0:01f31e923fe2 43 self.warnings = 0
Pawel Zarembski 0:01f31e923fe2 44 self.infos = 0
Pawel Zarembski 0:01f31e923fe2 45 self.name = name
Pawel Zarembski 0:01f31e923fe2 46 if init_print:
Pawel Zarembski 0:01f31e923fe2 47 self._print_msg("SubTest: " + name)
Pawel Zarembski 0:01f31e923fe2 48
Pawel Zarembski 0:01f31e923fe2 49 def failure(self, msg):
Pawel Zarembski 0:01f31e923fe2 50 assert isinstance(msg, six.string_types)
Pawel Zarembski 0:01f31e923fe2 51 self._add_entry(self.FAILURE, msg)
Pawel Zarembski 0:01f31e923fe2 52
Pawel Zarembski 0:01f31e923fe2 53 def warning(self, msg):
Pawel Zarembski 0:01f31e923fe2 54 assert isinstance(msg, six.string_types)
Pawel Zarembski 0:01f31e923fe2 55 self._add_entry(self.WARNING, msg)
Pawel Zarembski 0:01f31e923fe2 56
Pawel Zarembski 0:01f31e923fe2 57 def info(self, msg):
Pawel Zarembski 0:01f31e923fe2 58 assert isinstance(msg, six.string_types)
Pawel Zarembski 0:01f31e923fe2 59 self._add_entry(self.INFO, msg)
Pawel Zarembski 0:01f31e923fe2 60
Pawel Zarembski 0:01f31e923fe2 61 def print_msg(self, warning_level, max_recursion=0, spacing=2,
Pawel Zarembski 0:01f31e923fe2 62 log_file=sys.stdout, _recursion_level=0):
Pawel Zarembski 0:01f31e923fe2 63 """
Pawel Zarembski 0:01f31e923fe2 64 Print problems at the given level
Pawel Zarembski 0:01f31e923fe2 65
Pawel Zarembski 0:01f31e923fe2 66 By default only the top level passes and fails are printed.
Pawel Zarembski 0:01f31e923fe2 67 Set max_recursion to the number of subtests to be printed, or
Pawel Zarembski 0:01f31e923fe2 68 to None if all levels should be printed.
Pawel Zarembski 0:01f31e923fe2 69 """
Pawel Zarembski 0:01f31e923fe2 70 assert warning_level in self._MSG_TYPES
Pawel Zarembski 0:01f31e923fe2 71 assert max_recursion is None or max_recursion >= 0
Pawel Zarembski 0:01f31e923fe2 72
Pawel Zarembski 0:01f31e923fe2 73 if self.get_failed():
Pawel Zarembski 0:01f31e923fe2 74 result_str = 'Failure'
Pawel Zarembski 0:01f31e923fe2 75 test_level = self.FAILURE
Pawel Zarembski 0:01f31e923fe2 76 elif self.get_warning():
Pawel Zarembski 0:01f31e923fe2 77 result_str = 'Warning'
Pawel Zarembski 0:01f31e923fe2 78 test_level = self.WARNING
Pawel Zarembski 0:01f31e923fe2 79 else:
Pawel Zarembski 0:01f31e923fe2 80 result_str = 'Pass'
Pawel Zarembski 0:01f31e923fe2 81 test_level = self.INFO
Pawel Zarembski 0:01f31e923fe2 82 prefix = ' ' * (_recursion_level * spacing)
Pawel Zarembski 0:01f31e923fe2 83
Pawel Zarembski 0:01f31e923fe2 84 # Check if test should be printed - the waning level
Pawel Zarembski 0:01f31e923fe2 85 # is enabled, or this is the top level test
Pawel Zarembski 0:01f31e923fe2 86 if test_level < warning_level and _recursion_level != 0:
Pawel Zarembski 0:01f31e923fe2 87 return
Pawel Zarembski 0:01f31e923fe2 88
Pawel Zarembski 0:01f31e923fe2 89 # Print test header
Pawel Zarembski 0:01f31e923fe2 90 print(prefix + "Test: %s: %s" % (self.name, result_str),
Pawel Zarembski 0:01f31e923fe2 91 file=log_file)
Pawel Zarembski 0:01f31e923fe2 92
Pawel Zarembski 0:01f31e923fe2 93 # Check for recursion termination
Pawel Zarembski 0:01f31e923fe2 94 if max_recursion is not None and _recursion_level > max_recursion:
Pawel Zarembski 0:01f31e923fe2 95 return
Pawel Zarembski 0:01f31e923fe2 96 _recursion_level += 1
Pawel Zarembski 0:01f31e923fe2 97
Pawel Zarembski 0:01f31e923fe2 98 # Print messages
Pawel Zarembski 0:01f31e923fe2 99 prefix = ' ' * (_recursion_level * spacing)
Pawel Zarembski 0:01f31e923fe2 100 for msg_level, msg in self._all:
Pawel Zarembski 0:01f31e923fe2 101 if msg_level == self.SUBTEST:
Pawel Zarembski 0:01f31e923fe2 102 test_info = msg
Pawel Zarembski 0:01f31e923fe2 103 test_info.print_msg(warning_level, max_recursion,
Pawel Zarembski 0:01f31e923fe2 104 spacing, log_file, _recursion_level)
Pawel Zarembski 0:01f31e923fe2 105 else:
Pawel Zarembski 0:01f31e923fe2 106 fmt = prefix + self._MSG_LEVEL_TO_FMT_STR[msg_level]
Pawel Zarembski 0:01f31e923fe2 107 if msg_level >= warning_level:
Pawel Zarembski 0:01f31e923fe2 108 print(fmt % msg, file=log_file)
Pawel Zarembski 0:01f31e923fe2 109
Pawel Zarembski 0:01f31e923fe2 110 def get_failed(self):
Pawel Zarembski 0:01f31e923fe2 111 self._update_counts()
Pawel Zarembski 0:01f31e923fe2 112 return self.failures != 0
Pawel Zarembski 0:01f31e923fe2 113
Pawel Zarembski 0:01f31e923fe2 114 def get_warning(self):
Pawel Zarembski 0:01f31e923fe2 115 self._update_counts()
Pawel Zarembski 0:01f31e923fe2 116 return self.warnings != 0
Pawel Zarembski 0:01f31e923fe2 117
Pawel Zarembski 0:01f31e923fe2 118 def get_name(self):
Pawel Zarembski 0:01f31e923fe2 119 return self.name
Pawel Zarembski 0:01f31e923fe2 120
Pawel Zarembski 0:01f31e923fe2 121 def create_subtest(self, name):
Pawel Zarembski 0:01f31e923fe2 122 assert isinstance(name, six.string_types)
Pawel Zarembski 0:01f31e923fe2 123 test_info = TestInfo(name)
Pawel Zarembski 0:01f31e923fe2 124 self._add_entry(self.SUBTEST, test_info)
Pawel Zarembski 0:01f31e923fe2 125 return test_info
Pawel Zarembski 0:01f31e923fe2 126
Pawel Zarembski 0:01f31e923fe2 127 def attach_subtest(self, subtest):
Pawel Zarembski 0:01f31e923fe2 128 assert isinstance(subtest, TestInfo)
Pawel Zarembski 0:01f31e923fe2 129 self._add_entry(self.SUBTEST, subtest)
Pawel Zarembski 0:01f31e923fe2 130
Pawel Zarembski 0:01f31e923fe2 131 def get_counts(self):
Pawel Zarembski 0:01f31e923fe2 132 """
Pawel Zarembski 0:01f31e923fe2 133 Return the number of events that occured
Pawel Zarembski 0:01f31e923fe2 134
Pawel Zarembski 0:01f31e923fe2 135 Return the number of even messages as a
Pawel Zarembski 0:01f31e923fe2 136 tuple containing (failure_count, warning_count, info_count).
Pawel Zarembski 0:01f31e923fe2 137 """
Pawel Zarembski 0:01f31e923fe2 138 self._update_counts()
Pawel Zarembski 0:01f31e923fe2 139 return self.failures, self.warnings, self.infos
Pawel Zarembski 0:01f31e923fe2 140
Pawel Zarembski 0:01f31e923fe2 141 def _update_counts(self):
Pawel Zarembski 0:01f31e923fe2 142 self.failures, self.warnings, self.infos = 0, 0, 0
Pawel Zarembski 0:01f31e923fe2 143 for msg_level, msg in self._all:
Pawel Zarembski 0:01f31e923fe2 144 if msg_level == self.SUBTEST:
Pawel Zarembski 0:01f31e923fe2 145 test_info = msg
Pawel Zarembski 0:01f31e923fe2 146 failures, warnings, infos = test_info.get_counts()
Pawel Zarembski 0:01f31e923fe2 147 self.failures += failures
Pawel Zarembski 0:01f31e923fe2 148 self.warnings += warnings
Pawel Zarembski 0:01f31e923fe2 149 self.infos += infos
Pawel Zarembski 0:01f31e923fe2 150 else:
Pawel Zarembski 0:01f31e923fe2 151 if msg_level == self.FAILURE:
Pawel Zarembski 0:01f31e923fe2 152 self.failures += 1
Pawel Zarembski 0:01f31e923fe2 153 elif msg_level == self.WARNING:
Pawel Zarembski 0:01f31e923fe2 154 self.warnings += 1
Pawel Zarembski 0:01f31e923fe2 155 elif msg_level == self.INFO:
Pawel Zarembski 0:01f31e923fe2 156 self.infos += 1
Pawel Zarembski 0:01f31e923fe2 157 else:
Pawel Zarembski 0:01f31e923fe2 158 # Should never get here
Pawel Zarembski 0:01f31e923fe2 159 assert False
Pawel Zarembski 0:01f31e923fe2 160
Pawel Zarembski 0:01f31e923fe2 161 def _add_entry(self, entry_type, msg):
Pawel Zarembski 0:01f31e923fe2 162 if entry_type is self.SUBTEST:
Pawel Zarembski 0:01f31e923fe2 163 assert isinstance(msg, TestInfo)
Pawel Zarembski 0:01f31e923fe2 164 # Test name printed in constructor
Pawel Zarembski 0:01f31e923fe2 165 else:
Pawel Zarembski 0:01f31e923fe2 166 assert isinstance(msg, six.string_types)
Pawel Zarembski 0:01f31e923fe2 167 self._print_msg(msg)
Pawel Zarembski 0:01f31e923fe2 168 self._all.append((entry_type, msg))
Pawel Zarembski 0:01f31e923fe2 169
Pawel Zarembski 0:01f31e923fe2 170 @staticmethod
Pawel Zarembski 0:01f31e923fe2 171 def _print_msg(msg):
Pawel Zarembski 0:01f31e923fe2 172 print(get_timestamp_tag() + msg)
Pawel Zarembski 0:01f31e923fe2 173
Pawel Zarembski 0:01f31e923fe2 174
Pawel Zarembski 0:01f31e923fe2 175 class TestInfoStub(TestInfo):
Pawel Zarembski 0:01f31e923fe2 176
Pawel Zarembski 0:01f31e923fe2 177 def __init__(self):
Pawel Zarembski 0:01f31e923fe2 178 super(TestInfoStub, self).__init__('stub test', False)
Pawel Zarembski 0:01f31e923fe2 179
Pawel Zarembski 0:01f31e923fe2 180 def create_subtest(self, name):
Pawel Zarembski 0:01f31e923fe2 181 assert isinstance(name, six.string_types)
Pawel Zarembski 0:01f31e923fe2 182 return TestInfoStub()
Pawel Zarembski 0:01f31e923fe2 183
Pawel Zarembski 0:01f31e923fe2 184 @staticmethod
Pawel Zarembski 0:01f31e923fe2 185 def _print_msg(msg):
Pawel Zarembski 0:01f31e923fe2 186 print(get_timestamp_tag() + "%s"%(msg,))
Pawel Zarembski 0:01f31e923fe2 187
Pawel Zarembski 0:01f31e923fe2 188 def get_timestamp_tag():
Pawel Zarembski 0:01f31e923fe2 189 return "[{:0<17f}] ".format(time.time())