Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_commands/CN0241/Command.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file Commanad.c
3 * @brief Implementation of the commands given by user through UART for CN0241.
4 * @author Lucian Sin ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2014(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 "Command.h"
46 #include "Console.h"
47 #include "ad7920.h"
48
49 /******************************************************************************/
50 /************************ Constants Definitions *******************************/
51 /******************************************************************************/
52 const struct cmd_info cmdList[] = {
53 [0] = {
54 .name = "help?",
55 .description = "Displays all available commands.",
56 .acceptedValue = "",
57 .example = "",
58 },
59 [1] = {
60 .name = "voltage?",
61 .description = "Displays the input voltage.",
62 .acceptedValue = "",
63 .example = "",
64 },
65 [2] = {
66 .name = "adcCode?",
67 .description = "Displays the output ADC code.",
68 .acceptedValue = "",
69 .example = "",
70 },
71 };
72
73 const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info));
74 const float VREF = 5;
75 const float GAIN = 20;
76 /******************************************************************************/
77 /************************ Variables Definitions *******************************/
78 /******************************************************************************/
79 cmdFunction cmdFunctions[] = {GetHelp, GetVoltage, GetAdcCode};
80
81 /***************************************************************************//**
82 * @brief Displays all available commands.
83 *
84 * @return None.
85 *******************************************************************************/
86 void GetHelp(double* param, char paramNo) // "help?" command
87 {
88 unsigned char displayCmd;
89
90 CONSOLE_Print("Available commands:\r\n");
91 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
92 {
93 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name,
94 (char*)cmdList[displayCmd].description,
95 (char*)cmdList[displayCmd].acceptedValue);
96 }
97 }
98
99 /***************************************************************************//**
100 * @brief Internal function for displaying all the command with its description.
101 *
102 * @return None.
103 *******************************************************************************/
104 void DisplayCmdList()
105 {
106 unsigned char displayCmd;
107
108 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
109 {
110 CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \
111 (char*)cmdList[displayCmd].description);
112 }
113 }
114
115 /***************************************************************************//**
116 * @brief Displays error message.
117 *
118 * @return None.
119 *******************************************************************************/
120 void DisplayError(unsigned char funcNo)
121 {
122 /* Display error messages */
123 CONSOLE_Print("Invalid parameter!\r\n");
124 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \
125 (char*)cmdList[funcNo].description, \
126 (char*)cmdList[funcNo].acceptedValue);
127 CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example);
128 }
129
130 /***************************************************************************//**
131 * @brief Initializes the device.
132 *
133 * @return - The result of the initialization.
134 * Example: ERROR - the device was not initialized or the device
135 * is not present.
136 * SUCCES - the device was initialized and the device
137 * is present.
138 *******************************************************************************/
139 char DoDeviceInit(void)
140 {
141 if(AD7920_Init() == 0)
142 {
143 CONSOLE_Print("Device OK\r\n");
144 DisplayCmdList();
145 return SUCCESS;
146 }
147 else
148 {
149 CONSOLE_Print("Device Error\r\n");
150 return ERROR;
151 }
152 }
153
154 /***************************************************************************//**
155 * @brief Displays the input voltage in [mV].
156 *
157 * @return None.
158 *******************************************************************************/
159 void GetVoltage(double* param, char paramNo) // "voltage?" command
160 {
161 float vin = 0;
162
163 vin = ad7920_GetVoltage(VREF);
164 vin = (vin / GAIN) * 1000;
165
166 /* Send feedback to user */
167 CONSOLE_Print("Voltage=%.3f[mV].\r\n", vin);
168 }
169
170 /***************************************************************************//**
171 * @brief Displays the output ADC code.
172 *
173 * @return None.
174 *******************************************************************************/
175 void GetAdcCode(double* param, char paramNo) // "adcCode?" command
176 {
177 unsigned short adcCode = 0;
178
179 adcCode = ad7920_GetAdcCode();
180 /* Send feedback to user */
181 CONSOLE_Print("ADC Code=%d.\r\n", adcCode);
182 }