...

Dependents:   2doejemplo Labo_TRSE_Drone

Fork of mbed by mbed official

Committer:
simon.ford@mbed.co.uk
Date:
Thu May 14 14:44:00 2009 +0000
Revision:
10:fcb9359f0959
Parent:
5:62573be585e9
Minor fix: Modified rtc time() functions to be in std namespace

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon.ford@mbed.co.uk 5:62573be585e9 1 /* mbed Microcontroller Library - rtc
simon.ford@mbed.co.uk 5:62573be585e9 2 * Copyright (c) 2008, sford
simon.ford@mbed.co.uk 5:62573be585e9 3 */
simon.ford@mbed.co.uk 5:62573be585e9 4
simon.ford@mbed.co.uk 5:62573be585e9 5 #ifndef MBED_RTC_TIME_H
simon.ford@mbed.co.uk 5:62573be585e9 6 #define MBED_RTC_TIME_H
simon.ford@mbed.co.uk 5:62573be585e9 7
simon.ford@mbed.co.uk 5:62573be585e9 8 #include <time.h>
simon.ford@mbed.co.uk 5:62573be585e9 9
simon.ford@mbed.co.uk 10:fcb9359f0959 10 using namespace std;
simon.ford@mbed.co.uk 10:fcb9359f0959 11
simon.ford@mbed.co.uk 5:62573be585e9 12 #ifdef __ARMCC_VERSION
simon.ford@mbed.co.uk 5:62573be585e9 13
simon.ford@mbed.co.uk 5:62573be585e9 14 typedef unsigned long clockid_t;
simon.ford@mbed.co.uk 5:62573be585e9 15 struct timespec {
simon.ford@mbed.co.uk 5:62573be585e9 16 time_t tv_sec;
simon.ford@mbed.co.uk 5:62573be585e9 17 long tv_nsec;
simon.ford@mbed.co.uk 5:62573be585e9 18 };
simon.ford@mbed.co.uk 5:62573be585e9 19 #define CLOCK_REALTIME (clockid_t)1
simon.ford@mbed.co.uk 5:62573be585e9 20
simon.ford@mbed.co.uk 5:62573be585e9 21 #endif
simon.ford@mbed.co.uk 5:62573be585e9 22
simon.ford@mbed.co.uk 5:62573be585e9 23 /* Section: rtc
simon.ford@mbed.co.uk 5:62573be585e9 24 * Functions for manipulating the RTC (real-time clock).
simon.ford@mbed.co.uk 5:62573be585e9 25 */
simon.ford@mbed.co.uk 5:62573be585e9 26
simon.ford@mbed.co.uk 5:62573be585e9 27 extern "C" {
simon.ford@mbed.co.uk 5:62573be585e9 28
simon.ford@mbed.co.uk 10:fcb9359f0959 29 namespace std {
simon.ford@mbed.co.uk 10:fcb9359f0959 30
simon.ford@mbed.co.uk 5:62573be585e9 31 /* Function: time
simon.ford@mbed.co.uk 5:62573be585e9 32 * Returns the number of seconds since the epoch (00:00:00 UTC,
simon.ford@mbed.co.uk 5:62573be585e9 33 * January 1, 1970), and also stores the return value in the address
simon.ford@mbed.co.uk 5:62573be585e9 34 * pointed to by timer if it is non-NULL.
simon.ford@mbed.co.uk 5:62573be585e9 35 */
simon.ford@mbed.co.uk 5:62573be585e9 36 time_t time(time_t *timer);
simon.ford@mbed.co.uk 5:62573be585e9 37
simon.ford@mbed.co.uk 10:fcb9359f0959 38 /* Function: stime
simon.ford@mbed.co.uk 10:fcb9359f0959 39 * Sets the current time, measured in seconds since the epoch, using
simon.ford@mbed.co.uk 10:fcb9359f0959 40 * the value pointed to by timer.
simon.ford@mbed.co.uk 10:fcb9359f0959 41 */
simon.ford@mbed.co.uk 10:fcb9359f0959 42 void stime(const time_t *timer);
simon.ford@mbed.co.uk 10:fcb9359f0959 43
simon.ford@mbed.co.uk 10:fcb9359f0959 44 }
simon.ford@mbed.co.uk 10:fcb9359f0959 45
simon.ford@mbed.co.uk 5:62573be585e9 46 /* Function: time_str
simon.ford@mbed.co.uk 5:62573be585e9 47 * Returns a pointer to a string representing the current time
simon.ford@mbed.co.uk 5:62573be585e9 48 * in human readable form, as generated by ctime()
simon.ford@mbed.co.uk 5:62573be585e9 49 */
simon.ford@mbed.co.uk 5:62573be585e9 50 char *time_str();
simon.ford@mbed.co.uk 5:62573be585e9 51
simon.ford@mbed.co.uk 5:62573be585e9 52
simon.ford@mbed.co.uk 5:62573be585e9 53 /* Function: set_time
simon.ford@mbed.co.uk 5:62573be585e9 54 * Sets the current time, specifying year through to day
simon.ford@mbed.co.uk 5:62573be585e9 55 */
simon.ford@mbed.co.uk 5:62573be585e9 56 void set_time(int year, int month, int day, int hour, int minute, int second);
simon.ford@mbed.co.uk 5:62573be585e9 57
simon.ford@mbed.co.uk 5:62573be585e9 58 /* Function: clock_settime
simon.ford@mbed.co.uk 5:62573be585e9 59 * Sets the time of the clock specified by clock_id, which must be
simon.ford@mbed.co.uk 5:62573be585e9 60 * CLOCK_REALTIME, according to the value of *tp.
simon.ford@mbed.co.uk 5:62573be585e9 61 */
simon.ford@mbed.co.uk 5:62573be585e9 62 int clock_settime(clockid_t clock_id, const struct timespec *tp);
simon.ford@mbed.co.uk 5:62573be585e9 63
simon.ford@mbed.co.uk 5:62573be585e9 64 /* Function: clock_gettime
simon.ford@mbed.co.uk 5:62573be585e9 65 * Sets *tp to be the current time of the clock specified by
simon.ford@mbed.co.uk 5:62573be585e9 66 * clock_id, which must be CLOCK_REALTIME.
simon.ford@mbed.co.uk 5:62573be585e9 67 */
simon.ford@mbed.co.uk 5:62573be585e9 68 int clock_gettime(clockid_t clock_id, struct timespec *tp);
simon.ford@mbed.co.uk 5:62573be585e9 69
simon.ford@mbed.co.uk 5:62573be585e9 70 /* Function: clock_getres
simon.ford@mbed.co.uk 5:62573be585e9 71 * Sets *tp to be the resolution of the clock specified by clock_id,
simon.ford@mbed.co.uk 5:62573be585e9 72 * which must be CLOCK_REALTIME.
simon.ford@mbed.co.uk 5:62573be585e9 73 */
simon.ford@mbed.co.uk 5:62573be585e9 74 int clock_getres(clockid_t clock_id, struct timespec *tp);
simon.ford@mbed.co.uk 5:62573be585e9 75
simon.ford@mbed.co.uk 5:62573be585e9 76 /* Function: create_time
simon.ford@mbed.co.uk 5:62573be585e9 77 * A convenience function for constructing a time_t value.
simon.ford@mbed.co.uk 5:62573be585e9 78 */
simon.ford@mbed.co.uk 5:62573be585e9 79 time_t create_time(int year, int month, int day, int hour, int minute, int second);
simon.ford@mbed.co.uk 5:62573be585e9 80
simon.ford@mbed.co.uk 5:62573be585e9 81 }
simon.ford@mbed.co.uk 5:62573be585e9 82
simon.ford@mbed.co.uk 5:62573be585e9 83 #endif
simon.ford@mbed.co.uk 5:62573be585e9 84