mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 """
dkato 0:f782d9c66c49 2 mbed SDK
dkato 0:f782d9c66c49 3 Copyright (c) 2011-2013 ARM Limited
dkato 0:f782d9c66c49 4
dkato 0:f782d9c66c49 5 Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:f782d9c66c49 6 you may not use this file except in compliance with the License.
dkato 0:f782d9c66c49 7 You may obtain a copy of the License at
dkato 0:f782d9c66c49 8
dkato 0:f782d9c66c49 9 http://www.apache.org/licenses/LICENSE-2.0
dkato 0:f782d9c66c49 10
dkato 0:f782d9c66c49 11 Unless required by applicable law or agreed to in writing, software
dkato 0:f782d9c66c49 12 distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:f782d9c66c49 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:f782d9c66c49 14 See the License for the specific language governing permissions and
dkato 0:f782d9c66c49 15 limitations under the License.
dkato 0:f782d9c66c49 16 """
dkato 0:f782d9c66c49 17
dkato 0:f782d9c66c49 18 from time import time
dkato 0:f782d9c66c49 19
dkato 0:f782d9c66c49 20 class WaitusTest():
dkato 0:f782d9c66c49 21 """ This test is reading single characters from stdio
dkato 0:f782d9c66c49 22 and measures time between their occurrences.
dkato 0:f782d9c66c49 23 """
dkato 0:f782d9c66c49 24 TICK_LOOP_COUNTER = 13
dkato 0:f782d9c66c49 25 TICK_LOOP_SUCCESSFUL_COUNTS = 10
dkato 0:f782d9c66c49 26 DEVIATION = 0.10 # +/-10%
dkato 0:f782d9c66c49 27
dkato 0:f782d9c66c49 28 def test(self, selftest):
dkato 0:f782d9c66c49 29 test_result = True
dkato 0:f782d9c66c49 30 # First character to start test (to know after reset when test starts)
dkato 0:f782d9c66c49 31 if selftest.mbed.set_serial_timeout(None) is None:
dkato 0:f782d9c66c49 32 return selftest.RESULT_IO_SERIAL
dkato 0:f782d9c66c49 33 c = selftest.mbed.serial_read(1)
dkato 0:f782d9c66c49 34 if c is None:
dkato 0:f782d9c66c49 35 return selftest.RESULT_IO_SERIAL
dkato 0:f782d9c66c49 36 if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6
dkato 0:f782d9c66c49 37 #Read additional 39 bytes of TargetID
dkato 0:f782d9c66c49 38 if selftest.mbed.serial_read(39) is None:
dkato 0:f782d9c66c49 39 return selftest.RESULT_IO_SERIAL
dkato 0:f782d9c66c49 40 c = selftest.mbed.serial_read(1) # Re-read first 'tick'
dkato 0:f782d9c66c49 41 if c is None:
dkato 0:f782d9c66c49 42 return selftest.RESULT_IO_SERIAL
dkato 0:f782d9c66c49 43 start_serial_pool = time()
dkato 0:f782d9c66c49 44 start = time()
dkato 0:f782d9c66c49 45
dkato 0:f782d9c66c49 46 success_counter = 0
dkato 0:f782d9c66c49 47
dkato 0:f782d9c66c49 48 for i in range(0, self.TICK_LOOP_COUNTER):
dkato 0:f782d9c66c49 49 c = selftest.mbed.serial_read(1)
dkato 0:f782d9c66c49 50 if c is None:
dkato 0:f782d9c66c49 51 return selftest.RESULT_IO_SERIAL
dkato 0:f782d9c66c49 52 delta = time() - start
dkato 0:f782d9c66c49 53 deviation = abs(delta - 1)
dkato 0:f782d9c66c49 54 # Round values
dkato 0:f782d9c66c49 55 delta = round(delta, 2)
dkato 0:f782d9c66c49 56 deviation = round(deviation, 2)
dkato 0:f782d9c66c49 57 # Check if time measurements are in given range
dkato 0:f782d9c66c49 58 deviation_ok = True if delta > 0 and deviation <= self.DEVIATION else False
dkato 0:f782d9c66c49 59 success_counter = success_counter+1 if deviation_ok else 0
dkato 0:f782d9c66c49 60 msg = "OK" if deviation_ok else "FAIL"
dkato 0:f782d9c66c49 61 selftest.notify("%s in %.2f sec (%.2f) [%s]"% (c, delta, deviation, msg))
dkato 0:f782d9c66c49 62 start = time()
dkato 0:f782d9c66c49 63 if success_counter >= self.TICK_LOOP_SUCCESSFUL_COUNTS:
dkato 0:f782d9c66c49 64 break
dkato 0:f782d9c66c49 65 measurement_time = time() - start_serial_pool
dkato 0:f782d9c66c49 66 selftest.notify("Consecutive OK timer reads: %d"% success_counter)
dkato 0:f782d9c66c49 67 selftest.notify("Completed in %.2f sec" % (measurement_time))
dkato 0:f782d9c66c49 68 test_result = True if success_counter >= self.TICK_LOOP_SUCCESSFUL_COUNTS else False
dkato 0:f782d9c66c49 69 return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE