| 1 | /**************************************************************************//** |
| 2 | * @file ps7_interrupts.c |
| 3 | * @brief PS7 interrupts configuration driver file |
| 4 | * @author ATofan ([email protected]) |
| 5 | * |
| 6 | ******************************************************************************* |
| 7 | * Copyright 2012(c) Analog Devices, Inc. |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without modification, |
| 12 | * are permitted provided that the following conditions are met: |
| 13 | * - Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * - Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in |
| 17 | * the documentation and/or other materials provided with the |
| 18 | * distribution. |
| 19 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 20 | * contributors may be used to endorse or promote products derived |
| 21 | * from this software without specific prior written permission. |
| 22 | * - The use of this software may or may not infringe the patent rights |
| 23 | * of one or more patent holders. This license does not release you |
| 24 | * from the requirement that you obtain separate licenses from these |
| 25 | * patent holders to use this software. |
| 26 | * - Use of the software either in source or binary form, must be run |
| 27 | * on or directly connected to an Analog Devices Inc. component. |
| 28 | * |
| 29 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED |
| 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY |
| 31 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 32 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 34 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 35 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 36 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 38 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 39 | * |
| 40 | ******************************************************************************* |
| 41 | * SVN Revision: 468 |
| 42 | ******************************************************************************/ |
| 43 | |
| 44 | /*****************************************************************************/ |
| 45 | /***************************** Include Files *********************************/ |
| 46 | /*****************************************************************************/ |
| 47 | #include "system_config.h" |
| 48 | |
| 49 | #if(USE_PS7 == 1) |
| 50 | #include "xparameters.h" |
| 51 | #include "xil_io.h" |
| 52 | #include "xil_exception.h" |
| 53 | |
| 54 | XScuGic IntcInstance; // Interrupt controller instance |
| 55 | extern volatile int rxData; // Data read from UART |
| 56 | extern volatile int timeStepValue; // Value to be loaded in timer |
| 57 | |
| 58 | /****************************************************************************** |
| 59 | * @brief Initialize Interrupt Controller |
| 60 | * |
| 61 | * @param None. |
| 62 | * |
| 63 | * @return None. |
| 64 | ******************************************************************************/ |
| 65 | void Ps7IntcInit(void) |
| 66 | { |
| 67 | XScuGic_Config *IntcConfig; |
| 68 | /* Initialize the interrupt controller driver */ |
| 69 | IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID); |
| 70 | |
| 71 | XScuGic_CfgInitialize(&IntcInstance, IntcConfig, IntcConfig->CpuBaseAddress); |
| 72 | |
| 73 | Xil_ExceptionInit(); |
| 74 | |
| 75 | /* Connect the interrupt controller interrupt handler to the hardware interrupt logic */ |
| 76 | Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, &IntcInstance); |
| 77 | } |
| 78 | |
| 79 | /****************************************************************************** |
| 80 | * @brief Enable Uart Interrupts |
| 81 | * |
| 82 | * @param None. |
| 83 | * |
| 84 | * @return None. |
| 85 | ******************************************************************************/ |
| 86 | void Ps7UartIntrEnable(void) |
| 87 | { |
| 88 | /* Connect device driver handler to be called when interrupt occures */ |
| 89 | XScuGic_Connect(&IntcInstance, UART_INTERRUPT, (Xil_ExceptionHandler)Ps7UartIntrHandler, (void *)0); |
| 90 | |
| 91 | /* Enable interrupts for the device */ |
| 92 | XScuGic_Enable(&IntcInstance, UART_INTERRUPT); |
| 93 | |
| 94 | /* Enable UART RX Empty interrupt */ |
| 95 | Xil_Out32(UART_BASEADDR + 0x08, 0x01); |
| 96 | Xil_Out32(UART_BASEADDR + 0x0C, 0xFE); |
| 97 | |
| 98 | /* Clear Interrupt Flags */ |
| 99 | Xil_Out32(UART_BASEADDR + 0x14, 0xFF); |
| 100 | |
| 101 | /* Set RX trigger level */ |
| 102 | Xil_Out32(UART_BASEADDR + 0x20, 0x01); |
| 103 | |
| 104 | /* Enable interrupts in the processor */ |
| 105 | Xil_ExceptionEnable(); |
| 106 | } |
| 107 | |
| 108 | /****************************************************************************** |
| 109 | * @brief Uart Interrupt Handler |
| 110 | * |
| 111 | * @param None. |
| 112 | * |
| 113 | * @return None. |
| 114 | ******************************************************************************/ |
| 115 | void Ps7UartIntrHandler(void) |
| 116 | { |
| 117 | // Read data from RX Fifo |
| 118 | rxData = Xil_In32(UART_BASEADDR + 0x30); |
| 119 | |
| 120 | // Clear interrupt |
| 121 | Xil_Out32(UART_BASEADDR + 0x14, 0x01); |
| 122 | } |
| 123 | |
| 124 | /****************************************************************************** |
| 125 | * @brief Enable Timer Interrupts |
| 126 | * |
| 127 | * @param None. |
| 128 | * |
| 129 | * @return None. |
| 130 | ******************************************************************************/ |
| 131 | void Ps7TimerIntrEnable(void) |
| 132 | { |
| 133 | /* Connect device driver handler to be called when interrupt occures */ |
| 134 | XScuGic_Connect(&IntcInstance, TIMER_INTERRUPT, (Xil_ExceptionHandler)Ps7TimerIntrHandler, (void *)0); |
| 135 | |
| 136 | /* Enable interrupts for the device */ |
| 137 | XScuGic_Enable(&IntcInstance, TIMER_INTERRUPT); |
| 138 | |
| 139 | // cnt cntrl |
| 140 | Xil_Out32(TIMER_BASEADDR + 0x0C, 0x07); |
| 141 | // clock control |
| 142 | Xil_Out32(TIMER_BASEADDR + 0x00, 0x1B); |
| 143 | // interval value |
| 144 | Xil_Out32(TIMER_BASEADDR + 0x24, timeStepValue); |
| 145 | // intr en |
| 146 | Xil_Out32(TIMER_BASEADDR + 0x60, 0x01); |
| 147 | |
| 148 | /* Enable interrupts in the processor */ |
| 149 | Xil_ExceptionEnable(); |
| 150 | } |
| 151 | |
| 152 | /****************************************************************************** |
| 153 | * @brief Timer Interrupt Handler |
| 154 | * |
| 155 | * @param None. |
| 156 | * |
| 157 | * @return None. |
| 158 | ******************************************************************************/ |
| 159 | void Ps7TimerIntrHandler(void) |
| 160 | { |
| 161 | char interrupt; |
| 162 | |
| 163 | interrupt = Xil_In32(TIMER_BASEADDR + 0x54); |
| 164 | |
| 165 | if((interrupt & 0x01) == 0x01) |
| 166 | { |
| 167 | TimerIntrFunction(); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /****************************************************************************** |
| 172 | * @brief Enable External Interrupts |
| 173 | * |
| 174 | * @param None. |
| 175 | * |
| 176 | * @return None. |
| 177 | ******************************************************************************/ |
| 178 | void Ps7ExtIntrEnable(void) |
| 179 | { |
| 180 | /* Connect device driver handler to be called when interrupt occures */ |
| 181 | XScuGic_Connect(&IntcInstance, XPS_FPGA11_INT_ID, (Xil_ExceptionHandler)Ps7ExtIntrHandler, (void *)0); |
| 182 | XScuGic_Connect(&IntcInstance, XPS_FPGA12_INT_ID, (Xil_ExceptionHandler)Ps7ExtIntrHandler, (void *)0); |
| 183 | |
| 184 | /* Enable interrupts for the device */ |
| 185 | XScuGic_Enable(&IntcInstance, XPS_FPGA11_INT_ID); |
| 186 | XScuGic_Enable(&IntcInstance, XPS_FPGA12_INT_ID); |
| 187 | |
| 188 | /* Enable interrupts in the processor */ |
| 189 | Xil_ExceptionEnable(); |
| 190 | } |
| 191 | |
| 192 | /****************************************************************************** |
| 193 | * @brief External Interrupt Handler |
| 194 | * |
| 195 | * @param None. |
| 196 | * |
| 197 | * @return None. |
| 198 | ******************************************************************************/ |
| 199 | void Ps7ExtIntrHandler(void) |
| 200 | { |
| 201 | ExtIntrFunction(); |
| 202 | } |
| 203 | |
| 204 | /****************************************************************************** |
| 205 | * @brief Initialize Interrupt System |
| 206 | * |
| 207 | * @param None. |
| 208 | * |
| 209 | * @return None. |
| 210 | ******************************************************************************/ |
| 211 | void Ps7IntrInit(void) |
| 212 | { |
| 213 | // Initialize interrupt controller |
| 214 | Ps7IntcInit(); |
| 215 | |
| 216 | // Enable UART Interrupts |
| 217 | Ps7UartIntrEnable(); |
| 218 | |
| 219 | if(USE_TIMER == 1) |
| 220 | { |
| 221 | // Enable Timer Interrupts |
| 222 | Ps7TimerIntrEnable(); |
| 223 | } |
| 224 | |
| 225 | if(USE_EXTERNAL == 1) |
| 226 | { |
| 227 | // Enable External Interrupts |
| 228 | Ps7ExtIntrEnable(); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /****************************************************************************** |
| 233 | * @brief Enable Interrupt |
| 234 | * |
| 235 | * @param intrNr - interrupt number. |
| 236 | * |
| 237 | * @return None. |
| 238 | ******************************************************************************/ |
| 239 | void Ps7IntrEnable(int intrNr) |
| 240 | { |
| 241 | // Enable interrupts |
| 242 | XScuGic_Enable(&IntcInstance, intrNr); |
| 243 | } |
| 244 | |
| 245 | /****************************************************************************** |
| 246 | * @brief Disable Interrupts |
| 247 | * |
| 248 | * @param intrNr - interrupt number |
| 249 | * |
| 250 | * @return None. |
| 251 | ******************************************************************************/ |
| 252 | void Ps7IntrDisable(int intrNr) |
| 253 | { |
| 254 | // Disable interrupts in order to use normal polling |
| 255 | XScuGic_Disable(&IntcInstance, intrNr); |
| 256 | } |
| 257 | |
| 258 | /****************************************************************************** |
| 259 | * @brief Read a single char from Uart |
| 260 | * |
| 261 | * @param None. |
| 262 | * |
| 263 | * @return None. |
| 264 | ******************************************************************************/ |
| 265 | char Ps7UartReadChar(void) |
| 266 | { |
| 267 | char rx; |
| 268 | |
| 269 | // Check if data is available on the UART |
| 270 | while (!((Xil_In32(UART_BASEADDR + 0x14)) & 0x01)); |
| 271 | rx = Xil_In32(UART_BASEADDR + 0x30); |
| 272 | Xil_Out32(UART_BASEADDR + 0x14, 0x01); |
| 273 | |
| 274 | return(rx); |
| 275 | } |
| 276 | #endif |