]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/rtcpsu_v1_3/src/xrtcpsu_intr.c
xTaskGenericNotify() now sets xYieldPending to pdTRUE even when the 'higher priority...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / rtcpsu_v1_3 / src / xrtcpsu_intr.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2015 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xrtcpsu_intr.c
36 * @addtogroup rtcpsu_v1_0
37 * @{
38 *
39 * This file contains functions related to RTC interrupt handling.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
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).
49 * </pre>
50 *
51 ******************************************************************************/
52
53 /***************************** Include Files *********************************/
54
55 #include "xrtcpsu.h"
56
57 /************************** Constant Definitions *****************************/
58
59 /**************************** Type Definitions *******************************/
60
61 /***************** Macros (Inline Functions) Definitions *********************/
62
63 /************************** Variable Definitions *****************************/
64
65 /************************** Function Prototypes ******************************/
66
67 /************************** Variable Definitions ****************************/
68
69 /****************************************************************************/
70 /**
71 *
72 * This function sets the interrupt mask.
73 *
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.
77 *
78 * @return       None.
79 *
80 * @note         None.
81 *
82 *****************************************************************************/
83 void XRtcPsu_SetInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
84 {
85         /*
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.
88          */
89         XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr + XRTC_INT_STS_OFFSET,
90                         ((u32)XRTC_INT_STS_ALRM_MASK | (u32)XRTC_INT_STS_SECS_MASK));
91
92         /*
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.
96          */
97
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));
101
102 }
103
104 /****************************************************************************/
105 /**
106 *
107 * This function clears the interrupt mask.
108 *
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.
112 *
113 * @return       None.
114 *
115 * @note         None.
116 *
117 *****************************************************************************/
118 void XRtcPsu_ClearInterruptMask(XRtcPsu *InstancePtr, u32 Mask)
119 {
120         /*
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.
124          */
125
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));
129 }
130
131 /****************************************************************************/
132 /**
133 *
134 * This function sets the handler that will be called when an event (interrupt)
135 * occurs that needs application's attention.
136 *
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.
141 *
142 * @return       None.
143 *
144 * @note
145 *
146 * There is no assert on the CallBackRef since the driver doesn't know what it
147 * is (nor should it)
148 *
149 *****************************************************************************/
150 void XRtcPsu_SetHandler(XRtcPsu *InstancePtr, XRtcPsu_Handler FuncPtr,
151                  void *CallBackRef)
152 {
153         /*
154          * Asserts validate the input arguments
155          * CallBackRef not checked, no way to know what is valid
156          */
157         Xil_AssertVoid(InstancePtr != NULL);
158         Xil_AssertVoid(FuncPtr != NULL);
159         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
160
161         InstancePtr->Handler = FuncPtr;
162         InstancePtr->CallBackRef = CallBackRef;
163 }
164
165 /****************************************************************************/
166 /**
167 *
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.
171 *
172 * @param        InstancePtr contains a pointer to the driver instance
173 *
174 * @return       None.
175 *
176 * @note         None.
177 *
178 ******************************************************************************/
179 void XRtcPsu_InterruptHandler(XRtcPsu *InstancePtr)
180 {
181         u32 IsrStatus;
182
183         Xil_AssertVoid(InstancePtr != NULL);
184         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
185
186         /*
187          * Read the interrupt ID register to determine which
188          * interrupt is active.
189          */
190         IsrStatus = ~(XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
191                         XRTC_INT_MSK_OFFSET));
192
193         IsrStatus &= XRtcPsu_ReadReg(InstancePtr->RtcConfig.BaseAddr +
194                         XRTC_INT_STS_OFFSET);
195
196         /*
197          * Clear the interrupt status to allow future
198          * interrupts before this generated interrupt is serviced.
199          */
200         XRtcPsu_WriteReg(InstancePtr->RtcConfig.BaseAddr +
201                         XRTC_INT_STS_OFFSET, IsrStatus);
202
203         /* Handle the generated interrupts appropriately. */
204
205         /* Alarm interrupt */
206         if((IsrStatus & XRTC_INT_STS_ALRM_MASK) != (u32)0) {
207
208                 if(InstancePtr->IsPeriodicAlarm != 0U) {
209                         XRtcPsu_SetAlarm(InstancePtr,
210                                         (XRtcPsu_GetCurrentTime(InstancePtr)+InstancePtr->PeriodicAlarmTime),1U);
211                 }
212
213                 /*
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.
217                  */
218                 InstancePtr->Handler(InstancePtr->CallBackRef,
219                                         XRTCPSU_EVENT_ALARM_GEN);
220         }
221
222         /* Seconds interrupt */
223         if((IsrStatus & XRTC_INT_STS_SECS_MASK) != (u32)0) {
224                 /* Set the CurrTimeUpdated flag to 1 */
225                 InstancePtr->CurrTimeUpdated = 1;
226
227                 if(InstancePtr->TimeUpdated == (u32)1) {
228                         /* Clear the TimeUpdated */
229                         InstancePtr->TimeUpdated = (u32)0;
230                 }
231
232                 /*
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.
236                  */
237                 InstancePtr->Handler(InstancePtr->CallBackRef,
238                                         XRTCPSU_EVENT_SECS_GEN);
239         }
240
241 }
242 /** @} */