Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/Microchip/PIC32MX320F128H/PmodAD4/Command.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Command.c
3 * @brief Implementation of the commands given by user through UART for PmodAD4.
4 * @author DNechita ([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
41 /******************************************************************************/
42 /***************************** Include Files **********************************/
43 /******************************************************************************/
44 #include "Command.h"
45 #include "AD7980.h"
46 #include "Console.h"
47
48 /******************************************************************************/
49 /************************ Constants Definitions *******************************/
50 /******************************************************************************/
51 /*!< List of available commands */
52 const char* cmdList[] = {"help?",
53 "voltage?",
54 "register?"};
55 const char* cmdDescription[] = {
56 " - Diplays all available commands.",
57 " - Initiates a conversion and displays the captured voltage.",
58 " - Initiates a conversion and displays the data register in decimal format."};
59
60 const char* cmdExample[] = {
61 "",
62 "",
63 ""};
64 const char cmdNo = (sizeof(cmdList) / sizeof(const char*));
65 const float VREF = 2.5; /*!< VREF = 2.5V */
66
67 /******************************************************************************/
68 /************************ Variables Definitions *******************************/
69 /******************************************************************************/
70 cmdFunction cmdFunctions[3] = {GetHelp, GetVoltage, GetRegister};
71
72 /*!< Variables holding information about the device */
73 unsigned short registerValue = 0; /*!< Last value captured from convertor register */
74
75 /***************************************************************************//**
76 * @brief Displays all available commands.
77 *
78 * @return None.
79 *******************************************************************************/
80 void GetHelp(double* param, char paramNo) /*!< "help?" command */
81 {
82 char displayCmd;
83
84 CONSOLE_Print("Available commands:\r\n");
85 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
86 {
87 CONSOLE_Print("%s%s\r\n", (char*)cmdList[displayCmd],
88 (char*)cmdDescription[displayCmd]);
89 }
90 }
91
92 /***************************************************************************//**
93 * @brief Initializes the device.
94 *
95 * @return - The result of the initialization.
96 * Example: ERROR - the device was not initialized or the device
97 * is not present.
98 * SUCCES - the device was initialized and the device
99 * is present.
100 *******************************************************************************/
101 char DoDeviceInit(void)
102 {
103 if(AD7980_Init() == 0)
104 {
105 CONSOLE_Print("AD7980 OK\r\n");
106 GetHelp(NULL, 0);
107 return SUCCESS;
108 }
109 else
110 {
111 CONSOLE_Print("AD7980 Error\r\n");
112 return ERROR;
113 }
114 }
115
116 /***************************************************************************//**
117 * @brief Initiates a conversion and displays the captured voltage.
118 *
119 * @return None.
120 *******************************************************************************/
121 void GetRegister(double* param, char paramNo) /*!< "register?" command */
122 {
123 unsigned long data = 0;
124
125 /*!< Start a conversion */
126 data = AD7980_Conversion();
127 /*!< Send the requested value to user */
128 CONSOLE_Print("register=%d\r\n",data);
129 }
130
131 /***************************************************************************//**
132 * @brief Initiates a conversion and displays the data register in decimal format.
133 *
134 * @return None.
135 *******************************************************************************/
136 void GetVoltage(double* param, char paramNo) /*!< "voltage?" command */
137 {
138 unsigned long data = 0;
139 double voltage = 0;
140
141 /*!< Start a conversion */
142 data = AD7980_Conversion();
143 /*!< Get the input voltage from the straight binary raw data */
144 voltage = AD7980_ConvertToVolts(data, VREF);
145 /*!< Send the requested value to user */
146 CONSOLE_Print("voltage=%.3f [V]\r\n",voltage);
147 }