mbed libraries for KL25Z
rtc_time.h@8:c14af7958ef5, 2012-11-09 (annotated)
- Committer:
- emilmont
- Date:
- Fri Nov 09 11:33:53 2012 +0000
- Revision:
- 8:c14af7958ef5
- Parent:
- 2:e9a661555b58
- Child:
- 9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 8:c14af7958ef5 | 1 | /** Implementation of the C time.h functions |
emilmont | 2:e9a661555b58 | 2 | * |
emilmont | 2:e9a661555b58 | 3 | * Provides mechanisms to set and read the current time, based |
emilmont | 2:e9a661555b58 | 4 | * on the microcontroller Real-Time Clock (RTC), plus some |
emilmont | 2:e9a661555b58 | 5 | * standard C manipulation and formating functions. |
emilmont | 2:e9a661555b58 | 6 | * |
emilmont | 2:e9a661555b58 | 7 | * Example: |
emilmont | 8:c14af7958ef5 | 8 | * @code |
emilmont | 8:c14af7958ef5 | 9 | * #include "mbed.h" |
emilmont | 8:c14af7958ef5 | 10 | * |
emilmont | 8:c14af7958ef5 | 11 | * int main() { |
emilmont | 8:c14af7958ef5 | 12 | * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
emilmont | 8:c14af7958ef5 | 13 | * |
emilmont | 8:c14af7958ef5 | 14 | * while(1) { |
emilmont | 8:c14af7958ef5 | 15 | * time_t seconds = time(NULL); |
emilmont | 8:c14af7958ef5 | 16 | * |
emilmont | 8:c14af7958ef5 | 17 | * printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
emilmont | 8:c14af7958ef5 | 18 | * |
emilmont | 8:c14af7958ef5 | 19 | * printf("Time as a basic string = %s", ctime(&seconds)); |
emilmont | 8:c14af7958ef5 | 20 | * |
emilmont | 8:c14af7958ef5 | 21 | * char buffer[32]; |
emilmont | 8:c14af7958ef5 | 22 | * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
emilmont | 8:c14af7958ef5 | 23 | * printf("Time as a custom formatted string = %s", buffer); |
emilmont | 8:c14af7958ef5 | 24 | * |
emilmont | 8:c14af7958ef5 | 25 | * wait(1); |
emilmont | 8:c14af7958ef5 | 26 | * } |
emilmont | 8:c14af7958ef5 | 27 | * } |
emilmont | 8:c14af7958ef5 | 28 | * @endcode |
emilmont | 2:e9a661555b58 | 29 | */ |
emilmont | 2:e9a661555b58 | 30 | |
emilmont | 2:e9a661555b58 | 31 | /* mbed Microcontroller Library - rtc_time |
emilmont | 2:e9a661555b58 | 32 | * Copyright (c) 2009 ARM Limited. All rights reserved. |
emilmont | 2:e9a661555b58 | 33 | */ |
emilmont | 2:e9a661555b58 | 34 | |
emilmont | 2:e9a661555b58 | 35 | #include <time.h> |
emilmont | 2:e9a661555b58 | 36 | |
emilmont | 2:e9a661555b58 | 37 | #ifdef __cplusplus |
emilmont | 2:e9a661555b58 | 38 | extern "C" { |
emilmont | 2:e9a661555b58 | 39 | #endif |
emilmont | 2:e9a661555b58 | 40 | |
emilmont | 8:c14af7958ef5 | 41 | /** Set the current time |
emilmont | 2:e9a661555b58 | 42 | * |
emilmont | 2:e9a661555b58 | 43 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) |
emilmont | 2:e9a661555b58 | 44 | * to the time represented by the number of seconds since January 1, 1970 |
emilmont | 2:e9a661555b58 | 45 | * (the UNIX timestamp). |
emilmont | 2:e9a661555b58 | 46 | * |
emilmont | 8:c14af7958ef5 | 47 | * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) |
emilmont | 2:e9a661555b58 | 48 | * |
emilmont | 2:e9a661555b58 | 49 | * Example: |
emilmont | 8:c14af7958ef5 | 50 | * @code |
emilmont | 8:c14af7958ef5 | 51 | * #include "mbed.h" |
emilmont | 2:e9a661555b58 | 52 | * |
emilmont | 8:c14af7958ef5 | 53 | * int main() { |
emilmont | 8:c14af7958ef5 | 54 | * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 |
emilmont | 8:c14af7958ef5 | 55 | * } |
emilmont | 8:c14af7958ef5 | 56 | * @endcode |
emilmont | 8:c14af7958ef5 | 57 | */ |
emilmont | 8:c14af7958ef5 | 58 | void set_time(time_t t); |
emilmont | 2:e9a661555b58 | 59 | |
emilmont | 2:e9a661555b58 | 60 | #ifdef __cplusplus |
emilmont | 2:e9a661555b58 | 61 | } |
emilmont | 2:e9a661555b58 | 62 | #endif |