TM STM32F4xx Libraries  v1.0.0
Libraries for STM32F4xx devices from Tilen Majerle
tm_stm32f4_rtc.h
1 
30 #ifndef TM_RTC_H
31 #define TM_RTC_H 171
32 
33 /* C++ detection */
34 #ifdef __cplusplus
35 extern C {
36 #endif
37 
142 #include "stm32f4xx.h"
143 #include "stm32f4xx_rcc.h"
144 #include "stm32f4xx_rtc.h"
145 #include "stm32f4xx_pwr.h"
146 #include "stm32f4xx_exti.h"
147 #include "misc.h"
148 #include "defines.h"
149 #include "attributes.h"
150 
160 /* RTC clock is: f_clk = RTCCLK(LSI or LSE) / ((RTC_SYNC_PREDIV + 1) * (RTC_ASYNC_PREDIV + 1)) */
161 /* Sync pre division for clock */
162 #ifndef RTC_SYNC_PREDIV
163 #define RTC_SYNC_PREDIV 0x3FF
164 #endif
165 /* Async pre division for clock */
166 #ifndef RTC_ASYNC_PREDIV
167 #define RTC_ASYNC_PREDIV 0x1F
168 #endif
169 /* NVIC global Priority set */
170 #ifndef RTC_PRIORITY
171 #define RTC_PRIORITY 0x04
172 #endif
173 /* Sub priority for wakeup trigger */
174 #ifndef RTC_WAKEUP_SUBPRIORITY
175 #define RTC_WAKEUP_SUBPRIORITY 0x00
176 #endif
177 /* Sub priority for alarm trigger */
178 #ifndef RTC_ALARM_SUBPRIORITY
179 #define RTC_ALARM_SUBPRIORITY 0x01
180 #endif
181 
195 typedef struct {
196  uint8_t seconds;
197  uint16_t subseconds;
199  uint8_t minutes;
200  uint8_t hours;
201  uint8_t day;
202  uint8_t date;
203  uint8_t month;
204  uint8_t year;
205  uint32_t unix;
206 } TM_RTC_t;
207 
212 
216 typedef enum {
220 
224 typedef enum {
228 
232 typedef enum {
244 } TM_RTC_Int_t;
245 
250 typedef enum {
254 
258 typedef enum {
262 
266 typedef enum {
267  TM_RTC_Alarm_A = 0x00,
270 
274 typedef struct {
276  uint8_t seconds;
277  uint8_t minutes;
278  uint8_t hours;
279  uint8_t day;
284 
304 uint32_t TM_RTC_Init(TM_RTC_ClockSource_t source);
305 
311 uint32_t TM_RTC_GetUnixTimeStamp(TM_RTC_t* data);
312 
321 void TM_RTC_GetDateTimeFromUnix(TM_RTC_t* data, uint32_t unix);
322 
329 void TM_RTC_Interrupts(TM_RTC_Int_t int_value);
330 
340 
357 
364 void TM_RTC_GetDateTime(TM_RTC_t* data, TM_RTC_Format_t format);
365 
373 uint8_t TM_RTC_GetDaysInMonth(uint8_t month, uint8_t year);
374 
381 uint16_t TM_RTC_GetDaysInYear(uint8_t year);
382 
395 void TM_RTC_WriteBackupRegister(uint8_t location, uint32_t value);
396 
408 uint32_t TM_RTC_ReadBackupRegister(uint8_t location);
409 
417 void TM_RTC_SetAlarm(TM_RTC_Alarm_t Alarm, TM_RTC_AlarmTime_t* AlarmTime, TM_RTC_Format_t format);
418 
425 
433 void TM_RTC_RequestHandler(void);
434 
442 void TM_RTC_AlarmAHandler(void);
443 
451 void TM_RTC_AlarmBHandler(void);
452 
465 /* C++ detection */
466 #ifdef __cplusplus
467 }
468 #endif
469 
470 #endif
471 
void TM_RTC_DisableAlarm(TM_RTC_Alarm_t Alarm)
Disables specific alarm.
RTC Struct for date/time.
Definition: tm_stm32f4_rtc.h:195
uint8_t TM_RTC_GetDaysInMonth(uint8_t month, uint8_t year)
Get number of days in month.
void TM_RTC_GetDateTime(TM_RTC_t *data, TM_RTC_Format_t format)
Get date and time from internal RTC registers.
uint16_t subseconds
Definition: tm_stm32f4_rtc.h:197
Definition: tm_stm32f4_rtc.h:233
uint32_t unix
Definition: tm_stm32f4_rtc.h:205
Definition: tm_stm32f4_rtc.h:268
uint8_t seconds
Definition: tm_stm32f4_rtc.h:196
void TM_RTC_Interrupts(TM_RTC_Int_t int_value)
Select RTC wakeup interrupts interval.
uint8_t year
Definition: tm_stm32f4_rtc.h:204
uint8_t day
Definition: tm_stm32f4_rtc.h:279
void TM_RTC_AlarmBHandler(void)
RTC Alarm B handler function. Called when interrupt is triggered for alarm B.
void TM_RTC_AlarmAHandler(void)
RTC Alarm A handler function. Called when interrupt is triggered for alarm A.
Definition: tm_stm32f4_rtc.h:241
TM_RTC_Int_t
RTC Interrupt enumeration.
Definition: tm_stm32f4_rtc.h:232
TM_RTC_Result_t TM_RTC_SetDateTime(TM_RTC_t *data, TM_RTC_Format_t format)
Set date and time to internal RTC registers.
Definition: tm_stm32f4_rtc.h:240
Definition: tm_stm32f4_rtc.h:243
TM_RTC_ClockSource_t
Select RTC clock source.
Definition: tm_stm32f4_rtc.h:250
Definition: tm_stm32f4_rtc.h:234
TM_RTC_Result_t
RTC Result enumeration.
Definition: tm_stm32f4_rtc.h:216
Definition: tm_stm32f4_rtc.h:259
Definition: tm_stm32f4_rtc.h:237
uint8_t minutes
Definition: tm_stm32f4_rtc.h:277
Definition: tm_stm32f4_rtc.h:242
uint8_t hours
Definition: tm_stm32f4_rtc.h:200
TM_RTC_AlarmType_t alarmtype
Definition: tm_stm32f4_rtc.h:275
uint32_t TM_RTC_ReadBackupRegister(uint8_t location)
Read RTC backup register value. This method allows you to read 32bit value from backup register 0 - 1...
TM_RTC_AlarmType_t
RTC Alarm type.
Definition: tm_stm32f4_rtc.h:258
Definition: tm_stm32f4_rtc.h:252
Definition: tm_stm32f4_rtc.h:251
Definition: tm_stm32f4_rtc.h:217
Definition: tm_stm32f4_rtc.h:260
uint8_t minutes
Definition: tm_stm32f4_rtc.h:199
TM_RTC_Alarm_t
Alarm identifier you will use for Alarm functions.
Definition: tm_stm32f4_rtc.h:266
Definition: tm_stm32f4_rtc.h:225
Definition: tm_stm32f4_rtc.h:267
Definition: tm_stm32f4_rtc.h:238
Definition: tm_stm32f4_rtc.h:218
uint8_t day
Definition: tm_stm32f4_rtc.h:201
uint32_t TM_RTC_GetUnixTimeStamp(TM_RTC_t *data)
Get number of seconds from date and time since 01.01.1970 00:00:00.
uint32_t TM_RTC_Init(TM_RTC_ClockSource_t source)
Initializes RTC and starts counting.
Definition: tm_stm32f4_rtc.h:236
void TM_RTC_RequestHandler(void)
RTC Wakeup handler function. Called when wakeup interrupt is triggered.
RTC structure for alarm time.
Definition: tm_stm32f4_rtc.h:274
uint8_t date
Definition: tm_stm32f4_rtc.h:202
Definition: tm_stm32f4_rtc.h:235
TM_RTC_Format_t
RTC date and time format.
Definition: tm_stm32f4_rtc.h:224
Definition: tm_stm32f4_rtc.h:226
TM_RTC_t TM_RTC_Time_t
Backward compatibility for RTC time.
Definition: tm_stm32f4_rtc.h:211
Definition: tm_stm32f4_rtc.h:239
uint8_t month
Definition: tm_stm32f4_rtc.h:203
TM_RTC_Result_t TM_RTC_SetDateTimeString(char *str)
Set date and time using string formatted date time.
uint8_t hours
Definition: tm_stm32f4_rtc.h:278
uint8_t seconds
Definition: tm_stm32f4_rtc.h:276
void TM_RTC_WriteBackupRegister(uint8_t location, uint32_t value)
Write RTC backup register value. This method allows you to write 32bit value from backup register 0 -...
uint16_t TM_RTC_GetDaysInYear(uint8_t year)
Get number of days in specific year.
void TM_RTC_GetDateTimeFromUnix(TM_RTC_t *data, uint32_t unix)
Get formatted time from seconds till 01.01.1970 00:00:00 It fills struct with valid data...
void TM_RTC_SetAlarm(TM_RTC_Alarm_t Alarm, TM_RTC_AlarmTime_t *AlarmTime, TM_RTC_Format_t format)
Enables alarm A or alarm B.