aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-11-01 15:44:30 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-11-01 15:44:30 +0000
commitd37f6cb1f3cac35b1f7f7373062fddb638707570 (patch)
treee81bc626c722cd995fae688f8605a23e5db1aecc /os
parent96f976382d7b94911dac7bea9477b3e2bc560408 (diff)
downloadChibiOS-d37f6cb1f3cac35b1f7f7373062fddb638707570.tar.gz
ChibiOS-d37f6cb1f3cac35b1f7f7373062fddb638707570.tar.bz2
ChibiOS-d37f6cb1f3cac35b1f7f7373062fddb638707570.zip
RTCv1. Time converstion functions moved to rtc.c(h). Chrtclib deleted.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7443 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/include/rtc.h19
-rw-r--r--os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c2
-rw-r--r--os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h2
-rw-r--r--os/hal/src/rtc.c100
-rw-r--r--os/various/chrtclib.c129
-rw-r--r--os/various/chrtclib.h59
6 files changed, 118 insertions, 193 deletions
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h
index a775ec570..a0f02b502 100644
--- a/os/hal/include/rtc.h
+++ b/os/hal/include/rtc.h
@@ -87,8 +87,20 @@
*/
typedef struct RTCDriver RTCDriver;
-#include "chrtclib.h"
+/**
+ * @brief Type of a structure representing an RTC date/time stamp.
+ */
+typedef struct {
+ uint32_t year: 8; /**< @brief Years since 1980. */
+ uint32_t month: 4; /**< @brief Months 1..12. */
+ uint32_t dstflag: 1; /**< @brief DST correction flag. */
+ uint32_t dayofweek: 3; /**< @brief Day of week 1..7. */
+ uint32_t day: 5; /**< @brief Day of the month 1..31. */
+ uint32_t millisecond: 27; /**< @brief Milliseconds since midnight.*/
+} RTCDateTime;
+
#include "rtc_lld.h"
+#include <time.h>
/*===========================================================================*/
/* Driver macros. */
@@ -113,6 +125,11 @@ extern "C" {
#if RTC_SUPPORTS_CALLBACKS
void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback);
#endif
+ void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
+ struct tm *timp);
+ void rtcConvertStructTmToDateTime(const struct tm *timp,
+ uint32_t tv_msec, RTCDateTime *timespec);
+ uint32_t rtcConvertDateTimeToFAT(const RTCDateTime *timespec);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c
index f17a553b4..c8ccd41bd 100644
--- a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c
+++ b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c
@@ -30,8 +30,6 @@
#if HAL_USE_RTC || defined(__DOXYGEN__)
-#include "chrtclib.h"
-
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
diff --git a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h
index 31d2b576b..0685ef6bc 100644
--- a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h
+++ b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h
@@ -31,8 +31,6 @@
#if HAL_USE_RTC || defined(__DOXYGEN__)
-#include "chrtclib.h"
-
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c
index e67abb746..63a9a8b3e 100644
--- a/os/hal/src/rtc.c
+++ b/os/hal/src/rtc.c
@@ -185,6 +185,106 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) {
}
#endif /* RTC_SUPPORTS_CALLBACKS */
+/**
+ * @brief Convert @p RTCDateTime to broken-down time structure.
+ *
+ * @param[in] timespec pointer to a @p RTCDateTime structure
+ * @param[out] timp pointer to a broken-down time structure
+ *
+ * @api
+ */
+void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
+ struct tm *timp) {
+ uint32_t tmp;
+
+ timp->tm_year = timespec->year + (1980 - 1900);
+ timp->tm_mon = timespec->month - 1;
+ timp->tm_mday = timespec->day;
+ timp->tm_isdst = timespec->dstflag;
+
+ tmp = timespec->millisecond / 1000;
+ timp->tm_sec = tmp % 60;
+ tmp -= timp->tm_sec;
+ timp->tm_min = tmp % 3600;
+ tmp -= timp->tm_min * 60;
+ timp->tm_hour = tmp / 3600;
+}
+
+/**
+ * @brief Convert broken-down time structure to @p RTCDateTime.
+ *
+ * @param[in] timp pointer to a broken-down time structure
+ * @param[in] tv_msec milliseconds value
+ * @param[out] timespec pointer to a @p RTCDateTime structure
+ *
+ * @api
+ */
+void rtcConvertStructTmToDateTime(const struct tm *timp,
+ uint32_t tv_msec, RTCDateTime *timespec) {
+
+ timespec->year = timp->tm_year - (1980 - 1900);
+ timespec->month = timp->tm_mon + 1;
+ timespec->day = timp->tm_mday;
+ timespec->dayofweek = timp->tm_wday + 1;
+ if (-1 == timp->tm_isdst)
+ timespec->dstflag = 0; /* set zero if dst is unknown */
+ else
+ timespec->dstflag = timp->tm_isdst;
+ timespec->millisecond = tv_msec +
+ (timp->tm_hour * 3600 + timp->tm_min * 60 + timp->tm_sec) * 1000;
+}
+
+/*
+ * Lookup table with months' length
+ */
+static const uint8_t month_len[12] = {
+ 31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+};
+
+/**
+ * @brief Get current time in format suitable for usage in FAT file system.
+ * @note The information about day of week and DST is lost in DOS
+ * format, the second field loses its least significant bit.
+ *
+ * @param[out] timespec pointer to a @p RTCDateTime structure
+ * @return FAT date/time value.
+ *
+ * @api
+ */
+uint32_t rtcConvertDateTimeToFAT(const RTCDateTime *timespec) {
+ uint32_t fattime;
+ uint32_t sec, min, hour, day, month, tmp;
+
+ tmp = timespec->millisecond / 1000;
+ sec = tmp % 60;
+ min = (tmp - sec) % 3600;
+ hour = (tmp - sec - min * 60) / 3600;
+ day = timespec->day;
+ month = timespec->month;
+
+ /* handle DST flag */
+ if (1 == timespec->dstflag) {
+ hour += 1;
+ if (hour == 24) {
+ hour = 0;
+ day += 1;
+ if (day > month_len[month - 1]) {
+ day = 1;
+ month += 1;
+ }
+ }
+ }
+
+ fattime = sec >> 1;
+ fattime |= min << 5;
+ fattime |= hour << 11;
+ fattime |= day << 16;
+ fattime |= month << 21;
+ fattime |= timespec->year << 25;
+
+ return fattime;
+}
+
#endif /* HAL_USE_RTC */
/** @} */
diff --git a/os/various/chrtclib.c b/os/various/chrtclib.c
deleted file mode 100644
index 5512fd42e..000000000
--- a/os/various/chrtclib.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- ChibiOS - Copyright (C) 2014 Uladzimir Pylinsky aka barthess
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file chrtclib.c
- * @brief Time conversion routines.
- *
- * @addtogroup chrtclib
- * @{
- */
-
-#include <time.h>
-
-#include "chrtclib.h"
-
-/**
- * @brief Convert @p RTCDateTime to broken-down time structure.
- *
- * @param[in] timespec pointer to a @p RTCDateTime structure
- * @param[out] timp pointer to a broken-down time structure
- *
- * @api
- */
-void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
- struct tm *timp) {
- uint32_t tmp;
-
- timp->tm_year = timespec->year + (1980 - 1900);
- timp->tm_mon = timespec->month - 1;
- timp->tm_mday = timespec->day;
- timp->tm_isdst = timespec->dstflag;
-
- tmp = timespec->millisecond / 1000;
- timp->tm_sec = tmp % 60;
- tmp -= timp->tm_sec;
- timp->tm_min = tmp % 3600;
- tmp -= timp->tm_min * 60;
- timp->tm_hour = tmp / 3600;
-}
-
-/**
- * @brief Convert broken-down time structure to @p RTCDateTime.
- *
- * @param[in] timp pointer to a broken-down time structure
- * @param[in] tv_msec milliseconds value
- * @param[out] timespec pointer to a @p RTCDateTime structure
- *
- * @api
- */
-void rtcConvertStructTmToDateTime(const struct tm *timp,
- uint32_t tv_msec, RTCDateTime *timespec) {
-
- timespec->year = timp->tm_year - (1980 - 1900);
- timespec->month = timp->tm_mon + 1;
- timespec->day = timp->tm_mday;
- timespec->dayofweek = timp->tm_wday + 1;
- if (-1 == timp->tm_isdst)
- timespec->dstflag = 0; /* set zero if dst is unknown */
- else
- timespec->dstflag = timp->tm_isdst;
- timespec->millisecond = tv_msec +
- (timp->tm_hour * 3600 + timp->tm_min * 60 + timp->tm_sec) * 1000;
-}
-
-/*
- * Lookup table for months' length
- */
-static const uint8_t month_len[12] = {
- 31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-/**
- * @brief Get current time in format suitable for usage in FAT file system.
- * @note The information about day of week and DST is lost in DOS
- * format, the second field loses its least significant bit.
- *
- * @param[out] timespec pointer to a @p RTCDateTime structure
- * @return FAT date/time value.
- *
- * @api
- */
-uint32_t rtcConvertDateTimeToFAT(const RTCDateTime *timespec) {
- uint32_t fattime;
- uint32_t sec, min, hour, day, month, tmp;
-
- tmp = timespec->millisecond / 1000;
- sec = tmp % 60;
- min = (tmp - sec) % 3600;
- hour = (tmp - sec - min * 60) / 3600;
- day = timespec->day;
- month = timespec->month;
-
- /* handle DST flag */
- if (1 == timespec->dstflag) {
- hour += 1;
- if (hour == 24) {
- hour = 0;
- day += 1;
- if (day > month_len[month - 1]) {
- day = 1;
- month += 1;
- }
- }
- }
-
- fattime = sec >> 1;
- fattime |= min << 5;
- fattime |= hour << 11;
- fattime |= day << 16;
- fattime |= month << 21;
- fattime |= timespec->year << 25;
-
- return fattime;
-}
-
-/** @} */
diff --git a/os/various/chrtclib.h b/os/various/chrtclib.h
deleted file mode 100644
index ad9b4c706..000000000
--- a/os/various/chrtclib.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- ChibiOS - Copyright (C) 2014 Uladzimir Pylinsky aka barthess
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef _CHRTCLIB_H_
-#define _CHRTCLIB_H_
-
-#include <time.h>
-#include <stdint.h>
-
-/**
- * @file chrtclib.h
- * @brief Time conversion routines.
- *
- * @addtogroup chrtclib
- * @{
- */
-
-/**
- * @brief Type of a structure representing an RTC date/time stamp.
- */
-typedef struct {
- uint32_t year: 8; /**< @brief Years since 1980. */
- uint32_t month: 4; /**< @brief Months 1..12. */
- uint32_t dstflag: 1; /**< @brief DST correction flag. */
- uint32_t dayofweek: 3; /**< @brief Day of week 1..7. */
- uint32_t day: 5; /**< @brief Day of the month 1..31. */
- uint32_t millisecond: 27; /**< @brief Milliseconds since midnight.*/
-} RTCDateTime;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
- uint32_t rtcConvertDateTimeToFAT(const RTCDateTime *timespec);
- void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
- struct tm *timp);
- void rtcConvertStructTmToDateTime(const struct tm *timp,
- uint32_t tv_msec,
- RTCDateTime *timespec);
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _CHRTCLIB_H_ */
-
-/** @} */