diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-29 06:29:54 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-29 06:29:54 +0000 |
commit | ef678a479cc4d4d60e16300e8654d19ebb6e43f0 (patch) | |
tree | da968df0580f1043b353d76ed550a56b35864974 /host/lib/ic_reg_maps/gen_ad9777_regs.py | |
parent | 4e97e9c4845814994e1e9d3deabb5abd4d177738 (diff) | |
parent | c7df3878779cf461cef01d910e6c52c7ac3e1105 (diff) | |
download | uhd-ef678a479cc4d4d60e16300e8654d19ebb6e43f0.tar.gz uhd-ef678a479cc4d4d60e16300e8654d19ebb6e43f0.tar.bz2 uhd-ef678a479cc4d4d60e16300e8654d19ebb6e43f0.zip |
Merge branch 'master' of git@ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Diffstat (limited to 'host/lib/ic_reg_maps/gen_ad9777_regs.py')
-rwxr-xr-x | host/lib/ic_reg_maps/gen_ad9777_regs.py | 93 |
1 files changed, 30 insertions, 63 deletions
diff --git a/host/lib/ic_reg_maps/gen_ad9777_regs.py b/host/lib/ic_reg_maps/gen_ad9777_regs.py index 2ac73efcf..abb839f0f 100755 --- a/host/lib/ic_reg_maps/gen_ad9777_regs.py +++ b/host/lib/ic_reg_maps/gen_ad9777_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="""\ ######################################################################## ## address 0 ######################################################################## @@ -73,79 +70,49 @@ qdac_fine_gain_adjust 9[0:7] 0 ## address 6 and A ######################################################################## idac_coarse_gain_adjust 6[0:3] 0 -qdac_coarse_gain_adjust A[0:3] 0 +qdac_coarse_gain_adjust 0xA[0:3] 0 ######################################################################## ## address 7, 8 and B, C ######################################################################## idac_offset_adjust_msb 7[0:7] 0 idac_offset_adjust_lsb 8[0:1] 0 idac_ioffset_direction 8[7] 0 out_a, out_b -qdac_offset_adjust_msb B[0:7] 0 -qdac_offset_adjust_lsb C[0:1] 0 -qdac_ioffset_direction C[7] 0 out_a, out_b +qdac_offset_adjust_msb 0xB[0:7] 0 +qdac_offset_adjust_lsb 0xC[0:1] 0 +qdac_ioffset_direction 0xC[7] 0 out_a, out_b """ ######################################################################## -# 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_AD9777_REGS_HPP -\#define INCLUDED_AD9777_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct ad9777_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 - #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - ad9777_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for - } - - boost::uint8_t get_reg(boost::uint8_t addr){ - boost::uint8_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::uint8_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - break; +BODY_TMPL="""\ +boost::uint8_t get_reg(boost::uint8_t addr){ + boost::uint8_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::uint8_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for - } - return reg; + break; + #end for } + return reg; +} - boost::uint16_t get_write_reg(boost::uint8_t addr){ - return (boost::uint16_t(addr) << 8) | get_reg(addr); - } - - boost::uint16_t get_read_reg(boost::uint8_t addr){ - return (boost::uint16_t(addr) << 8) | (1 << 7); - } -}; +boost::uint16_t get_write_reg(boost::uint8_t addr){ + return (boost::uint16_t(addr) << 8) | get_reg(addr); +} -\#endif /* INCLUDED_AD9777_REGS_HPP */ +boost::uint16_t get_read_reg(boost::uint8_t addr){ + return (boost::uint16_t(addr) << 8) | (1 << 7); +} """ 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='ad9777_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) |