Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 00019 /* 00020 * Tests is to measure the accuracy of Timeout over a period of time 00021 * 00022 * 00023 * 1) DUT would start to update callback_trigger_count every milli sec 00024 * 2) Host would query what is current count base_time, Device responds by the callback_trigger_count 00025 * 3) Host after waiting for measurement stretch. It will query for device time again final_time. 00026 * 4) Host computes the drift considering base_time, final_time, transport delay and measurement stretch 00027 * 5) Finally host send the results back to device pass/fail based on tolerance. 00028 * 6) More details on tests can be found in timing_drift_auto.py 00029 * 00030 */ 00031 00032 #include "mbed.h" 00033 #include "greentea-client/test_env.h" 00034 #include "utest/utest.h" 00035 #include "unity/unity.h" 00036 00037 using namespace utest::v1; 00038 00039 #define PERIOD_US 10000 00040 00041 volatile int ticker_count = 0; 00042 volatile uint32_t callback_trigger_count = 0; 00043 static const int test_timeout = 240; 00044 Timeout timeout; 00045 00046 void set_incremeant_count() { 00047 timeout.attach_us(set_incremeant_count, PERIOD_US); 00048 ++callback_trigger_count; 00049 } 00050 00051 void test_case_timeout() { 00052 00053 char _key[11] = { }; 00054 char _value[128] = { }; 00055 int expected_key = 1; 00056 uint8_t results_size = 0; 00057 00058 greentea_send_kv("timing_drift_check_start", 0); 00059 timeout.attach_us(set_incremeant_count, PERIOD_US); 00060 00061 // wait for 1st signal from host 00062 do { 00063 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00064 expected_key = strcmp(_key, "base_time"); 00065 } while (expected_key); 00066 00067 greentea_send_kv(_key, callback_trigger_count * PERIOD_US); 00068 00069 // wait for 2nd signal from host 00070 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00071 greentea_send_kv(_key, callback_trigger_count * PERIOD_US); 00072 00073 //get the results from host 00074 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00075 00076 TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key,"Host side script reported a fail..."); 00077 } 00078 00079 // Test casess 00080 Case cases[] = { Case("Timers: toggle on/off", test_case_timeout), }; 00081 00082 utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { 00083 GREENTEA_SETUP(test_timeout, "timing_drift_auto"); 00084 return greentea_test_setup_handler(number_of_cases); 00085 } 00086 00087 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); 00088 00089 int main() { 00090 Harness::run(specification); 00091 }
Generated on Sun Jul 17 2022 08:25:27 by 1.7.2