thirdparty/analogdevicesinc/no-OS/platform_drivers/Xilinx/SDP_Common/Communication.h
raw symbols SCIP| 1 | /***************************************************************************//** |
| 2 | * @file Communication.h |
| 3 | * @brief Header file of Communication Driver. |
| 4 | * @author Istvan Csomortani ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2013(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | ******************************************************************************/ |
| 40 | #ifndef _COMMUNICATION_H_ |
| 41 | #define _COMMUNICATION_H_ |
| 42 | |
| 43 | /******************************************************************************/ |
| 44 | /************************ Include Files ***************************************/ |
| 45 | /******************************************************************************/ |
| 46 | #include "xil_types.h" |
| 47 | #include "xparameters.h" |
| 48 | #include "xil_io.h" |
| 49 | #include "xil_cache.h" |
| 50 | |
| 51 | /*****************************************************************************/ |
| 52 | /******************* Macros and Constants Definitions ************************/ |
| 53 | /*****************************************************************************/ |
| 54 | /* DEVICE MACROS : Please uncomment the '#define' with the desired device name, |
| 55 | * before compilation */ |
| 56 | /*****************************************************************************/ |
| 57 | /************************** Digital to Analog Converters *********************/ |
| 58 | /*****************************************************************************/ |
| 59 | //#define AD5415 |
| 60 | //#define AD5443 |
| 61 | //#define AD5449 |
| 62 | //#define AD5421 |
| 63 | //#define AD5425 |
| 64 | //#define AD5541A |
| 65 | //#define AD5542A |
| 66 | //#define AD5446 |
| 67 | //#define AD5453 |
| 68 | //#define AD5543 |
| 69 | //#define AD5553 |
| 70 | //#define AD5629R |
| 71 | //#define AD5669R |
| 72 | //#define AD5668 |
| 73 | //#define AD5648 |
| 74 | //#define AD5628 |
| 75 | //#define AD5684R |
| 76 | //#define AD5686R |
| 77 | //#define AD5694R |
| 78 | //#define AD5696R |
| 79 | //#define AD5755 |
| 80 | //#define AD5755_1 |
| 81 | //#define AD5757 |
| 82 | //#define AD5760 |
| 83 | //#define AD5780 |
| 84 | //#define AD5781 |
| 85 | //#define AD5790 |
| 86 | //#define AD5791 |
| 87 | //#define AD5570 |
| 88 | |
| 89 | /*****************************************************************************/ |
| 90 | /************************** Digital Potentiometers ***************************/ |
| 91 | /*****************************************************************************/ |
| 92 | //#define AD5162 |
| 93 | //#define AD5172 |
| 94 | //#define AD5173 |
| 95 | //#define AD5232 |
| 96 | //#define AD5235 |
| 97 | //#define AD5252 |
| 98 | //#define AD5251 |
| 99 | //#define AD5254 |
| 100 | //#define AD5253 |
| 101 | //#define AD5270 |
| 102 | //#define AD5271 |
| 103 | //#define AD5272 |
| 104 | //#define AD5274 |
| 105 | //#define AD8403 |
| 106 | //#define AD8402 |
| 107 | //#define AD8400 |
| 108 | //#define ADN2850 |
| 109 | //#define AD5110 |
| 110 | //#define AD5111 |
| 111 | |
| 112 | /*****************************************************************************/ |
| 113 | /******************* Direct Digital Synthesis & Modulators *******************/ |
| 114 | /*****************************************************************************/ |
| 115 | //#define AD9833 |
| 116 | //#define AD9834 |
| 117 | //#define AD9837 |
| 118 | //#define AD9838 |
| 119 | |
| 120 | /*****************************************************************************/ |
| 121 | /************************* PLL Synthesizers / VCOs ***************************/ |
| 122 | /*****************************************************************************/ |
| 123 | //#define ADF4001 |
| 124 | //#define ADF4002 |
| 125 | //#define ADF4106 |
| 126 | //#define ADF4153 |
| 127 | //#define ADF4156 |
| 128 | //#define ADF4157 |
| 129 | |
| 130 | /*****************************************************************************/ |
| 131 | /**************** Synchro/Resolver to Digital Converters *********************/ |
| 132 | /*****************************************************************************/ |
| 133 | //#define AD2S1205 |
| 134 | |
| 135 | /*****************************************************************************/ |
| 136 | /************************** Circuits from the Lab ****************************/ |
| 137 | /*****************************************************************************/ |
| 138 | //#define CN0150 |
| 139 | //#define CN0178 |
| 140 | //#define CN0187 |
| 141 | //#define CN0188 |
| 142 | //#define CN0189 |
| 143 | //#define CN0194 |
| 144 | //#define CN0202 |
| 145 | //#define CN0203 |
| 146 | //#define CN0204 |
| 147 | //#define CN0209 |
| 148 | //#define CN0216 |
| 149 | //#define CN0218 |
| 150 | //#define CN0235 |
| 151 | //#define CN0240 |
| 152 | //#define CN0241 |
| 153 | //#define CN0271 |
| 154 | |
| 155 | /*****************************************************************************/ |
| 156 | /**************************** UART Definitions *******************************/ |
| 157 | /*****************************************************************************/ |
| 158 | #define UART_BASEADDR XPAR_RS232_UART_1_BASEADDR |
| 159 | #define UART_DEV_ID XPAR_RS232_UART_1_DEVICE_ID |
| 160 | |
| 161 | /* UART registers*/ |
| 162 | #define UART_RX UART_BASEADDR + 0x0 |
| 163 | #define UART_TX UART_BASEADDR + 0x4 |
| 164 | #define UART_STAT UART_BASEADDR + 0x8 |
| 165 | #define UART_CNTRL UART_BASEADDR + 0xC |
| 166 | |
| 167 | /* UART Control Register */ |
| 168 | #define UART_RST_TX (1 << 0x0) |
| 169 | #define UART_RST_RX (1 << 0x1) |
| 170 | #define UART_EN_INTR (1 << 0x4) |
| 171 | |
| 172 | /* UART Status Register */ |
| 173 | #define UART_RX_VALID (1 << 0x0) |
| 174 | #define UART_RX_FULL (1 << 0x1) |
| 175 | #define UART_TX_EMPTY (1 << 0x2) |
| 176 | #define UART_TX_FULL (1 << 0x3) |
| 177 | #define UART_INTR_EN (1 << 0x4) |
| 178 | #define UART_OVER_RUN (1 << 0x5) |
| 179 | #define UART_FRM_ERR (1 << 0x6) |
| 180 | #define UART_PRT_ERR (1 << 0x7) |
| 181 | |
| 182 | /*****************************************************************************/ |
| 183 | /***************************** SPI Definitions *******************************/ |
| 184 | /*****************************************************************************/ |
| 185 | /* Register address */ |
| 186 | #define SRR 0x40 |
| 187 | #define SPICR 0x60 |
| 188 | #define SPISR 0x64 |
| 189 | #define SPIDTR 0x68 |
| 190 | #define SPIDRR 0x6C |
| 191 | #define SPISSR 0x70 |
| 192 | #define SPI_T_FIFO 0x74 |
| 193 | #define SPI_R_FIFO 0x78 |
| 194 | #define DGIER 0x1C |
| 195 | #define IPISR 0x20 |
| 196 | #define IPIER 0x28 |
| 197 | |
| 198 | /* SPI Control Register (SPICR) */ |
| 199 | #define LSBFirst 9 |
| 200 | #define MasterTranInh 8 |
| 201 | #define ManualSlaveAssEn 7 |
| 202 | #define RxFifoReset 6 |
| 203 | #define TxFifoReset 5 |
| 204 | #define CHPA 4 |
| 205 | #define CPOL 3 |
| 206 | #define Master 2 |
| 207 | #define SPE 1 |
| 208 | #define LOOP 0 |
| 209 | |
| 210 | /* SPI Status Register (SPISR) */ |
| 211 | #define SlaveModeSel 5 |
| 212 | #define MODF 4 |
| 213 | #define TxFull 3 |
| 214 | #define TxEmpty 2 |
| 215 | #define RxFull 1 |
| 216 | #define RxEmpty 0 |
| 217 | |
| 218 | /* IP Interrupt Status Register */ |
| 219 | #define DDRNotEmpty 8 |
| 220 | #define SlaveModeSel_int 7 |
| 221 | #define TxFifoHalfEmpty 6 |
| 222 | #define DDROverRun 5 |
| 223 | #define DDRFull 4 |
| 224 | #define DTRUnderRun 3 |
| 225 | #define DTREmpty 2 |
| 226 | #define SlaveMODF 1 |
| 227 | #define MODF_int 0 |
| 228 | |
| 229 | /*****************************************************************************/ |
| 230 | /*********************** I2C Registers Definitions ***************************/ |
| 231 | /*****************************************************************************/ |
| 232 | #define GIE 0x01C |
| 233 | #define ISR 0x020 |
| 234 | #define IER 0x028 |
| 235 | #define SOFTR 0x040 |
| 236 | #define CR 0x100 |
| 237 | #define SR 0x104 |
| 238 | #define TX_FIFO 0x108 |
| 239 | #define RX_FIFO 0x10C |
| 240 | #define ADR 0x110 |
| 241 | #define TX_FIFO_OCY 0x114 |
| 242 | #define RX_FIFO_OCY 0x118 |
| 243 | #define TEN_ADDR 0x11C |
| 244 | #define RX_FIFO_PIRQ 0x120 |
| 245 | #define GPO 0x124 |
| 246 | |
| 247 | /*****************************************************************************/ |
| 248 | /*********************** GPIO Registers Definitions **************************/ |
| 249 | /*****************************************************************************/ |
| 250 | #define GPIO_DATA 0x00 |
| 251 | #define GPIO_TRI 0x04 |
| 252 | |
| 253 | /****************************************************************************/ |
| 254 | /********************** GPIO macros redefinitions ***************************/ |
| 255 | /****************************************************************************/ |
| 256 | #define GPIO_SET_PINS_OUT(GPIO_BASEADDR, cfgWord) \ |
| 257 | { \ |
| 258 | int currCfgWord = 0; \ |
| 259 | currCfgWord = Xil_In32((GPIO_BASEADDR + GPIO_TRI)); \ |
| 260 | Xil_Out32((GPIO_BASEADDR + GPIO_TRI), (currCfgWord & ~cfgWord)); \ |
| 261 | } |
| 262 | #define GPIO_SET_PINS_IN(GPIO_BASEADDR, cfgWord) \ |
| 263 | { \ |
| 264 | int currCfgWord = 0; \ |
| 265 | currCfgWord = Xil_In32((GPIO_BASEADDR + GPIO_TRI)); \ |
| 266 | Xil_Out32((GPIO_BASEADDR + GPIO_TRI), (currCfgWord | cfgWord)); \ |
| 267 | } |
| 268 | #define GPIO_CLEAR_BITS(GPIO_BASEADDR, cfgWord) \ |
| 269 | { \ |
| 270 | int currCfgWord = 0; \ |
| 271 | currCfgWord = Xil_In32((GPIO_BASEADDR + GPIO_DATA)); \ |
| 272 | Xil_Out32((GPIO_BASEADDR + GPIO_DATA), currCfgWord & ~cfgWord); \ |
| 273 | } |
| 274 | #define GPIO_SET_BITS(GPIO_BASEADDR, cfgWord) \ |
| 275 | { \ |
| 276 | int currCfgWord = 0; \ |
| 277 | currCfgWord = Xil_In32((GPIO_BASEADDR + GPIO_DATA)); \ |
| 278 | Xil_Out32((GPIO_BASEADDR + GPIO_DATA), currCfgWord | cfgWord); \ |
| 279 | } |
| 280 | #define GPIO_GET_DATA(GPIO_BASE_ADDR) \ |
| 281 | Xil_In32((GPIO_BASE_ADDR + GPIO_DATA)) |
| 282 | |
| 283 | #define GPIO_SET_DATA(GPIO_BASE_ADDR, cfgWord) \ |
| 284 | Xil_Out32((GPIO_BASE_ADDR + GPIO_DATA), cfgWord); |
| 285 | |
| 286 | #define GET_REGISTER(AXI_REG_ADDR) \ |
| 287 | Xil_In32((AXI_REG_ADDR)) |
| 288 | |
| 289 | #define SET_REGISTER(AXI_REG_ADDR, AXI_REG_DATA) \ |
| 290 | Xil_Out32((AXI_REG_ADDR), (AXI_REG_DATA)) |
| 291 | |
| 292 | #define FLUSH_CACHE() \ |
| 293 | { \ |
| 294 | microblaze_flush_dcache(); \ |
| 295 | microblaze_invalidate_dcache(); \ |
| 296 | } |
| 297 | |
| 298 | #if(defined(AD5541A) || defined(AD5542A)) |
| 299 | #define GPIO_0_MASK 0x02 |
| 300 | #define GPIO_1_MASK 0x01 |
| 301 | #define GPIO_2_MASK 0x04 |
| 302 | #define GPIO_3_MASK 0x08 |
| 303 | #else |
| 304 | #if (defined(AD5760) || defined(AD5780) || defined(AD5781) || defined(AD5790) || defined(AD5791)) |
| 305 | #define GPIO_2_MASK 0x04 |
| 306 | #define GPIO_3_MASK 0x02 |
| 307 | #define GPIO_4_MASK 0x01 |
| 308 | #else |
| 309 | #define GPIO_0_MASK 0x01 |
| 310 | #define GPIO_1_MASK 0x02 |
| 311 | #define GPIO_2_MASK 0x04 |
| 312 | #define GPIO_3_MASK 0x08 |
| 313 | #define GPIO_4_MASK 0x10 |
| 314 | #define GPIO_5_MASK 0x20 |
| 315 | #define GPIO_6_MASK 0x40 |
| 316 | #define GPIO_7_MASK 0x80 |
| 317 | #endif |
| 318 | #endif |
| 319 | |
| 320 | /* GPIO[0] */ |
| 321 | #define GPIO0_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_0_MASK) |
| 322 | #define GPIO0_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_0_MASK) |
| 323 | #define GPIO0_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_0_MASK) |
| 324 | #define GPIO0_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_0_MASK) |
| 325 | |
| 326 | /* GPIO[1] */ |
| 327 | #define GPIO1_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_1_MASK) |
| 328 | #define GPIO1_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_1_MASK) |
| 329 | #define GPIO1_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_1_MASK) |
| 330 | #define GPIO1_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_1_MASK) |
| 331 | |
| 332 | /* GPIO[2] */ |
| 333 | #define GPIO2_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_2_MASK) |
| 334 | #define GPIO2_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_2_MASK) |
| 335 | #define GPIO2_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_2_MASK) |
| 336 | #define GPIO2_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_2_MASK) |
| 337 | |
| 338 | /* GPIO[3] */ |
| 339 | #define GPIO3_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_3_MASK) |
| 340 | #define GPIO3_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_3_MASK) |
| 341 | #define GPIO3_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_3_MASK) |
| 342 | #define GPIO3_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_3_MASK) |
| 343 | |
| 344 | /* GPIO[4] */ |
| 345 | #define GPIO4_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_4_MASK) |
| 346 | #define GPIO4_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_4_MASK) |
| 347 | #define GPIO4_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_4_MASK) |
| 348 | #define GPIO4_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_4_MASK) |
| 349 | |
| 350 | /* GPIO[5] */ |
| 351 | #define GPIO5_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_5_MASK) |
| 352 | #define GPIO5_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_5_MASK) |
| 353 | #define GPIO5_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_5_MASK) |
| 354 | #define GPIO5_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_5_MASK) |
| 355 | |
| 356 | /* GPIO[6] */ |
| 357 | #define GPIO6_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_6_MASK) |
| 358 | #define GPIO6_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_6_MASK) |
| 359 | #define GPIO6_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_6_MASK) |
| 360 | #define GPIO6_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_6_MASK) |
| 361 | |
| 362 | /* GPIO[7] */ |
| 363 | #define GPIO7_PIN_OUT GPIO_SET_PINS_OUT(GPIO_BASEADDR, GPIO_7_MASK) |
| 364 | #define GPIO7_PIN_IN GPIO_SET_PINS_IN(GPIO_BASEADDR, GPIO_7_MASK) |
| 365 | #define GPIO7_LOW GPIO_CLEAR_BITS(GPIO_BASEADDR, GPIO_7_MASK) |
| 366 | #define GPIO7_HIGH GPIO_SET_BITS(GPIO_BASEADDR, GPIO_7_MASK) |
| 367 | |
| 368 | /*****************************************************************************/ |
| 369 | /*************************** Types Declarations ******************************/ |
| 370 | /*****************************************************************************/ |
| 371 | typedef enum |
| 372 | { |
| 373 | XILINX_KC705 = 1 |
| 374 | }platformBoard; |
| 375 | |
| 376 | /*****************************************************************************/ |
| 377 | /************************* Variables Declarations ****************************/ |
| 378 | /*****************************************************************************/ |
| 379 | u32 SPI_BASEADDR; |
| 380 | u32 I2C_BASEADDR; |
| 381 | u32 GPIO_BASEADDR; |
| 382 | u32 PAR_BASEADDR; |
| 383 | u32 UART_BAUDRATE; |
| 384 | |
| 385 | /*****************************************************************************/ |
| 386 | /************************* Functions Declarations ****************************/ |
| 387 | /*****************************************************************************/ |
| 388 | /* Initializes the selected platform. */ |
| 389 | char PLATFORM_Init(platformBoard); |
| 390 | |
| 391 | /* Initializes the SPI communication peripheral. */ |
| 392 | char SPI_Init(unsigned char lsbFirst, |
| 393 | unsigned long clockFreq, |
| 394 | unsigned char clockPol, |
| 395 | unsigned char clockEdg); |
| 396 | |
| 397 | /* Writes multiple bytes to SPI. */ |
| 398 | char SPI_Write(unsigned char slaveDeviceId, |
| 399 | unsigned char* data, |
| 400 | unsigned char bytesNumber); |
| 401 | |
| 402 | /* Reads multiple bytes from SPI. */ |
| 403 | char SPI_Read(unsigned char slaveDeviceId, |
| 404 | unsigned char* data, |
| 405 | unsigned char bytesNumber); |
| 406 | |
| 407 | /* Initializes the UART communication peripheral. */ |
| 408 | char UART_Init(unsigned long baudRate); |
| 409 | |
| 410 | /* Reads one character from UART.. */ |
| 411 | void UART_ReadChar(char* data); |
| 412 | |
| 413 | /* Writes one character to UART. */ |
| 414 | void UART_WriteChar(char data); |
| 415 | |
| 416 | /* Writes one character string to UART. */ |
| 417 | void UART_WriteString(const char* string); |
| 418 | |
| 419 | /* Initializes the I2C communication peripheral. */ |
| 420 | unsigned char I2C_Init(unsigned long clockFreq); |
| 421 | |
| 422 | /* Reads data from a slave device. */ |
| 423 | unsigned char I2C_Read(unsigned char slaveAddress, |
| 424 | unsigned char* dataBuffer, |
| 425 | unsigned char bytesNumber, |
| 426 | unsigned char stopBit); |
| 427 | |
| 428 | /* Writes data to a slave device. */ |
| 429 | unsigned char I2C_Write(unsigned char slaveAddress, |
| 430 | unsigned char* dataBuffer, |
| 431 | unsigned char bytesNumber, |
| 432 | unsigned char stopBit); |
| 433 | |
| 434 | #endif /*_COMMUNICATION_H_*/ |