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.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
main.cpp
00001 #include <utility> // std::pair 00002 #include "mbed.h" 00003 #include "greentea-client/test_env.h" 00004 00005 uint32_t test_64(uint64_t ticks) { 00006 ticks >>= 3; // divide by 8 00007 if (ticks > 0xFFFFFFFF) { 00008 ticks /= 3; 00009 } else { 00010 ticks = (ticks * 0x55555556) >> 32; // divide by 3 00011 } 00012 return (uint32_t)(0xFFFFFFFF & ticks); 00013 } 00014 00015 const char *result_str(bool result) { 00016 return result ? "[OK]" : "[FAIL]"; 00017 } 00018 00019 int main() { 00020 GREENTEA_SETUP(5, "default_auto"); 00021 00022 bool result = true; 00023 00024 { // 0xFFFFFFFF * 8 = 0x7fffffff8 00025 std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8); 00026 uint32_t test_ret = test_64(values.second); 00027 bool test_res = values.first == test_ret; 00028 result = result && test_res; 00029 printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res)); 00030 } 00031 00032 { // 0xFFFFFFFF * 24 = 0x17ffffffe8 00033 std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8); 00034 uint32_t test_ret = test_64(values.second); 00035 bool test_res = values.first == test_ret; 00036 result = result && test_res; 00037 printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res)); 00038 } 00039 00040 GREENTEA_TESTSUITE_RESULT(result); 00041 }
Generated on Tue Jul 12 2022 11:02:45 by
