@@ -829,19 +829,20 @@ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday)
829
829
}
830
830
831
831
/**
832
- * @brief Set RTC alarm and activate it with IT mode
832
+ * @brief Set RTC alarm and activate it with IT mode with 64bit accuracy on subsecond param
833
+ * Mainly used by Lorawan in RTC BIN or MIX mode
833
834
* @param name: ALARM_A or ALARM_B if exists
834
835
* @param day: 1-31 (day of the month)
835
836
* @param hours: 0-12 or 0-23 depends on the hours mode.
836
837
* @param minutes: 0-59
837
838
* @param seconds: 0-59
838
- * @param subSeconds: 0-999 milliseconds
839
+ * @param subSeconds: 0-999 milliseeconds or 64bit nb of milliseconds in no BCD mode
839
840
* @param period: HOUR_AM or HOUR_PM if in 12 hours mode else ignored.
840
841
* @param mask: configure alarm behavior using alarmMask_t combination.
841
842
* See AN4579 Table 5 for possible values.
842
843
* @retval None
843
844
*/
844
- void RTC_StartAlarm (alarm_t name , uint8_t day , uint8_t hours , uint8_t minutes , uint8_t seconds , uint32_t subSeconds , hourAM_PM_t period , uint8_t mask )
845
+ void RTC_StartAlarm64 (alarm_t name , uint8_t day , uint8_t hours , uint8_t minutes , uint8_t seconds , uint64_t subSeconds , hourAM_PM_t period , uint8_t mask )
845
846
{
846
847
#if !defined(RTC_SSR_SS )
847
848
UNUSED (subSeconds );
@@ -879,9 +880,9 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
879
880
*/
880
881
if ((initMode == MODE_BINARY_ONLY ) || (initMode == MODE_BINARY_MIX )) {
881
882
/* the subsecond is the millisecond to be converted in a subsecond downcounter value */
882
- RTC_AlarmStructure .AlarmTime .SubSeconds = UINT32_MAX - (subSeconds * (predivSync + 1 )) / 1000 ;
883
+ RTC_AlarmStructure .AlarmTime .SubSeconds = UINT32_MAX - (( uint32_t ) subSeconds * (predivSync + 1 )) / 1000 ;
883
884
} else {
884
- RTC_AlarmStructure .AlarmTime .SubSeconds = predivSync - (subSeconds * (predivSync + 1 )) / 1000 ;
885
+ RTC_AlarmStructure .AlarmTime .SubSeconds = predivSync - (( uint32_t ) subSeconds * (predivSync + 1 )) / 1000 ;
885
886
}
886
887
} else {
887
888
RTC_AlarmStructure .AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL ;
@@ -945,8 +946,15 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
945
946
#if defined(RTC_ICSR_BIN )
946
947
if ((initMode == MODE_BINARY_ONLY ) || (initMode == MODE_BINARY_MIX )) {
947
948
/* We have an SubSecond alarm to set in RTC_BINARY_MIX or RTC_BINARY_ONLY mode */
948
- /* The subsecond in ms is converted in ticks unit 1 tick is 1000 / fqce_apre */
949
- RTC_AlarmStructure .AlarmTime .SubSeconds = UINT32_MAX - (subSeconds * (predivSync + 1 )) / 1000 ;
949
+ /* The subsecond in ms is converted in ticks unit 1 tick is 1000 / fqce_apre
950
+ * It keeps the subsecond accuracy on 64 bits if needed
951
+ */
952
+ if (subSeconds > (uint64_t )UINT32_MAX ) {
953
+ uint64_t tmp = ((uint64_t )subSeconds * (predivSync + 1 )) / (uint64_t )1000 ;
954
+ RTC_AlarmStructure .AlarmTime .SubSeconds = (uint32_t )UINT32_MAX - (uint32_t )tmp ;
955
+ } else {
956
+ RTC_AlarmStructure .AlarmTime .SubSeconds = (uint32_t )(UINT32_MAX - (subSeconds * (predivSync + 1 )) / 1000 );
957
+ }
950
958
} else
951
959
#endif /* RTC_ICSR_BIN */
952
960
{
@@ -960,6 +968,25 @@ void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, u
960
968
#endif /* RTC_SSR_SS */
961
969
}
962
970
971
+ /**
972
+ * @brief Set RTC alarm and activate it with IT mode
973
+ * @param name: ALARM_A or ALARM_B if exists
974
+ * @param day: 1-31 (day of the month)
975
+ * @param hours: 0-12 or 0-23 depends on the hours mode.
976
+ * @param minutes: 0-59
977
+ * @param seconds: 0-59
978
+ * @param subSeconds: 0-999 milliseconds
979
+ * @param period: HOUR_AM or HOUR_PM if in 12 hours mode else ignored.
980
+ * @param mask: configure alarm behavior using alarmMask_t combination.
981
+ * See AN4579 Table 5 for possible values.
982
+ * @retval None
983
+ */
984
+ void RTC_StartAlarm (alarm_t name , uint8_t day , uint8_t hours , uint8_t minutes , uint8_t seconds , uint32_t subSeconds , hourAM_PM_t period , uint8_t mask )
985
+ {
986
+ /* Same RTC_StartAlarm where the nb of SubSeconds is lower than UINT32_MAX */
987
+ RTC_StartAlarm64 (name , day , hours , minutes , seconds , (uint64_t )subSeconds , period , mask );
988
+ }
989
+
963
990
/**
964
991
* @brief Disable RTC alarm
965
992
* @param name: ALARM_A or ALARM_B if exists
0 commit comments