| 1 | /**************************************************************************//** |
| 2 | * @file system_config.c |
| 3 | * @brief System 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 | |
| 48 | #include "system_config.h" |
| 49 | |
| 50 | #if(USE_TIMER == 1) |
| 51 | |
| 52 | /****************************************************************************** |
| 53 | * @brief Start PS7 Timer |
| 54 | * |
| 55 | * @param None. |
| 56 | * |
| 57 | * @return None. |
| 58 | ******************************************************************************/ |
| 59 | void Ps7StartTimer(void) |
| 60 | { |
| 61 | // Start Timer |
| 62 | Xil_Out32(TIMER_BASEADDR + 0x0C, 0x06); |
| 63 | } |
| 64 | |
| 65 | /****************************************************************************** |
| 66 | * @brief Stop PS7 Timer |
| 67 | * |
| 68 | * @param None. |
| 69 | * |
| 70 | * @return None. |
| 71 | ******************************************************************************/ |
| 72 | void Ps7StopTimer(void) |
| 73 | { |
| 74 | while(Xil_In32(TIMER_BASEADDR + 0x18) == 0x00); |
| 75 | Xil_Out32(TIMER_BASEADDR + 0x0C, 0x07); |
| 76 | } |
| 77 | |
| 78 | /****************************************************************************** |
| 79 | * @brief Load PS7 Timer |
| 80 | * |
| 81 | * @param value - value to be loaded in timer. |
| 82 | * |
| 83 | * @return None. |
| 84 | ******************************************************************************/ |
| 85 | void Ps7LoadTimer(int value) |
| 86 | { |
| 87 | Xil_Out32(TIMER_BASEADDR + 0x24, value); |
| 88 | } |
| 89 | |
| 90 | /****************************************************************************** |
| 91 | * @brief Start AXI Timer |
| 92 | * |
| 93 | * @param None. |
| 94 | * |
| 95 | * @return None. |
| 96 | ******************************************************************************/ |
| 97 | void AxiStartTimer(void) |
| 98 | { |
| 99 | // Start Timer |
| 100 | Xil_Out32(TIMER_BASEADDR + 0x00, 0x000001C0); |
| 101 | } |
| 102 | |
| 103 | /****************************************************************************** |
| 104 | * @brief Stop AXI Timer |
| 105 | * |
| 106 | * @param None. |
| 107 | * |
| 108 | * @return None. |
| 109 | ******************************************************************************/ |
| 110 | void AxiStopTimer(void) |
| 111 | { |
| 112 | // Stop Timer |
| 113 | Xil_Out32(TIMER_BASEADDR + 0x00, 0x00000000); |
| 114 | } |
| 115 | |
| 116 | /****************************************************************************** |
| 117 | * @brief Load AXI Timer |
| 118 | * |
| 119 | * @param value - value to be loaded in timer. |
| 120 | * |
| 121 | * @return None. |
| 122 | ******************************************************************************/ |
| 123 | void AxiLoadTimer(int value) |
| 124 | { |
| 125 | Xil_Out32(TIMER_BASEADDR + 0x04, value); |
| 126 | Xil_Out32(TIMER_BASEADDR + 0x00, 0x60); |
| 127 | } |
| 128 | |
| 129 | #else |
| 130 | void ADITimerIntrFunction(void) |
| 131 | { |
| 132 | |
| 133 | } |
| 134 | volatile int timeStepValue = 0; |
| 135 | #endif |
| 136 | |
| 137 | #if(USE_EXTERNAL == 1) |
| 138 | |
| 139 | #else |
| 140 | void ADIExtIntrFunction(void) |
| 141 | { |
| 142 | |
| 143 | } |
| 144 | #endif |
| 145 | /****************************************************************************** |
| 146 | * @brief Output GPIO PS7 |
| 147 | * |
| 148 | * @param value - value to be output |
| 149 | * |
| 150 | * @return None. |
| 151 | ******************************************************************************/ |
| 152 | void Ps7GpioOut(int addr, int value) |
| 153 | { |
| 154 | Xil_Out32(addr + 0x48, value); |
| 155 | } |
| 156 | |
| 157 | /****************************************************************************** |
| 158 | * @brief Output GPIO AXI |
| 159 | * |
| 160 | * @param value - value to be output |
| 161 | * |
| 162 | * @return None. |
| 163 | ******************************************************************************/ |
| 164 | void AxiGpioOut(int addr, int value) |
| 165 | { |
| 166 | Xil_Out32(addr, value); |
| 167 | } |
| 168 | |
| 169 | /****************************************************************************** |
| 170 | * @brief Select which SPI functions to use according to system (AXI or PS7) |
| 171 | * |
| 172 | * @param None. |
| 173 | * |
| 174 | * @return None. |
| 175 | ******************************************************************************/ |
| 176 | void SystemSpiConfiguration(void) |
| 177 | { |
| 178 | // Select between HW SPI or AXI SPI Core |
| 179 | if(USE_PS7 == 1) |
| 180 | { |
| 181 | SPI_Init = &SPI_Init_ps7; |
| 182 | SPI_TransferData = &SPI_TransferData_ps7; |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | SPI_Init = &SPI_Init_axi; |
| 187 | SPI_TransferData = &SPI_TransferData_axi; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /****************************************************************************** |
| 192 | * @brief Select which Interrupt functions to use according to system (AXI or PS7) |
| 193 | * |
| 194 | * @param None. |
| 195 | * |
| 196 | * @return None. |
| 197 | ******************************************************************************/ |
| 198 | void SystemConfiguration(void) |
| 199 | { |
| 200 | // Select between PS7 or AXI interfaces |
| 201 | if(USE_PS7 == 1) |
| 202 | { |
| 203 | // Interrupt management functions |
| 204 | InterruptsInit = &Ps7IntrInit; |
| 205 | DisableInterrupts = &Ps7IntrDisable; |
| 206 | EnableInterrupts = &Ps7IntrEnable; |
| 207 | |
| 208 | // Read character from UART function |
| 209 | UartReadChar = &Ps7UartReadChar; |
| 210 | |
| 211 | // SPI driver |
| 212 | if(USE_SPI == 1) |
| 213 | { |
| 214 | SPI_Init = &SPI_Init_ps7; |
| 215 | SPI_TransferData = &SPI_TransferData_ps7; |
| 216 | } |
| 217 | |
| 218 | // I2C driver |
| 219 | if(USE_I2C == 1) |
| 220 | { |
| 221 | I2C_Init = &I2C_Init_axi; |
| 222 | I2C_Write = &I2C_Write_axi; |
| 223 | I2C_Read = &I2C_Read_axi; |
| 224 | } |
| 225 | |
| 226 | // Timer driver |
| 227 | if(USE_TIMER == 1) |
| 228 | { |
| 229 | TimerIntrFunction = &ADITimerIntrFunction; |
| 230 | StartTimer = &Ps7StartTimer; |
| 231 | StopTimer = &Ps7StopTimer; |
| 232 | LoadTimer = &Ps7LoadTimer; |
| 233 | } |
| 234 | |
| 235 | // External interrupts handling |
| 236 | if(USE_EXTERNAL == 1) |
| 237 | { |
| 238 | ExtIntrFunction = &ADIExtIntrFunction; |
| 239 | } |
| 240 | |
| 241 | // GPIO manipulation |
| 242 | if(USE_GPIO == 1) |
| 243 | { |
| 244 | GpioOut = &Ps7GpioOut; |
| 245 | } |
| 246 | } |
| 247 | else |
| 248 | { |
| 249 | // Interrupt management functions |
| 250 | InterruptsInit = &AxiIntrInit; |
| 251 | DisableInterrupts = &AxiIntrDisable; |
| 252 | EnableInterrupts = &AxiIntrEnable; |
| 253 | |
| 254 | // Read character from UART function |
| 255 | UartReadChar = &AxiUartReadChar; |
| 256 | |
| 257 | // SPI driver |
| 258 | if(USE_SPI == 1) |
| 259 | { |
| 260 | SPI_Init = &SPI_Init_axi; |
| 261 | SPI_TransferData = &SPI_TransferData_axi; |
| 262 | } |
| 263 | |
| 264 | // I2C driver |
| 265 | if(USE_I2C == 1) |
| 266 | { |
| 267 | I2C_Init = &I2C_Init_axi; |
| 268 | I2C_Write = &I2C_Write_axi; |
| 269 | I2C_Read = &I2C_Read_axi; |
| 270 | } |
| 271 | |
| 272 | // Timer driver |
| 273 | if(USE_TIMER == 1) |
| 274 | { |
| 275 | TimerIntrFunction = &ADITimerIntrFunction; |
| 276 | StartTimer = &AxiStartTimer; |
| 277 | StopTimer = &AxiStopTimer; |
| 278 | LoadTimer = &AxiLoadTimer; |
| 279 | } |
| 280 | |
| 281 | // External interrupts handling |
| 282 | if(USE_EXTERNAL == 1) |
| 283 | { |
| 284 | ExtIntrFunction = &ADIExtIntrFunction; |
| 285 | } |
| 286 | |
| 287 | // GPIO manipulation |
| 288 | if(USE_GPIO == 1) |
| 289 | { |
| 290 | GpioOut = &AxiGpioOut; |
| 291 | } |
| 292 | } |
| 293 | } |