foxBMS - Unit Tests  1.6.0
The foxBMS Unit Tests API Documentation
rtc.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file rtc.c
44  * @author foxBMS Team
45  * @date 2021-02-22 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS
49  * @prefix RTC
50  *
51  * @brief Implementation of the RTC driver
52  * @details Uses the NXP PCF2131 RTC over I2C
53  *
54  */
55 
56 /*========== Includes =======================================================*/
57 #include "rtc.h"
58 
59 #include "database.h"
60 #include "diag.h"
61 #include "foxmath.h"
62 #include "fstd_types.h"
63 #include "ftask.h"
64 #include "i2c.h"
65 
66 #include <stdint.h>
67 /* AXIVION Disable Style MisraC2012-21.10: Time implementation is suitable fpr the application */
68 #include <time.h>
69 
70 /*========== Macros and Definitions =========================================*/
71 
72 /** Time data of the RTC */
73 typedef struct {
75  uint16_t milliseconds;
77 
78 /*========== Static Constant and Variable Definitions =======================*/
79 
80 /* AXIVION Disable Style MisraC2012-1.2: i2c buffer must be put in shared RAM section if used with DMA and cache */
81 #pragma SET_DATA_SECTION(".sharedRAM")
82 /** I2C buffer for write transactions with RTC */
84 /** I2C buffer for read transactions with RTC */
86 #pragma SET_DATA_SECTION()
87 /* AXIVION Enable Style MisraC2012-1.2: only i2c buffer needs to be in the shared RAM section */
88 
89 /** Variable containing the RTC system time */
91 
92 /*========== Extern Constant and Variable Definitions =======================*/
93 
94 /*========== Static Function Prototypes =====================================*/
95 
96 /**
97  * @brief Reads the time from the RTC IC.
98  * @details This function reads the time from the RTC IC over I2C.
99  * @return RTC time read from the RTC IC
100  */
101 static RTC_TIME_DATA_s RTC_ReadTime(void);
102 
103 static void RTC_WriteTime(RTC_TIME_DATA_s rtcTime);
104 static void RTC_SetOverCanMessage(void);
105 static void RTC_AdjustTime(void);
106 static void RTC_CheckBatteryLowVoltageAlert(void);
107 
108 static void RTC_SetSystemTimeEpochFormat(time_t timeEpochFormat, uint16_t milliseconds);
110 
111 static struct tm RTC_rtcFormatToTmFormat(RTC_TIME_DATA_s timeRtcFormat);
112 static RTC_TIME_DATA_s RTC_tmFormatToRtcFormat(struct tm timeTmFormat);
113 
114 /*========== Static Function Implementations ================================*/
115 
116 /**
117  * @brief Write the time to the RTC IC.
118  * @details This function writes the time to the RTC IC over I2C.
119  * @param rtcTime RTC time to write to the IC
120  */
121 static void RTC_WriteTime(RTC_TIME_DATA_s rtcTime) {
122  /* AXIVION Routine Generic-MissingParameterAssert: rtcTime: parameter accepts whole range */
123  STD_RETURN_TYPE_e retValI2c = STD_OK;
124  STD_RETURN_TYPE_e retVal = STD_OK;
125 
126  /* Write control_1 register to stop RTC */
128  /* Set stop bit, clear 12/24hour mode bit */
129  rtc_i2cWriteBuffer[1u] = 0u;
132  retValI2c = I2C_WriteDma(
134  if (retValI2c == STD_NOT_OK) {
135  retVal = STD_NOT_OK;
136  }
137  /* Write 0xA4 to software reset register */
140  /* Address counters rolls to time data */
146  (rtcTime.seconds % RTC_TENS_PLACE_FACTOR);
149  (rtcTime.minutes % RTC_TENS_PLACE_FACTOR);
156  (rtcTime.weekday % RTC_TENS_PLACE_FACTOR);
161  /* Write time data */
162  retValI2c =
164  if (retValI2c == STD_NOT_OK) {
165  retVal = STD_NOT_OK;
166  }
167  /* Wait external reference */
168  /* Now write control_1 register again to start RTC */
170  rtc_i2cWriteBuffer[1u] = 0u;
171  rtc_i2cWriteBuffer[1u] &= ~((uint8_t)RTC_CTRL1_STOP_BIT_MASK);
173  retValI2c = I2C_WriteDma(
175  if (retValI2c == STD_NOT_OK) {
176  retVal = STD_NOT_OK;
177  }
178 
179  if (retVal == STD_NOT_OK) {
181  } else {
183  }
184 }
185 
186 /**
187  * @brief Check if a CAN message was received to set the RTC time.
188  *
189  * When a CAN message to set the RTC time is received, it is written
190  * in the dedicated queue. This function check if an element is present
191  * in the queue. If yes, the time is first written to the RTC IC over
192  * I2C, then to the RTC system timer.
193  *
194  */
195 static void RTC_SetOverCanMessage(void) {
196  RTC_TIME_DATA_s rtc_time = {0};
197 
198  if (OS_ReceiveFromQueue(ftsk_rtcSetTimeQueue, (void *)&rtc_time, 0u) == OS_SUCCESS) {
199  /* Write time data to RTC */
200  RTC_WriteTime(rtc_time);
201  /* Set system timer */
202  RTC_SetSystemTimeRtcFormat(rtc_time);
203  }
204 }
205 
206 /**
207  * @brief Adjust RTC system timer with time from RTC IC.
208  *
209  * The time is read from the RTC IC and compared to the
210  * RTC system timer. If the difference is greater than the
211  * limit, the RTC system timer is adjusted.
212  */
213 static void RTC_AdjustTime(void) {
214  RTC_TIME_DATA_s rtcTimeFromTimerRtcFormat = {0};
215  RTC_TIME_DATA_s rtcTimeFromIcRtcFormat = {0};
216  time_t rtcTimeFromTimerEpochFormat = 0;
217  time_t rtcTimeFromIcEpochFormat = 0;
218  struct tm rtcTimeFromTimerTmFormat = {0};
219  struct tm rtcTimeFromIcTmFormat = {0};
220 
221  rtcTimeFromIcRtcFormat = RTC_ReadTime();
222  /* Convert time and date from RTC to tm struct */
223  rtcTimeFromIcTmFormat = RTC_rtcFormatToTmFormat(rtcTimeFromIcRtcFormat);
224  /* Convert tm struct to timer in seconds since epoch */
225  rtcTimeFromIcEpochFormat = mktime(&rtcTimeFromIcTmFormat);
226 
227  rtcTimeFromTimerRtcFormat = RTC_GetSystemTimeRtcFormat();
228  /* Convert time and date from RTC to tm struct */
229  rtcTimeFromTimerTmFormat = RTC_rtcFormatToTmFormat(rtcTimeFromTimerRtcFormat);
230  /* Convert tm struct to timer in seconds since epoch */
231  rtcTimeFromTimerEpochFormat = mktime(&rtcTimeFromTimerTmFormat);
232 
233  if (abs(rtcTimeFromIcEpochFormat - rtcTimeFromTimerEpochFormat) > RTC_MAX_DIFFERENCE_BETWEEN_TIMER_AND_IC_s) {
234  /* Difference between RTC timer and RTC IC higher than limit: adjust RTC timer */
236  }
237 }
238 
239 /**
240  * @brief Read bit for battery voltage low flag.
241  */
243  STD_RETURN_TYPE_e retValI2c = STD_OK;
244  STD_RETURN_TYPE_e retVal = STD_OK;
245  uint8_t blfBit = 0u; /* Battery Low Flag (BLF) */
246 
247  /* Set address to read from */
250  if (retValI2c == STD_NOT_OK) {
251  retVal = STD_NOT_OK;
252  }
253  /* Address set, read register data */
255  if (retValI2c == STD_NOT_OK) {
256  retVal = STD_NOT_OK;
257  }
258 
259  /* OSF bit is stored at position 7 in seconds register */
261 
262  if (retVal == STD_NOT_OK) {
264  } else {
266  /* If I2C communication successful, check BLF bit */
267  if (blfBit != 0u) {
269  } else {
271  }
272  }
273 }
274 
275 /**
276  * @brief Set the RTC system timer value.
277  *
278  * This function sets the timer value directly.
279  * It is called by RTC_SetSystemTimeRtcFormat() which
280  * takes a RTC_TIME_DATA_s parameter as input.
281  *
282  * @param timeEpochFormat RTC system timer value to set, main value in seconds
283  * @param milliseconds RTC system timer value to set, secondary value in milliseconds
284  */
285 static void RTC_SetSystemTimeEpochFormat(time_t timeEpochFormat, uint16_t milliseconds) {
287  rtc_SystemTime.secondsSinceEpoch = timeEpochFormat;
288  rtc_SystemTime.milliseconds = milliseconds;
290 }
291 
292 /**
293  * @brief Get the RTC system timer value.
294  *
295  * This function gets the timer value directly.
296  * It is called by RTC_GetSystemTimeRtcFormat() which
297  * returns a RTC_TIME_DATA_s parameter.
298  *
299  * @return RTC system timer value in seconds since epoch format
300  */
302  RTC_SYSTEM_TIMER_EPOCH_s systemTimerValueEpoch = {0};
304  systemTimerValueEpoch = rtc_SystemTime;
306  return systemTimerValueEpoch;
307 }
308 
309 /**
310  * @brief Convert time from RTC_TIME_DATA_s to struct tm format.
311  *
312  * @param timeRtcFormat time in RTC_TIME_DATA_s format
313  * @return time in struct tm format
314  */
315 static struct tm RTC_rtcFormatToTmFormat(RTC_TIME_DATA_s timeRtcFormat) {
316  struct tm timeTmFormat = {0};
317 
318  timeTmFormat.tm_year = (RTC_START_YEAR + timeRtcFormat.year) - RTC_CTIME_YEAR_START;
319  timeTmFormat.tm_mon = timeRtcFormat.month - RTC_CTIME_MONTH_START;
320  timeTmFormat.tm_mday = timeRtcFormat.day;
321  timeTmFormat.tm_hour = timeRtcFormat.hours;
322  timeTmFormat.tm_min = timeRtcFormat.minutes;
323  timeTmFormat.tm_sec = timeRtcFormat.seconds;
324  timeTmFormat.tm_wday = timeRtcFormat.weekday;
325 
326  return timeTmFormat;
327 }
328 
329 /**
330  * @brief Convert time from struct tm to RTC_TIME_DATA_s format.
331  *
332  * @param timeTmFormat time in struct tm format
333  * @return time in RTC_TIME_DATA_s format
334  */
335 static RTC_TIME_DATA_s RTC_tmFormatToRtcFormat(struct tm timeTmFormat) {
336  RTC_TIME_DATA_s timeRtcFormat = {0};
337 
338  timeRtcFormat.year = timeTmFormat.tm_year + RTC_CTIME_YEAR_START - RTC_START_YEAR;
339  timeRtcFormat.month = timeTmFormat.tm_mon + RTC_CTIME_MONTH_START;
340  timeRtcFormat.day = timeTmFormat.tm_mday;
341  timeRtcFormat.hours = timeTmFormat.tm_hour;
342  timeRtcFormat.minutes = timeTmFormat.tm_min;
343  timeRtcFormat.seconds = timeTmFormat.tm_sec;
344  timeRtcFormat.weekday = timeTmFormat.tm_wday;
345 
346  return timeRtcFormat;
347 }
348 
350  RTC_TIME_DATA_s rtcTime = {0};
351  STD_RETURN_TYPE_e retValI2c = STD_OK;
352  STD_RETURN_TYPE_e retVal = STD_OK;
353 
354  uint8_t osfBit = 0u;
355 
356  /* Set address to read from */
359  if (retValI2c == STD_NOT_OK) {
360  retVal = STD_NOT_OK;
361  }
362  /* Address set, read time data */
364  if (retValI2c == STD_NOT_OK) {
365  retVal = STD_NOT_OK;
366  }
367 
368  rtcTime.hundredthOfSeconds =
373  rtcTime.seconds =
377  /* OSF bit is stored at position 7 in seconds register */
379  rtcTime.minutes =
396 
397  if (retVal == STD_NOT_OK) {
399  } else {
401  /* If I2C communication successful, check OSF bit */
402  if (osfBit != 0u) {
404  } else {
406  }
407  }
408 
409  return rtcTime;
410 }
411 
412 /*========== Extern Function Implementations ================================*/
413 
414 extern void RTC_Trigger(void) {
415  static uint32_t initialTimeBatteryLowCheck = 0u;
416  static uint32_t initialTimeAdjustCheck = 0u;
417  uint32_t currentTime = OS_GetTickCount();
418 
419  STD_RETURN_TYPE_e initFinished = STD_NOT_OK;
420 
421  initFinished = RTC_Initialize();
422 
423  if (initFinished == STD_OK) {
424  /* Check if an RTC CAN message came */
426  /* Check battery low */
427  if ((currentTime - initialTimeBatteryLowCheck) >=
430  initialTimeBatteryLowCheck = OS_GetTickCount();
431  }
432  /* Adjust time if necessary */
433  if ((currentTime - initialTimeAdjustCheck) >=
435  RTC_AdjustTime();
436  initialTimeAdjustCheck = OS_GetTickCount();
437  }
438  }
439 }
440 
442  STD_RETURN_TYPE_e returnValue = STD_NOT_OK;
443  static RTC_INIT_STATES_e rtcInitState = RTC_SET_SYSTEM_TIMER;
444  STD_RETURN_TYPE_e retValI2c = STD_OK;
445  STD_RETURN_TYPE_e retVal = STD_OK;
446  uint8_t otprBit = 1u;
447  uint8_t otprTimeout = RTC_OTPR_BIT_WAIT_TIMEOUT_ms;
448  static uint32_t initTime = 0u;
449  uint32_t currentTime = OS_GetTickCount();
450 
451  switch (rtcInitState) {
454  rtcInitState = RTC_SET_BLF;
455  OS_DelayTaskUntil(&currentTime, 2u);
456  break;
457  case RTC_SET_BLF:
458  /* Write PWRMNG bits */
459  /* Set address to write to */
461  /* Set data to write, to activate direct switching mode and battery low detection */
462  rtc_i2cWriteBuffer[1u] = 0u;
465  retValI2c = I2C_WriteDma(
470  if (retValI2c == STD_NOT_OK) {
471  retVal = STD_NOT_OK;
472  }
473  rtcInitState = RTC_CLEAR_OTPR;
474  OS_DelayTaskUntil(&currentTime, 2u);
475  break;
476 
477  case RTC_CLEAR_OTPR:
478  /* OTP refresh begin */
479  /* Clear OTPR bit */
480  /* Set address to write to */
482  /* Set data to write, to clear OTPR to 0 */
483  rtc_i2cWriteBuffer[1u] = 0u;
485  retValI2c = I2C_WriteDma(
490  if (retValI2c == STD_NOT_OK) {
491  retVal = STD_NOT_OK;
492  }
493  initTime = OS_GetTickCount();
494  rtcInitState = RTC_WAIT_CLEAR_OTPR;
495  OS_DelayTaskUntil(&currentTime, 2u);
496  break;
497 
498  case RTC_WAIT_CLEAR_OTPR:
499  /* Read OTPR bit until cleared to 0 */
500 
501  /* Set address to read from */
504  if (retValI2c == STD_NOT_OK) {
505  retVal = STD_NOT_OK;
506  }
507  /* Address set, read data */
509  if (retValI2c == STD_NOT_OK) {
510  retVal = STD_NOT_OK;
511  }
513  if (((currentTime - initTime) > RTC_OTPR_BIT_WAIT_TIMEOUT_ms) || (otprTimeout == 0u)) {
514  rtcInitState = RTC_SET_OTPR;
515  }
516  OS_DelayTaskUntil(&currentTime, 2u);
517  break;
518 
519  case RTC_SET_OTPR:
520  /* Set OTPR bit */
521  /* Set address to write to */
523  /* Set data to write, to set OTPR to 1 */
524  rtc_i2cWriteBuffer[1u] = 0u;
526  retValI2c = I2C_WriteDma(
531  if (retValI2c == STD_NOT_OK) {
532  retVal = STD_NOT_OK;
533  }
534  initTime = OS_GetTickCount();
535  rtcInitState = RTC_WAIT_SET_OTPR;
536  OS_DelayTaskUntil(&currentTime, 2u);
537  break;
538 
539  case RTC_WAIT_SET_OTPR:
540  /* Read OTPR bit until set to 1 */
541  /* Set address to read from */
544  if (retValI2c == STD_NOT_OK) {
545  retVal = STD_NOT_OK;
546  }
547  /* Address set, read data */
549  if (retValI2c == STD_NOT_OK) {
550  retVal = STD_NOT_OK;
551  }
553  if (((currentTime - initTime) > RTC_OTPR_BIT_WAIT_TIMEOUT_ms) || (otprBit == 1u)) {
554  /* OTP refresh end */
555  rtcInitState = RTC_INIT_SET_FINISHED;
556  }
557  OS_DelayTaskUntil(&currentTime, 2u);
558  break;
559 
561  /* Init finished */
562  returnValue = STD_OK;
563  break;
564  default:
565  break;
566  }
567 
568  if (retVal == STD_NOT_OK) {
570  } else {
572  }
573 
574  return returnValue;
575 }
576 
578  RTC_TIME_DATA_s rtc_initTime = {0};
579 
580  /* Get time and date from RTC */
581  rtc_initTime = RTC_ReadTime();
582  /* Set system timer */
583  RTC_SetSystemTimeRtcFormat(rtc_initTime);
584 }
585 
586 extern void RTC_IncrementSystemTime(void) {
587  if (rtc_SystemTime.milliseconds < 999u) {
589  } else {
592  }
593 }
594 
595 extern void RTC_SetSystemTimeRtcFormat(RTC_TIME_DATA_s timeRtcFormat) {
596  time_t systemTimeEpochFormat = 0;
597  struct tm systemTimeTmFormat = {0};
598 
599  /* Convert time and date from RTC to tm struct */
600  systemTimeTmFormat = RTC_rtcFormatToTmFormat(timeRtcFormat);
601  /* Convert tm struct to timer in seconds since epoch */
602  systemTimeEpochFormat = mktime(&systemTimeTmFormat);
603  /* Set system timer */
604  RTC_SetSystemTimeEpochFormat(systemTimeEpochFormat, timeRtcFormat.hundredthOfSeconds * 10u);
605 }
606 
608  RTC_SYSTEM_TIMER_EPOCH_s systemTimeEpochFormat = {0};
609  struct tm systemTimeTmFormat = {0};
610  RTC_TIME_DATA_s systemTimeRtcFormat = {0};
611 
612  /* Get system timer */
613  systemTimeEpochFormat = RTC_GetSystemTimeEpochFormat();
614  /* Convert timer in seconds since epoch to tm struct */
615  systemTimeTmFormat = *(localtime(&(systemTimeEpochFormat.secondsSinceEpoch)));
616  /* Convert tm struct to RTC */
617  systemTimeRtcFormat = RTC_tmFormatToRtcFormat(systemTimeTmFormat);
618  systemTimeRtcFormat.hundredthOfSeconds = (systemTimeEpochFormat.milliseconds / 10u);
619 
620  return systemTimeRtcFormat;
621 }
622 /* AXIVION Enable Style MisraC2012-21.10: Time library only used in this module */
623 
624 /*========== Externalized Static Function Implementations (Unit Test) =======*/
625 #ifdef UNITY_UNIT_TEST
626 #endif
Database module header.
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
Definition: diag.c:246
Diagnosis driver header.
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:268
@ DIAG_EVENT_OK
Definition: diag_cfg.h:267
@ DIAG_SYSTEM
Definition: diag_cfg.h:280
@ DIAG_ID_I2C_RTC_ERROR
Definition: diag_cfg.h:256
@ DIAG_ID_RTC_CLOCK_INTEGRITY_ERROR
Definition: diag_cfg.h:257
@ DIAG_ID_RTC_BATTERY_LOW_ERROR
Definition: diag_cfg.h:258
math library for often used math functions
Definition of foxBMS standard types.
STD_RETURN_TYPE_e
Definition: fstd_types.h:82
@ STD_NOT_OK
Definition: fstd_types.h:84
@ STD_OK
Definition: fstd_types.h:83
Header of task driver implementation.
OS_QUEUE ftsk_rtcSetTimeQueue
STD_RETURN_TYPE_e I2C_ReadDma(i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, no register address written first, using DMA.
Definition: i2c.c:415
STD_RETURN_TYPE_e I2C_Read(i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, no register address written first, blocking.
Definition: i2c.c:226
STD_RETURN_TYPE_e I2C_Write(i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, no register address written first, blocking.
Definition: i2c.c:283
STD_RETURN_TYPE_e I2C_WriteDma(i2cBASE_t *pI2cInterface, uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, no register address written first, using DMA.
Definition: i2c.c:510
Header for the driver for the I2C module.
@ OS_SUCCESS
Definition: os.h:86
OS_STD_RETURN_e OS_ReceiveFromQueue(OS_QUEUE xQueue, void *const pvBuffer, uint32_t ticksToWait)
Receive an item from a queue.
Definition: os_freertos.c:264
void OS_DelayTaskUntil(uint32_t *pPreviousWakeTime, uint32_t milliseconds)
Delay a task until a specified time.
Definition: os_freertos.c:162
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:154
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:150
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:158
void RTC_IncrementSystemTime(void)
increment the RTC system timer.
Definition: rtc.c:586
void RTC_InitializeSystemTimeWithRtc(void)
initialize system time with RTC time.
Definition: rtc.c:577
static void RTC_AdjustTime(void)
Adjust RTC system timer with time from RTC IC.
Definition: rtc.c:213
void RTC_SetSystemTimeRtcFormat(RTC_TIME_DATA_s timeRtcFormat)
set the RTC system timer.
Definition: rtc.c:595
static RTC_TIME_DATA_s RTC_ReadTime(void)
Reads the time from the RTC IC.
Definition: rtc.c:349
static void RTC_SetOverCanMessage(void)
Check if a CAN message was received to set the RTC time.
Definition: rtc.c:195
static void RTC_WriteTime(RTC_TIME_DATA_s rtcTime)
Write the time to the RTC IC.
Definition: rtc.c:121
static RTC_SYSTEM_TIMER_EPOCH_s rtc_SystemTime
Definition: rtc.c:90
void RTC_Trigger(void)
trigger function for the RTC driver.
Definition: rtc.c:414
static void RTC_SetSystemTimeEpochFormat(time_t timeEpochFormat, uint16_t milliseconds)
Set the RTC system timer value.
Definition: rtc.c:285
static RTC_TIME_DATA_s RTC_tmFormatToRtcFormat(struct tm timeTmFormat)
Convert time from struct tm to RTC_TIME_DATA_s format.
Definition: rtc.c:335
STD_RETURN_TYPE_e RTC_Initialize(void)
initialization of the RTC IC.
Definition: rtc.c:441
static void RTC_CheckBatteryLowVoltageAlert(void)
Read bit for battery voltage low flag.
Definition: rtc.c:242
static RTC_SYSTEM_TIMER_EPOCH_s RTC_GetSystemTimeEpochFormat(void)
Get the RTC system timer value.
Definition: rtc.c:301
static uint8_t rtc_i2cWriteBuffer[RTC_MAX_I2C_TRANSACTION_SIZE_IN_BYTES]
Definition: rtc.c:83
RTC_TIME_DATA_s RTC_GetSystemTimeRtcFormat(void)
get the RTC system timer.
Definition: rtc.c:607
static struct tm RTC_rtcFormatToTmFormat(RTC_TIME_DATA_s timeRtcFormat)
Convert time from RTC_TIME_DATA_s to struct tm format.
Definition: rtc.c:315
static uint8_t rtc_i2cReadBuffer[RTC_MAX_I2C_TRANSACTION_SIZE_IN_BYTES]
Definition: rtc.c:85
Header file of the RTC driver.
#define RTC_TENS_PLACE_OFFSET
Definition: rtc.h:150
#define RTC_REG_TIME_START_ADDR
Definition: rtc.h:133
#define RTC_DAYS_TENS_PLACE_MASK
Definition: rtc.h:155
#define RTC_HOURS_TENS_PLACE_MASK
Definition: rtc.h:154
#define RTC_OTPR_BIT_WAIT_TIMEOUT_ms
Definition: rtc.h:118
#define RTC_NUMBER_OF_TIMEDATA_BYTES
Definition: rtc.h:145
#define RTC_UNITS_PLACE_MASK
Definition: rtc.h:162
#define RTC_SECONDS_OFFSET
Definition: rtc.h:135
#define RTC_CTRL3_BATTERY_LOW_FLAG_BIT_POSITION
Definition: rtc.h:103
#define RTC_TIME_BETWEEN_BLF_FLAG_CHECK_min
Definition: rtc.h:182
#define RTC_CTRL1_12_24HOUR_MODE_BIT_MASK
Definition: rtc.h:94
#define RTC_YEARS_TENS_PLACE_MASK
Definition: rtc.h:157
#define RTC_CTRL3_PWRMNG_DIRECTSWITCH_LOWDETECTIONENABLE_MODE
Definition: rtc.h:108
#define RTC_CLKOUT_CTL_OTPR_BIT_MASK
Definition: rtc.h:113
#define RTC_I2C_INTERFACE
Definition: rtc.h:68
#define RTC_HUNDREDTH_OF_SECONDS_TENS_PLACE_MASK
Definition: rtc.h:151
#define RTC_CTIME_MONTH_START
Definition: rtc.h:172
#define RTC_TENS_PLACE_FACTOR
Definition: rtc.h:149
#define RTC_MAX_I2C_TRANSACTION_SIZE_IN_BYTES
Definition: rtc.h:86
#define RTC_WRITE_REGISTER_I2C_TRANSACTION_SIZE_IN_BYTES
Definition: rtc.h:87
#define RTC_REG_CONTROL_3_ADDR
Definition: rtc.h:99
#define RTC_HOURS_OFFSET
Definition: rtc.h:137
#define RTC_CTIME_YEAR_START
Definition: rtc.h:171
RTC_INIT_STATES_e
Definition: rtc.h:185
@ RTC_WAIT_CLEAR_OTPR
Definition: rtc.h:189
@ RTC_SET_BLF
Definition: rtc.h:187
@ RTC_CLEAR_OTPR
Definition: rtc.h:188
@ RTC_SET_SYSTEM_TIMER
Definition: rtc.h:186
@ RTC_WAIT_SET_OTPR
Definition: rtc.h:192
@ RTC_SET_OTPR
Definition: rtc.h:191
@ RTC_INIT_SET_FINISHED
Definition: rtc.h:193
#define RTC_MINUTES_OFFSET
Definition: rtc.h:136
#define RTC_MINUTES_TENS_PLACE_MASK
Definition: rtc.h:153
#define RTC_REG_CLKOUT_CTL_ADDR
Definition: rtc.h:112
#define RTC_SWRESET_CLEARPRESCALER
Definition: rtc.h:128
#define RTC_SECONDS_TENS_PLACE_MASK
Definition: rtc.h:152
#define RTC_REG_SOFTWARE_RESET_ADDR
Definition: rtc.h:127
#define RTC_WEEKDAYS_OFFSET
Definition: rtc.h:139
#define RTC_REG_CONTROL_1_ADDR
Definition: rtc.h:92
#define RTC_MAX_DIFFERENCE_BETWEEN_TIMER_AND_IC_s
Definition: rtc.h:176
#define RTC_YEARS_OFFSET
Definition: rtc.h:141
#define RTC_I2C_ADDRESS
Definition: rtc.h:70
#define RTC_MONTHS_OFFSET
Definition: rtc.h:140
#define RTC_CTRL3_BATTERY_LOW_FLAG_BIT_MASK
Definition: rtc.h:102
#define RTC_SECONDS_OSF_BIT_POSITION
Definition: rtc.h:123
#define RTC_100TH_OF_SECONDS_OFFSET
Definition: rtc.h:134
#define RTC_WEEKDAYS_UNITS_PLACE_MASK
Definition: rtc.h:163
#define RTC_CTRL1_STOP_BIT_MASK
Definition: rtc.h:93
#define RTC_FACTOR_MIN_TO_MS
Definition: rtc.h:178
#define RTC_MONTHS_TENS_PLACE_MASK
Definition: rtc.h:156
#define RTC_START_YEAR
Definition: rtc.h:167
#define RTC_TIME_BETWEEN_RTC_TIMER_ADJUSTMENT_min
Definition: rtc.h:180
#define RTC_DAYS_OFFSET
Definition: rtc.h:138
#define RTC_CLKOUT_CTL_OTPR_BIT_POSITION
Definition: rtc.h:114
#define RTC_SECONDS_OSF_BIT_MASK
Definition: rtc.h:121
#define RTC_CTRL3_BATTERY_PWRMNG_BITS_POSITION
Definition: rtc.h:101
time_t secondsSinceEpoch
Definition: rtc.c:74
uint16_t milliseconds
Definition: rtc.c:75
uint8_t hours
Definition: rtc.h:77
uint8_t minutes
Definition: rtc.h:76
uint8_t seconds
Definition: rtc.h:75
uint8_t month
Definition: rtc.h:80
uint8_t weekday
Definition: rtc.h:78
uint8_t hundredthOfSeconds
Definition: rtc.h:74
uint8_t year
Definition: rtc.h:81
uint8_t day
Definition: rtc.h:79