Question
How to add an integer to RTC_TimeTypeDef structure
Posted on January 20, 2013 at 19:48
Dear all, is there anyone knows how to add an integer to RTC_TimeTypeDef structure?
For example, I have an RTC_TimeTypeDef variable 'timestamp'. After using the timestamp, I want to increase it by 45 seconds to get a new timestamp. Right now I am doing it with a self-defined function :
uint8_t time_add(RTC_TimeTypeDef *val, uint8_t delta) {
uint8_t carry = 0;
// Seconds
val->RTC_Seconds += delta;
if
(val->RTC_Seconds >= 60) {
// seconds field overflow
val->RTC_Seconds -= 60;
carry = 1;
}
else
{
carry = 0;
}
val->RTC_Minutes += carry;
return
carry;
}
I am wondering is there any better way to add an integer (say 45 seconds) to the RTC_TimeTypeDef structure?
PS: I am using STM32L151 and RTC_TimeTypeDef isdefined in stm32l1xx_rtc.h as follows:
/**
* @brief RTC Time structure definition
*/
typedef
struct
{
uint8_t RTC_Hours;
/*!< Specifies the RTC Time Hour.
This parameter must be set to a value in the 0-12 range
if the RTC_HourFormat_12 is selected or 0-23 range if
the RTC_HourFormat_24 is selected. */
uint8_t RTC_Minutes;
/*!< Specifies the RTC Time Minutes.
This parameter must be set to a value in the 0-59 range. */
uint8_t RTC_Seconds;
/*!< Specifies the RTC Time Seconds.
This parameter must be set to a value in the 0-59 range. */
uint8_t RTC_H12;
/*!< Specifies the RTC AM/PM Time.
This parameter can be a value of @ref RTC_AM_PM_Definitions */
}RTC_TimeTypeDef; 