S32 SDK
rtc_driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 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 #ifndef RTC_DRIVER_H
20 #define RTC_DRIVER_H
21 
22 #include <stddef.h>
23 #include "clock_manager.h"
24 #include "interrupt_manager.h"
25 #include "rtc_hal.h"
26 
34 /*******************************************************************************
35  * Definitions
36  ******************************************************************************/
37 #define SECONDS_IN_A_DAY (86400UL)
38 #define SECONDS_IN_A_HOUR (3600U)
39 #define SECONDS_IN_A_MIN (60U)
40 #define MINS_IN_A_HOUR (60U)
41 #define HOURS_IN_A_DAY (24U)
42 #define DAYS_IN_A_YEAR (365U)
43 #define DAYS_IN_A_LEAP_YEAR (366U)
44 #define YEAR_RANGE_START (1970U)
45 #define YEAR_RANGE_END (2099U)
46 
51 typedef struct
52 {
53  uint16_t year;
54  uint16_t month;
55  uint16_t day;
56  uint16_t hour;
57  uint16_t minutes;
58  uint8_t seconds;
60 
65 typedef struct
66 {
68  int8_t compensation;
71  bool updateEnable;
74 
79 typedef struct
80 {
82  uint32_t repetitionInterval;
83  uint32_t numberOfRepeats;
86  void (* alarmCallback)(void * callbackParam);
87  void * callbackParams;
89 
95 typedef struct
96 {
99  void (* rtcCallback)(void * callbackParam);
100  void * callbackParams;
102 
107 typedef struct
108 {
111  void (* rtcSecondsCallback)(void * callbackParam);
114 
119 typedef struct
120 {
126 
127 /*******************************************************************************
128  * Code
129  ******************************************************************************/
130 
131 #if defined(__cplusplus)
132 extern "C" {
133 #endif
134 
147 status_t RTC_DRV_Init(uint32_t instance, const rtc_init_config_t * const rtcUserCfg);
148 
158 status_t RTC_DRV_Deinit(uint32_t instance);
159 
168 status_t RTC_DRV_StartCounter(uint32_t instance);
169 
177 status_t RTC_DRV_StopCounter(uint32_t instance);
178 
186 status_t RTC_DRV_GetCurrentTimeDate(uint32_t instance, rtc_timedate_t * const currentTime);
187 
198 status_t RTC_DRV_SetTimeDate(uint32_t instance, const rtc_timedate_t * const time);
199 
211 status_t RTC_DRV_ConfigureRegisterLock(uint32_t instance, const rtc_register_lock_config_t * const lockConfig);
212 
221 void RTC_DRV_GetRegisterLock(uint32_t instance, rtc_register_lock_config_t * const lockConfig);
222 
235 status_t RTC_DRV_ConfigureTimeCompensation(uint32_t instance, uint8_t compInterval, int8_t compensation);
236 
248 void RTC_DRV_GetTimeCompensation(uint32_t instance, uint8_t * compInterval, int8_t * compensation);
249 
260 void RTC_DRV_ConfigureFaultInt(uint32_t instance, rtc_interrupt_config_t * const intConfig);
261 
270 void RTC_DRV_ConfigureSecondsInt(uint32_t instance, rtc_seconds_int_config_t * const intConfig);
271 
282 
291 void RTC_DRV_GetAlarmConfig(uint32_t instance, rtc_alarm_config_t * alarmConfig);
292 
299 bool RTC_DRV_IsAlarmPending(uint32_t instance);
300 
308 void RTC_DRV_ConvertSecondsToTimeDate(const uint32_t * seconds, rtc_timedate_t * const timeDate);
309 
317 void RTC_DRV_ConvertTimeDateToSeconds(const rtc_timedate_t * const timeDate, uint32_t * const seconds);
318 
325 bool RTC_DRV_IsYearLeap(uint16_t year);
326 
333 bool RTC_DRV_IsTimeDateCorrectFormat(const rtc_timedate_t * const timeDate);
334 
344 status_t RTC_DRV_GetNextAlarmTime(uint32_t instance, rtc_timedate_t * const alarmTime);
345 
354 void RTC_DRV_IRQHandler(uint32_t instance);
355 
363 void RTC_DRV_SecondsIRQHandler(uint32_t instance);
364 
365 #if defined(__cplusplus)
366 }
367 #endif
368 
369 
372 #endif /* RTC_DRIVER_H */
373 /*******************************************************************************
374  * EOF
375  ******************************************************************************/
rtc_interrupt_config_t * intConfig
Definition: rtc_driver.c:78
uint16_t day
Definition: rtc_driver.h:55
uint16_t month
Definition: rtc_driver.h:54
bool nonSupervisorAccessEnable
Definition: rtc_driver.h:72
RTC Initialization structure Implements : rtc_init_config_t_Class.
Definition: rtc_driver.h:65
uint16_t year
Definition: rtc_driver.h:53
rtc_clk_out_config_t
RTC CLKOUT pin configuration Implements : rtc_clk_out_config_t_Class.
Definition: rtc_hal.h:68
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_second_int_cfg_t
RTC Seconds interrupt configuration Implements : rtc_second_int_cfg_t_Class.
Definition: rtc_hal.h:52
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
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
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
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 *seconds, rtc_timedate_t *const timeDate)
Convert seconds to rtc_timedate_t structure.
Definition: rtc_driver.c:538
RTC alarm configuration Implements : rtc_alarm_config_t_Class.
Definition: rtc_driver.h:79
rtc_alarm_config_t * alarmConfig
Definition: rtc_driver.c:76
rtc_clk_select_t
RTC clock select Implements : rtc_clk_select_t_Class.
Definition: rtc_hal.h:79
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
void * callbackParams
Definition: rtc_driver.h:87
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
status_t RTC_DRV_GetNextAlarmTime(uint32_t instance, rtc_timedate_t *const alarmTime)
Gets the next alarm time.
Definition: rtc_driver.c:1000
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
uint8_t compensationInterval
Definition: rtc_driver.h:67
uint32_t repetitionInterval
Definition: rtc_driver.h:82
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
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
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
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
RTC Time Date structure Implements : rtc_timedate_t_Class.
Definition: rtc_driver.h:51
rtc_clk_select_t clockSelect
Definition: rtc_driver.h:69
uint16_t minutes
Definition: rtc_driver.h:57
uint8_t seconds
Definition: rtc_driver.h:58
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
int8_t compensation
Definition: rtc_driver.h:68
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