Skip to content

Commit cdb4354

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

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

cores/arduino/stm32/rtc.c

+36-4
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday)
546546
* @param period: AM or PM if in 12 hours mode else ignored.
547547
* @retval None
548548
*/
549-
void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period)
549+
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)
550550
{
551551
RTC_AlarmTypeDef RTC_AlarmStructure;
552552

@@ -578,11 +578,29 @@ void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds
578578
RTC_AlarmStructure.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
579579
RTC_AlarmStructure.AlarmDateWeekDay = day;
580580
RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
581-
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_NONE;
581+
/* configure AlarmMask (M_MSK and Y_MSK ignored) */
582+
if(mask == OFF_MSK) {
583+
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_ALL;
584+
} else {
585+
RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_NONE;
586+
if( !(mask & SS_MSK)) {
587+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_SECONDS;
588+
}
589+
if( !(mask & MM_MSK)) {
590+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_MINUTES;
591+
}
592+
if( !(mask & HH_MSK)) {
593+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_HOURS;
594+
}
595+
if( !(mask & D_MSK)) {
596+
RTC_AlarmStructure.AlarmMask |= RTC_ALARMMASK_DATEWEEKDAY;
597+
}
598+
}
582599
#else
583600
UNUSED(subSeconds);
584601
UNUSED(period);
585602
UNUSED(day);
603+
UNUSED(mask);
586604
#endif // !defined(STM32F1xx)
587605

588606
/* Set RTC_Alarm */
@@ -614,16 +632,17 @@ void RTC_StopAlarm(void)
614632
* @param period: AM or PM
615633
* @retval None
616634
*/
617-
void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *period)
635+
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)
618636
{
619637
RTC_AlarmTypeDef RTC_AlarmStructure;
620638

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

624642
*seconds = RTC_AlarmStructure.AlarmTime.Seconds;
625643
*minutes = RTC_AlarmStructure.AlarmTime.Minutes;
626644
*hours = RTC_AlarmStructure.AlarmTime.Hours;
645+
627646
#if !defined(STM32F1xx)
628647
*day = RTC_AlarmStructure.AlarmDateWeekDay;
629648
if(RTC_AlarmStructure.AlarmTime.TimeFormat == RTC_HOURFORMAT12_PM) {
@@ -634,6 +653,19 @@ void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *secon
634653
#if !defined(STM32F2xx) && !defined(STM32L1xx) || defined(STM32L1_ULPH)
635654
*subSeconds = RTC_AlarmStructure.AlarmTime.SubSeconds;
636655
#endif
656+
*mask = OFF_MSK;
657+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_SECONDS)) {
658+
*mask |= SS_MSK;
659+
}
660+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_MINUTES)) {
661+
*mask |= MM_MSK;
662+
}
663+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_HOURS)) {
664+
*mask |= HH_MSK;
665+
}
666+
if(!(RTC_AlarmStructure.AlarmMask & RTC_ALARMMASK_DATEWEEKDAY)) {
667+
*mask |= D_MSK;
668+
}
637669
#endif // !defined(STM32F1xx)
638670
}
639671
}

cores/arduino/stm32/rtc.h

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

62+
typedef enum {
63+
OFF_MSK = 0,
64+
SS_MSK = 1,
65+
MM_MSK = 2,
66+
HH_MSK = 4,
67+
D_MSK = 8,
68+
/* NOTE: STM32 RTC can't assign a month or a year to an alarm. Those enum
69+
are kept for compatibility but are ignored inside enableAlarm(). */
70+
M_MSK = 16,
71+
Y_MSK = 32
72+
} alarmMask_t;
73+
6274
// Clock source selection
6375
typedef enum {
6476
LSI_CLOCK,
@@ -122,9 +134,9 @@ void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *s
122134
void RTC_SetDate(uint8_t year, uint8_t month, uint8_t day, uint8_t wday);
123135
void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday);
124136

125-
void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period);
137+
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);
126138
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);
139+
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);
128140
void attachAlarmCallback(voidCallbackPtr func, void *data);
129141
void detachAlarmCallback(void);
130142

0 commit comments

Comments
 (0)