avr-libc-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-commit] [2311] Update includes and Makefiles


From: Mike Rice
Subject: [avr-libc-commit] [2311] Update includes and Makefiles
Date: Fri, 29 Mar 2013 10:05:14 +0000

Revision: 2311
          http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2311
Author:   swfltek
Date:     2013-03-29 10:05:13 +0000 (Fri, 29 Mar 2013)
Log Message:
-----------
Update includes and Makefiles

Modified Paths:
--------------
    trunk/avr-libc/include/Makefile.am
    trunk/avr-libc/include/util/Makefile.am
    trunk/avr-libc/libc/Makefile.am

Added Paths:
-----------
    trunk/avr-libc/include/time.h
    trunk/avr-libc/include/util/eu_dst.h
    trunk/avr-libc/include/util/usa_dst.h

Modified: trunk/avr-libc/include/Makefile.am
===================================================================
--- trunk/avr-libc/include/Makefile.am  2013-03-29 09:46:19 UTC (rev 2310)
+++ trunk/avr-libc/include/Makefile.am  2013-03-29 10:05:13 UTC (rev 2311)
@@ -44,4 +44,5 @@
     string.h \
     time.h
 
+
 SUBDIRS = avr compat util

Added: trunk/avr-libc/include/time.h
===================================================================
--- trunk/avr-libc/include/time.h                               (rev 0)
+++ trunk/avr-libc/include/time.h       2013-03-29 10:05:13 UTC (rev 2311)
@@ -0,0 +1,391 @@
+/*
+ * ©2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id$ */
+
+/** \file */
+       
+/**    \defgroup avr_time <time.h>: Time
+       \code #include <time.h> \endcode
+       <h3>Introduction to the Time functions</h3>
+    This file declares the time handling system that is implemented in \c 
avr-libc.
+    
+    The implementation attempts to conform to ISO/IEC 9899 (C90). However, 
since there is no 
+    platform standard method to obtain the current time, time zone, or 
daylight savings 
+    'rules', the application needs to initialize the system time with this 
information. 
+       The functions set_zone(), set_dst(), and set_system_time() are provided 
for this intialization.
+       
+       Once initialized, system time may be maintained by calling 
system_tick() at one
+       second intervals.
+            
+*/ 
+#ifndef TIME_H
+#define TIME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <inttypes.h>
+#include <stdlib.h>
+
+/** \ingroup avr_time */
+/address@hidden/
+
+/** 
+       time_t represents seconds elapsed from Midnight, Jan 1 2000 UTC (the 
Y2K 'epoch'). 
+       Its range allows time to be handled properly up to Tue Feb 6 01:28:15 
2136.
+*/
+typedef uint32_t time_t;
+
+/**
+The time function returns the systems current time stamp.
+If timer is not a null pointer, the return value is also assigned to the 
object it points to.
+*/
+time_t time( time_t *);        
+
+/**
+The difftime function returns the difference between two binary time stamps, 
+time1 - time0.
+*/
+int32_t difftime(time_t time1, time_t time0); 
+
+
+/**
+       The tm structure contains a representation of time 'broken down' into 
its components.
+       The normal ranges of the elements are..
+       
+\code
+       tm_sec          seconds after the minute — [0, 60]
+       tm_min          minutes after the hour — [0, 59]
+       tm_hour         hours since midnight — [0, 23]
+       tm_mday         day of the month — [1, 31]
+       tm_wday         days since Sunday — [0, 6]
+       tm_mon          months since January — [0, 11]  
+       tm_year         years since 1900
+       tm_yday         days since January 1 — [0, 365] 
+       tm_isdst        Daylight Saving Time flag
+
+\endcode
+       
+       The value of tm_isdst is zero if Daylight Saving Time is not in effect, 
+       negative if the information is not available. 
+       If Daylight Saving Time is in effect, the value represents the number 
of 
+       seconds the clock is advanced.
+
+*/
+struct tm{
+       int8_t tm_sec;          /*      seconds after the minute — [0, 60]      
        */
+       int8_t tm_min;          /*      minutes after the hour — [0, 59]        
        */
+       int8_t tm_hour;         /*      hours since midnight — [0, 23]          
        */
+       int8_t tm_mday;         /*      day of the month — [1, 31]              
                */
+       int8_t tm_wday;         /*      days since Sunday — [0, 6]              
                */
+       int8_t tm_mon;          /*      months since January — [0, 11]          
        */
+       int16_t tm_year;        /*      years since 1900                        
                        */
+       int16_t tm_yday;        /*      days since January 1 — [0, 365]         
        */
+       int16_t tm_isdst;       /*      Daylight Saving Time flag               
                */
+};
+
+
+/**
+This function 'compiles' the broken-down time, returning a time stamp.
+The values of timeptr are interpreted as representing Local time.
+
+The original values of the tm_wday and tm_yday components of the structure are 
ignored, 
+and the original values of the other components are not restricted.
+
+On successful completion, the values of all components of the structure are 
set to their appropriate ranges.
+*/
+time_t mktime(struct tm *timeptr); 
+
+/**
+This function 'compiles' the broken-down time, returning a time stamp.
+The values of timeptr are interpreted as representing UTC.
+
+The original values of the tm_wday and tm_yday components of the structure are 
ignored, 
+and the original values of the other components are not restricted.
+*/
+time_t mk_gmtime(struct tm * timeptr);
+
+/**
+The gmtime function converts the time stamp pointed to by timer into 
broken-down time, 
+expressed as UTC.
+*/
+struct tm *gmtime(const time_t *timer);
+
+/**
+       Re entrant version of gmtime(). 
+*/
+void gmtime_r(const time_t * timer, struct tm *timeptr);
+
+/**
+The localtime function converts the time stamp pointed to by timer into 
broken-down time, 
+expressed as Local time.
+*/
+struct tm *localtime(const time_t *timer);
+
+/**
+       Re entrant version of localtime(). 
+*/
+void localtime_r(const time_t * timer, struct tm *timeptr);
+
+/**
+The asctime function converts the broken-down time of timeptr, into an ascii 
string in the form
+
+       Sun Mar 23 01:03:52 2013
+*/
+char *asctime(const struct tm *timeptr); 
+
+/**
+       Re entrant version of asctime(). 
+*/
+void asctime_r(const struct tm *timeptr, char *buf);
+
+/**
+       The ctime function is equivalent to asctime(localtime(timer))
+*/
+char *ctime(const time_t *timer); 
+
+/**
+       Re entrant version of ctime(). 
+*/
+void ctime_r(const time_t *timer, char *buf);
+
+/**
+The isotime function converts the broken-down time of timeptr, into an ascii 
string in the form
+
+       2013-03-23 01:03:52
+*/
+char * isotime(struct tm * tmptr);
+
+/**
+       Re entrant version of isotime()
+*/
+void isotime_r(struct tm *, char *);
+
+/**
+A complete description of strftime() is beyond the pale of this document. 
+Refer to ISO/IEC document 9899 for details.
+
+This implementation handles all conversions specified by the standard, with 
the exception of g, G, V, and Z.
+
+All conversions are made in the 'C Locale', ignoring the E or O modifiers.
+*/
+size_t strftime(char * s, size_t maxsize, const char * format, const struct tm 
* timeptr);
+
+/**
+       Specify the Daylight Saving function.
+       
+       The Daylight Saving function should examine its parameters to determine 
whether
+       Daylight Saving is in effect, and return a value appropriate for 
tm_isdst.
+       
+       Working examples for the USA and the EU are available..
+               
+               \code #include <util/eu_dst.h>\endcode
+               for the European Union, and 
+               \code #include <util/usa_dst.h>\endcode
+               for the United States 
+               
+       If a Daylight Saving function is not specified, the system will ignore 
it.      
+*/
+void set_dst( int (*)(const time_t*, int32_t *));
+
+/** 
+       Set the 'time zone'. The parameter is given as seconds East of 
Greenwich.
+       Example for New York City:
+       \code set_zone(-5 * ONE_HOUR);\endcode
+       
+       If the time zone is not set, the time system will operate in UTC.
+*/
+void set_zone(int32_t);
+
+/**
+       Set the system time. The values of tmptr are interpreted as Local 
Standard Time.
+*/
+void set_system_time(struct tm * tmptr);
+
+/**
+       This function increments the system clock, and must be called at a rate 
of one Hertz 
+       to maintain the system time.
+*/
+void system_tick(void);
+
+enum _WEEK_DAYS_{
+       SUNDAY,
+       MONDAY,
+       TUESDAY,
+       WEDNESDAY,
+       THURSDAY,
+       FRIDAY,
+       SATURDAY
+} ;
+
+enum _MONTHS_{
+       JANUARY,
+       FEBRUARY,
+       MARCH,
+       APRIL,
+       MAY,
+       JUNE,
+       JULY,
+       AUGUST,
+       SEPTEMBER,
+       OCTOBER,
+       NOVEMBER,
+       DECEMBER
+} ;
+
+/**
+       Returns non-zero if year is a leap year.
+       Returns zero otherwise.
+*/
+uint8_t is_leap_year( int16_t year);
+
+/**
+       Returns the length of month, given the year and month, where month is 
in the range 1 to 12.
+ */
+uint8_t length_of_month(int16_t year, uint8_t month);
+
+/**
+       Returns the calendar week of year, where the first week is considered 
to begin on the
+       day of week specified by 'start'. Thus, the returned value may range 
from zero to 52.
+*/
+uint8_t week_of_year(const struct tm * timeptr, uint8_t start);
+
+/**
+       Returns the calendar week of month, where the first week is considered 
to begin on the
+       day of week specified by 'start'. Thus, the returned value may range 
from zero to 5.
+*/
+uint8_t week_of_month(const struct tm * timeptr, uint8_t start);
+
+/**
+       Convert a Y2K time stamp into a FAT file system time stamp.
+*/
+uint32_t fatfs_time(struct tm * timeptr);
+
+/** One hour, expressed in seconds */
+#define ONE_HOUR 3600
+
+/** Angular degree, expressed in arc seconds */
+#define ONE_DEGREE 3600
+
+/** One day, expressed in seconds */
+#define ONE_DAY 86400
+
+/** Difference between the Y2K and the UNIX epochs, in seconds. To convert a 
Y2K
+       timestamp to UNIX...
+       \code
+       long unix;
+       time_t y2k;
+       
+       y2k = time(NULL);
+       unix = y2k + UNIX_OFFSET;
+       \endcode
+*/
+#define UNIX_OFFSET 946684800
+
+/** Difference between the Y2K and the NTP epochs, in seconds. To convert a Y2K
+       timestamp to NTP...
+       \code
+       unsigned long ntp;
+       time_t y2k;
+       
+       y2k = time(NULL);
+       ntp = y2k + NTP_OFFSET;
+       \endcode
+*/
+#define NTP_OFFSET 3155673600
+
+/*     
===================================================================================
+                               Ephemera 
+*/
+
+/**
+       Set the geographic coordinates of the 'observer', for use with several 
of the
+       following functions. Parameters are passed as seconds of North 
Latitude, and seconds
+       of East Longitude.
+       
+       For New York City...
+       \code set_position( 40.7142 * ONE_DEGREE, -74.0064 * ONE_DEGREE); 
\endcode
+*/
+void set_position( int32_t latitude, int32_t longitude);
+
+/**
+       Computes the 'Equation of Time', which is the difference between 
apparent solar time and mean solar time.
+       The returned value is in seconds.
+*/
+int16_t equation_of_time(time_t * timer);
+
+/**
+       Computes the amount of time the sun is above the horizon, at the 
location of the observer.
+       
+       NOTE: At observer locations inside the polar circles, this value can be 
zero during the winter,
+       and can exceed ONE_DAY during the summer.
+       
+       The returned value is in seconds.
+*/
+int32_t daylight_seconds(time_t * timer );
+
+/**
+       Return the time of sunrise, at the location of the observer. See the 
note about daylight_seconds().
+*/
+time_t sun_rise(time_t * timer);
+
+/**
+       Return the time of sunset, at the location of the observer. See the 
note about daylight_seconds().
+*/
+time_t sun_set(time_t * timer);
+
+/**    Returns the declination of the sun in radians. */
+double solar_declination(time_t * timer);
+
+/**
+       Returns an approximation to the phase of the moon.
+       The sign of the returned value indicates a waning or waxing phase.
+       The magnitude of the returned value indicates the percentage 
illumination.
+*/
+int8_t moon_phase(time_t * timer);
+
+/**
+       Returns Greenwich Mean Sidereal Time, as seconds into the sidereal day.
+       The returned value will range from 0 through 86399 seconds.
+*/
+unsigned long gm_sidereal(const time_t * timer);
+
+/**
+       Returns Local Mean Sidereal Time, as seconds into the sidereal day.
+       The returned value will range from 0 through 86399 seconds.
+*/
+unsigned long lm_sidereal(const time_t * timer);
+
+/address@hidden/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*      TIME_H  */
\ No newline at end of file


Property changes on: trunk/avr-libc/include/time.h
___________________________________________________________________
Added: svn:executable
   + *

Modified: trunk/avr-libc/include/util/Makefile.am
===================================================================
--- trunk/avr-libc/include/util/Makefile.am     2013-03-29 09:46:19 UTC (rev 
2310)
+++ trunk/avr-libc/include/util/Makefile.am     2013-03-29 10:05:13 UTC (rev 
2311)
@@ -37,8 +37,8 @@
     setbaud.h \
     parity.h \
     twi.h \
-    eu_dst.h \
-    usa_dst.h
+    usa_dst.h \
+    eu_dst.h
 
 nodist_avr_HEADERS = \
     delay.h

Added: trunk/avr-libc/include/util/eu_dst.h
===================================================================
--- trunk/avr-libc/include/util/eu_dst.h                                (rev 0)
+++ trunk/avr-libc/include/util/eu_dst.h        2013-03-29 10:05:13 UTC (rev 
2311)
@@ -0,0 +1,100 @@
+/*
+ * ©2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id$ */
+
+/*
+       Summer Time function for the European Union as of this date.
+*/
+
+#ifndef EU_DST_H
+#define EU_DST_H
+
+#ifdef __cplusplus
+extern          "C" {
+#endif
+
+#include <time.h>
+#include <inttypes.h>
+
+       int             eu_dst(const time_t * timer, int32_t * z) {
+               struct tm       tmptr;
+               uint8_t         month, mday, hour, day_of_week, d;
+               int             n;
+
+               /* obtain the variables */
+                               gmtime_r(timer, &tmptr);
+                               month = tmptr.tm_mon;
+                               day_of_week = tmptr.tm_wday;
+                               mday = tmptr.tm_mday - 1;
+                               hour = tmptr.tm_hour;
+
+               if              ((month > MARCH) && (month < OCTOBER))
+                                       return ONE_HOUR;
+
+               if              (month < MARCH)
+                                       return 0;
+               if              (month > OCTOBER)
+                                       return 0;
+
+               /* determine mday of last Sunday */
+                               n = tmptr.tm_mday - 1;
+                               n -= day_of_week;
+                               n += 7;
+                               d = n % 7;      /* date of first Sunday */
+
+                               n = 31 - d;
+                               n /= 7; /* number of Sundays left in the
+                                        * month */
+
+                               d = d + 7 * n;  /* mday of final Sunday */
+
+               if              (month == MARCH) {
+                       if (d < mday)
+                               return 0;
+                       if (d > mday)
+                               return ONE_HOUR;
+                       if (hour < 1)
+                               return 0;
+                       return AN_HOUR;
+               }
+               if              (d < mday)
+                                       return ONE_HOUR;
+               if              (d > mday)
+                                       return 0;
+               if              (hour < 1)
+                                       return ONE_HOUR;
+                               return 0;
+
+       }
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif


Property changes on: trunk/avr-libc/include/util/eu_dst.h
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/avr-libc/include/util/usa_dst.h
===================================================================
--- trunk/avr-libc/include/util/usa_dst.h                               (rev 0)
+++ trunk/avr-libc/include/util/usa_dst.h       2013-03-29 10:05:13 UTC (rev 
2311)
@@ -0,0 +1,96 @@
+/*
+ * ©2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id$ */
+
+/*
+       Daylight Savings function for the USA as of this date
+*/
+
+#ifndef EU_DST_H
+#define EU_DST_H
+
+#ifdef __cplusplus
+extern          "C" {
+#endif
+
+#include <time.h>
+#include <inttypes.h>
+
+       int             usa_dst(const time_t * timer, int32_t * z) {
+               time_t          t;
+               struct tm       tmptr;
+               uint8_t         month, week, hour, day_of_week, d;
+               int             n;
+
+               /* obtain the variables */
+                               t = *timer + *z;
+                               gmtime_r(&t, &tmptr);
+                               month = tmptr.tm_mon;
+                               day_of_week = tmptr.tm_wday;
+                               week = week_of_month(&tmptr, 0);
+                               hour = tmptr.tm_hour;
+
+               if              ((month > MARCH) && (month < NOVEMBER))
+                                       return ONE_HOUR;
+
+               if              (month < MARCH)
+                                       return 0;
+               if              (month > NOVEMBER)
+                                       return 0;
+
+               if              (month == MARCH) {
+
+                       if (week < 2)
+                               return 0;
+                       if (week > 2)
+                               return ONE_HOUR;
+
+                       if (day_of_week > SUNDAY)
+                               return ONE_HOUR;
+                       if (hour >= 2)
+                               return ONE_HOUR;
+                       return 0;
+               }
+               if              (week > 1)
+                                       return 0;
+               if              (week < 1)
+                                       return ONE_HOUR;
+               if              (day_of_week > SUNDAY)
+                                       return 0;
+               if              (hour >= 1)
+                                       return 0;
+                               return ONE_HOUR;
+
+       }
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif


Property changes on: trunk/avr-libc/include/util/usa_dst.h
___________________________________________________________________
Added: svn:executable
   + *

Modified: trunk/avr-libc/libc/Makefile.am
===================================================================
--- trunk/avr-libc/libc/Makefile.am     2013-03-29 09:46:19 UTC (rev 2310)
+++ trunk/avr-libc/libc/Makefile.am     2013-03-29 10:05:13 UTC (rev 2311)
@@ -31,4 +31,3 @@
 
 SUBDIRS = stdlib pmstring string misc stdio time
 DIST_SUBDIRS = stdlib pmstring string misc stdio time
-




reply via email to

[Prev in Thread] Current Thread [Next in Thread]