Preliminary main mbed library for nexpaq development
TESTS/mbed_drivers/timeout/main.cpp@0:6c56fb4bc5f0, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:27:58 2016 +0000
- Revision:
- 0:6c56fb4bc5f0
Moving to library for sharing updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | /* |
nexpaq | 0:6c56fb4bc5f0 | 2 | * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved |
nexpaq | 0:6c56fb4bc5f0 | 3 | * SPDX-License-Identifier: Apache-2.0 |
nexpaq | 0:6c56fb4bc5f0 | 4 | * |
nexpaq | 0:6c56fb4bc5f0 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
nexpaq | 0:6c56fb4bc5f0 | 6 | * not use this file except in compliance with the License. |
nexpaq | 0:6c56fb4bc5f0 | 7 | * You may obtain a copy of the License at |
nexpaq | 0:6c56fb4bc5f0 | 8 | * |
nexpaq | 0:6c56fb4bc5f0 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 0:6c56fb4bc5f0 | 10 | * |
nexpaq | 0:6c56fb4bc5f0 | 11 | * Unless required by applicable law or agreed to in writing, software |
nexpaq | 0:6c56fb4bc5f0 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
nexpaq | 0:6c56fb4bc5f0 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 0:6c56fb4bc5f0 | 14 | * See the License for the specific language governing permissions and |
nexpaq | 0:6c56fb4bc5f0 | 15 | * limitations under the License. |
nexpaq | 0:6c56fb4bc5f0 | 16 | */ |
nexpaq | 0:6c56fb4bc5f0 | 17 | #include "mbed.h" |
nexpaq | 0:6c56fb4bc5f0 | 18 | #include "greentea-client/test_env.h" |
nexpaq | 0:6c56fb4bc5f0 | 19 | #include "utest/utest.h" |
nexpaq | 0:6c56fb4bc5f0 | 20 | |
nexpaq | 0:6c56fb4bc5f0 | 21 | using namespace utest::v1; |
nexpaq | 0:6c56fb4bc5f0 | 22 | |
nexpaq | 0:6c56fb4bc5f0 | 23 | Timeout timeout; |
nexpaq | 0:6c56fb4bc5f0 | 24 | DigitalOut led(LED1); |
nexpaq | 0:6c56fb4bc5f0 | 25 | volatile int ticker_count = 0; |
nexpaq | 0:6c56fb4bc5f0 | 26 | volatile bool print_tick = false; |
nexpaq | 0:6c56fb4bc5f0 | 27 | static const int total_ticks = 10; |
nexpaq | 0:6c56fb4bc5f0 | 28 | const int ONE_SECOND_US = 1000000; |
nexpaq | 0:6c56fb4bc5f0 | 29 | |
nexpaq | 0:6c56fb4bc5f0 | 30 | void send_kv_tick() { |
nexpaq | 0:6c56fb4bc5f0 | 31 | if (ticker_count <= total_ticks) { |
nexpaq | 0:6c56fb4bc5f0 | 32 | timeout.attach_us(send_kv_tick, ONE_SECOND_US); |
nexpaq | 0:6c56fb4bc5f0 | 33 | print_tick = true; |
nexpaq | 0:6c56fb4bc5f0 | 34 | } |
nexpaq | 0:6c56fb4bc5f0 | 35 | } |
nexpaq | 0:6c56fb4bc5f0 | 36 | |
nexpaq | 0:6c56fb4bc5f0 | 37 | void wait_and_print() { |
nexpaq | 0:6c56fb4bc5f0 | 38 | while(ticker_count <= total_ticks) { |
nexpaq | 0:6c56fb4bc5f0 | 39 | if (print_tick) { |
nexpaq | 0:6c56fb4bc5f0 | 40 | print_tick = false; |
nexpaq | 0:6c56fb4bc5f0 | 41 | greentea_send_kv("tick", ticker_count++); |
nexpaq | 0:6c56fb4bc5f0 | 42 | led = !led; |
nexpaq | 0:6c56fb4bc5f0 | 43 | } |
nexpaq | 0:6c56fb4bc5f0 | 44 | } |
nexpaq | 0:6c56fb4bc5f0 | 45 | } |
nexpaq | 0:6c56fb4bc5f0 | 46 | |
nexpaq | 0:6c56fb4bc5f0 | 47 | void test_case_ticker() { |
nexpaq | 0:6c56fb4bc5f0 | 48 | timeout.attach_us(send_kv_tick, ONE_SECOND_US); |
nexpaq | 0:6c56fb4bc5f0 | 49 | wait_and_print(); |
nexpaq | 0:6c56fb4bc5f0 | 50 | } |
nexpaq | 0:6c56fb4bc5f0 | 51 | |
nexpaq | 0:6c56fb4bc5f0 | 52 | // Test cases |
nexpaq | 0:6c56fb4bc5f0 | 53 | Case cases[] = { |
nexpaq | 0:6c56fb4bc5f0 | 54 | Case("Timers: toggle on/off", test_case_ticker), |
nexpaq | 0:6c56fb4bc5f0 | 55 | }; |
nexpaq | 0:6c56fb4bc5f0 | 56 | |
nexpaq | 0:6c56fb4bc5f0 | 57 | utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { |
nexpaq | 0:6c56fb4bc5f0 | 58 | GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto"); |
nexpaq | 0:6c56fb4bc5f0 | 59 | return greentea_test_setup_handler(number_of_cases); |
nexpaq | 0:6c56fb4bc5f0 | 60 | } |
nexpaq | 0:6c56fb4bc5f0 | 61 | |
nexpaq | 0:6c56fb4bc5f0 | 62 | Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
nexpaq | 0:6c56fb4bc5f0 | 63 | |
nexpaq | 0:6c56fb4bc5f0 | 64 | int main() { |
nexpaq | 0:6c56fb4bc5f0 | 65 | Harness::run(specification); |
nexpaq | 0:6c56fb4bc5f0 | 66 | } |
nexpaq | 0:6c56fb4bc5f0 | 67 |