19 #include "rtc_hw_access.h"
62 static const uint8_t
ULY[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
65 static const uint8_t
LY[] = {0U, 31U, 29U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
68 static const uint16_t
MONTH_DAYS[] = {0U, 0U, 31U, 59U, 90U, 120U, 151U, 181U, 212U, 243U, 273U, 304U, 334U};
106 RTC_Type * basePtr = g_rtcBase[instance];
127 RTC_SoftwareReset(basePtr);
132 RTC_SetLPOSelect(basePtr, rtcUserCfg->
clockSelect);
138 RTC_SetTimeCompensation(basePtr,
178 RTC_SoftwareReset(g_rtcBase[instance]);
236 else if (RTC_GetUpdateMode(g_rtcBase[instance]))
238 tifFlagSet = RTC_GetTimeInvalidFlag(g_rtcBase[instance]);
239 tofFlagSet = RTC_GetTimeOverflowFlag(g_rtcBase[instance]);
240 tceFlagSet = RTC_GetTimeCounterEnable(g_rtcBase[instance]);
243 if ((tifFlagSet ==
true) || (tofFlagSet ==
true) || (tceFlagSet ==
false))
282 statusCode = RTC_Enable(g_rtcBase[instance]);
311 statusCode = RTC_Disable(g_rtcBase[instance]);
336 uint32_t tempSeconds;
342 tempSeconds = RTC_GetTimeSecondsRegister(g_rtcBase[instance]);
343 seconds = RTC_GetTimeSecondsRegister(g_rtcBase[instance]);
347 if (tempSeconds != seconds)
352 tempSeconds = RTC_GetTimeSecondsRegister(g_rtcBase[instance]);
353 if (tempSeconds != seconds)
390 uint32_t seconds = 0;
409 statusCode = RTC_SetTimeSecondsRegister(g_rtcBase[instance], seconds);
452 statusCode = RTC_ConfigureRegisterLock(g_rtcBase[instance],
RTC_TCL_REG_LOCK);
520 RTC_SetTimeCompensation(g_rtcBase[instance], compensation, compInterval);
542 RTC_GetCurrentTimeCompensation(g_rtcBase[instance], compensation, compInterval);
559 bool yearLeap =
false;
560 uint32_t numberOfDays = 0U;
561 uint32_t tempSeconds;
587 while (numberOfDays >= daysInYear)
594 numberOfDays -= daysInYear;
620 for (i = 1U; i <= 12U; i++)
622 uint32_t daysInCurrentMonth = ((yearLeap ==
true) ? (uint32_t)
LY[i] : (uint32_t)
ULY[i]);
623 if (numberOfDays <= daysInCurrentMonth)
625 timeDate->
month = (uint16_t)i;
630 numberOfDays -= daysInCurrentMonth;
636 timeDate->
day = (uint16_t)numberOfDays;
701 bool returnCode =
true;
702 const uint8_t * pDays;
709 || (timeDate->
month < 1U) || (timeDate->
month > 12U)
710 || (timeDate->
day < 1U) || (timeDate->
day > 31U)
717 else if (timeDate->
day > pDays[timeDate->
month])
740 bool isYearLeap =
false;
742 if ((year % 4U) > 0U)
746 else if ((year % 100U) > 0U)
750 else if ((year % 400U) > 0U)
778 uint32_t tempSeconds;
785 if (RTC_GetTimeAlarmFlag(g_rtcBase[instance]) ==
true)
790 if ((alarmConfig != NULL))
798 tempSeconds = RTC_GetTimeSecondsRegister(g_rtcBase[instance]);
802 RTC_SetTimeAlarmRegister(g_rtcBase[instance], tempSeconds);
815 RTC_SetTimeAlarmRegister(g_rtcBase[instance], 0UL);
829 else if ( intConfig != NULL )
915 RTC_SetTimeSecondsIntConf(g_rtcBase[instance], intConfig->
secondIntConfig);
918 RTC_SetTimeSecondsIntEnable(g_rtcBase[instance], intConfig->
secondIntEnable);
941 uint32_t currentTime;
949 currentTime = RTC_GetTimeSecondsRegister(g_rtcBase[instance]);
952 if(alarmTime > currentTime)
959 RTC_SetTimeAlarmRegister(g_rtcBase[instance], alarmTime);
961 RTC_SetTimeAlarmIntEnable(g_rtcBase[instance], alarmConfig->
alarmIntEnable);
1008 return RTC_GetTimeAlarmFlag(g_rtcBase[instance]);
1026 uint32_t alarmInSec;
1030 alarmInSec = RTC_GetTimeAlarmRegister(g_rtcBase[instance]);
rtc_interrupt_config_t * intConfig
#define RTC_SECONDS_IRQS_CH_COUNT
bool nonSupervisorAccessEnable
RTC Initialization structure Implements : rtc_init_config_t_Class.
bool timeInvalidIntEnable
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...
status_t RTC_DRV_StopCounter(uint32_t instance)
Disable RTC instance counter.
RTC interrupt configuration. It is used to configure interrupt other than Time Alarm and Time Seconds...
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...
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...
status_t RTC_DRV_GetCurrentTimeDate(uint32_t instance, rtc_timedate_t *const currentTime)
Get current time and date from RTC instance.
#define RTC_INSTANCE_COUNT
void RTC_DRV_GetAlarmConfig(uint32_t instance, rtc_alarm_config_t *alarmConfig)
Get alarm configuration for RTC instance.
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 ...
void RTC_DRV_ConvertSecondsToTimeDate(const uint32_t *const seconds, rtc_timedate_t *const timeDate)
Convert seconds to rtc_timedate_t structure.
RTC alarm configuration Implements : rtc_alarm_config_t_Class.
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
rtc_alarm_config_t * alarmConfig
static bool RTC_DRV_CanWriteTCE(uint32_t instance)
bool RTC_DRV_IsTimeDateCorrectFormat(const rtc_timedate_t *const timeDate)
Check if the date time struct is configured properly.
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...
RTC Seconds Interrupt Configuration Implements : rtc_seconds_int_config_t_Class.
rtc_clk_out_config_t clockOutConfig
RTC Register Lock Configuration Implements : rtc_register_lock_config_t_Class.
static RTC_Type *const g_rtcBase[RTC_INSTANCE_COUNT]
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...
status_t RTC_DRV_GetNextAlarmTime(uint32_t instance, rtc_timedate_t *const alarmTime)
Gets the next alarm time.
static struct @18 g_rtcRuntimeConfig[RTC_INSTANCE_COUNT]
static RTC runtime structure, it is designed only for internal purposes such as storing interrupt con...
static const uint8_t LY[]
void(* alarmCallback)(void *callbackParam)
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
IRQn_Type
Defines the Interrupt Numbers definitions.
uint8_t compensationInterval
uint32_t repetitionInterval
void RTC_DRV_ConfigureFaultInt(uint32_t instance, rtc_interrupt_config_t *const intConfig)
This method configures fault interrupts such as:
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...
bool RTC_DRV_IsYearLeap(uint16_t year)
Check if the current year is leap.
rtc_second_int_cfg_t secondIntConfig
const IRQn_Type g_rtcIrqNumbers[RTC_IRQS_CH_COUNT]
Table used to store the RTC IRQ names.
void RTC_DRV_GetRegisterLock(uint32_t instance, rtc_register_lock_config_t *const lockConfig)
Get which registers are locked for RTC instance.
void(* rtcSecondsCallback)(void *callbackParam)
bool RTC_DRV_IsAlarmPending(uint32_t instance)
Check if alarm is pending.
void INT_SYS_ClearPending(IRQn_Type irqNumber)
Clear Pending Interrupt.
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...
void * secondsCallbackParams
RTC Time Date structure Implements : rtc_timedate_t_Class.
rtc_clk_select_t clockSelect
void RTC_DRV_GetDefaultConfig(rtc_init_config_t *const config)
This function will set the default configuration values into the structure passed as a parameter...
static const uint8_t ULY[]
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
status_t RTC_DRV_Deinit(uint32_t instance)
This function deinitializes the RTC instance. If the Control register is locked then this method retu...
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.
#define SECONDS_IN_A_HOUR
void(* rtcCallback)(void *callbackParam)
const IRQn_Type g_rtcSecondsIrqNb[RTC_SECONDS_IRQS_CH_COUNT]
bool timeCompensationRegisterLock
static const uint16_t MONTH_DAYS[]
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...
void RTC_DRV_ConvertTimeDateToSeconds(const rtc_timedate_t *const timeDate, uint32_t *const seconds)
Convert seconds to rtc_timedate_t structure.
#define RTC_IRQS_CH_COUNT
#define DAYS_IN_A_LEAP_YEAR
rtc_seconds_int_config_t * secondsIntConfig