Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2017 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include <utility> // std::pair 00017 #include "mbed.h" 00018 #include "greentea-client/test_env.h" 00019 00020 uint32_t test_64(uint64_t ticks) 00021 { 00022 ticks >>= 3; // divide by 8 00023 if (ticks > 0xFFFFFFFF) { 00024 ticks /= 3; 00025 } else { 00026 ticks = (ticks * 0x55555556) >> 32; // divide by 3 00027 } 00028 return (uint32_t)(0xFFFFFFFF & ticks); 00029 } 00030 00031 const char *result_str(bool result) 00032 { 00033 return result ? "[OK]" : "[FAIL]"; 00034 } 00035 00036 int main() 00037 { 00038 GREENTEA_SETUP(5, "default_auto"); 00039 00040 bool result = true; 00041 00042 { 00043 // 0xFFFFFFFF * 8 = 0x7fffffff8 00044 std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8); 00045 uint32_t test_ret = test_64(values.second); 00046 bool test_res = values.first == test_ret; 00047 result = result && test_res; 00048 printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res)); 00049 } 00050 00051 { 00052 // 0xFFFFFFFF * 24 = 0x17ffffffe8 00053 std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8); 00054 uint32_t test_ret = test_64(values.second); 00055 bool test_res = values.first == test_ret; 00056 result = result && test_res; 00057 printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res)); 00058 } 00059 00060 GREENTEA_TESTSUITE_RESULT(result); 00061 }
Generated on Tue Aug 9 2022 00:37:14 by
1.7.2