A collection of Analog Devices drivers for the mbed platform

For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all

Committer:
Adrian Suciu
Date:
Wed May 18 16:57:57 2016 +0300
Revision:
24:dae7123d432a
Improved compatibility with Linux systems

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Adrian Suciu 24:dae7123d432a 1 /**
Adrian Suciu 24:dae7123d432a 2 * @file ad5270_diag.cpp
Adrian Suciu 24:dae7123d432a 3 * @brief Source file for the AD5270 wrapper used by the driver diag
Adrian Suciu 24:dae7123d432a 4 * @author Analog Devices Inc.
Adrian Suciu 24:dae7123d432a 5 *
Adrian Suciu 24:dae7123d432a 6 * For support please go to:
Adrian Suciu 24:dae7123d432a 7 * Github: https://github.com/analogdevicesinc/mbed-adi
Adrian Suciu 24:dae7123d432a 8 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
Adrian Suciu 24:dae7123d432a 9 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
Adrian Suciu 24:dae7123d432a 10
Adrian Suciu 24:dae7123d432a 11 ********************************************************************************
Adrian Suciu 24:dae7123d432a 12 * Copyright 2016(c) Analog Devices, Inc.
Adrian Suciu 24:dae7123d432a 13 *
Adrian Suciu 24:dae7123d432a 14 * All rights reserved.
Adrian Suciu 24:dae7123d432a 15 *
Adrian Suciu 24:dae7123d432a 16 * Redistribution and use in source and binary forms, with or without
Adrian Suciu 24:dae7123d432a 17 * modification, are permitted provided that the following conditions are met:
Adrian Suciu 24:dae7123d432a 18 * - Redistributions of source code must retain the above copyright
Adrian Suciu 24:dae7123d432a 19 * notice, this list of conditions and the following disclaimer.
Adrian Suciu 24:dae7123d432a 20 * - Redistributions in binary form must reproduce the above copyright
Adrian Suciu 24:dae7123d432a 21 * notice, this list of conditions and the following disclaimer in
Adrian Suciu 24:dae7123d432a 22 * the documentation and/or other materials provided with the
Adrian Suciu 24:dae7123d432a 23 * distribution.
Adrian Suciu 24:dae7123d432a 24 * - Neither the name of Analog Devices, Inc. nor the names of its
Adrian Suciu 24:dae7123d432a 25 * contributors may be used to endorse or promote products derived
Adrian Suciu 24:dae7123d432a 26 * from this software without specific prior written permission.
Adrian Suciu 24:dae7123d432a 27 * - The use of this software may or may not infringe the patent rights
Adrian Suciu 24:dae7123d432a 28 * of one or more patent holders. This license does not release you
Adrian Suciu 24:dae7123d432a 29 * from the requirement that you obtain separate licenses from these
Adrian Suciu 24:dae7123d432a 30 * patent holders to use this software.
Adrian Suciu 24:dae7123d432a 31 * - Use of the software either in source or binary form, must be run
Adrian Suciu 24:dae7123d432a 32 * on or directly connected to an Analog Devices Inc. component.
Adrian Suciu 24:dae7123d432a 33 *
Adrian Suciu 24:dae7123d432a 34 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
Adrian Suciu 24:dae7123d432a 35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
Adrian Suciu 24:dae7123d432a 36 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Adrian Suciu 24:dae7123d432a 37 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
Adrian Suciu 24:dae7123d432a 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Adrian Suciu 24:dae7123d432a 39 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
Adrian Suciu 24:dae7123d432a 40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Adrian Suciu 24:dae7123d432a 41 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Adrian Suciu 24:dae7123d432a 42 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Adrian Suciu 24:dae7123d432a 43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Adrian Suciu 24:dae7123d432a 44 *
Adrian Suciu 24:dae7123d432a 45 ********************************************************************************/
Adrian Suciu 24:dae7123d432a 46
Adrian Suciu 24:dae7123d432a 47 #include "mbed.h"
Adrian Suciu 24:dae7123d432a 48 #include <stdio.h>
Adrian Suciu 24:dae7123d432a 49 #include <vector>
Adrian Suciu 24:dae7123d432a 50 #include <string>
Adrian Suciu 24:dae7123d432a 51 #include "AD5270_Diag.h"
Adrian Suciu 24:dae7123d432a 52
Adrian Suciu 24:dae7123d432a 53 extern Serial pc;
Adrian Suciu 24:dae7123d432a 54 extern vector<string> cmdbuffer;
Adrian Suciu 24:dae7123d432a 55
Adrian Suciu 24:dae7123d432a 56 AD5270_Diag::AD5270_Diag(AD5270& ad) : dut(ad)
Adrian Suciu 24:dae7123d432a 57 {
Adrian Suciu 24:dae7123d432a 58
Adrian Suciu 24:dae7123d432a 59 }
Adrian Suciu 24:dae7123d432a 60 void AD5270_Diag::enable_50TP_programming()
Adrian Suciu 24:dae7123d432a 61 {
Adrian Suciu 24:dae7123d432a 62 dut.enable_50TP_programming();
Adrian Suciu 24:dae7123d432a 63 pc.printf("Enabled 50TP prog");
Adrian Suciu 24:dae7123d432a 64
Adrian Suciu 24:dae7123d432a 65 }
Adrian Suciu 24:dae7123d432a 66 void AD5270_Diag::store_50TP()
Adrian Suciu 24:dae7123d432a 67 {
Adrian Suciu 24:dae7123d432a 68 dut.store_50TP();
Adrian Suciu 24:dae7123d432a 69 pc.printf("50TP stored");
Adrian Suciu 24:dae7123d432a 70 }
Adrian Suciu 24:dae7123d432a 71 void AD5270_Diag::disable_50TP_programming()
Adrian Suciu 24:dae7123d432a 72 {
Adrian Suciu 24:dae7123d432a 73 dut.disable_50TP_programming();
Adrian Suciu 24:dae7123d432a 74 pc.printf("Disabled 50TP prog");
Adrian Suciu 24:dae7123d432a 75 }
Adrian Suciu 24:dae7123d432a 76
Adrian Suciu 24:dae7123d432a 77 void AD5270_Diag::write_RDAC()
Adrian Suciu 24:dae7123d432a 78 {
Adrian Suciu 24:dae7123d432a 79 float res = strtof(cmdbuffer[1].c_str(), NULL);
Adrian Suciu 24:dae7123d432a 80 dut.write_RDAC(res);
Adrian Suciu 24:dae7123d432a 81 pc.printf("Wrote %f", res);
Adrian Suciu 24:dae7123d432a 82 }
Adrian Suciu 24:dae7123d432a 83 void AD5270_Diag::read_RDAC()
Adrian Suciu 24:dae7123d432a 84 {
Adrian Suciu 24:dae7123d432a 85 pc.printf("Read %f", dut.read_RDAC());
Adrian Suciu 24:dae7123d432a 86 }
Adrian Suciu 24:dae7123d432a 87 void AD5270_Diag::write_cmd()
Adrian Suciu 24:dae7123d432a 88 {
Adrian Suciu 24:dae7123d432a 89 uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 24:dae7123d432a 90 uint8_t regVal = strtol(cmdbuffer[2].c_str(), NULL, 16);
Adrian Suciu 24:dae7123d432a 91 pc.printf("Returned %x: ", dut.write_cmd(reg, regVal));
Adrian Suciu 24:dae7123d432a 92 }
Adrian Suciu 24:dae7123d432a 93
Adrian Suciu 24:dae7123d432a 94 void AD5270_Diag::set_HiZ()
Adrian Suciu 24:dae7123d432a 95 {
Adrian Suciu 24:dae7123d432a 96 pc.printf("SDO set to HiZ");
Adrian Suciu 24:dae7123d432a 97 dut.set_SDO_HiZ();
Adrian Suciu 24:dae7123d432a 98 }
Adrian Suciu 24:dae7123d432a 99
Adrian Suciu 24:dae7123d432a 100 void AD5270_Diag::read_50TP_last_address(void)
Adrian Suciu 24:dae7123d432a 101 {
Adrian Suciu 24:dae7123d432a 102 pc.printf("Returned %x:", dut.read_50TP_last_address());
Adrian Suciu 24:dae7123d432a 103 }
Adrian Suciu 24:dae7123d432a 104 void AD5270_Diag::read_50TP_memory(void)
Adrian Suciu 24:dae7123d432a 105 {
Adrian Suciu 24:dae7123d432a 106 uint8_t reg = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 24:dae7123d432a 107 pc.printf("Returned %x", dut.read_50TP_memory(reg));
Adrian Suciu 24:dae7123d432a 108 }
Adrian Suciu 24:dae7123d432a 109
Adrian Suciu 24:dae7123d432a 110 void AD5270_Diag::write_ctrl_reg(void)
Adrian Suciu 24:dae7123d432a 111 {
Adrian Suciu 24:dae7123d432a 112 uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 24:dae7123d432a 113 dut.write_ctrl_reg(val);
Adrian Suciu 24:dae7123d432a 114 pc.printf("Wrote %x to ctrl_reg", val );
Adrian Suciu 24:dae7123d432a 115 }
Adrian Suciu 24:dae7123d432a 116 void AD5270_Diag::read_ctrl_reg(void)
Adrian Suciu 24:dae7123d432a 117 {
Adrian Suciu 24:dae7123d432a 118 pc.printf("Read %x from ctrl_reg", dut.read_ctrl_reg());
Adrian Suciu 24:dae7123d432a 119 }
Adrian Suciu 24:dae7123d432a 120
Adrian Suciu 24:dae7123d432a 121 void AD5270_Diag::reset_RDAC(void)
Adrian Suciu 24:dae7123d432a 122 {
Adrian Suciu 24:dae7123d432a 123 dut.reset_RDAC();
Adrian Suciu 24:dae7123d432a 124 pc.printf("Resetted rdac");
Adrian Suciu 24:dae7123d432a 125 }
Adrian Suciu 24:dae7123d432a 126 void AD5270_Diag::change_mode(void)
Adrian Suciu 24:dae7123d432a 127 {
Adrian Suciu 24:dae7123d432a 128 uint8_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 24:dae7123d432a 129 dut.change_mode(static_cast<AD5270::AD5270Modes_t>(val));
Adrian Suciu 24:dae7123d432a 130 pc.printf("Changed mode to %x", val);
Adrian Suciu 24:dae7123d432a 131 }
Adrian Suciu 24:dae7123d432a 132
Adrian Suciu 24:dae7123d432a 133 void AD5270_Diag::write_wiper_reg(void)
Adrian Suciu 24:dae7123d432a 134 {
Adrian Suciu 24:dae7123d432a 135 uint16_t val = strtol(cmdbuffer[1].c_str(), NULL, 16);
Adrian Suciu 24:dae7123d432a 136 dut.write_wiper_reg(val);
Adrian Suciu 24:dae7123d432a 137 pc.printf("Wrote %x to wiper", val);
Adrian Suciu 24:dae7123d432a 138 }
Adrian Suciu 24:dae7123d432a 139 void AD5270_Diag::read_wiper_reg(void)
Adrian Suciu 24:dae7123d432a 140 {
Adrian Suciu 24:dae7123d432a 141 pc.printf("Read %x from wiper", dut.read_wiper_reg());
Adrian Suciu 24:dae7123d432a 142 }