Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/AD5111/AD5111.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file AD5111.c
3 * @brief Implementation of AD5111 Driver for Microblaze processor.
4 * @author Lucian Sin ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2013(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
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include "AD5111.h"
46 #include "Communication.h"
47 #include "TIME.h"
48
49 /******************************************************************************/
50 /*************************** Macros Definitions *******************************/
51 /******************************************************************************/
52 #define CS 1 // Chip select pin from Up/Down interface.
53 #define UnD 2 // Direction pin from Up/Down interface.
54 #define CLK 4 // Clock pin from Up/Down interface.
55
56 /******************************************************************************/
57 /************************* Functions Definitions ******************************/
58 /******************************************************************************/
59
60 /***************************************************************************//**
61 * @brief Increases the resistor value with one step.
62 *
63 * @param none.
64 *
65 * @return none.
66 *******************************************************************************/
67 void incValue(void)
68 {
69 GPIO_CLEAR_BITS(GPIO_BASEADDR, CLK);
70 GPIO_SET_BITS(GPIO_BASEADDR, UnD);
71 GPIO_CLEAR_BITS(GPIO_BASEADDR, CS);
72
73 GPIO_SET_BITS(GPIO_BASEADDR, CLK);
74 GPIO_CLEAR_BITS(GPIO_BASEADDR, CLK);
75 GPIO_SET_BITS(GPIO_BASEADDR, CLK);
76
77 GPIO_SET_BITS(GPIO_BASEADDR, CS);
78 TIME_DelayUs(1);
79 }
80 /***************************************************************************//**
81 * @brief Decreases the resistor value with one step.
82 *
83 * @param none.
84 *
85 * @return none.
86 *******************************************************************************/
87 void decValue(void)
88 {
89 GPIO_CLEAR_BITS(GPIO_BASEADDR, CLK);
90 GPIO_CLEAR_BITS(GPIO_BASEADDR, UnD);
91 GPIO_CLEAR_BITS(GPIO_BASEADDR, CS);
92
93 GPIO_SET_BITS(GPIO_BASEADDR, CLK);
94 GPIO_CLEAR_BITS(GPIO_BASEADDR, CLK);
95 GPIO_SET_BITS(GPIO_BASEADDR, CLK);
96
97 GPIO_SET_BITS(GPIO_BASEADDR, CS);
98 TIME_DelayUs(1);
99 }
100
101 /***************************************************************************//**
102 * @brief Device enters in shutdown mode.
103 *
104 * @param none.
105 *
106 * @return none.
107 *******************************************************************************/
108 void shutDown(void)
109 {
110 GPIO_CLEAR_BITS(GPIO_BASEADDR, UnD);
111 GPIO_SET_BITS(GPIO_BASEADDR, CLK);
112 GPIO_CLEAR_BITS(GPIO_BASEADDR, CS);
113 GPIO_SET_BITS(GPIO_BASEADDR, UnD);
114 GPIO_CLEAR_BITS(GPIO_BASEADDR, CLK);
115 }
116
117 /***************************************************************************//**
118 * @brief Device memorizes the current RDAC value in EEPROM.
119 *
120 * @param none.
121 *
122 * @return none.
123 *******************************************************************************/
124 void saveMem(void)
125 {
126 GPIO_CLEAR_BITS(GPIO_BASEADDR, UnD);
127 GPIO_SET_BITS(GPIO_BASEADDR, CLK);
128 GPIO_CLEAR_BITS(GPIO_BASEADDR, CS);
129 GPIO_SET_BITS(GPIO_BASEADDR, UnD);
130 GPIO_CLEAR_BITS(GPIO_BASEADDR, UnD);
131 TIME_DelayMs(20);
132 }
133
134 /***************************************************************************//**
135 * @brief Initializes the communication with the device.
136 *
137 * @param none.
138 *
139 * @return status - Result of the initialization procedure.
140 * Example: 0 - if initialization was successful;
141 * -1 - if initialization was unsuccessful.
142 *******************************************************************************/
143 unsigned char AD5111_Init(void)
144 {
145 unsigned char status = 0;
146
147 // Set GPIO0, GPIO1 and GPIO2 as outputs
148 GPIO_SET_PINS_OUT(GPIO_BASEADDR, 0x7);
149
150 return status;
151 }