| 1 | /**************************************************************************//** |
| 2 | * @file spi_interface.h |
| 3 | * @brief SPI interfrace header file. |
| 4 | * @author acozma ([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 | |
| 44 | #ifndef __SPI_INTERFACE_H__ |
| 45 | #define __SPI_INTERFACE_H__ |
| 46 | |
| 47 | /*****************************************************************************/ |
| 48 | /***************************** Include Files *********************************/ |
| 49 | /*****************************************************************************/ |
| 50 | #include <stdint.h> |
| 51 | |
| 52 | /*****************************************************************************/ |
| 53 | /************************** Types Declarations *******************************/ |
| 54 | /*****************************************************************************/ |
| 55 | typedef struct _stDevConfig |
| 56 | { |
| 57 | uint32_t addrWidth; /*!< Registers address width in bits */ |
| 58 | uint32_t dataWidth; /*!< Data width in bits */ |
| 59 | uint32_t spiConfig; /*!< SPI configuration */ |
| 60 | uint32_t spiCS; /*!< SPI CS value */ |
| 61 | } stDevConfig; |
| 62 | |
| 63 | /*****************************************************************************/ |
| 64 | /******************* I2C Addesses and SPI settings ***************************/ |
| 65 | /*****************************************************************************/ |
| 66 | /* IIC addresses */ |
| 67 | #define IICSEL_XCOMM 0x20 |
| 68 | #define IICSEL_PIC_0 0x59 |
| 69 | #define IICSEL_PIC_1 0x58 |
| 70 | |
| 71 | /* SPI selections*/ |
| 72 | #define SPI_SEL_AD9122 0x00 |
| 73 | #define SPI_SEL_AD9643 0x01 |
| 74 | #define SPI_SEL_AD9548 0x02 |
| 75 | #define SPI_SEL_AD9523 0x03 |
| 76 | #define SPI_SEL_ADF4351_RX 0x04 |
| 77 | #define SPI_SEL_ADF4351_TX 0x05 |
| 78 | #define SPI_SEL_AD8366 0x06 |
| 79 | |
| 80 | /* PIC control words*/ |
| 81 | #define REV_READ 0x01 |
| 82 | #define CTRL_WRITE 0x03 |
| 83 | #define DATA_WRITE 0x04 |
| 84 | |
| 85 | /* PIC Firmware Revision Size */ |
| 86 | #define PIC_FW_REV_LEN 32 |
| 87 | |
| 88 | /* SPI configuration options */ |
| 89 | #define SPI_RX_TRANSFER_CNT(x) ((x) << 10) |
| 90 | #define SPI_3_WIRE_MODE (1 << 6) |
| 91 | #define SPI_4_WIRE_MODE (0 << 6) |
| 92 | #define SPI_CS_HIGH_AT_TRANFER_END (1 << 5) |
| 93 | #define SPI_CS_LOW_AT_TRANFER_END (0 << 5) |
| 94 | #define SPI_SAMPLE_AT_CLK_END (1 << 4) |
| 95 | #define SPI_SAMPLE_AT_CLK_MIDDLE (0 << 4) |
| 96 | #define SPI_TX_ON_CLK_FALL (1 << 3) |
| 97 | #define SPI_TX_ON_CLK_RISE (0 << 3) |
| 98 | #define SPI_CLK_IDLE_HIGH (1 << 2) |
| 99 | #define SPI_CLK_IDLE_LOW (0 << 2) |
| 100 | #define SPI_CLK_INVALID 0x03 |
| 101 | #define SPI_CLK_FOSC_DIV_64 0x02 |
| 102 | #define SPI_CLK_FOSC_DIV_16 0x01 |
| 103 | #define SPI_CLK_FOSC_DIV_4 0x00 |
| 104 | |
| 105 | /*****************************************************************************/ |
| 106 | /************************ Functions Declarations *****************************/ |
| 107 | /*****************************************************************************/ |
| 108 | /** Reads the PIC firmware version */ |
| 109 | int32_t PIC_ReadFwVersion(); |
| 110 | /** Initializes the communication with the PIC */ |
| 111 | int32_t SPI_Init(uint32_t fmcPort, uint32_t enableCommMux, uint32_t ps7I2C, |
| 112 | uint32_t carrierBoard); |
| 113 | /** Reads data from the selected device */ |
| 114 | int32_t SPI_Read(uint32_t spiSel, uint32_t regAddr, uint32_t* data); |
| 115 | /** Writes data to the selected device */ |
| 116 | int32_t SPI_Write(uint32_t spiSel, uint32_t regAddr, uint32_t data); |
| 117 | |
| 118 | #endif /* __SPI_INTERFACE_H__ */ |