Skip to content

Commit 430606c

Browse files
committed
feat: adapt timer to use rtc
Signed-off-by: Frederic Pillon <[email protected]>
1 parent de8dd11 commit 430606c

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/STM32CubeWL/Utilities/misc/stm32_systime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void SysTimeSet( SysTime_t sysTime )
233233

234234
SysTime_t calendarTime = { .Seconds = 0, .SubSeconds = 0 };
235235

236-
calendarTime.Seconds = UTIL_SYSTIMDriver.GetCalendarTime( ( uint16_t* )&calendarTime.SubSeconds );
236+
calendarTime.Seconds = UTIL_SYSTIMDriver.GetCalendarTime( ( uint32_t* )&calendarTime.SubSeconds );
237237

238238
// sysTime is UNIX epoch
239239
DeltaTime = SysTimeSub( sysTime, calendarTime );
@@ -248,9 +248,9 @@ SysTime_t SysTimeGet( void )
248248
SysTime_t sysTime = { .Seconds = 0, .SubSeconds = 0 };
249249
SysTime_t DeltaTime;
250250

251-
calendarTime.Seconds = UTIL_SYSTIMDriver.GetCalendarTime( ( uint16_t* )&calendarTime.SubSeconds );
251+
calendarTime.Seconds = UTIL_SYSTIMDriver.GetCalendarTime( ( uint32_t* )&calendarTime.SubSeconds );
252252

253-
DeltaTime.SubSeconds = (int16_t)UTIL_SYSTIMDriver.BKUPRead_SubSeconds();
253+
DeltaTime.SubSeconds = (int32_t)UTIL_SYSTIMDriver.BKUPRead_SubSeconds();
254254
DeltaTime.Seconds = UTIL_SYSTIMDriver.BKUPRead_Seconds();
255255

256256
sysTime = SysTimeAdd( DeltaTime, calendarTime );
@@ -263,7 +263,7 @@ SysTime_t SysTimeGetMcuTime( void )
263263
{
264264
SysTime_t calendarTime = { .Seconds = 0, .SubSeconds = 0 };
265265

266-
calendarTime.Seconds = UTIL_SYSTIMDriver.GetCalendarTime( ( uint16_t* )&calendarTime.SubSeconds );
266+
calendarTime.Seconds = UTIL_SYSTIMDriver.GetCalendarTime( ( uint32_t* )&calendarTime.SubSeconds );
267267

268268
return calendarTime;
269269
}
@@ -284,7 +284,7 @@ SysTime_t SysTimeFromMs( uint32_t timeMs )
284284
SysTime_t sysTime = { .Seconds = seconds, .SubSeconds = timeMs - seconds * 1000 };
285285
SysTime_t DeltaTime = { 0 };
286286

287-
DeltaTime.SubSeconds = (int16_t)UTIL_SYSTIMDriver.BKUPRead_SubSeconds();
287+
DeltaTime.SubSeconds = (int32_t)UTIL_SYSTIMDriver.BKUPRead_SubSeconds();
288288
DeltaTime.Seconds = UTIL_SYSTIMDriver.BKUPRead_Seconds();
289289
return SysTimeAdd( sysTime, DeltaTime );
290290
}

src/STM32CubeWL/Utilities/misc/stm32_systime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef struct
133133
uint32_t (*BKUPRead_Seconds) ( void ); /*!< Get the timer differencebetween real time and rtc time */
134134
void (*BKUPWrite_SubSeconds) ( uint32_t SubSeconds); /*!< Set the timer differencebetween real time and rtc time */
135135
uint32_t (*BKUPRead_SubSeconds) ( void ); /*!< Get the timer differencebetween real time and rtc time */
136-
uint32_t (*GetCalendarTime)( uint16_t* SubSeconds ); /*!< Set the rtc time */
136+
uint32_t (*GetCalendarTime)( uint32_t* SubSeconds ); /*!< Set the rtc time */
137137
} UTIL_SYSTIM_Driver_s;
138138

139139
/**

src/STM32CubeWL/Utilities/timer/stm32_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ bool TimerExists( UTIL_TIMER_Object_t *TimerObject );
116116
* @{
117117
*/
118118

119-
UTIL_TIMER_Status_t UTIL_TIMER_Init(void)
119+
UTIL_TIMER_Status_t UTIL_TIMER_Init(RTC_HandleTypeDef *RtcHandle)
120120
{
121121
UTIL_TIMER_INIT_CRITICAL_SECTION();
122122
TimerListHead = NULL;
123-
return UTIL_TimerDriver.InitTimer();
123+
return UTIL_TimerDriver.InitTimer(RtcHandle);
124124
}
125125

126126
UTIL_TIMER_Status_t UTIL_TIMER_DeInit(void)

src/STM32CubeWL/Utilities/timer/stm32_timer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <stddef.h>
5858
#include <cmsis_compiler.h>
5959
#include "../../../BSP/utilities_conf.h"
60+
#include "rtc.h"
6061

6162
/* Exported types ------------------------------------------------------------*/
6263
/** @defgroup TIMER_SERVER_exported_TypeDef TIMER_SERVER exported Typedef
@@ -103,7 +104,7 @@ typedef struct TimerEvent_s
103104
*/
104105
typedef struct
105106
{
106-
UTIL_TIMER_Status_t (* InitTimer )( void ); /*!< Initialisation of the low layer timer */
107+
UTIL_TIMER_Status_t (* InitTimer )( RTC_HandleTypeDef * ); /*!< Initialisation of the low layer timer */
107108
UTIL_TIMER_Status_t (* DeInitTimer )( void ); /*!< Un-Initialisation of the low layer timer */
108109

109110
UTIL_TIMER_Status_t (* StartTimerEvt )( uint32_t timeout ); /*!< Start the low layer timer */
@@ -156,9 +157,10 @@ extern const UTIL_TIMER_Driver_s UTIL_TimerDriver;
156157
/**
157158
* @brief Initialize the timer server
158159
*
160+
* @param RtcHandle RTC_HandleTypeDef
159161
* @retval Status based on @ref UTIL_TIMER_Status_t
160162
*/
161-
UTIL_TIMER_Status_t UTIL_TIMER_Init(void);
163+
UTIL_TIMER_Status_t UTIL_TIMER_Init(RTC_HandleTypeDef *RtcHandle);
162164

163165
/**
164166
* @brief Un-Initialize the timer server

0 commit comments

Comments
 (0)