5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 """
group-onsemi 0:098463de4c5d 2 mbed SDK
group-onsemi 0:098463de4c5d 3 Copyright (c) 2011-2013 ARM Limited
group-onsemi 0:098463de4c5d 4
group-onsemi 0:098463de4c5d 5 Licensed under the Apache License, Version 2.0 (the "License");
group-onsemi 0:098463de4c5d 6 you may not use this file except in compliance with the License.
group-onsemi 0:098463de4c5d 7 You may obtain a copy of the License at
group-onsemi 0:098463de4c5d 8
group-onsemi 0:098463de4c5d 9 http://www.apache.org/licenses/LICENSE-2.0
group-onsemi 0:098463de4c5d 10
group-onsemi 0:098463de4c5d 11 Unless required by applicable law or agreed to in writing, software
group-onsemi 0:098463de4c5d 12 distributed under the License is distributed on an "AS IS" BASIS,
group-onsemi 0:098463de4c5d 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-onsemi 0:098463de4c5d 14 See the License for the specific language governing permissions and
group-onsemi 0:098463de4c5d 15 limitations under the License.
group-onsemi 0:098463de4c5d 16 """
group-onsemi 0:098463de4c5d 17
group-onsemi 0:098463de4c5d 18 from mbed_host_tests import BaseHostTest
group-onsemi 0:098463de4c5d 19
group-onsemi 0:098463de4c5d 20
group-onsemi 0:098463de4c5d 21 class TimingDriftTest(BaseHostTest):
group-onsemi 0:098463de4c5d 22 """ This test is reading single characters from stdio
group-onsemi 0:098463de4c5d 23 and measures time between their occurrences.
group-onsemi 0:098463de4c5d 24 """
group-onsemi 0:098463de4c5d 25 __result = None
group-onsemi 0:098463de4c5d 26
group-onsemi 0:098463de4c5d 27 # This is calculated later: average_drift_max * number of tick events
group-onsemi 0:098463de4c5d 28 total_drift_max = None
group-onsemi 0:098463de4c5d 29
group-onsemi 0:098463de4c5d 30 average_drift_max = 0.05
group-onsemi 0:098463de4c5d 31 ticks = []
group-onsemi 0:098463de4c5d 32 start_time = None
group-onsemi 0:098463de4c5d 33 finish_time = None
group-onsemi 0:098463de4c5d 34 dut_seconds_passed = None
group-onsemi 0:098463de4c5d 35 total_time = None
group-onsemi 0:098463de4c5d 36 total_drift = None
group-onsemi 0:098463de4c5d 37 average_drift = None
group-onsemi 0:098463de4c5d 38
group-onsemi 0:098463de4c5d 39 def _callback_result(self, key, value, timestamp):
group-onsemi 0:098463de4c5d 40 # We should not see result data in this test
group-onsemi 0:098463de4c5d 41 self.__result = False
group-onsemi 0:098463de4c5d 42
group-onsemi 0:098463de4c5d 43 def _callback_end(self, key, value, timestamp):
group-onsemi 0:098463de4c5d 44 """ {{end;%s}}} """
group-onsemi 0:098463de4c5d 45 self.log("Received end event, timestamp: %f" % timestamp)
group-onsemi 0:098463de4c5d 46 self.notify_complete(result=self.result(print_stats=True))
group-onsemi 0:098463de4c5d 47
group-onsemi 0:098463de4c5d 48
group-onsemi 0:098463de4c5d 49 def _callback_tick(self, key, value, timestamp):
group-onsemi 0:098463de4c5d 50 """ {{tick;%d}}} """
group-onsemi 0:098463de4c5d 51 self.log("tick! %f" % timestamp)
group-onsemi 0:098463de4c5d 52 self.ticks.append((key, value, timestamp))
group-onsemi 0:098463de4c5d 53
group-onsemi 0:098463de4c5d 54
group-onsemi 0:098463de4c5d 55 def setup(self):
group-onsemi 0:098463de4c5d 56 self.register_callback("end", self._callback_end)
group-onsemi 0:098463de4c5d 57 self.register_callback('tick', self._callback_tick)
group-onsemi 0:098463de4c5d 58
group-onsemi 0:098463de4c5d 59
group-onsemi 0:098463de4c5d 60 def result(self, print_stats=True):
group-onsemi 0:098463de4c5d 61 self.dut_seconds_passed = len(self.ticks) - 1
group-onsemi 0:098463de4c5d 62
group-onsemi 0:098463de4c5d 63 if self.dut_seconds_passed < 1:
group-onsemi 0:098463de4c5d 64 if print_stats:
group-onsemi 0:098463de4c5d 65 self.log("FAIL: failed to receive at least two tick events")
group-onsemi 0:098463de4c5d 66 self.__result = False
group-onsemi 0:098463de4c5d 67 return self.__result
group-onsemi 0:098463de4c5d 68
group-onsemi 0:098463de4c5d 69 self.total_drift_max = self.dut_seconds_passed * self.average_drift_max
group-onsemi 0:098463de4c5d 70
group-onsemi 0:098463de4c5d 71 self.start_time = self.ticks[0][2]
group-onsemi 0:098463de4c5d 72 self.finish_time = self.ticks[-1][2]
group-onsemi 0:098463de4c5d 73 self.total_time = self.finish_time - self.start_time
group-onsemi 0:098463de4c5d 74 self.total_drift = self.total_time - self.dut_seconds_passed
group-onsemi 0:098463de4c5d 75 self.average_drift = self.total_drift / self.dut_seconds_passed
group-onsemi 0:098463de4c5d 76
group-onsemi 0:098463de4c5d 77 if print_stats:
group-onsemi 0:098463de4c5d 78 self.log("Start: %f" % self.start_time)
group-onsemi 0:098463de4c5d 79 self.log("Finish: %f" % self.finish_time)
group-onsemi 0:098463de4c5d 80 self.log("Total time taken: %f" % self.total_time)
group-onsemi 0:098463de4c5d 81
group-onsemi 0:098463de4c5d 82 total_drift_ratio_string = "Total drift/Max total drift: %f/%f"
group-onsemi 0:098463de4c5d 83 self.log(total_drift_ratio_string % (self.total_drift,
group-onsemi 0:098463de4c5d 84 self.total_drift_max))
group-onsemi 0:098463de4c5d 85
group-onsemi 0:098463de4c5d 86 average_drift_ratio_string = "Average drift/Max average drift: %f/%f"
group-onsemi 0:098463de4c5d 87 self.log(average_drift_ratio_string % (self.average_drift,
group-onsemi 0:098463de4c5d 88 self.average_drift_max))
group-onsemi 0:098463de4c5d 89
group-onsemi 0:098463de4c5d 90
group-onsemi 0:098463de4c5d 91 if abs(self.total_drift) > self.total_drift_max:
group-onsemi 0:098463de4c5d 92 if print_stats:
group-onsemi 0:098463de4c5d 93 self.log("FAIL: Total drift exceeded max total drift")
group-onsemi 0:098463de4c5d 94 self.__result = False
group-onsemi 0:098463de4c5d 95 elif self.average_drift > self.average_drift_max:
group-onsemi 0:098463de4c5d 96 if print_stats:
group-onsemi 0:098463de4c5d 97 self.log("FAIL: Average drift exceeded max average drift")
group-onsemi 0:098463de4c5d 98 self.__result = False
group-onsemi 0:098463de4c5d 99 else:
group-onsemi 0:098463de4c5d 100 self.__result = True
group-onsemi 0:098463de4c5d 101
group-onsemi 0:098463de4c5d 102 return self.__result
group-onsemi 0:098463de4c5d 103
group-onsemi 0:098463de4c5d 104
group-onsemi 0:098463de4c5d 105 def teardown(self):
group-onsemi 0:098463de4c5d 106 pass