summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-29 18:11:26 -0700
committerJosh Blum <josh@joshknows.com>2010-04-29 18:11:26 -0700
commit2bba9ca0831ecc40ac2e02ed66e615778a1bd17f (patch)
tree610dc52edb770a98e1ac9315931dd55cd429ed70
parent15b0f5feef3e30f762ded1d27235bd167e3e5c28 (diff)
downloaduhd-2bba9ca0831ecc40ac2e02ed66e615778a1bd17f.tar.gz
uhd-2bba9ca0831ecc40ac2e02ed66e615778a1bd17f.tar.bz2
uhd-2bba9ca0831ecc40ac2e02ed66e615778a1bd17f.zip
Moved a bunch of register map code into common.
-rw-r--r--host/lib/ic_reg_maps/common.py55
-rwxr-xr-xhost/lib/ic_reg_maps/gen_ad5624_regs.py66
-rwxr-xr-xhost/lib/ic_reg_maps/gen_ad7922_regs.py78
-rwxr-xr-xhost/lib/ic_reg_maps/gen_ad9510_regs.py86
-rwxr-xr-xhost/lib/ic_reg_maps/gen_ad9777_regs.py85
-rwxr-xr-xhost/lib/ic_reg_maps/gen_ad9862_regs.py113
-rwxr-xr-xhost/lib/ic_reg_maps/gen_adf4360_regs.py83
-rwxr-xr-xhost/lib/ic_reg_maps/gen_max2829_regs.py73
8 files changed, 228 insertions, 411 deletions
diff --git a/host/lib/ic_reg_maps/common.py b/host/lib/ic_reg_maps/common.py
index b33961b03..4aa1ef35e 100644
--- a/host/lib/ic_reg_maps/common.py
+++ b/host/lib/ic_reg_maps/common.py
@@ -16,9 +16,48 @@
#
import re
+import sys
import math
from Cheetah.Template import Template
+COMMON_TMPL = """\
+#import time
+/***********************************************************************
+ * This file was generated by $file on $time.strftime("%c")
+ **********************************************************************/
+
+\#ifndef INCLUDED_$(name.upper())_HPP
+\#define INCLUDED_$(name.upper())_HPP
+
+\#include <boost/cstdint.hpp>
+
+struct $(name)_t{
+
+ #for $reg in $regs
+ #if $reg.get_enums()
+ enum $reg.get_type(){
+ #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
+ };
+ #end if
+ $reg.get_type() $reg.get_name();
+ #end for
+
+ $(name)_t(void){
+ #for $reg in $regs
+ $reg.get_name() = $reg.get_default();
+ #end for
+ }
+
+$body
+
+};
+
+\#endif /* INCLUDED_$(name.upper())_HPP */
+"""
+
def parse_tmpl(_tmpl_text, **kwargs):
return str(Template(_tmpl_text, kwargs))
@@ -60,8 +99,20 @@ class reg:
for key, val in self.get_enums():
if val == self._default: return str.upper('%s_%s'%(self.get_name(), key))
return self._default
- def get_stdint_type(self):\
- return 'uint%d_t'%max(2**math.ceil(math.log(self.get_bit_width(), 2)), 8)
+ def get_type(self):
+ if self.get_enums(): return '%s_t'%self.get_name()
+ return 'boost::uint%d_t'%max(2**math.ceil(math.log(self.get_bit_width(), 2)), 8)
def get_shift(self): return self._addr_spec[0]
def get_mask(self): return hex(int('1'*self.get_bit_width(), 2))
def get_bit_width(self): return self._addr_spec[1] - self._addr_spec[0] + 1
+
+def generate(name, regs_tmpl, body_tmpl='', file=__file__):
+ regs = map(reg, parse_tmpl(regs_tmpl).splitlines())
+ body = parse_tmpl(body_tmpl, regs=regs).replace('\n', '\n ').strip()
+ code = parse_tmpl(COMMON_TMPL,
+ name=name,
+ regs=regs,
+ body=body,
+ file=file,
+ )
+ open(sys.argv[1], 'w').write(code)
diff --git a/host/lib/ic_reg_maps/gen_ad5624_regs.py b/host/lib/ic_reg_maps/gen_ad5624_regs.py
index 9e8ae5be5..24401b878 100755
--- a/host/lib/ic_reg_maps/gen_ad5624_regs.py
+++ b/host/lib/ic_reg_maps/gen_ad5624_regs.py
@@ -16,67 +16,33 @@
# 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="""\
data 0[4:15] 0
addr 0[16:18] 0 DAC_A=0, DAC_B=1, DAC_C=2, DAC_D=3, ALL=7
cmd 0[19:21] 0 wr_input_n, up_dac_n, wr_input_n_up_all, wr_up_dac_chan_n, power_down, reset, load_ldac
"""
########################################################################
-# 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_AD5624_REGS_HPP
-\#define INCLUDED_AD5624_REGS_HPP
-
-\#include <boost/cstdint.hpp>
-
-struct ad5624_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
-
- ad5624_regs_t(void){
-#for $reg in $regs
- $reg.get_name() = $reg.get_default();
-#end for
- }
-
- boost::uint32_t get_reg(void){
- boost::uint32_t reg = 0;
- #for $reg in filter(lambda r: r.get_addr() == 0, $regs)
- reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
- #end for
- return reg;
- }
-
-};
-
-\#endif /* INCLUDED_AD5624_REGS_HPP */
+BODY_TMPL="""\
+boost::uint32_t get_reg(void){
+ boost::uint32_t reg = 0;
+ #for $reg in filter(lambda r: r.get_addr() == 0, $regs)
+ reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
+ #end for
+ return reg;
+}
"""
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='ad5624_regs',
+ regs_tmpl=REGS_TMPL,
+ body_tmpl=BODY_TMPL,
+ file=__file__,
+ )
diff --git a/host/lib/ic_reg_maps/gen_ad7922_regs.py b/host/lib/ic_reg_maps/gen_ad7922_regs.py
index 23f28c0da..842d40430 100755
--- a/host/lib/ic_reg_maps/gen_ad7922_regs.py
+++ b/host/lib/ic_reg_maps/gen_ad7922_regs.py
@@ -16,73 +16,39 @@
# 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="""\
result 0[0:11] 0
mod 0[12] 0
chn 0[13] 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_AD7922_REGS_HPP
-\#define INCLUDED_AD7922_REGS_HPP
-
-\#include <boost/cstdint.hpp>
-
-struct ad7922_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
-
- ad7922_regs_t(void){
-#for $reg in $regs
- $reg.get_name() = $reg.get_default();
-#end for
- }
-
- boost::uint16_t get_reg(void){
- boost::uint16_t reg = 0;
- #for $reg in filter(lambda r: r.get_addr() == 0, $regs)
- reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
- #end for
- return reg;
- }
-
- void set_reg(boost::uint16_t reg){
- #for $reg in filter(lambda r: r.get_addr() == 0, $regs)
- $reg.get_name() = (reg >> $reg.get_shift()) & $reg.get_mask();
- #end for
- }
-
-};
-
-\#endif /* INCLUDED_AD7922_REGS_HPP */
+BODY_TMPL="""\
+boost::uint16_t get_reg(void){
+ boost::uint16_t reg = 0;
+ #for $reg in filter(lambda r: r.get_addr() == 0, $regs)
+ reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
+ #end for
+ return reg;
+}
+
+void set_reg(boost::uint16_t reg){
+ #for $reg in filter(lambda r: r.get_addr() == 0, $regs)
+ $reg.get_name() = (reg >> $reg.get_shift()) & $reg.get_mask();
+ #end for
+}
"""
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='ad7922_regs',
+ regs_tmpl=REGS_TMPL,
+ body_tmpl=BODY_TMPL,
+ file=__file__,
+ )
diff --git a/host/lib/ic_reg_maps/gen_ad9510_regs.py b/host/lib/ic_reg_maps/gen_ad9510_regs.py
index 17cc141fc..903063df1 100755
--- a/host/lib/ic_reg_maps/gen_ad9510_regs.py
+++ b/host/lib/ic_reg_maps/gen_ad9510_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="""\
########################################################################
## serial control port config
########################################################################
@@ -107,67 +104,36 @@ update_registers 0x5A[0] 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_AD9510_REGS_HPP
-\#define INCLUDED_AD9510_REGS_HPP
-
-\#include <boost/cstdint.hpp>
-
-struct ad9510_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::uint8_t get_reg(boost::uint16_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::uint32_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
-
- ad9510_regs_t(void){
-#for $reg in $regs
- $reg.get_name() = $reg.get_default();
-#end for
- }
-
- boost::uint8_t get_reg(boost::uint16_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::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
- #end for
- break;
- #end for
- }
- return reg;
- }
-
- boost::uint32_t get_write_reg(boost::uint16_t addr){
- return (boost::uint32_t(addr) << 8) | get_reg(addr);
- }
-
- boost::uint32_t get_read_reg(boost::uint16_t addr){
- return (boost::uint32_t(addr) << 8) | (1 << 15);
+ break;
+ #end for
}
+ return reg;
+}
-};
+boost::uint32_t get_write_reg(boost::uint16_t addr){
+ return (boost::uint32_t(addr) << 8) | get_reg(addr);
+}
-\#endif /* INCLUDED_AD9510_REGS_HPP */
+boost::uint32_t get_read_reg(boost::uint16_t addr){
+ return (boost::uint32_t(addr) << 8) | (1 << 15);
+}
"""
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='ad9510_regs',
+ regs_tmpl=REGS_TMPL,
+ body_tmpl=BODY_TMPL,
+ file=__file__,
+ )
diff --git a/host/lib/ic_reg_maps/gen_ad9777_regs.py b/host/lib/ic_reg_maps/gen_ad9777_regs.py
index 6ff212b4d..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
########################################################################
@@ -86,66 +83,36 @@ 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__,
+ )
diff --git a/host/lib/ic_reg_maps/gen_ad9862_regs.py b/host/lib/ic_reg_maps/gen_ad9862_regs.py
index 0d03c7bb6..c912403ef 100755
--- a/host/lib/ic_reg_maps/gen_ad9862_regs.py
+++ b/host/lib/ic_reg_maps/gen_ad9862_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="""\
########################################################################
## General
########################################################################
@@ -204,82 +201,52 @@ chip_id 63[0:7] 0
########################################################################
# Header and Source templates below
########################################################################
-HEADER_TEXT="""
-#import time
-
-/***********************************************************************
- * This file was generated by $file on $time.strftime("%c")
- **********************************************************************/
-
-\#ifndef INCLUDED_AD9862_REGS_HPP
-\#define INCLUDED_AD9862_REGS_HPP
-
-\#include <boost/cstdint.hpp>
-
-struct ad9862_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
-
- ad9862_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 range(0, 63+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;
+BODY_TMPL="""
+boost::uint8_t get_reg(boost::uint8_t addr){
+ boost::uint8_t reg = 0;
+ switch(addr){
+ #for $addr in range(0, 63+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
- }
- return reg;
+ break;
+ #end for
}
+ return reg;
+}
- void set_reg(boost::uint16_t reg_word){
- boost::uint8_t addr = (reg_word >> 8) & 0x1f;
- boost::uint8_t reg = (reg_word >> 0) & 0xff;
- switch(addr){
- #for $addr in range(0, 63+1)
- case $addr:
- #for $reg in filter(lambda r: r.get_addr() == addr, $regs)
- #if $reg.get_enums()
- $reg.get_name() = $(reg.get_name())_t((reg >> $reg.get_shift()) & $reg.get_mask());
- #else
- $reg.get_name() = (reg >> $reg.get_shift()) & $reg.get_mask();
- #end if
- #end for
- break;
+void set_reg(boost::uint16_t reg_word){
+ boost::uint8_t addr = (reg_word >> 8) & 0x1f;
+ boost::uint8_t reg = (reg_word >> 0) & 0xff;
+ switch(addr){
+ #for $addr in range(0, 63+1)
+ case $addr:
+ #for $reg in filter(lambda r: r.get_addr() == addr, $regs)
+ #if $reg.get_enums()
+ $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask());
+ #else
+ $reg.get_name() = (reg >> $reg.get_shift()) & $reg.get_mask();
+ #end if
#end for
- }
+ break;
+ #end for
}
+}
- 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_AD9862_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='ad9862_regs',
+ regs_tmpl=REGS_TMPL,
+ body_tmpl=BODY_TMPL,
+ file=__file__,
+ )
diff --git a/host/lib/ic_reg_maps/gen_adf4360_regs.py b/host/lib/ic_reg_maps/gen_adf4360_regs.py
index 478e471a3..2a88dad8a 100755
--- a/host/lib/ic_reg_maps/gen_adf4360_regs.py
+++ b/host/lib/ic_reg_maps/gen_adf4360_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
########################################################################
@@ -59,64 +56,34 @@ band_select_clock_div 1[20:21] 0 1, 2, 4, 8
"""
########################################################################
-# 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_ADF4360_REGS_HPP
-\#define INCLUDED_ADF4360_REGS_HPP
-
-\#include <boost/cstdint.hpp>
-
-struct adf4360_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
-
- adf4360_regs_t(void){
-#for $reg in $regs
- $reg.get_name() = $reg.get_default();
-#end for
- }
-
- enum addr_t{
- ADDR_CONTROL = 0,
- ADDR_NCOUNTER = 2,
- ADDR_RCOUNTER = 1
- };
+BODY_TMPL="""\
+enum addr_t{
+ ADDR_CONTROL = 0,
+ ADDR_NCOUNTER = 2,
+ ADDR_RCOUNTER = 1
+};
- boost::uint32_t get_reg(addr_t addr){
- boost::uint32_t reg = addr & 0x3;
- switch(addr){
- #for $addr in (0, 1, 2)
- case $addr:
- #for $reg in filter(lambda r: r.get_addr() == addr, $regs)
- reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
- #end for
- break;
+boost::uint32_t get_reg(addr_t addr){
+ boost::uint32_t reg = addr & 0x3;
+ switch(addr){
+ #for $addr in (0, 1, 2)
+ case $addr:
+ #for $reg in filter(lambda r: r.get_addr() == addr, $regs)
+ reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
#end for
- }
- return reg;
+ break;
+ #end for
}
-};
-
-\#endif /* INCLUDED_ADF4360_REGS_HPP */
+ return reg;
+}
"""
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='adf4360_regs',
+ regs_tmpl=REGS_TMPL,
+ body_tmpl=BODY_TMPL,
+ file=__file__,
+ )
diff --git a/host/lib/ic_reg_maps/gen_max2829_regs.py b/host/lib/ic_reg_maps/gen_max2829_regs.py
index 6c6958707..7f9f08daa 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)
########################################################################
@@ -109,58 +106,28 @@ 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 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
- } $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__,
+ )