1 /******************************************************************************
3 * Copyright (C) 2015 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
35 * @file xrtcpsu_intr.c
36 * @addtogroup rtcpsu_v1_0
39 * This file contains functions related to RTC interrupt handling.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ----- -------- -----------------------------------------------
46 * 1.00 kvn 04/21/15 First release
47 * 1.3 vak 04/25/16 Changed the XRtcPsu_InterruptHandler() for updating RTC
48 * read and write time logic(cr#948833).
51 ******************************************************************************/
53 /***************************** Include Files *********************************/
57 /************************** Constant Definitions *****************************/
59 /**************************** Type Definitions *******************************/
61 /***************** Macros (Inline Functions) Definitions *********************/
63 /************************** Variable Definitions *****************************/
65 /************************** Function Prototypes ******************************/
67 /************************** Variable Definitions ****************************/
69 /****************************************************************************/
72 * This function sets the interrupt mask.
74 * @param InstancePtr is a pointer to the XRtcPsu instance
75 * @param Mask contains the interrupts to be enabled.
76 * A '1' enables an interupt, and a '0' disables.
82 *****************************************************************************/
83 void XRtcPsu_SetInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
86 * Clear the Status register to be sure of no pending interrupts.
87 * Writing mask values to interrupt bits as it is a WTC register.
89 XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_INT_STS_OFFSET,
90 ((u32)XRTC_INT_STS_ALRM_MASK | (u32)XRTC_INT_STS_SECS_MASK));
93 * XRTC_INT_MSK_RSTVAL contains the valid interrupts
94 * for the RTC device. The AND operation on Mask makes sure one
95 * of the valid bits are only set.
98 /* Write the mask to the IER Register */
99 XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr+XRTC_INT_EN_OFFSET,
100 (Mask & (u32)XRTC_INT_MSK_RSTVAL));
104 /****************************************************************************/
107 * This function clears the interrupt mask.
109 * @param InstancePtr is a pointer to the XRtcPsu instance
110 * @param Mask contains the interrupts to be disabled.
111 * A '1' enables an interrupt, and a '0' disables.
117 *****************************************************************************/
118 void XRtcPsu_ClearInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
121 * XRTC_INT_MSK_RSTVAL contains the valid interrupts
122 * for the RTC device. The AND operation on mask makes sure one
123 * of the valid bits are only cleared.
126 /* Write the Mask to the IDR register */
127 XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr+XRTC_INT_DIS_OFFSET,
128 (Mask & (u32)XRTC_INT_MSK_RSTVAL));
131 /****************************************************************************/
134 * This function sets the handler that will be called when an event (interrupt)
135 * occurs that needs application's attention.
137 * @param InstancePtr is a pointer to the XRtcPsu instance
138 * @param FuncPtr is the pointer to the callback function.
139 * @param CallBackRef is the upper layer callback reference passed back
140 * when the callback function is invoked.
146 * There is no assert on the CallBackRef since the driver doesn't know what it
149 *****************************************************************************/
150 void XRtcPsu_SetHandler(XRtcPsu *InstancePtr, XRtcPsu_Handler FuncPtr,
154 * Asserts validate the input arguments
155 * CallBackRef not checked, no way to know what is valid
157 Xil_AssertVoid(InstancePtr != NULL);
158 Xil_AssertVoid(FuncPtr != NULL);
159 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
161 InstancePtr->Handler = FuncPtr;
162 InstancePtr->CallBackRef = CallBackRef;
165 /****************************************************************************/
168 * This function is the interrupt handler for the driver.
169 * It must be connected to an interrupt system by the application such that it
170 * can be called when an interrupt occurs.
172 * @param InstancePtr contains a pointer to the driver instance
178 ******************************************************************************/
179 void XRtcPsu_InterruptHandler(XRtcPsu *InstancePtr)
183 Xil_AssertVoid(InstancePtr != NULL);
184 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
187 * Read the interrupt ID register to determine which
188 * interrupt is active.
190 IsrStatus = ~(XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
191 XRTC_INT_MSK_OFFSET));
193 IsrStatus &= XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
194 XRTC_INT_STS_OFFSET);
197 * Clear the interrupt status to allow future
198 * interrupts before this generated interrupt is serviced.
200 XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr +
201 XRTC_INT_STS_OFFSET, IsrStatus);
203 /* Handle the generated interrupts appropriately. */
205 /* Alarm interrupt */
206 if((IsrStatus & XRTC_INT_STS_ALRM_MASK) != (u32)0) {
208 if(InstancePtr->IsPeriodicAlarm != 0U) {
209 XRtcPsu_SetAlarm(InstancePtr,
210 (XRtcPsu_GetCurrentTime(InstancePtr)+InstancePtr->PeriodicAlarmTime),1U);
214 * Call the application handler to indicate that there is an
215 * alarm interrupt. If the application cares about this alarm,
216 * it will act accordingly through its own handler.
218 InstancePtr->Handler(InstancePtr->CallBackRef,
219 XRTCPSU_EVENT_ALARM_GEN);
222 /* Seconds interrupt */
223 if((IsrStatus & XRTC_INT_STS_SECS_MASK) != (u32)0) {
224 /* Set the CurrTimeUpdated flag to 1 */
225 InstancePtr->CurrTimeUpdated = 1;
227 if(InstancePtr->TimeUpdated == (u32)1) {
228 /* Clear the TimeUpdated */
229 InstancePtr->TimeUpdated = (u32)0;
233 * Call the application handler to indicate that there is an
234 * seconds interrupt. If the application cares about this seconds
235 * interrupt, it will act accordingly through its own handler.
237 InstancePtr->Handler(InstancePtr->CallBackRef,
238 XRTCPSU_EVENT_SECS_GEN);