S32 SDK
rtc_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
19 #include "rtc_driver.h"
20 
55 
60 
61 /* Table of month length (in days) for the Un-leap-year*/
62 static const uint8_t ULY[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
63 
64 /* Table of month length (in days) for the Leap-year*/
65 static const uint8_t LY[] = {0U, 31U, 29U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
66 
67 /* Number of days from begin of the non Leap-year*/
68 static const uint16_t MONTH_DAYS[] = {0U, 0U, 31U, 59U, 90U, 120U, 151U, 181U, 212U, 243U, 273U, 304U, 334U};
69 
74 static struct
75 {
82 
83 
84 /*******************************************************************************
85  * Code
86  ******************************************************************************/
87 
88 /*FUNCTION**********************************************************************
89  *
90  * Function Name : RTC_DRV_Init
91  * Description : This function initializes the RTC instance with the settings
92  * provided by the user via the rtcUserCfg parameter. The user must ensure
93  * that clock is enabled for the RTC instance used. If the Control register
94  * is locked then this method returns STATUS_ERROR.
95  * In order to clear the CR Lock the user must perform a power-on reset.
96  * Return : STATUS_SUCCESS if the operation was successful, STATUS_ERROR
97  * if Control Register is locked.
98  * Implements : RTC_DRV_Init_Activity
99  *END**************************************************************************/
100 status_t RTC_DRV_Init(uint32_t instance, const rtc_init_config_t * const rtcUserCfg)
101 {
102  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
103  DEV_ASSERT(rtcUserCfg != NULL);
104 
105  status_t statusCode = STATUS_SUCCESS;
106  RTC_Type * basePtr = g_rtcBase[instance];
107 
108  /* Initialize runtime structure */
109  g_rtcRuntimeConfig[instance].alarmConfig = NULL;
110  g_rtcRuntimeConfig[instance].intConfig = NULL;
111  g_rtcRuntimeConfig[instance].secondsIntConfig = NULL;
112  g_rtcRuntimeConfig[instance].isAlarmTimeNew = false;
113 
114  /* Check if the control register is locked. If true, the method cannot
115  * continue.
116  */
117  if (RTC_HAL_IsRegisterLocked(basePtr, RTC_CTRL_REG_LOCK) == true)
118  {
119  /* Return status code */
120  statusCode = STATUS_ERROR;
121  }
122  else
123  {
124  /* Disable the RTC instance IRQ to perform a software reset */
126  /* Perform a software reset */
127  RTC_HAL_SetSoftwareReset(basePtr);
129  /* Initialize the RTC Instance */
130  statusCode = RTC_HAL_Init(basePtr);
131 
132  /* Clear the pending interrupt generated by the software reset */
134 
135  /* Setup the RTC instance as configured in the structure */
136  (void)RTC_HAL_ConfigureClockOut(basePtr, rtcUserCfg->clockOutConfig);
137  RTC_HAL_SetLPOSelect(basePtr, rtcUserCfg->clockSelect);
138  RTC_HAL_SetUpdateMode(basePtr, rtcUserCfg->updateEnable);
140 
141  /* Check if compensation needs to be updated */
142  if (rtcUserCfg->compensation != 0)
143  {
144  (void)RTC_DRV_ConfigureTimeCompensation(instance,
145  rtcUserCfg->compensationInterval,
146  rtcUserCfg->compensation);
147  }
148  }
149 
150  /* Return the exit code */
151  return statusCode;
152 }
153 
154 /*FUNCTION**********************************************************************
155  *
156  * Function Name : RTC_DRV_Deinit
157  * Description : This function deinitializes the RTC instance.
158  * If the Control register is locked then this method returns
159  * STATUS_ERROR.
160  * In order to clear the CR Lock the user must perform a power-on reset.
161  * Return : STATUS_SUCCESS if the operation was successful or
162  * STATUS_ERROR if Control register is locked.
163  * Implements : RTC_DRV_Deinit_Activity
164  *END**************************************************************************/
165 status_t RTC_DRV_Deinit(uint32_t instance)
166 {
167  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
168 
169  status_t statusCode = STATUS_SUCCESS;
170 
171  /* Check if the control register is locked. If true, the method cannot
172  * continue.
173  */
174  if (RTC_HAL_IsRegisterLocked(g_rtcBase[instance], RTC_CTRL_REG_LOCK) == true)
175  {
176  statusCode = STATUS_ERROR;
177  }
178  else
179  {
180  /* Disable RTC instance's interrupts */
183  /* Perform a software reset */
184  RTC_HAL_SetSoftwareReset(g_rtcBase[instance]);
185  RTC_HAL_ClearSoftwareReset(g_rtcBase[instance]);
186  /* Clear the pending interrupt generated by the software reset */
188  }
189 
190  /* Return the exit code */
191  return statusCode;
192 }
193 
194 /*FUNCTION**********************************************************************
195  *
196  * Function Name : RTC_DRV_CanWriteTCE
197  * Description : This function checks the following conditions to find if the
198  * Time Counter Enable bit is writable.
199  * - if Update Mode bitfield if 1 and:
200  * - Time is invalid or
201  * - Time Seconds Register has overflowed or
202  * - Time Counter is disabled,
203  * then the TCE bit can be set even if Status Register is locked.
204  *
205  * This method is a private one, it is used only by the API internally.
206  * Return : True if the TCE can be set, otherwise false
207  *END**************************************************************************/
208 static bool RTC_DRV_CanWriteTCE(uint32_t instance)
209 {
210  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
211 
212  bool result = false;
213  bool tifFlagSet;
214  bool tofFlagSet;
215  bool tceFlagSet;
216 
217  /* Check if the status register is locked */
218  if (RTC_HAL_IsRegisterLocked(g_rtcBase[instance], RTC_STATUS_REG_LOCK) == false)
219  {
220  result = true;
221  }
222  /* Get the Update Mode bit */
223  else if (RTC_HAL_GetUpdateMode(g_rtcBase[instance]))
224  {
225  tifFlagSet = RTC_HAL_GetTimeInvalidFlag(g_rtcBase[instance]);
226  tofFlagSet = RTC_HAL_GetTimeOverflowFlag(g_rtcBase[instance]);
227  tceFlagSet = RTC_HAL_GetTimeCounterEnable(g_rtcBase[instance]);
228 
229  /* Check for the specified conditions */
230  if ((tifFlagSet == true) || (tofFlagSet == true) || (tceFlagSet == false))
231  {
232  result = true;
233  }
234  }
235  else
236  {
237  result = false;
238  }
239 
240  /* Return the exit code */
241  return result;
242 }
243 
244 /*FUNCTION**********************************************************************
245  *
246  * Function Name : RTC_DRV_StartCounter
247  * Description : Start RTC instance counter. Before calling this function the user
248  * should use RTC_DRV_SetTimeDate to configure the start time
249  * Return : STATUS_SUCCESS if the operation was successful, STATUS_ERROR
250  * if the counter cannot be enabled or is already enabled.
251  * Implements : RTC_DRV_StartCounter_Activity
252  *END**************************************************************************/
253 status_t RTC_DRV_StartCounter(uint32_t instance)
254 {
255  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
256 
257  status_t statusCode = STATUS_SUCCESS;
258 
259  /* Check if the TCE is writable and return corresponding status
260  * if it is not
261  */
262  if (RTC_DRV_CanWriteTCE(instance) == false)
263  {
264  statusCode = STATUS_ERROR;
265  }
266  else
267  {
268  /* Enable the counter */
269  statusCode = RTC_HAL_Enable(g_rtcBase[instance]);
270  }
271 
272  /* Return the exit code */
273  return statusCode;
274 }
275 
276 /*FUNCTION**********************************************************************
277  *
278  * Function Name : RTC_DRV_StopCounter
279  * Description : This function disables the RTC instance counter.
280  * Return : STATUS_SUCCESS if the operation was successful, STATUS_ERROR
281  * if the counter could not be stopped.
282  * Implements : RTC_DRV_StopCounter_Activity
283  *END**************************************************************************/
284 status_t RTC_DRV_StopCounter(uint32_t instance)
285 {
286  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
287 
288  status_t statusCode = STATUS_SUCCESS;
289 
290  /* Check if the TCE is writable */
291  if (RTC_DRV_CanWriteTCE(instance) == false)
292  {
293  statusCode = STATUS_ERROR;
294  }
295  else
296  {
297  /* Disable the RTC instance */
298  statusCode = RTC_HAL_Disable(g_rtcBase[instance]);
299  }
300 
301  /* Return the exit code */
302  return statusCode;
303 }
304 
305 /*FUNCTION**********************************************************************
306  *
307  * Function Name : RTC_DRV_GetCurrentTimeDate
308  * Description : This retrieves the current time and date from the RTC instance.
309  * Data is saved into currentTime, which is a pointer of the rtc_timedate_t
310  * type.
311  * Return : STATUS_SUCCESS if the operation was successful, STATUS_ERROR
312  * if there was a problem.
313  * Implements : RTC_DRV_GetCurrentTimeDate_Activity
314  *END**************************************************************************/
315 status_t RTC_DRV_GetCurrentTimeDate(uint32_t instance, rtc_timedate_t * const currentTime)
316 {
317  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
318  DEV_ASSERT(currentTime != NULL);
319 
320  /* Declare local variables */
321  status_t statusCode = STATUS_SUCCESS;
322  uint32_t seconds;
323  uint32_t tempSeconds;
324 
325  /* Make two consecutive reads to ensure that the read was not
326  * done when the counter is incrementing.
327  * This is recommended in the reference manual.
328  */
329  tempSeconds = RTC_HAL_GetTimeSecondsRegister(g_rtcBase[instance]);
330  seconds = RTC_HAL_GetTimeSecondsRegister(g_rtcBase[instance]);
331  /* If the read was done when the counter was incrementing,
332  * try and read again.
333  */
334  if (tempSeconds != seconds)
335  {
336  /* Reinitialize the temporary variable */
337  tempSeconds = 0UL;
338  /* Get the current time again */
339  tempSeconds = RTC_HAL_GetTimeSecondsRegister(g_rtcBase[instance]);
340  if (tempSeconds != seconds)
341  {
342  /* If the last two reads are not equal, there is an error */
343  statusCode = STATUS_ERROR;
344  }
345  else
346  {
347  /* Convert the current time from seconds to time date structure */
348  RTC_DRV_ConvertSecondsToTimeDate(&seconds, currentTime);
349  }
350  }
351  else
352  {
353  /* Convert the current time from seconds to time date structure */
354  RTC_DRV_ConvertSecondsToTimeDate(&seconds, currentTime);
355  }
356 
357  /* Return the exit code */
358  return statusCode;
359 }
360 
361 /*FUNCTION**********************************************************************
362  *
363  * Function Name : RTC_DRV_SetTimeDate
364  * Description : This modifies the time and date of the RTC instance.
365  * Return : STATUS_SUCCESS if the operation was successful, STATUS_ERROR
366  * if the time provided was invalid or if the counter was not
367  * stopped.
368  * Implements : RTC_DRV_SetTimeDate_Activity
369  *END**************************************************************************/
370 status_t RTC_DRV_SetTimeDate(uint32_t instance, const rtc_timedate_t * const time)
371 {
372  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
373 
374  /* Declare local variables */
375  status_t statusCode = STATUS_SUCCESS;
376  uint32_t seconds = 0;
377 
378  /* Check if the time is in the correct format */
379  if (RTC_DRV_IsTimeDateCorrectFormat(time) == false)
380  {
381  /* Set the exit code to error */
382  statusCode = STATUS_ERROR;
383  }
384  /* Check if the TCE bit is writable */
385  else if (RTC_DRV_CanWriteTCE(instance) == false)
386  {
387  /* Set the exit code to locked */
388  statusCode = STATUS_ERROR;
389  }
390  else
391  {
392  /* Convert the desired time to seconds */
393  RTC_DRV_ConvertTimeDateToSeconds(time, &seconds);
394  /* Set the time */
395  (void)RTC_HAL_SetTimeSecondsRegister(g_rtcBase[instance], seconds);
396  }
397 
398  /* Return the exit code */
399  return statusCode;
400 }
401 
402 /*FUNCTION**********************************************************************
403  *
404  * Function Name : RTC_DRV_ConfigureRegisterLock
405  * Description : This method configures register lock for the corresponding
406  * RTC instance. Remember that all the registers are unlocked
407  * only by software reset or power on reset.
408  * (Except for CR that is unlocked only by POR).
409  * Return : STATUS_SUCCESS if the operation was successful,
410  * STATUS_ERROR if the Lock Register is locked.
411  * Implements : RTC_DRV_ConfigureRegisterLock_Activity
412  *END**************************************************************************/
413 status_t RTC_DRV_ConfigureRegisterLock(uint32_t instance, const rtc_register_lock_config_t * const lockConfig)
414 {
415  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
416  DEV_ASSERT(lockConfig != NULL);
417 
418  /* Declare local variables */
419  status_t statusCode = STATUS_SUCCESS;
420 
421  /* Lock the requested registers, but always the Lock register last,
422  * otherwise other registers can not be locked.
423  */
424 
425  /* Configure Control register lock */
426  if (lockConfig->controlRegisterLock)
427  {
428  statusCode = RTC_HAL_ConfigureRegisterLock(g_rtcBase[instance], RTC_CTRL_REG_LOCK);
429  }
430  /* Configure Status register lock */
431  if (lockConfig->statusRegisterLock)
432  {
433  statusCode = RTC_HAL_ConfigureRegisterLock(g_rtcBase[instance], RTC_STATUS_REG_LOCK);
434  }
435  /* Configure Time Compensation register lock */
436  if (lockConfig->timeCompensationRegisterLock)
437  {
438  statusCode = RTC_HAL_ConfigureRegisterLock(g_rtcBase[instance], RTC_TCL_REG_LOCK);
439  }
440  /* Configure Lock register lock */
441  if (lockConfig->lockRegisterLock)
442  {
443  statusCode = RTC_HAL_ConfigureRegisterLock(g_rtcBase[instance], RTC_LOCK_REG_LOCK);
444  }
445 
446  /* Return the exit code */
447  return statusCode;
448 }
449 
450 /*FUNCTION**********************************************************************
451  *
452  * Function Name : RTC_DRV_GetRegisterLock
453  * Description : This retrieves the register lock configuration from the RTC
454  * instance.
455  * Data is stored in the structure referenced by the lockConfig
456  * pointer.
457  * Return : None
458  * Implements : RTC_DRV_GetRegisterLock_Activity
459  *END**************************************************************************/
460 void RTC_DRV_GetRegisterLock(uint32_t instance, rtc_register_lock_config_t * const lockConfig)
461 {
462  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
463  DEV_ASSERT(lockConfig != NULL);
464 
465  /* Get the configuration of the register lock */
466 
467  /* For the Lock Register */
468  lockConfig->lockRegisterLock = RTC_HAL_IsRegisterLocked(g_rtcBase[instance], RTC_LOCK_REG_LOCK);
469  /* For the Control Register */
470  lockConfig->controlRegisterLock = RTC_HAL_IsRegisterLocked(g_rtcBase[instance], RTC_CTRL_REG_LOCK);
471  /* For the Status Register */
472  lockConfig->statusRegisterLock = RTC_HAL_IsRegisterLocked(g_rtcBase[instance], RTC_STATUS_REG_LOCK);
473  /* For the Time Compensation Register */
474  lockConfig->timeCompensationRegisterLock = RTC_HAL_IsRegisterLocked(g_rtcBase[instance], RTC_TCL_REG_LOCK);
475 }
476 
477 /*FUNCTION**********************************************************************
478  *
479  * Function Name : RTC_DRV_ConfigureTimeCompensation
480  * Description : This method configures time compensation. Data is passed by
481  * the compInterval and compensation parameters.
482  * For more details regarding coefficient calculation see the
483  * Reference Manual.
484  * Return : STATUS_SUCCESS if the operation was successful,
485  * STATUS_ERROR if the TC Register is locked.
486  * Implements : RTC_DRV_ConfigureTimeCompensation_Activity
487  *END**************************************************************************/
488 status_t RTC_DRV_ConfigureTimeCompensation(uint32_t instance, uint8_t compInterval, int8_t compensation)
489 {
490  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
491 
492  /* Declare local variables */
493  status_t statusCode = STATUS_SUCCESS;
494 
495  /* Check if the TCR is locked */
496  if (RTC_HAL_IsRegisterLocked(g_rtcBase[instance], RTC_TCL_REG_LOCK) == true)
497  {
498  /* Set the exit code to locked */
499  statusCode = STATUS_ERROR;
500  }
501  else
502  {
503  /* Set the corresponding values for compensation and compensation
504  * interval.
505  */
506  RTC_HAL_SetTimeCompensation(g_rtcBase[instance], compensation, compInterval);
507  }
508 
509  /* Return the exit code */
510  return statusCode;
511 }
512 
513 /*FUNCTION**********************************************************************
514  *
515  * Function Name : RTC_DRV_GetTimeCompensation
516  * Description : This retrieves the time compensation coefficients and saves
517  * them on the variables referenced by the parameters.
518  * Return : None
519  * Implements : RTC_DRV_GetTimeCompensation_Activity
520  *END**************************************************************************/
521 void RTC_DRV_GetTimeCompensation(uint32_t instance, uint8_t * compInterval, int8_t * compensation)
522 {
523  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
524  DEV_ASSERT(compInterval != NULL);
525  DEV_ASSERT(compensation != NULL);
526 
527  /* Get the compensation interval */
528  RTC_HAL_GetCurrentTimeCompensation(g_rtcBase[instance], compensation, compInterval);
529 }
530 
531 /*FUNCTION**********************************************************************
532  *
533  * Function Name : RTC_DRV_ConvertSecondsToTimeDate
534  * Description : This method converts seconds into time-date format.
535  * Return : None
536  * Implements : RTC_DRV_ConvertSecondsToTimeDate_Activity
537  *END**************************************************************************/
538 void RTC_DRV_ConvertSecondsToTimeDate(const uint32_t * const seconds, rtc_timedate_t * const timeDate)
539 {
540  DEV_ASSERT(seconds != NULL);
541  DEV_ASSERT(timeDate != NULL);
542 
543  /* Declare the variables needed */
544  uint8_t i;
545  bool yearLeap = false;
546  uint32_t numberOfDays = 0U;
547  uint32_t tempSeconds;
548  uint16_t daysInYear;
549 
550  /* Because the starting year(1970) is not leap, set the daysInYear
551  * variable with the number of the days in a normal year
552  */
553  daysInYear = DAYS_IN_A_YEAR;
554 
555  /* Set the year to the beginning of the range */
556  timeDate->year = YEAR_RANGE_START;
557 
558  /* Get the number of days */
559  numberOfDays = (*seconds) / SECONDS_IN_A_DAY;
560  /* Get the number of seconds remaining */
561  tempSeconds = (*seconds) % SECONDS_IN_A_DAY;
562 
563  /* Get the current hour */
564  timeDate->hour = (uint16_t)(tempSeconds / SECONDS_IN_A_HOUR);
565  /* Get the remaining seconds */
566  tempSeconds = tempSeconds % SECONDS_IN_A_HOUR;
567  /* Get the minutes */
568  timeDate->minutes = (uint16_t)(tempSeconds / SECONDS_IN_A_MIN);
569  /* Get seconds */
570  timeDate->seconds = (uint8_t)(tempSeconds % SECONDS_IN_A_MIN);
571 
572  /* Get the current year */
573  while (numberOfDays >= daysInYear)
574  {
575  /* Increment year if the number of days is greater than the ones in
576  * one year
577  */
578  timeDate->year++;
579  /* Subtract the number of the days */
580  numberOfDays -= daysInYear;
581 
582  /* Check if the year is leap or unleap */
583  if (!RTC_DRV_IsYearLeap(timeDate->year))
584  {
585  /* Set the number of non leap year to the current year number
586  * of days.
587  */
588  daysInYear = DAYS_IN_A_YEAR;
589  }
590  else
591  {
592  /* Set the number of leap year to the current year number
593  * of days.
594  */
595  daysInYear = DAYS_IN_A_LEAP_YEAR;
596  }
597  }
598 
599  /* Add the current day */
600  numberOfDays += 1U;
601 
602  /* Check if the current year is leap */
603  yearLeap = RTC_DRV_IsYearLeap(timeDate->year);
604 
605  /* Get the month */
606  for (i = 1U; i <= 12U; i++)
607  {
608  uint32_t daysInCurrentMonth = ((yearLeap == true) ? (uint32_t)LY[i] : (uint32_t)ULY[i]);
609  if (numberOfDays <= daysInCurrentMonth)
610  {
611  timeDate->month = (uint16_t)i;
612  break;
613  }
614  else
615  {
616  numberOfDays -= daysInCurrentMonth;
617  }
618 
619  }
620 
621  /* Set the current day */
622  timeDate->day = (uint16_t)numberOfDays;
623 }
624 
625 /*FUNCTION**********************************************************************
626  *
627  * Function Name : RTC_DRV_ConvertTimeDateToSeconds
628  * Description : This method converts time-date into seconds.
629  * Return : None
630  * Implements : RTC_DRV_ConvertTimeDateToSeconds_Activity
631  *END**************************************************************************/
632 void RTC_DRV_ConvertTimeDateToSeconds(const rtc_timedate_t * const timeDate, uint32_t * const seconds)
633 {
634  DEV_ASSERT(seconds != NULL);
635  DEV_ASSERT(timeDate != NULL);
636 
637  /* Declare local variables */
638  uint16_t year;
639 
640  /* Convert years to seconds */
641  (*seconds) = (uint32_t)(DAYS_IN_A_YEAR * (uint32_t)(SECONDS_IN_A_DAY));
642  (*seconds) *= ((uint32_t)timeDate->year - YEAR_RANGE_START);
643 
644  /* Add the seconds from the leap years */
645  for (year = YEAR_RANGE_START; year < timeDate->year; year++)
646  {
647  if (RTC_DRV_IsYearLeap(year))
648  {
649  (*seconds) += SECONDS_IN_A_DAY;
650  }
651  }
652 
653  /* If the current year is leap and 29th of February has passed, add
654  * another day to seconds passed.
655  */
656  if ((RTC_DRV_IsYearLeap(year)) && (timeDate->month > 2U))
657  {
658  (*seconds) += SECONDS_IN_A_DAY;
659  }
660 
661  /* Add the rest of the seconds from the current month */
662  (*seconds) += MONTH_DAYS[timeDate->month] * SECONDS_IN_A_DAY;
663  /* Add the rest of the seconds from the current day */
664  (*seconds) += (uint32_t)(((uint32_t)timeDate->day - 1U) * (uint32_t)SECONDS_IN_A_DAY);
665  /* Add the rest of the seconds from the current time */
666  (*seconds) += (uint32_t)(((uint32_t)timeDate->hour * SECONDS_IN_A_HOUR) + \
667  ((uint32_t)timeDate->minutes * SECONDS_IN_A_MIN) + \
668  (uint32_t)timeDate->seconds);
669 }
670 
671 /*FUNCTION**********************************************************************
672  *
673  * Function Name : RTC_DRV_IsTimeDateCorrectFormat
674  * Description : This method checks if date-time structure is in a correct
675  * format
676  * Return : True if the following conditions are met:
677  * - is a valid year, month and date
678  * - is a valid time format
679  * False otherwise
680  * Implements : RTC_DRV_IsTimeDateCorrectFormat_Activity
681  *END**************************************************************************/
683 {
684  DEV_ASSERT(timeDate != NULL);
685 
686  /* Declare local variables */
687  bool returnCode = true;
688  const uint8_t * pDays;
689 
690  /* Set the days-in-month table for the corresponding year */
691  pDays = RTC_DRV_IsYearLeap(timeDate->year) ? (LY) : (ULY);
692 
693  /* Check if the time and date are in the correct ranges */
694  if ((timeDate->year < YEAR_RANGE_START) || (timeDate->year > YEAR_RANGE_END)
695  || (timeDate->month < 1U) || (timeDate->month > 12U)
696  || (timeDate->day < 1U) || (timeDate->day > 31U)
697  || (timeDate->hour > HOURS_IN_A_DAY)
698  || (timeDate->minutes > MINS_IN_A_HOUR) || (timeDate->seconds > SECONDS_IN_A_MIN))
699  {
700  returnCode = false;
701  }
702  /* Check if the day is a valid day from the corresponding month */
703  else if (timeDate->day > pDays[timeDate->month])
704  {
705  returnCode = false;
706  }
707  else
708  {
709  returnCode = true;
710  }
711 
712  /* Return the exit code */
713  return returnCode;
714 }
715 
716 /*FUNCTION**********************************************************************
717  *
718  * Function Name : RTC_DRV_IsYearLeap
719  * Description : This method checks if the year passed as a parameter is a leap
720  * one.
721  * Return : True if the year is leap, false if otherwise.
722  * Implements : RTC_DRV_IsYearLeap_Activity
723  *END**************************************************************************/
724 bool RTC_DRV_IsYearLeap(uint16_t year)
725 {
726  bool isYearLeap = false;
727 
728  if ((year % 4U) > 0U)
729  {
730  isYearLeap = false;
731  }
732  else if ((year % 100U) > 0U)
733  {
734  isYearLeap = true;
735  }
736  else if ((year % 400U) > 0U)
737  {
738  isYearLeap = false;
739  }
740  else
741  {
742  isYearLeap = true;
743  }
744 
745  /* Return the exit code */
746  return isYearLeap;
747 }
748 
749 
750 /*FUNCTION**********************************************************************
751  *
752  * Function Name : RTC_DRV_IRQHandler
753  * Description : This method is the API's Interrupt handler for generic and
754  * alarm IRQ. It will handle the alarm repetition and calls the
755  * user callbacks if they are not NULL.
756  * Return : None
757  *
758  * Implements : RTC_DRV_IRQHandler_Activity
759  *END**************************************************************************/
760 void RTC_DRV_IRQHandler(uint32_t instance)
761 {
762  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
763 
764  uint32_t tempSeconds;
765  /* Get the alarm configuration */
766  rtc_alarm_config_t * alarmConfig = g_rtcRuntimeConfig[instance].alarmConfig;
767  /* Get the fault interrupt configuration */
768  const rtc_interrupt_config_t * const intConfig = g_rtcRuntimeConfig[instance].intConfig;
769 
770  /* Check if an alarm has occurred */
771  if (RTC_HAL_GetTimeAlarmFlag(g_rtcBase[instance]) == true)
772  {
773  /* If the alarm interrupt configuration has been defined process the
774  * alarm IRQ
775  */
776  if ((alarmConfig != NULL))
777  {
778  /* If recurrence is enabled modify the alarm register to the next
779  * alarm.
780  */
781  if ((alarmConfig->numberOfRepeats > 0UL) || (alarmConfig->repeatForever == true))
782  {
783  tempSeconds = RTC_HAL_GetTimeSecondsRegister(g_rtcBase[instance]);
784  tempSeconds += alarmConfig->repetitionInterval - 1UL;
785 
786  RTC_HAL_SetTimeAlarmRegister(g_rtcBase[instance], tempSeconds);
787 
788  g_rtcRuntimeConfig[instance].isAlarmTimeNew = true;
789  /* If the alarm repeats forever, set number of repeats to 0
790  * to avoid an accidental trigger of the core overflow flag
791  */
792  alarmConfig->numberOfRepeats = (alarmConfig->repeatForever == false) ? (alarmConfig->numberOfRepeats - 1UL) : 0UL;
793  }
794  else
795  {
796  /* If the alarm does not repeat, write 0 to TAR to clear the
797  * alarm flag.
798  */
799  RTC_HAL_SetTimeAlarmRegister(g_rtcBase[instance], 0UL);
800  /* Set the internal variabile which indicates that a new alarm is enabled to false */
801  g_rtcRuntimeConfig[instance].isAlarmTimeNew = false;
802  }
803  /* If the user has defined a callback, call it */
804  if (alarmConfig->alarmCallback != NULL)
805  {
806  alarmConfig->alarmCallback(alarmConfig->callbackParams);
807  }
808  }
809  }
810  /* If the IRQ is not caused by the alarm then call the user callback if
811  * defined.
812  */
813  else if ((intConfig->rtcCallback != NULL) && (intConfig != NULL))
814  {
815  intConfig->rtcCallback(intConfig->callbackParams);
816  }
817  else
818  {
819  /* Do nothing*/
820  ;
821  }
822 }
823 
824 /*FUNCTION**********************************************************************
825  *
826  * Function Name : RTC_DRV_SecondsIRQHandler
827  * Description : This method is the API's Interrupt handler for RTC Second
828  * interrupt. This ISR will call the user callback if defined.
829  * Return : None
830  * Implements : RTC_DRV_SecondsIRQHandler_Activity
831  *END**************************************************************************/
832 void RTC_DRV_SecondsIRQHandler(uint32_t instance)
833 {
834  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
835 
836  const rtc_seconds_int_config_t * const intCfg = g_rtcRuntimeConfig[instance].secondsIntConfig;
837 
838  /* If the interrupt is configured by the driver API and the user callback
839  * is not NULL, then call it.
840  */
841  if ((intCfg != NULL) && (intCfg->rtcSecondsCallback != NULL))
842  {
843  intCfg->rtcSecondsCallback(intCfg->secondsCallbackParams);
844  }
845 }
846 
847 /*FUNCTION**********************************************************************
848  *
849  * Function Name : RTC_DRV_ConfigureFaultInt
850  * Description : This method configures fault interrupts such as:
851  * - Time Overflow Interrupt
852  * - Time Invalid Interrupt
853  * with the user provided configuration struct intConfig.
854  * Return : None
855  * Implements : RTC_DRV_ConfigureFaultInt_Activity
856  *END**************************************************************************/
858 {
859  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
860  DEV_ASSERT(intConfig != NULL);
861 
862  /* Disable the IRQ to avoid accidental interrupt requests */
864  /* Save the configuration into the instance's runtime structure */
865  g_rtcRuntimeConfig[instance].intConfig = intConfig;
866 
867  /* Enable or disable selected interrupts */
868  RTC_HAL_SetTimeOverflowIntEnable(g_rtcBase[instance], intConfig->overflowIntEnable);
869 
870  RTC_HAL_SetTimeInvalidIntEnable(g_rtcBase[instance], intConfig->timeInvalidIntEnable);
871 
872  /* After the configuration is done, re-enable the interrupt in NVIC */
874 }
875 
876 /*FUNCTION**********************************************************************
877  *
878  * Function Name : RTC_DRV_ConfigureSecondsInt
879  * Description : This method configures the Time Seconds Interrupt with the
880  * configuration from the intConfig parameter.
881  * Return : None
882  * Implements : RTC_DRV_ConfigureSecondsInt_Activity
883  *END**************************************************************************/
885 {
886  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
887  DEV_ASSERT(intConfig != NULL);
888 
889  /* Disable the IRQ to avoid accidental interrupt requests */
891  /* Disable the IRQ to avoid accidental interrupt requests */
892  g_rtcRuntimeConfig[instance].secondsIntConfig = intConfig;
893 
894  /* Configure the interrupt frequency */
895  RTC_HAL_SetTimeSecondsIntConf(g_rtcBase[instance], intConfig->secondIntConfig);
896 
897  /* Enable or disable Time Seconds interrupt */
898  RTC_HAL_SetTimeSecondsIntEnable(g_rtcBase[instance], intConfig->secondIntEnable);
899 
900  /* After the configuration is done, re-enable the interrupt in NVIC */
902 }
903 
904 /*FUNCTION**********************************************************************
905  *
906  * Function Name : RTC_DRV_ConfigureAlarm
907  * Description : This method configures the alarm with the
908  * configuration from the alarmConfig parameter.
909  *
910  * Return : STATUS_SUCCESS if the configuration is successful or
911  * STATUS_ERROR if the alarm time is invalid.
912  * Implements : RTC_DRV_ConfigureAlarm_Activity
913  *END**************************************************************************/
915 {
916  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
917  DEV_ASSERT(alarmConfig != NULL);
918 
919  status_t statusCode = STATUS_SUCCESS;
920  uint32_t alarmTime;
921  uint32_t currentTime;
922 
923  /* Check if the alarm time is in a correct format */
924  if (RTC_DRV_IsTimeDateCorrectFormat(&(alarmConfig->alarmTime)) == true)
925  {
926  /* Convert the time date to seconds */
927  RTC_DRV_ConvertTimeDateToSeconds(&(alarmConfig->alarmTime), &alarmTime);
928  /* Get current time in seconds */
929  currentTime = RTC_HAL_GetTimeSecondsRegister(g_rtcBase[instance]);
930 
931  /* Check if the alarm time is greater than current time */
932  if(alarmTime > currentTime)
933  {
934  /* Disable the IRQ to avoid accidental interrupt requests */
936  g_rtcRuntimeConfig[instance].alarmConfig = alarmConfig;
937 
938  /* Write alarm time into Time Alarm Register */
939  RTC_HAL_SetTimeAlarmRegister(g_rtcBase[instance], alarmTime);
940  /* Enable/disable interrupt source based on the configuration */
941  RTC_HAL_SetTimeAlarmIntEnable(g_rtcBase[instance], alarmConfig->alarmIntEnable);
942  /* After the configuration is done, re-enable the interrupt in
943  * NVIC.
944  */
946  }
947  else
948  {
949  statusCode = STATUS_ERROR;
950  }
951  }
952  else
953  {
954  statusCode = STATUS_ERROR;
955  }
956 
957  /* Return the exit code */
958  return statusCode;
959 }
960 
961 /*FUNCTION**********************************************************************
962  *
963  * Function Name : RTC_DRV_GetAlarmConfig
964  * Description : This method retrieves the alarm configuration.
965  * Return : None
966  * Implements : RTC_DRV_GetAlarmConfig_Activity
967  *END**************************************************************************/
969 {
970  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
971  DEV_ASSERT(alarmConfig != NULL);
972 
973  *alarmConfig = *(g_rtcRuntimeConfig[instance].alarmConfig);
974 }
975 
976 /*FUNCTION**********************************************************************
977  *
978  * Function Name : RTC_DRV_IsAlarmPending
979  * Description : This method specifies if an alarm has occurred.
980  * Return : True if an alarm has occurred, false if not.
981  * Implements : RTC_DRV_IsAlarmPending_Activity
982  *END**************************************************************************/
983 bool RTC_DRV_IsAlarmPending(uint32_t instance)
984 {
985  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
986 
987  /* Return the exit code */
988  return RTC_HAL_GetTimeAlarmFlag(g_rtcBase[instance]);
989 }
990 
991 /*FUNCTION**********************************************************************
992  *
993  * Function Name : RTC_DRV_GetNextAlarmTime
994  * Description : This method retrieves the next alarm time;
995  * Return : STATUS_SUCCESS if the next alarm time is valid
996  * STATUS_ERROR if there is no new alarm
997  *
998  * Implements : RTC_DRV_GetNextAlarmTime_Activity
999  *END**************************************************************************/
1000 status_t RTC_DRV_GetNextAlarmTime(uint32_t instance, rtc_timedate_t * const alarmTime)
1001 {
1002  DEV_ASSERT(instance < RTC_INSTANCE_COUNT);
1003  DEV_ASSERT(alarmTime != NULL);
1004 
1005  status_t statusCode = STATUS_SUCCESS;
1006  uint32_t alarmInSec;
1007 
1008  if (g_rtcRuntimeConfig[instance].isAlarmTimeNew == true)
1009  {
1010  alarmInSec = RTC_HAL_GetTimeAlarmRegister(g_rtcBase[instance]);
1011  RTC_DRV_ConvertSecondsToTimeDate(&alarmInSec, alarmTime);
1012  }
1013  else
1014  {
1015  statusCode = STATUS_ERROR;
1016  }
1017  /* Return the exit code */
1018 
1019  return statusCode;
1020 }
1021 /*******************************************************************************
1022  * EOF
1023  ******************************************************************************/
static void INT_SYS_ClearPending(IRQn_Type irqNumber)
Clear Pending Interrupt.
status_t RTC_HAL_ConfigureClockOut(RTC_Type *const base, rtc_clk_out_config_t config)
This function configures the Clock Out pin source.
Definition: rtc_hal.c:293
rtc_interrupt_config_t * intConfig
Definition: rtc_driver.c:78
#define RTC_SECONDS_IRQS_CH_COUNT
Definition: S32K144.h:9011
uint16_t day
Definition: rtc_driver.h:55
uint16_t month
Definition: rtc_driver.h:54
status_t RTC_HAL_Disable(RTC_Type *const base)
Disable RTC instance counter.
Definition: rtc_hal.c:125
bool nonSupervisorAccessEnable
Definition: rtc_driver.h:72
RTC Initialization structure Implements : rtc_init_config_t_Class.
Definition: rtc_driver.h:65
#define SECONDS_IN_A_DAY
Definition: rtc_driver.h:37
uint16_t year
Definition: rtc_driver.h:53
#define DAYS_IN_A_YEAR
Definition: rtc_driver.h:42
static void RTC_HAL_SetTimeSecondsIntConf(RTC_Type *const base, rtc_second_int_cfg_t intCfg)
Configure Time Seconds interrupt.
Definition: rtc_hal.h:750
status_t RTC_DRV_StartCounter(uint32_t instance)
Start RTC instance counter. Before calling this function the user should use RTC_DRV_SetTimeDate to c...
Definition: rtc_driver.c:253
status_t RTC_DRV_StopCounter(uint32_t instance)
Disable RTC instance counter.
Definition: rtc_driver.c:284
RTC interrupt configuration. It is used to configure interrupt other than Time Alarm and Time Seconds...
Definition: rtc_driver.h:95
status_t RTC_DRV_ConfigureRegisterLock(uint32_t instance, const rtc_register_lock_config_t *const lockConfig)
This method configures register lock for the corresponding RTC instance. Remember that all the regist...
Definition: rtc_driver.c:413
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K144.h:269
uint32_t numberOfRepeats
Definition: rtc_driver.h:83
void RTC_DRV_GetTimeCompensation(uint32_t instance, uint8_t *compInterval, int8_t *compensation)
This retrieves the time compensation coefficients and saves them on the variables referenced by the p...
Definition: rtc_driver.c:521
static void RTC_HAL_SetUpdateMode(RTC_Type *const base, bool updateEnable)
Set Update Mode of the registers when locked.
Definition: rtc_hal.h:420
status_t RTC_DRV_GetCurrentTimeDate(uint32_t instance, rtc_timedate_t *const currentTime)
Get current time and date from RTC instance.
Definition: rtc_driver.c:315
#define RTC_INSTANCE_COUNT
Definition: S32K144.h:8994
static bool RTC_HAL_GetTimeInvalidFlag(const RTC_Type *const base)
Get Time Invalid flag.
Definition: rtc_hal.h:598
void RTC_DRV_GetAlarmConfig(uint32_t instance, rtc_alarm_config_t *alarmConfig)
Get alarm configuration for RTC instance.
Definition: rtc_driver.c:968
status_t RTC_DRV_Init(uint32_t instance, const rtc_init_config_t *const rtcUserCfg)
This function initializes the RTC instance with the settings provided by the user via the rtcUserCfg ...
Definition: rtc_driver.c:100
void RTC_DRV_ConvertSecondsToTimeDate(const uint32_t *const seconds, rtc_timedate_t *const timeDate)
Convert seconds to rtc_timedate_t structure.
Definition: rtc_driver.c:538
static void RTC_HAL_SetTimeCompensation(RTC_Type *const base, int8_t compensationValue, uint8_t compensationInterval)
Set Time Compensation.
Definition: rtc_hal.h:332
#define RTC_BASE_PTRS
Definition: S32K144.h:9005
RTC alarm configuration Implements : rtc_alarm_config_t_Class.
Definition: rtc_driver.h:79
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
static void RTC_HAL_SetTimeSecondsIntEnable(RTC_Type *const base, bool enable)
Enable TimeSeconds interrupt.
Definition: rtc_hal.h:814
rtc_alarm_config_t * alarmConfig
Definition: rtc_driver.c:76
#define DEV_ASSERT(x)
Definition: devassert.h:78
static void RTC_HAL_SetTimeOverflowIntEnable(RTC_Type *const base, bool enable)
Enable TimeOverflow interrupt.
Definition: rtc_hal.h:880
static bool RTC_DRV_CanWriteTCE(uint32_t instance)
Definition: rtc_driver.c:208
status_t RTC_HAL_ConfigureRegisterLock(RTC_Type *const base, rtc_lock_register_select_t registerToConfig)
This function configures register lock status.
Definition: rtc_hal.c:210
bool RTC_DRV_IsTimeDateCorrectFormat(const rtc_timedate_t *const timeDate)
Check if the date time struct is configured properly.
Definition: rtc_driver.c:682
status_t RTC_DRV_ConfigureTimeCompensation(uint32_t instance, uint8_t compInterval, int8_t compensation)
This method configures time compensation. Data is passed by the compInterval and compensation paramet...
Definition: rtc_driver.c:488
RTC Seconds Interrupt Configuration Implements : rtc_seconds_int_config_t_Class.
Definition: rtc_driver.h:107
rtc_clk_out_config_t clockOutConfig
Definition: rtc_driver.h:70
RTC Register Lock Configuration Implements : rtc_register_lock_config_t_Class.
Definition: rtc_driver.h:119
static void RTC_HAL_GetCurrentTimeCompensation(const RTC_Type *const base, int8_t *compensationValue, uint8_t *compensationInterval)
Get TimeCompensation Value and Interval.
Definition: rtc_hal.h:359
void * callbackParams
Definition: rtc_driver.h:87
static RTC_Type *const g_rtcBase[RTC_INSTANCE_COUNT]
Definition: rtc_driver.c:54
void RTC_DRV_SecondsIRQHandler(uint32_t instance)
This method is the API's Interrupt handler for RTC Second interrupt. This ISR will call the user call...
Definition: rtc_driver.c:832
static uint32_t RTC_HAL_GetTimeSecondsRegister(const RTC_Type *const base)
Get Time Seconds Register Value.
Definition: rtc_hal.h:186
static void RTC_HAL_SetLPOSelect(RTC_Type *const base, rtc_clk_select_t clk_select)
Select clock source for RTC prescaler.
Definition: rtc_hal.h:384
status_t RTC_DRV_GetNextAlarmTime(uint32_t instance, rtc_timedate_t *const alarmTime)
Gets the next alarm time.
Definition: rtc_driver.c:1000
static void RTC_HAL_SetTimeAlarmRegister(RTC_Type *const base, uint32_t seconds)
Set Time Alarm Register.
Definition: rtc_hal.h:269
static const uint8_t LY[]
Definition: rtc_driver.c:65
void(* alarmCallback)(void *callbackParam)
Definition: rtc_driver.h:86
status_t RTC_HAL_Enable(RTC_Type *const base)
Enable RTC instance counter.
Definition: rtc_hal.c:95
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
#define YEAR_RANGE_START
Definition: rtc_driver.h:44
uint8_t compensationInterval
Definition: rtc_driver.h:67
uint32_t repetitionInterval
Definition: rtc_driver.h:82
static bool RTC_HAL_GetTimeAlarmFlag(const RTC_Type *const base)
Get the Time alarm flag.
Definition: rtc_hal.h:558
#define SECONDS_IN_A_MIN
Definition: rtc_driver.h:39
void RTC_DRV_ConfigureFaultInt(uint32_t instance, rtc_interrupt_config_t *const intConfig)
This method configures fault interrupts such as:
Definition: rtc_driver.c:857
void RTC_DRV_ConfigureSecondsInt(uint32_t instance, rtc_seconds_int_config_t *const intConfig)
This method configures the Time Seconds Interrupt with the configuration from the intConfig parameter...
Definition: rtc_driver.c:884
static uint32_t RTC_HAL_GetTimeAlarmRegister(const RTC_Type *const base)
Get Time Alarm Register.
Definition: rtc_hal.h:253
bool RTC_DRV_IsYearLeap(uint16_t year)
Check if the current year is leap.
Definition: rtc_driver.c:724
rtc_second_int_cfg_t secondIntConfig
Definition: rtc_driver.h:109
const IRQn_Type g_rtcIrqNumbers[RTC_IRQS_CH_COUNT]
Table used to store the RTC IRQ names.
Definition: rtc_irq.c:35
void RTC_DRV_GetRegisterLock(uint32_t instance, rtc_register_lock_config_t *const lockConfig)
Get which registers are locked for RTC instance.
Definition: rtc_driver.c:460
void(* rtcSecondsCallback)(void *callbackParam)
Definition: rtc_driver.h:111
#define MINS_IN_A_HOUR
Definition: rtc_driver.h:40
bool RTC_DRV_IsAlarmPending(uint32_t instance)
Check if alarm is pending.
Definition: rtc_driver.c:983
void RTC_DRV_IRQHandler(uint32_t instance)
This method is the API's Interrupt handler for generic and alarm IRQ. It will handle the alarm repeti...
Definition: rtc_driver.c:760
rtc_timedate_t alarmTime
Definition: rtc_driver.h:81
uint16_t hour
Definition: rtc_driver.h:56
#define HOURS_IN_A_DAY
Definition: rtc_driver.h:41
RTC Time Date structure Implements : rtc_timedate_t_Class.
Definition: rtc_driver.h:51
rtc_clk_select_t clockSelect
Definition: rtc_driver.h:69
bool RTC_HAL_IsRegisterLocked(const RTC_Type *const base, rtc_lock_register_select_t reg)
This function gets register lock status.
Definition: rtc_hal.c:258
static const uint8_t ULY[]
Definition: rtc_driver.c:62
static void RTC_HAL_SetNonSupervisorAccess(RTC_Type *const base, bool enable)
Set Non-Supervisor access mode.
Definition: rtc_hal.h:454
uint16_t minutes
Definition: rtc_driver.h:57
status_t RTC_HAL_SetTimeSecondsRegister(RTC_Type *const base, uint32_t seconds)
Set Time Seconds Register.
Definition: rtc_hal.c:151
uint8_t seconds
Definition: rtc_driver.h:58
static void RTC_HAL_ClearSoftwareReset(RTC_Type *const base)
Clear Software reset flag.
Definition: rtc_hal.h:498
static bool RTC_HAL_GetTimeCounterEnable(const RTC_Type *const base)
Get the Time Counter Enable value.
Definition: rtc_hal.h:540
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
bool isAlarmTimeNew
Definition: rtc_driver.c:77
status_t RTC_DRV_Deinit(uint32_t instance)
This function deinitializes the RTC instance. If the Control register is locked then this method retu...
Definition: rtc_driver.c:165
status_t RTC_DRV_ConfigureAlarm(uint32_t instance, rtc_alarm_config_t *const alarmConfig)
This method configures the alarm with the configuration from the alarmConfig parameter.
Definition: rtc_driver.c:914
static bool RTC_HAL_GetUpdateMode(const RTC_Type *const base)
Get the Update Mode of the registers when locked.
Definition: rtc_hal.h:437
static void RTC_HAL_SetTimeInvalidIntEnable(RTC_Type *const base, bool enable)
Enable TimeInvalid interrupt.
Definition: rtc_hal.h:913
#define SECONDS_IN_A_HOUR
Definition: rtc_driver.h:38
void(* rtcCallback)(void *callbackParam)
Definition: rtc_driver.h:99
const IRQn_Type g_rtcSecondsIrqNb[RTC_SECONDS_IRQS_CH_COUNT]
Definition: rtc_irq.c:37
static const uint16_t MONTH_DAYS[]
Definition: rtc_driver.c:68
status_t RTC_HAL_Init(RTC_Type *const base)
Initialize RTC instance.
Definition: rtc_hal.c:47
int8_t compensation
Definition: rtc_driver.h:68
static bool RTC_HAL_GetTimeOverflowFlag(const RTC_Type *const base)
Get Time Overflow Flag.
Definition: rtc_hal.h:577
static struct @19 g_rtcRuntimeConfig[RTC_INSTANCE_COUNT]
static RTC runtime structure, it is designed only for internal purposes such as storing interrupt con...
status_t RTC_DRV_SetTimeDate(uint32_t instance, const rtc_timedate_t *const time)
Set time and date for RTC instance. The user must stop the counter before using this function...
Definition: rtc_driver.c:370
void RTC_DRV_ConvertTimeDateToSeconds(const rtc_timedate_t *const timeDate, uint32_t *const seconds)
Convert seconds to rtc_timedate_t structure.
Definition: rtc_driver.c:632
static void RTC_HAL_SetSoftwareReset(RTC_Type *const base)
Trigger a software reset.
Definition: rtc_hal.h:484
#define RTC_IRQS_CH_COUNT
Definition: S32K144.h:9009
#define YEAR_RANGE_END
Definition: rtc_driver.h:45
static void RTC_HAL_SetTimeAlarmIntEnable(RTC_Type *const base, bool enable)
Enable TimeAlarm interrupt.
Definition: rtc_hal.h:847
#define DAYS_IN_A_LEAP_YEAR
Definition: rtc_driver.h:43
rtc_seconds_int_config_t * secondsIntConfig
Definition: rtc_driver.c:79