Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <utility>      // std::pair
00002 #include "mbed.h"
00003 #include "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     MBED_HOSTTEST_TIMEOUT(20);
00021     MBED_HOSTTEST_SELECT(default_auto);
00022     MBED_HOSTTEST_DESCRIPTION(Integer constant division);
00023     MBED_HOSTTEST_START("MBED_26");
00024 
00025     bool result = true;
00026 
00027     {   // 0xFFFFFFFF *  8 =  0x7fffffff8
00028         std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
00029         uint32_t test_ret = test_64(values.second);
00030         bool test_res = values.first == test_ret;
00031         result = result && test_res;
00032         printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
00033     }
00034 
00035     {   // 0xFFFFFFFF * 24 = 0x17ffffffe8
00036         std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
00037         uint32_t test_ret = test_64(values.second);
00038         bool test_res = values.first == test_ret;
00039         result = result && test_res;
00040         printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
00041     }
00042 
00043     MBED_HOSTTEST_RESULT(result);
00044 }