| 1 | /**************************************************************************//** |
| 2 | * @file axi_interrupts.c |
| 3 | * @brief AXI Interrupts handling functions driver file. |
| 4 | * @author ATofan ([email protected]) |
| 5 | * |
| 6 | ******************************************************************************* |
| 7 | * Copyright 2011(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: $WCREV$ |
| 42 | ******************************************************************************/ |
| 43 | #include "system_config.h" |
| 44 | #include <stdio.h> |
| 45 | #include "xil_io.h" |
| 46 | |
| 47 | #if(USE_PS7 == 0) |
| 48 | #include "axi_interrupts.h" |
| 49 | |
| 50 | extern volatile int rxData; |
| 51 | extern volatile int timeStepValue; |
| 52 | |
| 53 | /****************************************************************************** |
| 54 | * @brief Enable Interrupt Controller. |
| 55 | * |
| 56 | * @param None. |
| 57 | * |
| 58 | * @return None. |
| 59 | ******************************************************************************/ |
| 60 | void AxiIntcInit(void) |
| 61 | { |
| 62 | // Enable Interrupt Controller |
| 63 | XIntc_MasterEnable(INTC_BASEADDR); |
| 64 | } |
| 65 | |
| 66 | /****************************************************************************** |
| 67 | * @brief Enable Uart Interrupts |
| 68 | * |
| 69 | * @param None. |
| 70 | * |
| 71 | * @return None. |
| 72 | ******************************************************************************/ |
| 73 | void AxiUartIntrEnable(void) |
| 74 | { |
| 75 | int prevIntrMask = 0; |
| 76 | // Register UART Interrupt Service Routine |
| 77 | XIntc_RegisterHandler(INTC_BASEADDR, UART_INTERRUPT, (XInterruptHandler)AxiUartIntrHandler, (void *) 0); |
| 78 | prevIntrMask = Xil_In32(INTC_BASEADDR + XIN_IER_OFFSET); |
| 79 | XIntc_EnableIntr(INTC_BASEADDR, prevIntrMask | UART_INTERRUPT_MASK); |
| 80 | // Enable UART Interrupts |
| 81 | Xil_Out32(UART_BASEADDR + 0x0C, (1 << 4)); |
| 82 | // Enable MicroBlaze Interrupts |
| 83 | microblaze_enable_interrupts(); |
| 84 | } |
| 85 | |
| 86 | /****************************************************************************** |
| 87 | * @brief UART Interrupt Handler. |
| 88 | * |
| 89 | * @param None. |
| 90 | * |
| 91 | * @return None. |
| 92 | ******************************************************************************/ |
| 93 | void AxiUartIntrHandler(void) |
| 94 | { |
| 95 | // If UART has triggered a RX DATA Interrupt |
| 96 | // store the read value in rxData |
| 97 | if(Xil_In32(UART_BASEADDR + 0x08) & 0x01) |
| 98 | { |
| 99 | // Save read data from UART |
| 100 | rxData = Xil_In32(UART_BASEADDR); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /****************************************************************************** |
| 105 | * @brief Enable Timer Interrupts |
| 106 | * |
| 107 | * @param None. |
| 108 | * |
| 109 | * @return None. |
| 110 | ******************************************************************************/ |
| 111 | #if(USE_TIMER == 1) |
| 112 | void AxiTimerIntrEnable(void) |
| 113 | { |
| 114 | int prevIntrMask = 0; |
| 115 | // Register UART Interrupt Service Routine |
| 116 | XIntc_RegisterHandler(INTC_BASEADDR, TIMER_INTERRUPT, (XInterruptHandler)AxiTimerIntrHandler, (void *) 0); |
| 117 | prevIntrMask = Xil_In32(INTC_BASEADDR + XIN_IER_OFFSET); |
| 118 | XIntc_EnableIntr(INTC_BASEADDR, prevIntrMask | TIMER_INTERRUPT_MASK); |
| 119 | // Enable TIMER Initial Settings |
| 120 | Xil_Out32(TIMER_BASEADDR + 0x04, timeStepValue); |
| 121 | Xil_Out32(TIMER_BASEADDR + 0x00, 0x00000060); |
| 122 | // Enable MicroBlaze Interrupts |
| 123 | microblaze_enable_interrupts(); |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | /****************************************************************************** |
| 128 | * @brief Timer Interrupt Handler |
| 129 | * |
| 130 | * @param None. |
| 131 | * |
| 132 | * @return None. |
| 133 | ******************************************************************************/ |
| 134 | void AxiTimerIntrHandler(void) |
| 135 | { |
| 136 | TimerIntrFunction(); |
| 137 | } |
| 138 | |
| 139 | #if(USE_EXTERNAL == 1) |
| 140 | /****************************************************************************** |
| 141 | * @brief Enable External Interrupts |
| 142 | * |
| 143 | * @param None. |
| 144 | * |
| 145 | * @return None. |
| 146 | ******************************************************************************/ |
| 147 | void AxiExtIntrEnable(void) |
| 148 | { |
| 149 | int prevIntrMask = 0; |
| 150 | // Register UART Interrupt Service Routine |
| 151 | XIntc_RegisterHandler(INTC_BASEADDR, EXT_INTERRUPT, (XInterruptHandler)AxiExtIntrHandler, (void *) 0); |
| 152 | prevIntrMask = Xil_In32(INTC_BASEADDR + XIN_IER_OFFSET); |
| 153 | XIntc_EnableIntr(INTC_BASEADDR, prevIntrMask | EXT_INTERRUPT_MASK); |
| 154 | // Set GPIO as Inputs |
| 155 | Xil_Out32(EXT_BASEADDR + 0x04, 0x0F); |
| 156 | // Enable GPIO Interrupts |
| 157 | Xil_Out32(EXT_BASEADDR + 0x11C, 0xFFFFFFFF); |
| 158 | Xil_Out32(EXT_BASEADDR + 0x128, 0x01); |
| 159 | // Enable MicroBlaze Interrupts |
| 160 | microblaze_enable_interrupts(); |
| 161 | } |
| 162 | #endif |
| 163 | /****************************************************************************** |
| 164 | * @brief External Interrupt Handler |
| 165 | * |
| 166 | * @param None. |
| 167 | * |
| 168 | * @return None. |
| 169 | ******************************************************************************/ |
| 170 | void AxiExtIntrHandler(void) |
| 171 | { |
| 172 | ExtIntrFunction(); |
| 173 | } |
| 174 | |
| 175 | /****************************************************************************** |
| 176 | * @brief Enable Interrupts System |
| 177 | * |
| 178 | * @param None. |
| 179 | * |
| 180 | * @return None. |
| 181 | ******************************************************************************/ |
| 182 | void AxiIntrInit(void) |
| 183 | { |
| 184 | // Initialize interrupt controller |
| 185 | AxiIntcInit(); |
| 186 | |
| 187 | // Enable UART Interrupts |
| 188 | AxiUartIntrEnable(); |
| 189 | |
| 190 | if(USE_TIMER == 1) |
| 191 | { |
| 192 | // Enable Timer Interrupts |
| 193 | AxiTimerIntrEnable(); |
| 194 | } |
| 195 | |
| 196 | if(USE_EXTERNAL == 1) |
| 197 | { |
| 198 | // Enable External Interrupts |
| 199 | AxiExtIntrEnable(); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /****************************************************************************** |
| 204 | * @brief Enable Interrupts |
| 205 | * |
| 206 | * @param None. |
| 207 | * |
| 208 | * @return None. |
| 209 | ******************************************************************************/ |
| 210 | void AxiIntrEnable(int intrNr) |
| 211 | { |
| 212 | // Enable interrupts |
| 213 | microblaze_enable_interrupts(); |
| 214 | } |
| 215 | |
| 216 | /****************************************************************************** |
| 217 | * @brief Disable Interrupts |
| 218 | * |
| 219 | * @param None. |
| 220 | * |
| 221 | * @return None. |
| 222 | ******************************************************************************/ |
| 223 | void AxiIntrDisable(int intrNr) |
| 224 | { |
| 225 | // Disable interrupts in order to use normal polling |
| 226 | microblaze_disable_interrupts(); |
| 227 | } |
| 228 | |
| 229 | /****************************************************************************** |
| 230 | * @brief Read a single char from Uart |
| 231 | * |
| 232 | * @param None. |
| 233 | * |
| 234 | * @return None. |
| 235 | ******************************************************************************/ |
| 236 | char AxiUartReadChar(void) |
| 237 | { |
| 238 | char rx; |
| 239 | |
| 240 | // Check if data is available on the UART |
| 241 | while (!((Xil_In32(UART_BASEADDR + 0x08)) & 0x01)); |
| 242 | rx = Xil_In32(UART_BASEADDR); |
| 243 | |
| 244 | return(rx); |
| 245 | } |
| 246 | #endif |