Added missing files
[hackover2013-badge-firmware.git] / drivers / rtc / rtc.c
1 /**************************************************************************/
2 /*!
3 @file rtc.c
4 @author K. Townsend (microBuilder.eu)
5
6 @brief Generic time and RTC-related helper functions
7
8 @section DESCRIPTION
9
10 Time and RTC-related helper functions.
11
12 @section LICENSE
13
14 Software License Agreement (BSD License)
15
16 Copyright (c) 2012, microBuilder SARL
17 All rights reserved.
18
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions are met:
21 1. Redistributions of source code must retain the above copyright
22 notice, this list of conditions and the following disclaimer.
23 2. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
26 3. Neither the name of the copyright holders nor the
27 names of its contributors may be used to endorse or promote products
28 derived from this software without specific prior written permission.
29
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
31 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41 /**************************************************************************/
42 #include "rtc.h"
43
44 /**************************************************************************/
45 /*!
46 @brief Converts the supplied date and time to seconds since the
47 epoch (00h00, 1 Jan 1970).
48
49 @section EXAMPLE
50
51 @code
52
53 long epochTime;
54 // 19 Jan 2012 at 13:42:27 ... DST unnknown (-1)
55 epochTime = rtcToEpochTime(2012, 0, 19, 13, 42, 27, -1);
56
57 // Should return 1326980547 (number of seconds since epoch)
58
59 @endcode
60 */
61 /**************************************************************************/
62 long rtcToEpochTime(int year, int month, int mday, int hour, int min, int sec, int isdst)
63 {
64 // This is purely a convenience function since it uses mktime beneath the hood
65 struct tm t;
66 time_t time;
67
68 if (year > 1900) year -= 1900;
69
70 t.tm_year = year;
71 t.tm_mon = month; // Month, 0 - jan
72 t.tm_mday = mday; // Day of the month
73 t.tm_hour = hour;
74 t.tm_min = min;
75 t.tm_sec = sec;
76 t.tm_isdst = isdst; // Is DST on? 1 = yes, 0 = no, -1 = unknown
77 time = mktime(&t);
78
79 // Return seconds since the epoch (00h00, 1 Jan 1970)
80 return (long)time;
81 }
82
83 void rtcFunction(void)
84 {
85 }
This page took 0.061336 seconds and 5 git commands to generate.