| 1 | /***************************************************************************//** |
| 2 | * @file ad7091.h |
| 3 | * @brief Header file of ADC core driver for AD7091. |
| 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 _AD7091_H_ |
| 41 | #define _AD7091_H_ |
| 42 | |
| 43 | /*****************************************************************************/ |
| 44 | /******************* Macros and Constants Definitions ************************/ |
| 45 | /*****************************************************************************/ |
| 46 | |
| 47 | /* Register Map - Offset from the Base Address */ |
| 48 | // General registers |
| 49 | #define AD7091_REG_VERSION 0x0000 |
| 50 | #define AD7091_REG_ID 0x0004 |
| 51 | #define AD7091_REG_SCRATCH 0x0008 |
| 52 | |
| 53 | // ADC Common Type |
| 54 | #define AD7091_REG_RSTN 0x0040 // RW |
| 55 | #define AD7091_REG_CNTRL 0x0044 // RW |
| 56 | #define AD7091_REG_CLK_FREQ 0x0054 // RO |
| 57 | #define AD7091_REG_CLK_RATIO 0x0058 // RO |
| 58 | #define AD7091_REG_STATUS 0x005C // RO |
| 59 | #define AD7091_REG_DELAY_CNTRL 0x0060 // RW |
| 60 | #define AD7091_REG_DELAY_STATUS 0x0064 // RO |
| 61 | #define AD7091_REG_DRP_CNTRL 0x0070 // RW |
| 62 | #define AD7091_REG_DRP_STATUS 0x0074 // RO |
| 63 | #define AD7091_REG_DMA_CNTRL 0x0080 // RW |
| 64 | #define AD7091_REG_DMA_COUNT 0x0084 // RW |
| 65 | #define AD7091_REG_DMA_STATUS 0x0088 // RW1C |
| 66 | #define AD7091_REG_DMA_BUSWIDTH 0x008C // RO |
| 67 | #define AD7091_REG_USR_CNTRL_1 0x00A0 // RW |
| 68 | #define AD7091_REG_USR_CNTRL_2 0x00C0 // RO |
| 69 | |
| 70 | // Definition of register AD7091_REG_RSTN |
| 71 | #define ADC_MMCM_RSTN (1 << 0x01) |
| 72 | #define ADC_RSTN (1 << 0x00) |
| 73 | |
| 74 | // Definition of register AD7091_REG_CNTRL |
| 75 | #define ADC_R1_MODE (1 << 0x02) |
| 76 | #define ADC_DDR_EDGESEL (1 << 0x01) |
| 77 | #define ADC_PIN_MODE (1 << 0x00) |
| 78 | |
| 79 | // Definition of register AD7091_REG_STATUS |
| 80 | #define ADC_PN_ERR (1 << 0x03) |
| 81 | #define ADC_PN_OOS (1 << 0x02) |
| 82 | #define ADC_OVER_RANGE (1 << 0x01) |
| 83 | #define ADC_STATUS (1 << 0x00) |
| 84 | |
| 85 | // Definition of register AD7091_REG_DELAY_CNTRL |
| 86 | #define ADC_DELAY_SEL (1 << 0x11) |
| 87 | #define ADC_DELAY_RWN (1 << 0x10) |
| 88 | #define ADC_DELAY_ADDRESS (1 << 0x08) |
| 89 | #define ADC_DELAY_WDATA (1 << 0x00) |
| 90 | |
| 91 | #define ADC_DELAY_ADDRESS_MASK 0x00FF |
| 92 | #define ADC_DELAY_WDATA_MASK 0x001F |
| 93 | |
| 94 | // Definition of register AD7091_REG_DELAY_STATUS |
| 95 | #define ADC_DELAY_LOCKED (1 << 0x09) |
| 96 | #define ADC_DELAY_STATUS (1 << 0x08) |
| 97 | #define ADC_DELAY_RDATA (1 << 0x00) |
| 98 | |
| 99 | #define ADC_DELAY_RDATA_MASK 0x001F |
| 100 | |
| 101 | // Definition of register AD7091_REG_DRP_CNTRL |
| 102 | #define ADC_DRP_RWN (1 << 0x1C) |
| 103 | #define ADC_DRP_ADDRESS (1 << 0x10) |
| 104 | #define ADC_DRP_WDATA (1 << 0x00) |
| 105 | |
| 106 | #define ADC_DRP_ADDRESS_MASK 0x0FFF |
| 107 | #define ADC_DRP_DATA_MASK 0xFFFF |
| 108 | |
| 109 | // Definition of register AD7091_REG_DRP_STATUS |
| 110 | #define ADC_DRP_STATUS (1 << 0x10) |
| 111 | #define ADC_DRP_RDATA (1 << 0x00) |
| 112 | |
| 113 | // Definition of register AD7091_REG_DMA_CNTRL |
| 114 | #define ADC_DMA_STREAM (1 << 0x01) |
| 115 | #define ADC_DMA_START (1 << 0x00) |
| 116 | |
| 117 | // Definition of register AD7091_REG_STATUS |
| 118 | #define ADC_DMA_OVF (1 << 0x02) |
| 119 | #define ADC_DMA_UNF (1 << 0x01) |
| 120 | #define ADC_DMA_STATUS (1 << 0x00) |
| 121 | |
| 122 | // Definition of register AD7091_REG_USER_CNTRL_1 |
| 123 | #define ADC_USR_CHANMAX (1 << 0x00) |
| 124 | #define ADC_USR_CHANMAX_MASK 0x00FF |
| 125 | |
| 126 | // Definition of register AD7091_REG_USER_CNTRL_2 |
| 127 | #define ADC_DP_DISABLE (1 << 0x00) |
| 128 | |
| 129 | #define BUS_WIDTH 4 |
| 130 | |
| 131 | /*****************************************************************************/ |
| 132 | /************************* Functions Declarations ****************************/ |
| 133 | /*****************************************************************************/ |
| 134 | // Initialization |
| 135 | void AD7091_Init(unsigned int baseAddress); |
| 136 | |
| 137 | // Functions for register access |
| 138 | void AD7091_SetRegister(unsigned int address, unsigned int data); |
| 139 | unsigned int AD7091_GetRegister(unsigned int address); |
| 140 | |
| 141 | // Initiate data acquisition |
| 142 | unsigned int AD7091_GetData(unsigned int size); |
| 143 | |
| 144 | #endif /* _AD7091_H_ */ |