Debian Codegraph @

libs/lmh6521_regs.hpp

raw symbols SCIP
1 /***********************************************************************
2 * Defines and sets the LMH6521 High Performance Dual Differential DVGA
3 *
4 * (c) 2013 Per Vices Corporation
5 * See LICENSE.txt for license and copyright information.
6 **********************************************************************/
7
8 #ifndef INCLUDED_LMH6521_REGS_HPP
9 #define INCLUDED_LMH6521_REGS_HPPcxx . . $ `libs/lmh6521_regs.hpp:9:9`!
10
11 /* Specifications */
12 #define LMH6521_MAX_GAINcxx . . $ `libs/lmh6521_regs.hpp:12:9`! 31.5 /* dB */
13 #define LMH6521_MIN_GAINcxx . . $ `libs/lmh6521_regs.hpp:13:9`! 31.5 /* dB */
14 #define LMH6521_STEP_SIZEcxx . . $ `libs/lmh6521_regs.hpp:14:9`! 0.5 /* dB */
15
16 #include <stdint.h>
17 #include <math.h>
18 #include <set>
19 #include <iostream>
20 #include <bitset>
21
22
23 class lmh6521_regs_tcxx . . $ lmh6521_regs_t#{
24 public:
25 enum read_write_bit_tcxx . . $ lmh6521_regs_t#read_write_bit_t#{
26 READ_WRITE_BIT_WRITEcxx . . $ lmh6521_regs_t#READ_WRITE_BIT_WRITE. = 0,
27 READ_WRITE_BIT_READcxx . . $ lmh6521_regs_t#READ_WRITE_BIT_READ. = 1
28 };
29 read_write_bit_tcxx . . $ lmh6521_regs_t#read_write_bit_t# read_write_bitcxx . . $ lmh6521_regs_t#read_write_bit.;
30
31 enum address_tcxx . . $ lmh6521_regs_t#address_t#{
32 CHANNEL_Acxx . . $ lmh6521_regs_t#CHANNEL_A. = 0,
33 CHANNEL_Bcxx . . $ lmh6521_regs_t#CHANNEL_B. = 1
34 };
35 address_tcxx . . $ lmh6521_regs_t#address_t# addresscxx . . $ lmh6521_regs_t#address.;
36
37 enum enable_tcxx . . $ lmh6521_regs_t#enable_t#{
38 ENABLE_DISABLEDcxx . . $ lmh6521_regs_t#ENABLE_DISABLED. = 0,
39 ENABLE_ENABLEDcxx . . $ lmh6521_regs_t#ENABLE_ENABLED. = 1
40 };
41 enable_tcxx . . $ lmh6521_regs_t#enable_t# enablecxx . . $ lmh6521_regs_t#enable.;
42
43 int gaincxx . . $ lmh6521_regs_t#gain.; //Gain setting in 0.5dB increments.
44
45 //Output registers A and B to stdout.
46 void show_regscxx . . $ lmh6521_regs_t#show_regs(49f6e7a06ebc5aa8).(){
47 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\tRegister " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "=>\t" <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::hexcxx . . $ std/hex(cf36cc481190cd1f). <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). get_regscxx . . $ lmh6521_regs_t#get_regs(db52760e79bf9054).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
48 };
49
50 //Turn off channel
51 void turn_offcxx . . $ lmh6521_regs_t#turn_off(d4f767463ce0a6b3).(int u_channel){
52 addresscxx . . $ lmh6521_regs_t#address. = (address_tcxx . . $ lmh6521_regs_t#address_t#)(u_channel);
53 enablecxx . . $ lmh6521_regs_t#enable. = ENABLE_DISABLEDcxx . . $ lmh6521_regs_t#ENABLE_DISABLED.;
54 };
55
56 //Turn on channel
57 void turn_oncxx . . $ lmh6521_regs_t#turn_on(d4f767463ce0a6b3).(int u_channel){
58 addresscxx . . $ lmh6521_regs_t#address. = u_channel == 0 ? CHANNEL_Acxx . . $ lmh6521_regs_t#CHANNEL_A. : CHANNEL_Bcxx . . $ lmh6521_regs_t#CHANNEL_B.;
59 enablecxx . . $ lmh6521_regs_t#enable. = ENABLE_DISABLEDcxx . . $ lmh6521_regs_t#ENABLE_DISABLED.;
60 };
61
62 //INITIALIZATION ROUTINE (Initialize in Safe State)
63 //POWER OFF, LOWEST POWER SETTING.
64 lmh6521_regs_tcxx . . $ lmh6521_regs_t#lmh6521_regs_t(49f6e7a06ebc5aa8).(){
65 read_write_bitcxx . . $ lmh6521_regs_t#read_write_bit. = READ_WRITE_BIT_READcxx . . $ lmh6521_regs_t#READ_WRITE_BIT_READ.;
66 addresscxx . . $ lmh6521_regs_t#address. = CHANNEL_Acxx . . $ lmh6521_regs_t#CHANNEL_A.;
67 enablecxx . . $ lmh6521_regs_t#enable. = ENABLE_DISABLEDcxx . . $ lmh6521_regs_t#ENABLE_DISABLED.;
68 gaincxx . . $ lmh6521_regs_t#gain. = 0;
69 }
70
71 //Generate the registers
72 uint32_tcxx . . $ uint32_t# get_regscxx . . $ lmh6521_regs_t#get_regs(db52760e79bf9054).(){
73 int32_t reg = 0;
74 //Start writing to the registers;
75 reg |= (uint32_tcxx . . $ uint32_t#(gaincxx . . $ lmh6521_regs_t#gain.) & 0x3f) << 1;
76 reg |= (uint32_tcxx . . $ uint32_t#(enablecxx . . $ lmh6521_regs_t#enable.) & 0x1) << 7;
77 reg |= (uint32_tcxx . . $ uint32_t#(addresscxx . . $ lmh6521_regs_t#address.) & 0x1) << 8;
78 reg |= (uint32_tcxx . . $ uint32_t#(read_write_bitcxx . . $ lmh6521_regs_t#read_write_bit.) & 0x1) << 15;
79 return reg;
80 };
81
82 //Set the gain (from 0-31.5) on specified channel (0 or 1)
83 double set_gaincxx . . $ lmh6521_regs_t#set_gain(f7856f627868a823).(double u_gain, int u_channel) {
84 read_write_bitcxx . . $ lmh6521_regs_t#read_write_bit. = READ_WRITE_BIT_WRITEcxx . . $ lmh6521_regs_t#READ_WRITE_BIT_WRITE.;
85 addresscxx . . $ lmh6521_regs_t#address. = u_channel == 0 ? CHANNEL_Acxx . . $ lmh6521_regs_t#CHANNEL_A. : CHANNEL_Bcxx . . $ lmh6521_regs_t#CHANNEL_B.;
86 enablecxx . . $ lmh6521_regs_t#enable. = ENABLE_ENABLEDcxx . . $ lmh6521_regs_t#ENABLE_ENABLED.;
87 gaincxx . . $ lmh6521_regs_t#gain. = u_gain <= 0 ? 0 : int(u_gain); //Sanity check for min gain.
88 gaincxx . . $ lmh6521_regs_t#gain. = u_gain >= 31.5 ? 63 : int(u_gain*2) ; //Sanity check for max gain.
89 return ((double) gaincxx . . $ lmh6521_regs_t#gain./2);
90 };
91
92 double read_channelcxx . . $ lmh6521_regs_t#read_channel(447c67c6676f75c3).(double u_channel) {
93 read_write_bitcxx . . $ lmh6521_regs_t#read_write_bit. = READ_WRITE_BIT_READcxx . . $ lmh6521_regs_t#READ_WRITE_BIT_READ.;
94 addresscxx . . $ lmh6521_regs_t#address. = u_channel == 0 ? CHANNEL_Acxx . . $ lmh6521_regs_t#CHANNEL_A. : CHANNEL_Bcxx . . $ lmh6521_regs_t#CHANNEL_B.;
95 //enable = ENABLE_ENABLED;
96 //gain = u_gain <= 0 ? 0 : int(u_gain); //Sanity check for min gain.
97 //gain = u_gain >= 31.5 ? 63 : int(u_gain*2) ; //Sanity check for max gain.
98 return ((double) u_channel);
99 };
100
101 };
102
103
104
105
106
107 #endif /* INCLUDED_ADF4350_REGS_HPP */