mbed-os
Fork of mbed-os by
features/unsupported/tests/mbed/rtc/main.cpp@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #include "mbed.h" |
elessair | 0:f269e3021894 | 2 | #include "test_env.h" |
elessair | 0:f269e3021894 | 3 | |
elessair | 0:f269e3021894 | 4 | #if !DEVICE_RTC |
elessair | 0:f269e3021894 | 5 | #error [NOT_SUPPORTED] RTC is not supported |
elessair | 0:f269e3021894 | 6 | #endif |
elessair | 0:f269e3021894 | 7 | |
elessair | 0:f269e3021894 | 8 | #define CUSTOM_TIME 1256729737 |
elessair | 0:f269e3021894 | 9 | |
elessair | 0:f269e3021894 | 10 | int main() { |
elessair | 0:f269e3021894 | 11 | MBED_HOSTTEST_TIMEOUT(20); |
elessair | 0:f269e3021894 | 12 | MBED_HOSTTEST_SELECT(rtc_auto); |
elessair | 0:f269e3021894 | 13 | MBED_HOSTTEST_DESCRIPTION(RTC); |
elessair | 0:f269e3021894 | 14 | MBED_HOSTTEST_START("MBED_16"); |
elessair | 0:f269e3021894 | 15 | |
elessair | 0:f269e3021894 | 16 | char buffer[32] = {0}; |
elessair | 0:f269e3021894 | 17 | set_time(CUSTOM_TIME); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
elessair | 0:f269e3021894 | 18 | while(1) { |
elessair | 0:f269e3021894 | 19 | time_t seconds = time(NULL); |
elessair | 0:f269e3021894 | 20 | strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds)); |
elessair | 0:f269e3021894 | 21 | printf("MBED: [%ld] [%s]\r\n", seconds, buffer); |
elessair | 0:f269e3021894 | 22 | wait(1); |
elessair | 0:f269e3021894 | 23 | } |
elessair | 0:f269e3021894 | 24 | } |