Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Command.c
3 * @brief Implementation of the commands given by user through UART for PmodTMP2.
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 "AD74xx.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 voltage captured on A0 channel.",
58 " - Initiates a conversion and displays the raw data in decimal format."};
59 const char* cmdExample[] = {
60 "",
61 "",
62 ""};
63
64 const char cmdNo = (sizeof(cmdList) / sizeof(const char*));
65 const float VDD = 3.3; /*!< VDD = 3.3V */
66 /******************************************************************************/
67 /************************ Variables Definitions *******************************/
68 /******************************************************************************/
69 cmdFunction cmdFunctions[3] = {GetHelp, GetVoltage, GetRegister};
70
71 /*!< Variables holding information about the device */
72 unsigned short registerValue = 0; /*!< Raw value of the conversion */
73
74 /***************************************************************************//**
75 * @brief Displays all available commands.
76 *
77 * @return None.
78 *******************************************************************************/
79 void GetHelp(double* param, char paramNo) /*!< "help?" command */
80 {
81 char displayCmd;
82
83 CONSOLE_Print("Available commands:\r\n");
84 for(displayCmd = 0; displayCmd < cmdNo; displayCmd++)
85 {
86 CONSOLE_Print("%s%s\r\n", (char*)cmdList[displayCmd],
87 (char*)cmdDescription[displayCmd]);
88 }
89 }
90
91 /***************************************************************************//**
92 * @brief Initializes the device.
93 *
94 * @return - The result of the initialization.
95 * Example: ERROR - the device was not initialized or the device
96 * is not present.
97 * SUCCES - the device was initialized and the device
98 * is present.
99 *******************************************************************************/
100 char DoDeviceInit(void)
101 {
102 if(AD74xx_Init(AD7476) == 0)
103 {
104 CONSOLE_Print("AD7476 OK\r\n");
105 GetHelp(NULL, 0);
106 return SUCCESS;
107 }
108 else
109 {
110 CONSOLE_Print("AD7476 Error\r\n");
111 return ERROR;
112 }
113 }
114
115 /***************************************************************************//**
116 * @brief Initiates a conversion and displays the voltage captured on A0 channel.
117 *
118 * @return None.
119 *******************************************************************************/
120 void GetVoltage(double* param, char paramNo) /*!< "voltage?" command */
121 {
122 double voltage = 0; /*!< Value of the conversion in Volts */
123 /*!< Start a conversion */
124 registerValue = AD74xx_GetRegisterValue();
125 /*!< Get the input voltage from the straight binary raw data */
126 voltage = AD74xx_ConvertToVolts(registerValue, VDD);
127 /*!< Send the requested value to user */
128 CONSOLE_Print("voltage=%.3f [V]\r\n",voltage);
129 }
130
131 /***************************************************************************//**
132 * @brief Initiates a conversion and displays the raw data in decimal format.
133 *
134 * @return None.
135 *******************************************************************************/
136 void GetRegister(double* param, char paramNo) /*!< "register?" command */
137 {
138 /*!< Start a conversion */
139 registerValue = AD74xx_GetRegisterValue();
140 /*!< Send the requested value to user */
141 CONSOLE_Print("register=%d\r\n",registerValue);
142 }