aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/ic_reg_maps/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/ic_reg_maps/common.py')
-rwxr-xr-x[-rw-r--r--]host/lib/ic_reg_maps/common.py117
1 files changed, 56 insertions, 61 deletions
diff --git a/host/lib/ic_reg_maps/common.py b/host/lib/ic_reg_maps/common.py
index 24f5bf8be..5c0cfc109 100644..100755
--- a/host/lib/ic_reg_maps/common.py
+++ b/host/lib/ic_reg_maps/common.py
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2011 Ettus Research LLC
+# Copyright 2010-2011,2015 Ettus Research LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,105 +18,99 @@
import re
import sys
import math
-from Cheetah.Template import Template
+from mako.template import Template
-COMMON_TMPL = """\
-#import time
+COMMON_TMPL = """<% import time %>\
/***********************************************************************
- * This file was generated by $file on $time.strftime("%c")
+ * This file was generated by ${file} on ${time.strftime("%c")}
**********************************************************************/
-\#ifndef INCLUDED_$(name.upper())_HPP
-\#define INCLUDED_$(name.upper())_HPP
+#ifndef INCLUDED_${name.upper()}_HPP
+#define INCLUDED_${name.upper()}_HPP
-\#include <uhd/config.hpp>
-\#include <uhd/exception.hpp>
-\#include <boost/cstdint.hpp>
-\#include <set>
+#include <uhd/config.hpp>
+#include <uhd/exception.hpp>
+#include <boost/cstdint.hpp>
+#include <set>
-class $(name)_t{
+class ${name}_t{
public:
- #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
+ % for reg in regs:
+ % if reg.get_enums():
+ enum ${reg.get_type()}{
+ % for i,enum in enumerate(reg.get_enums()):
+ ${reg.get_name().upper()}_${enum[0].upper()} = ${enum[1]}<% comma = ',' if i != (len(reg.get_enums())-1) else '' %>${comma}
+ % endfor
};
- #end if
- $reg.get_type() $reg.get_name();
- #end for
+ % endif
+ ${reg.get_type()} ${reg.get_name()};
+ % endfor
- $(name)_t(void){
+ ${name}_t(void){
_state = NULL;
- #for $reg in $regs
- $reg.get_name() = $reg.get_default();
- #end for
+ % for reg in regs:
+ ${reg.get_name()} = ${reg.get_default()};
+ % endfor
}
- ~$(name)_t(void){
+ ~${name}_t(void){
delete _state;
}
- $body
+ ${body}
void save_state(void){
- if (_state == NULL) _state = new $(name)_t();
- #for $reg in $regs
- _state->$reg.get_name() = this->$reg.get_name();
- #end for
+ if (_state == NULL) _state = new ${name}_t();
+ % for reg in regs:
+ _state->${reg.get_name()} = this->${reg.get_name()};
+ % endfor
}
template<typename T> std::set<T> get_changed_addrs(void){
if (_state == NULL) throw uhd::runtime_error("no saved state");
//check each register for changes
std::set<T> addrs;
- #for $reg in $regs
- if(_state->$reg.get_name() != this->$reg.get_name()){
- addrs.insert($reg.get_addr());
+ % for reg in regs:
+ if(_state->${reg.get_name()} != this->${reg.get_name()}){
+ addrs.insert(${reg.get_addr()});
}
- #end for
+ % endfor
return addrs;
}
- #for $mreg in $mregs
- $mreg.get_type() get_$(mreg.get_name())(void){
- return
- #set $shift = 0
- #for $reg in $mreg.get_regs()
- ($(mreg.get_type())($reg.get_name() & $reg.get_mask()) << $shift) |
- #set $shift = $shift + $reg.get_bit_width()
- #end for
+ % for mreg in mregs:
+ ${mreg.get_type()} get_${mreg.get_name()}(void){
+ return <% shift = 0 %>
+ % for reg in mreg.get_regs():
+ (${mreg.get_type()}(${reg.get_name()} & ${reg.get_mask()}) << ${shift}) |<% shift = shift + reg.get_bit_width() %>
+ % endfor
0;
}
- void set_$(mreg.get_name())($mreg.get_type() reg){
- #set $shift = 0
- #for $reg in $mreg.get_regs()
- $reg.get_name() = (reg >> $shift) & $reg.get_mask();
- #set $shift = $shift + $reg.get_bit_width()
- #end for
+ void set_${mreg.get_name()}(${mreg.get_type()} reg){<% shift = 0 %>
+ % for reg in mreg.get_regs():
+ ${reg.get_name()} = (reg >> ${shift}) & ${reg.get_mask()};<% shift = shift + reg.get_bit_width() %>
+ % endfor
}
- #end for
+ % endfor
private:
- $(name)_t *_state;
+ ${name}_t *_state;
};
-\#endif /* INCLUDED_$(name.upper())_HPP */
+#endif /* INCLUDED_${name.upper()}_HPP */
"""
def parse_tmpl(_tmpl_text, **kwargs):
- return str(Template(_tmpl_text, kwargs))
+ return Template(_tmpl_text).render(**kwargs)
def to_num(arg): return int(eval(arg))
class reg:
def __init__(self, reg_des):
try: self.parse(reg_des)
- except Exception, e:
- raise Exception, 'Error parsing register description: "%s"\nWhat: %s'%(reg_des, e)
+ except Exception as e:
+ raise Exception('Error parsing register description: "%s"\nWhat: %s'%(reg_des, e))
def parse(self, reg_des):
x = re.match('^(\w*)\s*(\w*)\[(.*)\]\s*(\w*)\s*(.*)$', reg_des)
@@ -133,7 +127,8 @@ class reg:
self._enums = list()
if enums:
enum_val = 0
- for enum_str in map(str.strip, enums.split(',')):
+ for enum_str_unstripped in enums.split(','):
+ enum_str = enum_str_unstripped.strip()
if '=' in enum_str:
enum_name, enum_val = enum_str.split('=')
enum_val = to_num(enum_val)
@@ -146,7 +141,7 @@ class reg:
def get_name(self): return self._name
def get_default(self):
for key, val in self.get_enums():
- if val == self._default: return str.upper('%s_%s'%(self.get_name(), key))
+ if val == self._default: return ('%s_%s'%(self.get_name(), key)).upper()
return self._default
def get_type(self):
if self.get_enums(): return '%s_t'%self.get_name()
@@ -158,14 +153,14 @@ class reg:
class mreg:
def __init__(self, mreg_des, regs):
try: self.parse(mreg_des, regs)
- except Exception, e:
- raise Exception, 'Error parsing meta register description: "%s"\nWhat: %s'%(mreg_des, e)
+ except Exception as e:
+ raise Exception('Error parsing meta register description: "%s"\nWhat: %s'%(mreg_des, e))
def parse(self, mreg_des, regs):
x = re.match('^~(\w*)\s+(.*)\s*$', mreg_des)
self._name, reg_names = x.groups()
regs_dict = dict([(reg.get_name(), reg) for reg in regs])
- self._regs = [regs_dict[reg_name] for reg_name in map(str.strip, reg_names.split(','))]
+ self._regs = [regs_dict[reg_name.strip()] for reg_name in reg_names.split(',')]
def get_name(self): return self._name
def get_regs(self): return self._regs