Skip to content

Commit 03ed45a

Browse files
committed
Add dynamic alarm match parameter to RTC_StartAlarm
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 6df1af8 commit 03ed45a

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

cores/arduino/stm32/rtc.c

+38-4
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,11 @@ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday)
544544
* @param seconds: 0-59
545545
* @param subSeconds: 0-999
546546
* @param period: AM or PM if in 12 hours mode else ignored.
547+
* @param mask: configure alarm behavior using alarmMask_t combination.
548+
* See AN4579 Table 5 for possible values.
547549
* @retval None
548550
*/
549-
void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period)
551+
void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period, uint8_t mask)
550552
{
551553
RTC_AlarmTypeDef RTC_AlarmStructure;
552554

@@ -578,11 +580,29 @@ void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds
578580
RTC_AlarmStructure.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
579581
RTC_AlarmStructure.AlarmDateWeekDay = day;
580582
RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
581-
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_NONE;
583+
/* configure AlarmMask (M_MSK and Y_MSK ignored) */
584+
if(mask == OFF_MSK) {
585+
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_ALL;
586+
} else {
587+
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_NONE;
588+
if( !(mask & SS_MSK)) {
589+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_SECONDS;
590+
}
591+
if( !(mask & MM_MSK)) {
592+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_MINUTES;
593+
}
594+
if( !(mask & HH_MSK)) {
595+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_HOURS;
596+
}
597+
if( !(mask & D_MSK)) {
598+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_DATEWEEKDAY;
599+
}
600+
}
582601
#else
583602
UNUSED(subSeconds);
584603
UNUSED(period);
585604
UNUSED(day);
605+
UNUSED(mask);
586606
#endif // !defined(STM32F1xx)
587607

588608
/* Set RTC_Alarm */
@@ -614,16 +634,17 @@ void RTC_StopAlarm(void)
614634
* @param period: AM or PM
615635
* @retval None
616636
*/
617-
void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period)
637+
void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period, uint8_t *mask)
618638
{
619639
RTC_AlarmTypeDef RTC_AlarmStructure;
620640

621-
if((day != NULL) && (hours != NULL) && (minutes != NULL) && (seconds != NULL) && (subSeconds != NULL) && (period != NULL)) {
641+
if((day != NULL) && (hours != NULL) && (minutes != NULL) && (seconds != NULL) && (subSeconds != NULL) && (period != NULL) && (mask != NULL)) {
622642
HAL_RTC_GetAlarm(&RtcHandle, &RTC_AlarmStructure, RTC_ALARM_A, RTC_FORMAT_BIN);
623643

624644
*seconds = RTC_AlarmStructure.AlarmTime.Seconds;
625645
*minutes = RTC_AlarmStructure.AlarmTime.Minutes;
626646
*hours = RTC_AlarmStructure.AlarmTime.Hours;
647+
627648
#if !defined(STM32F1xx)
628649
*day = RTC_AlarmStructure.AlarmDateWeekDay;
629650
if(RTC_AlarmStructure.AlarmTime.TimeFormat == RTC_HOURFORMAT12_PM) {
@@ -634,6 +655,19 @@ void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *secon
634655
#if !defined(STM32F2xx) && !defined(STM32L1xx) || defined(STM32L1_ULPH)
635656
*subSeconds = RTC_AlarmStructure.AlarmTime.SubSeconds;
636657
#endif
658+
*mask = OFF_MSK;
659+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_SECONDS)) {
660+
*mask |= SS_MSK;
661+
}
662+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_MINUTES)) {
663+
*mask |= MM_MSK;
664+
}
665+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_HOURS)) {
666+
*mask |= HH_MSK;
667+
}
668+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_DATEWEEKDAY)) {
669+
*mask |= D_MSK;
670+
}
637671
#endif // !defined(STM32F1xx)
638672
}
639673
}

cores/arduino/stm32/rtc.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ typedef enum {
5959
PM
6060
} hourAM_PM_t;
6161

62+
/* See AN4579 Table 5 for possible values */
63+
typedef enum {
64+
OFF_MSK = 0,
65+
SS_MSK = 1, /* MSK0 */
66+
MM_MSK = 2, /* MSK1 */
67+
HH_MSK = 4, /* MSK2 */
68+
D_MSK = 8, /* MSK3 */
69+
/* NOTE: STM32 RTC can't assign a month or a year to an alarm. Those enum
70+
are kept for compatibility but are ignored inside enableAlarm(). */
71+
M_MSK = 16,
72+
Y_MSK = 32
73+
} alarmMask_t;
74+
6275
// Clock source selection
6376
typedef enum {
6477
LSI_CLOCK,
@@ -122,9 +135,9 @@ void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *s
122135
void RTC_SetDate(uint8_t year, uint8_t month, uint8_t day, uint8_t wday);
123136
void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday);
124137

125-
void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period);
138+
void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period, uint8_t mask);
126139
void RTC_StopAlarm(void);
127-
void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period);
140+
void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period, uint8_t *mask);
128141
void attachAlarmCallback(voidCallbackPtr func, void *data);
129142
void detachAlarmCallback(void);
130143

0 commit comments

Comments
 (0)