Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/TESTS/mbed_drivers/timeout/main.cpp@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved |
marcozecchini | 0:9fca2b23d0ba | 3 | * SPDX-License-Identifier: Apache-2.0 |
marcozecchini | 0:9fca2b23d0ba | 4 | * |
marcozecchini | 0:9fca2b23d0ba | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
marcozecchini | 0:9fca2b23d0ba | 6 | * not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 7 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 8 | * |
marcozecchini | 0:9fca2b23d0ba | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 10 | * |
marcozecchini | 0:9fca2b23d0ba | 11 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
marcozecchini | 0:9fca2b23d0ba | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 14 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 15 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 16 | */ |
marcozecchini | 0:9fca2b23d0ba | 17 | |
marcozecchini | 0:9fca2b23d0ba | 18 | |
marcozecchini | 0:9fca2b23d0ba | 19 | /* |
marcozecchini | 0:9fca2b23d0ba | 20 | * Tests is to measure the accuracy of Timeout over a period of time |
marcozecchini | 0:9fca2b23d0ba | 21 | * |
marcozecchini | 0:9fca2b23d0ba | 22 | * |
marcozecchini | 0:9fca2b23d0ba | 23 | * 1) DUT would start to update callback_trigger_count every milli sec |
marcozecchini | 0:9fca2b23d0ba | 24 | * 2) Host would query what is current count base_time, Device responds by the callback_trigger_count |
marcozecchini | 0:9fca2b23d0ba | 25 | * 3) Host after waiting for measurement stretch. It will query for device time again final_time. |
marcozecchini | 0:9fca2b23d0ba | 26 | * 4) Host computes the drift considering base_time, final_time, transport delay and measurement stretch |
marcozecchini | 0:9fca2b23d0ba | 27 | * 5) Finally host send the results back to device pass/fail based on tolerance. |
marcozecchini | 0:9fca2b23d0ba | 28 | * 6) More details on tests can be found in timing_drift_auto.py |
marcozecchini | 0:9fca2b23d0ba | 29 | * |
marcozecchini | 0:9fca2b23d0ba | 30 | */ |
marcozecchini | 0:9fca2b23d0ba | 31 | |
marcozecchini | 0:9fca2b23d0ba | 32 | #include "mbed.h" |
marcozecchini | 0:9fca2b23d0ba | 33 | #include "greentea-client/test_env.h" |
marcozecchini | 0:9fca2b23d0ba | 34 | #include "utest/utest.h" |
marcozecchini | 0:9fca2b23d0ba | 35 | #include "unity/unity.h" |
marcozecchini | 0:9fca2b23d0ba | 36 | |
marcozecchini | 0:9fca2b23d0ba | 37 | using namespace utest::v1; |
marcozecchini | 0:9fca2b23d0ba | 38 | |
marcozecchini | 0:9fca2b23d0ba | 39 | #define PERIOD_US 10000 |
marcozecchini | 0:9fca2b23d0ba | 40 | |
marcozecchini | 0:9fca2b23d0ba | 41 | volatile int ticker_count = 0; |
marcozecchini | 0:9fca2b23d0ba | 42 | volatile uint32_t callback_trigger_count = 0; |
marcozecchini | 0:9fca2b23d0ba | 43 | static const int test_timeout = 240; |
marcozecchini | 0:9fca2b23d0ba | 44 | Timeout timeout; |
marcozecchini | 0:9fca2b23d0ba | 45 | |
marcozecchini | 0:9fca2b23d0ba | 46 | void set_incremeant_count() { |
marcozecchini | 0:9fca2b23d0ba | 47 | timeout.attach_us(set_incremeant_count, PERIOD_US); |
marcozecchini | 0:9fca2b23d0ba | 48 | ++callback_trigger_count; |
marcozecchini | 0:9fca2b23d0ba | 49 | } |
marcozecchini | 0:9fca2b23d0ba | 50 | |
marcozecchini | 0:9fca2b23d0ba | 51 | void test_case_timeout() { |
marcozecchini | 0:9fca2b23d0ba | 52 | |
marcozecchini | 0:9fca2b23d0ba | 53 | char _key[11] = { }; |
marcozecchini | 0:9fca2b23d0ba | 54 | char _value[128] = { }; |
marcozecchini | 0:9fca2b23d0ba | 55 | int expected_key = 1; |
marcozecchini | 0:9fca2b23d0ba | 56 | uint8_t results_size = 0; |
marcozecchini | 0:9fca2b23d0ba | 57 | |
marcozecchini | 0:9fca2b23d0ba | 58 | greentea_send_kv("timing_drift_check_start", 0); |
marcozecchini | 0:9fca2b23d0ba | 59 | timeout.attach_us(set_incremeant_count, PERIOD_US); |
marcozecchini | 0:9fca2b23d0ba | 60 | |
marcozecchini | 0:9fca2b23d0ba | 61 | // wait for 1st signal from host |
marcozecchini | 0:9fca2b23d0ba | 62 | do { |
marcozecchini | 0:9fca2b23d0ba | 63 | greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); |
marcozecchini | 0:9fca2b23d0ba | 64 | expected_key = strcmp(_key, "base_time"); |
marcozecchini | 0:9fca2b23d0ba | 65 | } while (expected_key); |
marcozecchini | 0:9fca2b23d0ba | 66 | |
marcozecchini | 0:9fca2b23d0ba | 67 | greentea_send_kv(_key, callback_trigger_count * PERIOD_US); |
marcozecchini | 0:9fca2b23d0ba | 68 | |
marcozecchini | 0:9fca2b23d0ba | 69 | // wait for 2nd signal from host |
marcozecchini | 0:9fca2b23d0ba | 70 | greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); |
marcozecchini | 0:9fca2b23d0ba | 71 | greentea_send_kv(_key, callback_trigger_count * PERIOD_US); |
marcozecchini | 0:9fca2b23d0ba | 72 | |
marcozecchini | 0:9fca2b23d0ba | 73 | //get the results from host |
marcozecchini | 0:9fca2b23d0ba | 74 | greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); |
marcozecchini | 0:9fca2b23d0ba | 75 | |
marcozecchini | 0:9fca2b23d0ba | 76 | TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key,"Host side script reported a fail..."); |
marcozecchini | 0:9fca2b23d0ba | 77 | } |
marcozecchini | 0:9fca2b23d0ba | 78 | |
marcozecchini | 0:9fca2b23d0ba | 79 | // Test casess |
marcozecchini | 0:9fca2b23d0ba | 80 | Case cases[] = { Case("Timers: toggle on/off", test_case_timeout), }; |
marcozecchini | 0:9fca2b23d0ba | 81 | |
marcozecchini | 0:9fca2b23d0ba | 82 | utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { |
marcozecchini | 0:9fca2b23d0ba | 83 | GREENTEA_SETUP(test_timeout, "timing_drift_auto"); |
marcozecchini | 0:9fca2b23d0ba | 84 | return greentea_test_setup_handler(number_of_cases); |
marcozecchini | 0:9fca2b23d0ba | 85 | } |
marcozecchini | 0:9fca2b23d0ba | 86 | |
marcozecchini | 0:9fca2b23d0ba | 87 | Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
marcozecchini | 0:9fca2b23d0ba | 88 | |
marcozecchini | 0:9fca2b23d0ba | 89 | int main() { |
marcozecchini | 0:9fca2b23d0ba | 90 | Harness::run(specification); |
marcozecchini | 0:9fca2b23d0ba | 91 | } |