Debian Codegraph @

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

raw symbols SCIP
1 /**************************************************************************//**
2 * @file Commanad.c
3 * @brief Implementation of the commands given by user through UART for CN0187.
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 "Command.h"
46 #include "Console.h"
47 #include "ad7266.h"
48 #include "TIME.h"
49
50 /******************************************************************************/
51 /************************ Constants Definitions *******************************/
52 /******************************************************************************/
53
54 const struct cmd_info cmdList[] = {
55 [0] = {
56 .name = "help?",
57 .description = "Displays all available commands.",
58 .acceptedValue = "",
59 .example = "",
60 },
61 [1] = {
62 .name = "data?",
63 .description = "Displays VRMS Code and Peak Code.",
64 .acceptedValue = "",
65 .example = "",
66 },
67 };
68
69 const char cmdNo = (sizeof(cmdList) / sizeof(struct cmd_info));
70
71 /******************************************************************************/
72 /************************ Variables Definitions *******************************/
73 /******************************************************************************/
74 cmdFunction cmdFunctions[] = {GetHelp, GetData};
75
76 /* Variables holding information about the device */
77 unsigned long ctrl = 0x0; /* control dword for ADC;
78 (VA1,VA2) and (VB1,VB2) - fully differential).*/
79
80 /***************************************************************************//**
81 * @brief Displays all available commands.
82 *
83 * @return None.
84 *******************************************************************************/
85 void GetHelp(double* param, char paramNo) // "help?" command
86 {
87 unsigned char displayCmd;
88
89 CONSOLE_Print("Available commands:\r\n");
90 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
91 {
92 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[displayCmd].name,
93 (char*)cmdList[displayCmd].description,
94 (char*)cmdList[displayCmd].acceptedValue);
95 }
96 }
97
98 /***************************************************************************//**
99 * @brief Internal function for displaying all the command with its description.
100 *
101 * @return None.
102 *******************************************************************************/
103 void DisplayCmdList()
104 {
105 unsigned char displayCmd;
106
107 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
108 {
109 CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \
110 (char*)cmdList[displayCmd].description);
111 }
112 }
113
114 /***************************************************************************//**
115 * @brief Displays error message.
116 *
117 * @return None.
118 *******************************************************************************/
119 void DisplayError(unsigned char funcNo)
120 {
121 /* Display error messages */
122 CONSOLE_Print("Invalid parameter!\r\n");
123 CONSOLE_Print("%s - %s %s\r\n", (char*)cmdList[funcNo].name, \
124 (char*)cmdList[funcNo].description, \
125 (char*)cmdList[funcNo].acceptedValue);
126 CONSOLE_Print("Example: %s\r\n", (char*)cmdList[funcNo].example);
127 }
128
129 /***************************************************************************//**
130 * @brief Initializes the device.
131 *
132 * @return - The result of the initialization.
133 * Example: ERROR - the device was not initialized or the device
134 * is not present.
135 * SUCCES - the device was initialized and the device
136 * is present.
137 *******************************************************************************/
138 char DoDeviceInit(void)
139 {
140 if(ad7266_Init() == 0)
141 {
142 AD7266_CNTL_OUT;
143 AD7266_CNTL_LOW;
144 CONSOLE_Print("Device OK\r\n");
145 DisplayCmdList();
146 return SUCCESS;
147 }
148 else
149 {
150 CONSOLE_Print("Device Error\r\n");
151 return ERROR;
152 }
153 }
154
155
156 /***************************************************************************//**
157 * @brief Displays VRMS Code and Peak Code.
158 *
159 * @return None.
160 *******************************************************************************/
161 void GetData(double* param, char paramNo) // "data?" command
162 {
163 unsigned long data = 0;
164 unsigned short vrmsData = 0;
165 unsigned short peakData = 0;
166
167 AD7266_CNTL_HIGH;
168 TIME_DelayUs(5);
169 AD7266_CNTL_LOW;
170 data = ad7266_Read32Bits(ctrl);
171 vrmsData = (data & 0x3FFC0000) >> 18;
172 peakData = (data & 0x00003FFC) >> 2;
173
174 /* Send feedback to user */
175 CONSOLE_Print("VRMS Code=%d. \r\n", vrmsData);
176 CONSOLE_Print("Peak Code=%d. \r\n", peakData);
177 }