Fork of the official mbed C/C++ SDK provides the software platform and libraries to build your applications. The fork has the documentation converted to Doxygen format

Dependents:   NervousPuppySprintOne NervousPuppySprint2602 Robot WarehouseBot1 ... more

Fork of mbed by mbed official

Committer:
rolf.meyer@arm.com
Date:
Wed Oct 28 17:43:46 2009 +0000
Revision:
14:20a79241b4a0
Child:
27:7110ebee3484
mbed integrates the rtc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rolf.meyer@arm.com 14:20a79241b4a0 1 /* Title: time
rolf.meyer@arm.com 14:20a79241b4a0 2 * Implementation of the C time.h functions
rolf.meyer@arm.com 14:20a79241b4a0 3 *
rolf.meyer@arm.com 14:20a79241b4a0 4 * Provides mechanisms to set and read the current time, based
rolf.meyer@arm.com 14:20a79241b4a0 5 * on the microcontroller Real-Time Clock (RTC), plus some
rolf.meyer@arm.com 14:20a79241b4a0 6 * standard C manipulation and formating functions.
rolf.meyer@arm.com 14:20a79241b4a0 7 *
rolf.meyer@arm.com 14:20a79241b4a0 8 * Example:
rolf.meyer@arm.com 14:20a79241b4a0 9 * > #include "mbed.h"
rolf.meyer@arm.com 14:20a79241b4a0 10 * >
rolf.meyer@arm.com 14:20a79241b4a0 11 * > int main() {
rolf.meyer@arm.com 14:20a79241b4a0 12 * > set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
rolf.meyer@arm.com 14:20a79241b4a0 13 * >
rolf.meyer@arm.com 14:20a79241b4a0 14 * > while(1) {
rolf.meyer@arm.com 14:20a79241b4a0 15 * > time_t seconds = time(NULL);
rolf.meyer@arm.com 14:20a79241b4a0 16 * >
rolf.meyer@arm.com 14:20a79241b4a0 17 * > printf("Time as seconds since January 1, 1970 = %d\n", seconds);
rolf.meyer@arm.com 14:20a79241b4a0 18 * >
rolf.meyer@arm.com 14:20a79241b4a0 19 * > printf("Time as a basic string = %s", ctime(&seconds));
rolf.meyer@arm.com 14:20a79241b4a0 20 * >
rolf.meyer@arm.com 14:20a79241b4a0 21 * > char buffer[32];
rolf.meyer@arm.com 14:20a79241b4a0 22 * > strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
rolf.meyer@arm.com 14:20a79241b4a0 23 * > printf("Time as a custom formatted string = %s", buffer);
rolf.meyer@arm.com 14:20a79241b4a0 24 * >
rolf.meyer@arm.com 14:20a79241b4a0 25 * > wait(1);
rolf.meyer@arm.com 14:20a79241b4a0 26 * > }
rolf.meyer@arm.com 14:20a79241b4a0 27 * > }
rolf.meyer@arm.com 14:20a79241b4a0 28 */
rolf.meyer@arm.com 14:20a79241b4a0 29
rolf.meyer@arm.com 14:20a79241b4a0 30 /* mbed Microcontroller Library - rtc_time
rolf.meyer@arm.com 14:20a79241b4a0 31 * Copyright (c) 2009 ARM Limited. All rights reserved.
rolf.meyer@arm.com 14:20a79241b4a0 32 * sford
rolf.meyer@arm.com 14:20a79241b4a0 33 */
rolf.meyer@arm.com 14:20a79241b4a0 34
rolf.meyer@arm.com 14:20a79241b4a0 35 #include <time.h>
rolf.meyer@arm.com 14:20a79241b4a0 36
rolf.meyer@arm.com 14:20a79241b4a0 37 #ifdef __cplusplus
rolf.meyer@arm.com 14:20a79241b4a0 38 extern "C" {
rolf.meyer@arm.com 14:20a79241b4a0 39 #endif
rolf.meyer@arm.com 14:20a79241b4a0 40
rolf.meyer@arm.com 14:20a79241b4a0 41 #if 0 // for documentation only
rolf.meyer@arm.com 14:20a79241b4a0 42 /* Function: time
rolf.meyer@arm.com 14:20a79241b4a0 43 * Get the current time
rolf.meyer@arm.com 14:20a79241b4a0 44 *
rolf.meyer@arm.com 14:20a79241b4a0 45 * Returns the current timestamp as the number of seconds since January 1, 1970
rolf.meyer@arm.com 14:20a79241b4a0 46 * (the UNIX timestamp). The value is based on the current value of the
rolf.meyer@arm.com 14:20a79241b4a0 47 * microcontroller Real-Time Clock (RTC), which can be set using <set_time>.
rolf.meyer@arm.com 14:20a79241b4a0 48 *
rolf.meyer@arm.com 14:20a79241b4a0 49 * Example:
rolf.meyer@arm.com 14:20a79241b4a0 50 * > #include "mbed.h"
rolf.meyer@arm.com 14:20a79241b4a0 51 * >
rolf.meyer@arm.com 14:20a79241b4a0 52 * > int main() {
rolf.meyer@arm.com 14:20a79241b4a0 53 * > time_t seconds = time(NULL);
rolf.meyer@arm.com 14:20a79241b4a0 54 * > printf("It is %d seconds since January 1, 1970\n", seconds);
rolf.meyer@arm.com 14:20a79241b4a0 55 * > }
rolf.meyer@arm.com 14:20a79241b4a0 56 *
rolf.meyer@arm.com 14:20a79241b4a0 57 * Variables:
rolf.meyer@arm.com 14:20a79241b4a0 58 * t - Pointer to a time_t to be set, or NULL if not used
rolf.meyer@arm.com 14:20a79241b4a0 59 * returns - Number of seconds since January 1, 1970 (the UNIX timestamp)
rolf.meyer@arm.com 14:20a79241b4a0 60 */
rolf.meyer@arm.com 14:20a79241b4a0 61 time_t time(time_t *t);
rolf.meyer@arm.com 14:20a79241b4a0 62 #endif
rolf.meyer@arm.com 14:20a79241b4a0 63
rolf.meyer@arm.com 14:20a79241b4a0 64 /* Function: set_time
rolf.meyer@arm.com 14:20a79241b4a0 65 * Set the current time
rolf.meyer@arm.com 14:20a79241b4a0 66 *
rolf.meyer@arm.com 14:20a79241b4a0 67 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
rolf.meyer@arm.com 14:20a79241b4a0 68 * to the time represented by the number of seconds since January 1, 1970
rolf.meyer@arm.com 14:20a79241b4a0 69 * (the UNIX timestamp).
rolf.meyer@arm.com 14:20a79241b4a0 70 *
rolf.meyer@arm.com 14:20a79241b4a0 71 * Example:
rolf.meyer@arm.com 14:20a79241b4a0 72 * > #include "mbed.h"
rolf.meyer@arm.com 14:20a79241b4a0 73 * >
rolf.meyer@arm.com 14:20a79241b4a0 74 * > int main() {
rolf.meyer@arm.com 14:20a79241b4a0 75 * > set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
rolf.meyer@arm.com 14:20a79241b4a0 76 * > }
rolf.meyer@arm.com 14:20a79241b4a0 77 *
rolf.meyer@arm.com 14:20a79241b4a0 78 * Variables:
rolf.meyer@arm.com 14:20a79241b4a0 79 * t - Number of seconds since January 1, 1970 (the UNIX timestamp)
rolf.meyer@arm.com 14:20a79241b4a0 80 */
rolf.meyer@arm.com 14:20a79241b4a0 81 void set_time(time_t t);
rolf.meyer@arm.com 14:20a79241b4a0 82
rolf.meyer@arm.com 14:20a79241b4a0 83 #if 0 // for documentation only
rolf.meyer@arm.com 14:20a79241b4a0 84 /* Function: mktime
rolf.meyer@arm.com 14:20a79241b4a0 85 * Converts a tm structure in to a timestamp
rolf.meyer@arm.com 14:20a79241b4a0 86 *
rolf.meyer@arm.com 14:20a79241b4a0 87 * Converts the tm structure in to a timestamp in seconds since January 1, 1970
rolf.meyer@arm.com 14:20a79241b4a0 88 * (the UNIX timestamp). The values of tm_wday and tm_yday of the tm structure
rolf.meyer@arm.com 14:20a79241b4a0 89 * are also updated to their appropriate values.
rolf.meyer@arm.com 14:20a79241b4a0 90 *
rolf.meyer@arm.com 14:20a79241b4a0 91 * Example:
rolf.meyer@arm.com 14:20a79241b4a0 92 * > #include "mbed.h"
rolf.meyer@arm.com 14:20a79241b4a0 93 * >
rolf.meyer@arm.com 14:20a79241b4a0 94 * > int main() {
rolf.meyer@arm.com 14:20a79241b4a0 95 * > // setup time structure for Wed, 28 Oct 2009 11:35:37
rolf.meyer@arm.com 14:20a79241b4a0 96 * > struct tm t;
rolf.meyer@arm.com 14:20a79241b4a0 97 * > t.tm_sec = 37; // 0-59
rolf.meyer@arm.com 14:20a79241b4a0 98 * > t.tm_min = 35; // 0-59
rolf.meyer@arm.com 14:20a79241b4a0 99 * > t.tm_hour = 11; // 0-23
rolf.meyer@arm.com 14:20a79241b4a0 100 * > t.tm_mday = 28; // 1-31
rolf.meyer@arm.com 14:20a79241b4a0 101 * > t.tm_mon = 9; // 0-11
rolf.meyer@arm.com 14:20a79241b4a0 102 * > t.tm_year = 109; // year since 1900
rolf.meyer@arm.com 14:20a79241b4a0 103 * >
rolf.meyer@arm.com 14:20a79241b4a0 104 * > // convert to timestamp and display (1256729737)
rolf.meyer@arm.com 14:20a79241b4a0 105 * > time_t seconds = mktime(&t);
rolf.meyer@arm.com 14:20a79241b4a0 106 * > printf("Time as seconds since January 1, 1970 = %d\n", seconds);
rolf.meyer@arm.com 14:20a79241b4a0 107 * > }
rolf.meyer@arm.com 14:20a79241b4a0 108 *
rolf.meyer@arm.com 14:20a79241b4a0 109 * Variables:
rolf.meyer@arm.com 14:20a79241b4a0 110 * t - The tm structure to convert
rolf.meyer@arm.com 14:20a79241b4a0 111 * returns - The converted timestamp
rolf.meyer@arm.com 14:20a79241b4a0 112 */
rolf.meyer@arm.com 14:20a79241b4a0 113 time_t mktime(struct tm *t);
rolf.meyer@arm.com 14:20a79241b4a0 114 #endif
rolf.meyer@arm.com 14:20a79241b4a0 115
rolf.meyer@arm.com 14:20a79241b4a0 116 #if 0 // for documentation only
rolf.meyer@arm.com 14:20a79241b4a0 117 /* Function: localtime
rolf.meyer@arm.com 14:20a79241b4a0 118 * Converts a timestamp in to a tm structure
rolf.meyer@arm.com 14:20a79241b4a0 119 *
rolf.meyer@arm.com 14:20a79241b4a0 120 * Converts the timestamp pointed to by t to a (statically allocated)
rolf.meyer@arm.com 14:20a79241b4a0 121 * tm structure.
rolf.meyer@arm.com 14:20a79241b4a0 122 *
rolf.meyer@arm.com 14:20a79241b4a0 123 * Example:
rolf.meyer@arm.com 14:20a79241b4a0 124 * > #include "mbed.h"
rolf.meyer@arm.com 14:20a79241b4a0 125 * >
rolf.meyer@arm.com 14:20a79241b4a0 126 * > int main() {
rolf.meyer@arm.com 14:20a79241b4a0 127 * > time_t seconds = 1256729737;
rolf.meyer@arm.com 14:20a79241b4a0 128 * > struct tm *t = localtime(&seconds);
rolf.meyer@arm.com 14:20a79241b4a0 129 * > }
rolf.meyer@arm.com 14:20a79241b4a0 130 *
rolf.meyer@arm.com 14:20a79241b4a0 131 * Variables:
rolf.meyer@arm.com 14:20a79241b4a0 132 * t - Pointer to the timestamp
rolf.meyer@arm.com 14:20a79241b4a0 133 * returns - Pointer to the (statically allocated) tm structure
rolf.meyer@arm.com 14:20a79241b4a0 134 */
rolf.meyer@arm.com 14:20a79241b4a0 135 struct tm *localtime(const time_t *t);
rolf.meyer@arm.com 14:20a79241b4a0 136 #endif
rolf.meyer@arm.com 14:20a79241b4a0 137
rolf.meyer@arm.com 14:20a79241b4a0 138 #if 0 // for documentation only
rolf.meyer@arm.com 14:20a79241b4a0 139 /* Function: ctime
rolf.meyer@arm.com 14:20a79241b4a0 140 * Converts a timestamp to a human-readable string
rolf.meyer@arm.com 14:20a79241b4a0 141 *
rolf.meyer@arm.com 14:20a79241b4a0 142 * Converts a time_t timestamp in seconds since January 1, 1970 (the UNIX
rolf.meyer@arm.com 14:20a79241b4a0 143 * timestamp) to a human readable string format. The result is of the
rolf.meyer@arm.com 14:20a79241b4a0 144 * format: "Wed Oct 28 11:35:37 2009\n"
rolf.meyer@arm.com 14:20a79241b4a0 145 *
rolf.meyer@arm.com 14:20a79241b4a0 146 * Example:
rolf.meyer@arm.com 14:20a79241b4a0 147 * > #include "mbed.h"
rolf.meyer@arm.com 14:20a79241b4a0 148 * >
rolf.meyer@arm.com 14:20a79241b4a0 149 * > int main() {
rolf.meyer@arm.com 14:20a79241b4a0 150 * > time_t seconds = time(NULL);
rolf.meyer@arm.com 14:20a79241b4a0 151 * > printf("Time as a string = %s", ctime(&seconds));
rolf.meyer@arm.com 14:20a79241b4a0 152 * > }
rolf.meyer@arm.com 14:20a79241b4a0 153 *
rolf.meyer@arm.com 14:20a79241b4a0 154 * Variables:
rolf.meyer@arm.com 14:20a79241b4a0 155 * t - The timestamp to convert
rolf.meyer@arm.com 14:20a79241b4a0 156 * returns - Pointer to a (statically allocated) string containing the
rolf.meyer@arm.com 14:20a79241b4a0 157 * human readable representation, including a '\n' character
rolf.meyer@arm.com 14:20a79241b4a0 158 */
rolf.meyer@arm.com 14:20a79241b4a0 159 char *ctime(const time_t *t);
rolf.meyer@arm.com 14:20a79241b4a0 160 #endif
rolf.meyer@arm.com 14:20a79241b4a0 161
rolf.meyer@arm.com 14:20a79241b4a0 162 #if 0 // for documentation only
rolf.meyer@arm.com 14:20a79241b4a0 163 /* Function: strftime
rolf.meyer@arm.com 14:20a79241b4a0 164 * Converts a tm structure to a custom format human-readable string
rolf.meyer@arm.com 14:20a79241b4a0 165 *
rolf.meyer@arm.com 14:20a79241b4a0 166 * Creates a formated string from a tm structure, based on a string format
rolf.meyer@arm.com 14:20a79241b4a0 167 * specifier provided.
rolf.meyer@arm.com 14:20a79241b4a0 168 *
rolf.meyer@arm.com 14:20a79241b4a0 169 * Format Specifiers:
rolf.meyer@arm.com 14:20a79241b4a0 170 * %S - Second (00-59)
rolf.meyer@arm.com 14:20a79241b4a0 171 * %M - Minute (00-59)
rolf.meyer@arm.com 14:20a79241b4a0 172 * %H - Hour (00-23)
rolf.meyer@arm.com 14:20a79241b4a0 173 * %d - Day (01-31)
rolf.meyer@arm.com 14:20a79241b4a0 174 * %m - Month (01-12)
rolf.meyer@arm.com 14:20a79241b4a0 175 * %Y/%y - Year (2009/09)
rolf.meyer@arm.com 14:20a79241b4a0 176 *
rolf.meyer@arm.com 14:20a79241b4a0 177 * %A/%a - Weekday Name (Monday/Mon)
rolf.meyer@arm.com 14:20a79241b4a0 178 * %B/%b - Month Name (January/Jan)
rolf.meyer@arm.com 14:20a79241b4a0 179 * %I - 12 Hour Format (01-12)
rolf.meyer@arm.com 14:20a79241b4a0 180 * %p - "AM" or "PM"
rolf.meyer@arm.com 14:20a79241b4a0 181 * %X - Time (14:55:02)
rolf.meyer@arm.com 14:20a79241b4a0 182 * %x - Date (08/23/01)
rolf.meyer@arm.com 14:20a79241b4a0 183 *
rolf.meyer@arm.com 14:20a79241b4a0 184 * Example:
rolf.meyer@arm.com 14:20a79241b4a0 185 * > #include "mbed.h"
rolf.meyer@arm.com 14:20a79241b4a0 186 * >
rolf.meyer@arm.com 14:20a79241b4a0 187 * > int main() {
rolf.meyer@arm.com 14:20a79241b4a0 188 * > time_t seconds = time(NULL);
rolf.meyer@arm.com 14:20a79241b4a0 189 * >
rolf.meyer@arm.com 14:20a79241b4a0 190 * > char buffer[32];
rolf.meyer@arm.com 14:20a79241b4a0 191 * > strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
rolf.meyer@arm.com 14:20a79241b4a0 192 * > printf("Time as a formatted string = %s", buffer);
rolf.meyer@arm.com 14:20a79241b4a0 193 * > }
rolf.meyer@arm.com 14:20a79241b4a0 194 *
rolf.meyer@arm.com 14:20a79241b4a0 195 * Variables:
rolf.meyer@arm.com 14:20a79241b4a0 196 * buffer - String buffer to store the result
rolf.meyer@arm.com 14:20a79241b4a0 197 * max - Maximum number of characters to store in the buffer
rolf.meyer@arm.com 14:20a79241b4a0 198 * format - Format specifier string
rolf.meyer@arm.com 14:20a79241b4a0 199 * t - Pointer to the tm structure to convert
rolf.meyer@arm.com 14:20a79241b4a0 200 * returns - Number of characters copied
rolf.meyer@arm.com 14:20a79241b4a0 201 */
rolf.meyer@arm.com 14:20a79241b4a0 202 size_t strftime(char *buffer, size_t max, const char *format, const struct tm *t);
rolf.meyer@arm.com 14:20a79241b4a0 203 #endif
rolf.meyer@arm.com 14:20a79241b4a0 204
rolf.meyer@arm.com 14:20a79241b4a0 205 #ifdef __cplusplus
rolf.meyer@arm.com 14:20a79241b4a0 206 }
rolf.meyer@arm.com 14:20a79241b4a0 207 #endif