1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-17 18:43:50 +01:00

Merge pull request #8857 from ZetaR60/RIOT_atmega_time_dot_h

cpu/atmega_common: Use updated time.h
This commit is contained in:
Francisco Acosta 2018-06-28 22:29:20 +02:00 committed by GitHub
commit 23d176f46b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 64 additions and 49 deletions

View File

@ -18,7 +18,7 @@ export USEMODULE += periph_common
export USEMODULE += uart_stdio export USEMODULE += uart_stdio
# include module specific includes # include module specific includes
export INCLUDES += -I$(RIOTCPU)/atmega_common/include -isystem$(RIOTCPU)/atmega_common/avr-libc-extra export INCLUDES += -I$(RIOTCPU)/atmega_common/include -isystem$(RIOTCPU)/atmega_common/include/vendor
ifeq ($(LTO),1) ifeq ($(LTO),1)
# avr-gcc <4.8.3 has a bug when using LTO which causes a warning to be printed always: # avr-gcc <4.8.3 has a bug when using LTO which causes a warning to be printed always:

View File

@ -35,7 +35,7 @@ typedef int pid_t; /**< Used for process IDs and process group ID
typedef unsigned int size_t; /**< Used for sizes of objects */ typedef unsigned int size_t; /**< Used for sizes of objects */
typedef signed int ssize_t; /**< Used for a count of bytes or an error indication */ typedef signed int ssize_t; /**< Used for a count of bytes or an error indication */
typedef int32_t suseconds_t; /**< Used for time in microseconds */ typedef int32_t suseconds_t; /**< Used for time in microseconds */
typedef int32_t time_t; /**< Used for time in seconds */ typedef uint32_t time_t; /**< Used for time in seconds */
typedef uint32_t timer_t; /**< Used for timer ID returned by timer_create() */ typedef uint32_t timer_t; /**< Used for timer ID returned by timer_create() */
typedef uint16_t uid_t; /**< Used for user IDs */ typedef uint16_t uid_t; /**< Used for user IDs */
typedef uint32_t useconds_t; /**< Used for time in microseconds */ typedef uint32_t useconds_t; /**< Used for time in microseconds */

View File

@ -26,9 +26,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
/* \cond DOXYGEN_BLACKLIST */ /* $Id: time.h 2503 2016-02-07 22:59:47Z joerg_wunsch $ */
/* $Id$ */
/** \file */ /** \file */
@ -101,16 +99,22 @@
#ifndef TIME_H #ifndef TIME_H
#define TIME_H #define TIME_H
#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <inttypes.h>
#include <stdlib.h>
/** \ingroup avr_time */ /** \ingroup avr_time */
/* @{ */ /* @{ */
/**
time_t represents seconds elapsed from Midnight, Jan 1 2000 UTC (the Y2K 'epoch').
Its range allows this implementation to represent time up to Tue Feb 7 06:28:15 2136 UTC.
*/
typedef uint32_t time_t;
/** /**
The time function returns the systems current time stamp. 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. If timer is not a null pointer, the return value is also assigned to the object it points to.
@ -128,22 +132,7 @@ extern "C" {
The tm structure contains a representation of time 'broken down' into components of the The tm structure contains a representation of time 'broken down' into components of the
Gregorian calendar. Gregorian calendar.
The normal ranges of the elements are.. The value of tm_isdst is zero if Daylight Saving Time is not in effect, and is negative if
\code
tm_sec seconds after the minute - [ 0 to 59 ]
tm_min minutes after the hour - [ 0 to 59 ]
tm_hour hours since midnight - [ 0 to 23 ]
tm_mday day of the month - [ 1 to 31 ]
tm_wday days since Sunday - [ 0 to 6 ]
tm_mon months since January - [ 0 to 11 ]
tm_year years since 1900
tm_yday days since January 1 - [ 0 to 365 ]
tm_isdst Daylight Saving Time flag *
\endcode
*The value of tm_isdst is zero if Daylight Saving Time is not in effect, and is negative if
the information is not available. the information is not available.
When Daylight Saving Time is in effect, the value represents the number of When Daylight Saving Time is in effect, the value represents the number of
@ -153,18 +142,24 @@ extern "C" {
*/ */
struct tm { struct tm {
int tm_sec; int8_t tm_sec; /**< seconds after the minute - [ 0 to 59 ] */
int tm_min; int8_t tm_min; /**< minutes after the hour - [ 0 to 59 ] */
int tm_hour; int8_t tm_hour; /**< hours since midnight - [ 0 to 23 ] */
int tm_mday; int8_t tm_mday; /**< day of the month - [ 1 to 31 ] */
int tm_wday; int8_t tm_wday; /**< days since Sunday - [ 0 to 6 ] */
int tm_mon; int8_t tm_mon; /**< months since January - [ 0 to 11 ] */
int tm_year; int16_t tm_year; /**< years since 1900 */
int tm_yday; int16_t tm_yday; /**< days since January 1 - [ 0 to 365 ] */
int tm_isdst; int16_t tm_isdst; /**< Daylight Saving Time flag */
}; };
/**
ATmega compatibility problem define
NOTE: Added for RIOT compatibility
*/
#define ATMEGA_INCOMPATIBLE_TIME_H
#ifndef __DOXYGEN__
/* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can /* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can
be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_ be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_
so that the user can provide the value on the link line, which should so that the user can provide the value on the link line, which should
@ -173,6 +168,7 @@ extern "C" {
extern char *_CLOCKS_PER_SEC_; extern char *_CLOCKS_PER_SEC_;
#define CLOCKS_PER_SEC ((clock_t) _CLOCKS_PER_SEC_) #define CLOCKS_PER_SEC ((clock_t) _CLOCKS_PER_SEC_)
extern clock_t clock(void); extern clock_t clock(void);
#endif /* !__DOXYGEN__ */
/** /**
This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp. This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp.
@ -388,9 +384,9 @@ extern "C" {
See http://en.wikipedia.org/wiki/ISO_week_date for more information. See http://en.wikipedia.org/wiki/ISO_week_date for more information.
*/ */
struct week_date { struct week_date {
int year; int year; /**< year number (Gregorian calendar) */
int week; int week; /**< week number (#1 is where first Thursday is in) */
int day; int day; /**< day within week */
}; };
/** /**
@ -511,21 +507,18 @@ extern "C" {
*/ */
unsigned long lm_sidereal(const time_t * timer); unsigned long lm_sidereal(const time_t * timer);
/**
Definition of struct timespec for the atmega
NOTE: Added for RIOT compatibility and standard compliance
*/
struct timespec { struct timespec {
time_t tv_sec; time_t tv_sec;
long tv_nsec; long tv_nsec;
}; };
/* @} */ /* @} */
/* /endcond */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* TIME_H */ #endif /* TIME_H */
/**
\endcond
*/

View File

@ -84,7 +84,11 @@ int tm_doomsday(int year) CONST;
* @param[out] wday Returns the day of the week. * @param[out] wday Returns the day of the week.
* @param[out] yday Returns the day of the year (Jan 1st is 0). * @param[out] yday Returns the day of the year (Jan 1st is 0).
*/ */
#ifndef ATMEGA_INCOMPATIBLE_TIME_H
void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday); void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday);
#else
void tm_get_wyday(int year, int mon, int mday, int8_t *wday, int16_t *yday);
#endif
/** /**
* @brief Fills in `struct tm::tm_wday` and `struct tm::tm_yday` given a date. * @brief Fills in `struct tm::tm_wday` and `struct tm::tm_yday` given a date.

View File

@ -49,7 +49,11 @@ int tm_doomsday(int year)
return result; return result;
} }
#ifndef ATMEGA_INCOMPATIBLE_TIME_H
void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday) void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday)
#else
void tm_get_wyday(int year, int mon, int mday, int8_t *wday, int16_t *yday)
#endif
{ {
int is_leap_year = tm_is_leap_year(year); int is_leap_year = tm_is_leap_year(year);
*yday = TM_MON_DAYS_ACCU[mon] + mday + (mon <= TM_MON_FEB ? 0 : is_leap_year) - 1; *yday = TM_MON_DAYS_ACCU[mon] + mday + (mon <= TM_MON_FEB ? 0 : is_leap_year) - 1;

View File

@ -5,6 +5,14 @@ USEPKG += minmea
# The MSP-430 toolchain lacks mktime and NAN # The MSP-430 toolchain lacks mktime and NAN
BOARD_BLACKLIST := chronos msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 BOARD_BLACKLIST := chronos msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1
# Incompatible due to non-standard ATmega time.h
BOARD_BLACKLIST += arduino-duemilanove \
arduino-mega2560 \
arduino-uno \
jiminy-mega256rfr2 \
mega-xplained \
waspmote-pro
TEST_ON_CI_WHITELIST += all TEST_ON_CI_WHITELIST += all
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -113,7 +113,13 @@ static int cmd_day(int argc, char **argv)
puts("The supplied date is invalid, but no error should occur."); puts("The supplied date is invalid, but no error should occur.");
} }
#ifndef ATMEGA_INCOMPATIBLE_TIME_H
int wday, yday; int wday, yday;
#else
int8_t wday;
int16_t yday;
#endif
tm_get_wyday(year, mon - 1, day, &wday, &yday); tm_get_wyday(year, mon - 1, day, &wday, &yday);
printf("What weekday was %04d-%02d-%02d? The %d(th) day of the year was a %.3s.\n", printf("What weekday was %04d-%02d-%02d? The %d(th) day of the year was a %.3s.\n",
year, mon, day, yday + 1, DAY_NAMES[wday]); year, mon, day, yday + 1, DAY_NAMES[wday]);