chrtclib. Fixed overflows in mcrosecond functions. Fixed initializations of RTCTime structs in functions.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4217 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
581267b0db
commit
ec65999d9b
|
@ -139,7 +139,11 @@ static void stm32_rtc_tm2bcd(struct tm *timp, RTCTime *timespec) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
|
#if STM32_RTC_HAS_SUBSECONDS
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0,FALSE,0};
|
||||||
|
#else
|
||||||
|
RTCTime timespec = {0,0,FALSE};
|
||||||
|
#endif
|
||||||
|
|
||||||
rtcGetTime(rtcp, ×pec);
|
rtcGetTime(rtcp, ×pec);
|
||||||
stm32_rtc_bcd2tm(timp, ×pec);
|
stm32_rtc_bcd2tm(timp, ×pec);
|
||||||
|
@ -154,7 +158,11 @@ void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
|
#if STM32_RTC_HAS_SUBSECONDS
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0,FALSE,0};
|
||||||
|
#else
|
||||||
|
RTCTime timespec = {0,0,FALSE};
|
||||||
|
#endif
|
||||||
|
|
||||||
stm32_rtc_tm2bcd(timp, ×pec);
|
stm32_rtc_tm2bcd(timp, ×pec);
|
||||||
rtcSetTime(rtcp, ×pec);
|
rtcSetTime(rtcp, ×pec);
|
||||||
|
@ -169,7 +177,11 @@ void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
time_t rtcGetTimeUnixSec(RTCDriver *rtcp) {
|
time_t rtcGetTimeUnixSec(RTCDriver *rtcp) {
|
||||||
|
#if STM32_RTC_HAS_SUBSECONDS
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0,FALSE,0};
|
||||||
|
#else
|
||||||
|
RTCTime timespec = {0,0,FALSE};
|
||||||
|
#endif
|
||||||
struct tm timp;
|
struct tm timp;
|
||||||
|
|
||||||
rtcGetTime(rtcp, ×pec);
|
rtcGetTime(rtcp, ×pec);
|
||||||
|
@ -187,11 +199,13 @@ time_t rtcGetTimeUnixSec(RTCDriver *rtcp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
|
void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
|
||||||
|
#if STM32_RTC_HAS_SUBSECONDS
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0,FALSE,0};
|
||||||
struct tm *timp;
|
#else
|
||||||
|
RTCTime timespec = {0,0,FALSE};
|
||||||
|
#endif
|
||||||
|
|
||||||
timp = localtime(&tv_sec);
|
stm32_rtc_tm2bcd(localtime(&tv_sec), ×pec);
|
||||||
stm32_rtc_tm2bcd(timp, ×pec);
|
|
||||||
rtcSetTime(rtcp, ×pec);
|
rtcSetTime(rtcp, ×pec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,20 +218,18 @@ void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) {
|
uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) {
|
||||||
|
#if STM32_RTC_HAS_SUBSECONDS
|
||||||
uint64_t result = 0;
|
uint64_t result = 0;
|
||||||
|
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0,FALSE,0};
|
||||||
struct tm timp;
|
struct tm timp;
|
||||||
|
|
||||||
rtcGetTime(rtcp, ×pec);
|
rtcGetTime(rtcp, ×pec);
|
||||||
stm32_rtc_bcd2tm(&timp, ×pec);
|
stm32_rtc_bcd2tm(&timp, ×pec);
|
||||||
|
|
||||||
result = mktime(&timp) * 1000000;
|
result = (uint64_t)mktime(&timp) * 1000000;
|
||||||
|
|
||||||
#if STM32_RTC_HAS_SUBSECONDS
|
|
||||||
return result + timespec.tv_msec * 1000;
|
return result + timespec.tv_msec * 1000;
|
||||||
#else
|
#else
|
||||||
return result;
|
return (uint64_t)rtcGetTimeUnixSec(rtcp) * 1000000;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +243,7 @@ uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0};
|
||||||
|
|
||||||
rtcGetTime(rtcp, ×pec);
|
rtcGetTime(rtcp, ×pec);
|
||||||
if (timp != NULL) /* this comparison needed to avoid compiler warning */
|
if (timp != NULL) /* this comparison needed to avoid compiler warning */
|
||||||
|
@ -247,7 +259,7 @@ void rtcGetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0};
|
||||||
|
|
||||||
timespec.tv_sec = mktime(timp);
|
timespec.tv_sec = mktime(timp);
|
||||||
timespec.tv_msec = 0;
|
timespec.tv_msec = 0;
|
||||||
|
@ -263,7 +275,7 @@ void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
time_t rtcGetTimeUnixSec(RTCDriver *rtcp) {
|
time_t rtcGetTimeUnixSec(RTCDriver *rtcp) {
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0};
|
||||||
|
|
||||||
rtcGetTime(rtcp, ×pec);
|
rtcGetTime(rtcp, ×pec);
|
||||||
return timespec.tv_sec;
|
return timespec.tv_sec;
|
||||||
|
@ -278,7 +290,7 @@ time_t rtcGetTimeUnixSec(RTCDriver *rtcp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
|
void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0};
|
||||||
|
|
||||||
timespec.tv_sec = tv_sec;
|
timespec.tv_sec = tv_sec;
|
||||||
timespec.tv_msec = 0;
|
timespec.tv_msec = 0;
|
||||||
|
@ -294,16 +306,15 @@ void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) {
|
uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) {
|
||||||
|
#if STM32_RTC_HAS_SUBSECONDS
|
||||||
uint64_t result = 0;
|
uint64_t result = 0;
|
||||||
RTCTime timespec = {0,0,FALSE,0};
|
RTCTime timespec = {0,0};
|
||||||
|
|
||||||
rtcGetTime(rtcp, ×pec);
|
rtcGetTime(rtcp, ×pec);
|
||||||
result = timespec.tv_sec * 1000000;
|
result = (uint64_t)timespec.tv_sec * 1000000;
|
||||||
|
|
||||||
#if STM32_RTC_HAS_SUBSECONDS
|
|
||||||
return result + timespec.tv_msec * 1000;
|
return result + timespec.tv_msec * 1000;
|
||||||
#else
|
#else
|
||||||
return result;
|
return (uint64_t)rtcGetTimeUnixSec(rtcp) * 1000000;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* STM32_RTC_IS_CALENDAR */
|
#endif /* STM32_RTC_IS_CALENDAR */
|
||||||
|
|
Loading…
Reference in New Issue