diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-30 11:11:09 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-30 11:11:09 -0700 |
commit | 29ea5f89b6f52dd5ad7fb0173ef5699f9c5f4ebf (patch) | |
tree | 557ea5a852716707ecfae03d2083dd7de3f954ce /host/lib/ic_reg_maps/gen_max2829_regs.py | |
parent | e837c65eb2b49f8fc2516f4eba45eafaa9b7b76b (diff) | |
parent | 333937760305f9c7c8dfb1db95f4821a800ce043 (diff) | |
download | uhd-29ea5f89b6f52dd5ad7fb0173ef5699f9c5f4ebf.tar.gz uhd-29ea5f89b6f52dd5ad7fb0173ef5699f9c5f4ebf.tar.bz2 uhd-29ea5f89b6f52dd5ad7fb0173ef5699f9c5f4ebf.zip |
Merge branch 'reg_maps'
Diffstat (limited to 'host/lib/ic_reg_maps/gen_max2829_regs.py')
-rwxr-xr-x | host/lib/ic_reg_maps/gen_max2829_regs.py | 85 |
1 files changed, 26 insertions, 59 deletions
diff --git a/host/lib/ic_reg_maps/gen_max2829_regs.py b/host/lib/ic_reg_maps/gen_max2829_regs.py index 7fef302a8..383131c18 100755 --- a/host/lib/ic_reg_maps/gen_max2829_regs.py +++ b/host/lib/ic_reg_maps/gen_max2829_regs.py @@ -16,14 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import sys -from common import * - ######################################################################## # Template for raw text data describing registers # name addr[bit range inclusive] default optional enums ######################################################################## -REGS_DATA_TMPL="""\ +REGS_TMPL="""\ ######################################################################## ## Note: offsets given from perspective of data bits (excludes address) ######################################################################## @@ -41,7 +38,7 @@ mimo_select 2[13] 0 normal, mimo ######################################################################## ## Integer Divider Ratio (3) ######################################################################## -int_div_ratio_word 3[0:7] a2 +int_div_ratio_word 3[0:7] 0xa2 frac_div_ratio_lsb 3[12:13] 0 ######################################################################## ## Fractional Divider Ratio (4) @@ -95,72 +92,42 @@ tx_vga_gain_spi 9[10] 0 io, spi ######################################################################## ## PA Bias DAC (10) ######################################################################## -pa_bias_dac_out_curr a[0:5] 0 -pa_bias_dac_delay a[6:9] f +pa_bias_dac_out_curr 10[0:5] 0 +pa_bias_dac_delay 10[6:9] 0xf ######################################################################## ## Rx Gain (11) ######################################################################## -rx_vga_gain b[0:4] 1f -rx_lna_gain b[5:6] 3 +rx_vga_gain 11[0:4] 0x1f +rx_lna_gain 11[5:6] 3 ######################################################################## ## Tx VGA Gain (12) ######################################################################## -tx_vga_gain c[0:5] 0 +tx_vga_gain 12[0:5] 0 """ ######################################################################## -# Header and Source templates below +# Template for methods in the body of the struct ######################################################################## -HEADER_TEXT=""" -#import time - -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#ifndef INCLUDED_MAX2829_REGS_HPP -\#define INCLUDED_MAX2829_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct max2829_regs_t{ -#for $reg in $regs - #if $reg.get_enums() - enum $(reg.get_name())_t{ - #for $i, $enum in enumerate($reg.get_enums()) - #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' - $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma +BODY_TMPL="""\ +boost::uint32_t get_reg(boost::uint8_t addr){ + boost::uint16_t reg = 0; + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + reg |= (boost::uint16_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - max2829_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for + break; + #end for } - - boost::uint32_t get_reg(boost::uint8_t addr){ - boost::uint16_t reg = 0; - switch(addr){ - #for $addr in range(2, 12+1) - case $addr: - #for $reg in filter(lambda r: r.get_addr() == addr, $regs) - reg |= (boost::uint16_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - break; - #end for - } - return (boost::uint32_t(reg) << 4) | (addr & 0xf); - } -}; - -\#endif /* INCLUDED_MAX2829_REGS_HPP */ + return (boost::uint32_t(reg) << 4) | (addr & 0xf); +} """ if __name__ == '__main__': - regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) + import common; common.generate( + name='max2829_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) |