| 1 | /*********************************************************************** |
| 2 | * This file programs the LMH6521 on board the langford device. |
| 3 | * |
| 4 | * (c) 2013 Per Vices Corporation |
| 5 | * See LICENSE.txt for license and copyright information. |
| 6 | **********************************************************************/ |
| 7 | |
| 8 | #include <iostream> |
| 9 | #include "lmh6521_regs.hpp"cxx . . $ `<file>/libs/lmh6521_regs.hpp`/ |
| 10 | #include <stdint.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <fcntl.h> |
| 13 | #include <unistd.h> |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <sys/stat.h> |
| 16 | #include "../langford_ioctl.h"cxx . . $ `<file>/langford_ioctl.h`/ |
| 17 | |
| 18 | |
| 19 | int WriteRegcxx . . $ WriteReg(300f4a078d529d2f).(stdcxx . . $ std/::stringcxx . . $ std/string# FileName, uint32_tcxx . . $ uint32_t# reg_val); |
| 20 | |
| 21 | |
| 22 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) { |
| 23 | double gain; |
| 24 | int channel; |
| 25 | int rc; |
| 26 | int verbosity; |
| 27 | |
| 28 | //Initialize |
| 29 | lmh6521_regs_tcxx . . $ lmh6521_regs_t# lmh6521_regscxx . . $ lmh6521_regs_t#lmh6521_regs_t(49f6e7a06ebc5aa8).; |
| 30 | |
| 31 | if ( (argc < 4) || (argc > 5) ){ |
| 32 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Usage: " <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 33 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\t" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). argv[0] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " [DEVICE_NAME] [CHANNEL] [GAIN] (OUTPUT)" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 34 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[DEVICE_NAME] default is /dev/langford" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 35 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[CHANNEL] = {0|1} to program I or Q channel." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 36 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[GAIN] (0 <= GAIN <= 31.5), Set desired channel gain (31.5dB range across (-5.5..26)dB )" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 37 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[OUTPUT] = {0|1|2} is the (optional) output format (0 = silent (default), 1 = verbose, 2=driver)" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 38 | return 1; |
| 39 | }; |
| 40 | |
| 41 | if ( (stdcxx . . $ std/::stringcxx . . $ std/string#(argv[2]) ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "0") || (stdcxx . . $ std/::stringcxx . . $ std/string#(argv[2]) ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "1") ){ channel = atofcxx . . $ atof(9b0361fcbc284e4f).(argv[2]); } |
| 42 | |
| 43 | else { |
| 44 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Invalid Channel Selection: Valid values for [CHANNEL] are: {0|1}" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 45 | return 1; |
| 46 | }; |
| 47 | |
| 48 | if ( (atofcxx . . $ atof(9b0361fcbc284e4f).(argv[3]) >= 0) && (atofcxx . . $ atof(9b0361fcbc284e4f).(argv[3]) <= 31.5) ) { gain = atofcxx . . $ atof(9b0361fcbc284e4f).(argv[3]); } |
| 49 | else { |
| 50 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Invalid Gain: Valid values for [GAIN] is limited to set [0,31.5]" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 51 | return 1; |
| 52 | }; |
| 53 | |
| 54 | if ( (argc == 5) ){ |
| 55 | if (stdcxx . . $ std/::stringcxx . . $ std/string#(argv[4]) ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "0") { verbosity = 0; } |
| 56 | else if (stdcxx . . $ std/::stringcxx . . $ std/string#(argv[4]) ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "1") { verbosity = 1; stdcxx . . $ std/::coutcxx . . $ std/cout..precisioncxx . . $ std/ios_base#precision(8ce0d1b217db7fd1).(10); } |
| 57 | else if (stdcxx . . $ std/::stringcxx . . $ std/string#(argv[4]) ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "2") { verbosity = 2; stdcxx . . $ std/::coutcxx . . $ std/cout..precisioncxx . . $ std/ios_base#precision(8ce0d1b217db7fd1).(10); } |
| 58 | else { stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Invalid output selection: 0 for verbose mode, 1 for driver"; return 1;}; |
| 59 | } |
| 60 | else { verbosity = 0; }; |
| 61 | |
| 62 | |
| 63 | gain = lmh6521_regs.set_gaincxx . . $ lmh6521_regs_t#set_gain(f7856f627868a823).(gain, channel); |
| 64 | |
| 65 | rc = WriteRegcxx . . $ WriteReg(300f4a078d529d2f).(argvcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).[1], lmh6521_regs.get_regscxx . . $ lmh6521_regs_t#get_regs(db52760e79bf9054).()); |
| 66 | |
| 67 | if (verbosity == 1){ |
| 68 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Programming Channel: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). channel |
| 69 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " => " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). gain |
| 70 | <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 71 | lmh6521_regs.show_regscxx . . $ lmh6521_regs_t#show_regs(49f6e7a06ebc5aa8).(); |
| 72 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Return code from io_ctl calls: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). rc <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 73 | } |
| 74 | else if (verbosity == 2){ |
| 75 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). channel |
| 76 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). gain |
| 77 | <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 78 | }; |
| 79 | |
| 80 | return rc; |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | int WriteRegcxx . . $ WriteReg(300f4a078d529d2f).(stdcxx . . $ std/::stringcxx . . $ std/string# FileName, uint32_tcxx . . $ uint32_t# reg_val) { |
| 85 | int DevFD; |
| 86 | int val; |
| 87 | int rc = 0; |
| 88 | const unsigned long long val0 = 0, val1 = 1; |
| 89 | int i; |
| 90 | |
| 91 | DevFD = open(FileName.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!); |
| 92 | if (!DevFD) { |
| 93 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Cannot open " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). FileName <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 94 | return 1; |
| 95 | }; |
| 96 | |
| 97 | rc |= ioctl(DevFD, IOCTL_SET_N7CScxx . . $ `langford_ioctl.h:54:9`!, &val0); |
| 98 | for (i = 0; i < 16; i++) { |
| 99 | rc |= ioctl(DevFD, IOCTL_SET_N7CLKcxx . . $ `langford_ioctl.h:52:9`!, &val0); |
| 100 | val = (reg_val >> (15 - i)) & 0x01; |
| 101 | rc |= ioctl(DevFD, IOCTL_SET_N7SDIcxx . . $ `langford_ioctl.h:56:9`!, &val); |
| 102 | rc |= ioctl(DevFD, IOCTL_SET_N7CLKcxx . . $ `langford_ioctl.h:52:9`!, &val1); |
| 103 | }; |
| 104 | rc |= ioctl(DevFD, IOCTL_SET_N7CLKcxx . . $ `langford_ioctl.h:52:9`!, &val0); |
| 105 | rc |= ioctl(DevFD, IOCTL_SET_N7SDIcxx . . $ `langford_ioctl.h:56:9`!, &val0); |
| 106 | rc |= ioctl(DevFD, IOCTL_SET_N7CScxx . . $ `langford_ioctl.h:54:9`!, &val1); |
| 107 | |
| 108 | close(DevFD); |
| 109 | |
| 110 | return rc; |
| 111 | }; |