Analog Devices / mbed-drivers
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AD5270_Diag.cpp Source File

AD5270_Diag.cpp

00001 /**
00002 *   @file     ad5270_diag.cpp
00003 *   @brief    Source file for the AD5270 wrapper used by the driver diag
00004 *   @author   Analog Devices Inc.
00005 *
00006 * For support please go to:
00007 * Github: https://github.com/analogdevicesinc/mbed-adi
00008 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
00009 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
00010 
00011 ********************************************************************************
00012 * Copyright 2016(c) Analog Devices, Inc.
00013 *
00014 * All rights reserved.
00015 *
00016 * Redistribution and use in source and binary forms, with or without
00017 * modification, are permitted provided that the following conditions are met:
00018 *  - Redistributions of source code must retain the above copyright
00019 *    notice, this list of conditions and the following disclaimer.
00020 *  - Redistributions in binary form must reproduce the above copyright
00021 *    notice, this list of conditions and the following disclaimer in
00022 *    the documentation and/or other materials provided with the
00023 *    distribution.
00024 *  - Neither the name of Analog Devices, Inc. nor the names of its
00025 *    contributors may be used to endorse or promote products derived
00026 *    from this software without specific prior written permission.
00027 *  - The use of this software may or may not infringe the patent rights
00028 *    of one or more patent holders.  This license does not release you
00029 *    from the requirement that you obtain separate licenses from these
00030 *    patent holders to use this software.
00031 *  - Use of the software either in source or binary form, must be run
00032 *    on or directly connected to an Analog Devices Inc. component.
00033 *
00034 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
00035 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
00036 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00037 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
00038 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00039 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
00040 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00041 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00042 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00043 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00044 *
00045 ********************************************************************************/
00046 
00047 #include "mbed.h"
00048 #include <stdio.h>
00049 #include <vector>
00050 #include <string>
00051 #include "AD5270_Diag.h"
00052 
00053 extern Serial pc;
00054 extern vector<string> cmdbuffer;
00055 
00056 AD5270_Diag::AD5270_Diag(AD5270& ad) : dut(ad)
00057 {
00058 
00059 }
00060 void AD5270_Diag::enable_50TP_programming()
00061 {
00062     dut.enable_50TP_programming();
00063     pc.printf("Enabled 50TP prog");
00064 
00065 }
00066 void AD5270_Diag::store_50TP()
00067 {
00068     dut.store_50TP();
00069     pc.printf("50TP stored");
00070 }
00071 void AD5270_Diag::disable_50TP_programming()
00072 {
00073     dut.disable_50TP_programming();
00074     pc.printf("Disabled 50TP prog");
00075 }
00076 
00077 void AD5270_Diag::write_RDAC()
00078 {
00079     float res = strtof(cmdbuffer[1].c_str(), NULL);
00080     dut.write_RDAC(res);
00081     pc.printf("Wrote %f", res);
00082 }
00083 void AD5270_Diag::read_RDAC()
00084 {
00085     pc.printf("Read %f", dut.read_RDAC());
00086 }
00087 void AD5270_Diag::write_cmd()
00088 {
00089     uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
00090     uint8_t regVal = strtol(cmdbuffer[2].c_str(), NULL, 16);
00091     pc.printf("Returned %x: ", dut.write_cmd(reg, regVal));
00092 }
00093 
00094 void AD5270_Diag::set_HiZ()
00095 {
00096     pc.printf("SDO set to HiZ");
00097     dut.set_SDO_HiZ();
00098 }
00099 
00100 void AD5270_Diag::read_50TP_last_address(void)
00101 {
00102     pc.printf("Returned %x:", dut.read_50TP_last_address());
00103 }
00104 void AD5270_Diag::read_50TP_memory(void)
00105 {
00106     uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
00107     pc.printf("Returned %x", dut.read_50TP_memory(reg));
00108 }
00109 
00110 void AD5270_Diag::write_ctrl_reg(void)
00111 {
00112     uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
00113     dut.write_ctrl_reg(val);
00114     pc.printf("Wrote %x to ctrl_reg", val );
00115 }
00116 void AD5270_Diag::read_ctrl_reg(void)
00117 {
00118     pc.printf("Read %x from ctrl_reg", dut.read_ctrl_reg());
00119 }
00120 
00121 void AD5270_Diag::reset_RDAC(void)
00122 {
00123     dut.reset_RDAC();
00124     pc.printf("Resetted rdac");
00125 }
00126 void AD5270_Diag::change_mode(void)
00127 {
00128     uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
00129     dut.change_mode(static_cast<AD5270::AD5270Modes_t>(val));
00130     pc.printf("Changed mode to %x", val);
00131 }
00132 
00133 void AD5270_Diag::write_wiper_reg(void)
00134 {
00135     uint16_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
00136     dut.write_wiper_reg(val);
00137     pc.printf("Wrote %x to wiper", val);
00138 }
00139 void AD5270_Diag::read_wiper_reg(void)
00140 {
00141     pc.printf("Read %x from wiper", dut.read_wiper_reg());
00142 }