dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
nexpaq
Date:
Sat Sep 17 16:32:05 2016 +0000
Revision:
1:55a6170b404f
checking in for sharing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 1:55a6170b404f 1 #include <utility> // std::pair
nexpaq 1:55a6170b404f 2 #include "mbed.h"
nexpaq 1:55a6170b404f 3 #include "greentea-client/test_env.h"
nexpaq 1:55a6170b404f 4
nexpaq 1:55a6170b404f 5 uint32_t test_64(uint64_t ticks) {
nexpaq 1:55a6170b404f 6 ticks >>= 3; // divide by 8
nexpaq 1:55a6170b404f 7 if (ticks > 0xFFFFFFFF) {
nexpaq 1:55a6170b404f 8 ticks /= 3;
nexpaq 1:55a6170b404f 9 } else {
nexpaq 1:55a6170b404f 10 ticks = (ticks * 0x55555556) >> 32; // divide by 3
nexpaq 1:55a6170b404f 11 }
nexpaq 1:55a6170b404f 12 return (uint32_t)(0xFFFFFFFF & ticks);
nexpaq 1:55a6170b404f 13 }
nexpaq 1:55a6170b404f 14
nexpaq 1:55a6170b404f 15 const char *result_str(bool result) {
nexpaq 1:55a6170b404f 16 return result ? "[OK]" : "[FAIL]";
nexpaq 1:55a6170b404f 17 }
nexpaq 1:55a6170b404f 18
nexpaq 1:55a6170b404f 19 int main() {
nexpaq 1:55a6170b404f 20 GREENTEA_SETUP(5, "default_auto");
nexpaq 1:55a6170b404f 21
nexpaq 1:55a6170b404f 22 bool result = true;
nexpaq 1:55a6170b404f 23
nexpaq 1:55a6170b404f 24 { // 0xFFFFFFFF * 8 = 0x7fffffff8
nexpaq 1:55a6170b404f 25 std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
nexpaq 1:55a6170b404f 26 uint32_t test_ret = test_64(values.second);
nexpaq 1:55a6170b404f 27 bool test_res = values.first == test_ret;
nexpaq 1:55a6170b404f 28 result = result && test_res;
nexpaq 1:55a6170b404f 29 printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
nexpaq 1:55a6170b404f 30 }
nexpaq 1:55a6170b404f 31
nexpaq 1:55a6170b404f 32 { // 0xFFFFFFFF * 24 = 0x17ffffffe8
nexpaq 1:55a6170b404f 33 std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
nexpaq 1:55a6170b404f 34 uint32_t test_ret = test_64(values.second);
nexpaq 1:55a6170b404f 35 bool test_res = values.first == test_ret;
nexpaq 1:55a6170b404f 36 result = result && test_res;
nexpaq 1:55a6170b404f 37 printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
nexpaq 1:55a6170b404f 38 }
nexpaq 1:55a6170b404f 39
nexpaq 1:55a6170b404f 40 GREENTEA_TESTSUITE_RESULT(result);
nexpaq 1:55a6170b404f 41 }