Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/AD2S1205/ad2s1205.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file ad2s1205.c
3 * @brief Implementation of ad2s1205 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 "AD2S1205.h"
46 #include "Communication.h"
47 #include "TIME.h"
48
49 /******************************************************************************/
50 /*************************** Functions Definitions ****************************/
51 /******************************************************************************/
52
53 /**************************************************************************//**
54 * @brief Initializes the parallel communication with the device.
55 *
56 * @param None.
57 *
58 * @return 0 = SUCCES.
59 ******************************************************************************/
60 char AD2S1205_Init(void)
61 {
62 /* Initialize PARALLEL output pins */
63 GPIO_SET_PINS_OUT(PAR_BASEADDR, (PAR_SAMPLE | PAR_RDVEL | PAR_CS | PAR_RD));
64 GPIO_SET_BITS(PAR_BASEADDR, (PAR_SAMPLE | PAR_RDVEL | PAR_CS | PAR_RD));
65
66 return 0;
67 }
68
69 /**************************************************************************//**
70 * @brief Reads the position and velocity information through parallel port.
71 *
72 * @param *position - pointer to position information;
73 * *velocity - pointer to velocity information.
74 *
75 * @return None.
76 ******************************************************************************/
77 void AD2S1205_Pos_Vel(unsigned short* position, short* velocity)
78 {
79 /* Set /SAMPLE signal low */
80 GPIO_CLEAR_BITS(PAR_BASEADDR, PAR_SAMPLE);
81 /* Wait t2 */
82 TIME_DelayNs(T2);
83 /* Set /SAMPLE signal high */
84 GPIO_SET_BITS(PAR_BASEADDR, PAR_SAMPLE);
85 /* Set RD/CS low */
86 GPIO_CLEAR_BITS(PAR_BASEADDR, (PAR_RD | PAR_CS));
87 /* Wait t6 */
88 TIME_DelayNs(T6);
89 /* Set RDVEL low */
90 GPIO_CLEAR_BITS(PAR_BASEADDR, PAR_RDVEL);
91 /* Read the position */
92 *position = (GPIO_GET_DATA(PAR_BASEADDR) & PAR_DATA_MASK) >> 6;
93 /* Set RD high */
94 GPIO_SET_BITS(PAR_BASEADDR, PAR_RD);
95 /* Wait t3 */
96 TIME_DelayNs(T3);
97 /* Set RD low */
98 GPIO_CLEAR_BITS(PAR_BASEADDR, PAR_RD);
99 /* Wait t6 */
100 TIME_DelayNs(T6);
101 /* Read the velocity */
102 *velocity = (GPIO_GET_DATA(PAR_BASEADDR) & PAR_DATA_MASK) >> 6;
103 if(*velocity >= 2048)
104 {
105 *velocity = *velocity - 4096;
106 }
107 /* Set RDVEL high */
108 GPIO_SET_BITS(PAR_BASEADDR, PAR_RDVEL);
109 /* Set RD/CS high */
110 GPIO_SET_BITS(PAR_BASEADDR, (PAR_RD | PAR_CS));
111 }