Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 /* mbed Microcontroller Library
marcozecchini 0:9fca2b23d0ba 2 * Copyright (c) 2017 ARM Limited
marcozecchini 0:9fca2b23d0ba 3 *
marcozecchini 0:9fca2b23d0ba 4 * Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 5 * you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 6 * You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 7 *
marcozecchini 0:9fca2b23d0ba 8 * http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 9 *
marcozecchini 0:9fca2b23d0ba 10 * Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 11 * distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 13 * See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 14 * limitations under the License.
marcozecchini 0:9fca2b23d0ba 15 */
marcozecchini 0:9fca2b23d0ba 16 #include <utility> // std::pair
marcozecchini 0:9fca2b23d0ba 17 #include "mbed.h"
marcozecchini 0:9fca2b23d0ba 18 #include "greentea-client/test_env.h"
marcozecchini 0:9fca2b23d0ba 19
marcozecchini 0:9fca2b23d0ba 20 uint32_t test_64(uint64_t ticks) {
marcozecchini 0:9fca2b23d0ba 21 ticks >>= 3; // divide by 8
marcozecchini 0:9fca2b23d0ba 22 if (ticks > 0xFFFFFFFF) {
marcozecchini 0:9fca2b23d0ba 23 ticks /= 3;
marcozecchini 0:9fca2b23d0ba 24 } else {
marcozecchini 0:9fca2b23d0ba 25 ticks = (ticks * 0x55555556) >> 32; // divide by 3
marcozecchini 0:9fca2b23d0ba 26 }
marcozecchini 0:9fca2b23d0ba 27 return (uint32_t)(0xFFFFFFFF & ticks);
marcozecchini 0:9fca2b23d0ba 28 }
marcozecchini 0:9fca2b23d0ba 29
marcozecchini 0:9fca2b23d0ba 30 const char *result_str(bool result) {
marcozecchini 0:9fca2b23d0ba 31 return result ? "[OK]" : "[FAIL]";
marcozecchini 0:9fca2b23d0ba 32 }
marcozecchini 0:9fca2b23d0ba 33
marcozecchini 0:9fca2b23d0ba 34 int main() {
marcozecchini 0:9fca2b23d0ba 35 GREENTEA_SETUP(5, "default_auto");
marcozecchini 0:9fca2b23d0ba 36
marcozecchini 0:9fca2b23d0ba 37 bool result = true;
marcozecchini 0:9fca2b23d0ba 38
marcozecchini 0:9fca2b23d0ba 39 { // 0xFFFFFFFF * 8 = 0x7fffffff8
marcozecchini 0:9fca2b23d0ba 40 std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
marcozecchini 0:9fca2b23d0ba 41 uint32_t test_ret = test_64(values.second);
marcozecchini 0:9fca2b23d0ba 42 bool test_res = values.first == test_ret;
marcozecchini 0:9fca2b23d0ba 43 result = result && test_res;
marcozecchini 0:9fca2b23d0ba 44 printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
marcozecchini 0:9fca2b23d0ba 45 }
marcozecchini 0:9fca2b23d0ba 46
marcozecchini 0:9fca2b23d0ba 47 { // 0xFFFFFFFF * 24 = 0x17ffffffe8
marcozecchini 0:9fca2b23d0ba 48 std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
marcozecchini 0:9fca2b23d0ba 49 uint32_t test_ret = test_64(values.second);
marcozecchini 0:9fca2b23d0ba 50 bool test_res = values.first == test_ret;
marcozecchini 0:9fca2b23d0ba 51 result = result && test_res;
marcozecchini 0:9fca2b23d0ba 52 printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
marcozecchini 0:9fca2b23d0ba 53 }
marcozecchini 0:9fca2b23d0ba 54
marcozecchini 0:9fca2b23d0ba 55 GREENTEA_TESTSUITE_RESULT(result);
marcozecchini 0:9fca2b23d0ba 56 }