root / host / lib / ic_reg_maps / gen_ad7922_regs.py @ 6b015b1c
History | View | Annotate | Download (2.88 KB)
| 1 |
#!/usr/bin/env python
|
|---|---|
| 2 |
#
|
| 3 |
# Copyright 2008,2009 Free Software Foundation, Inc.
|
| 4 |
#
|
| 5 |
# This file is part of GNU Radio
|
| 6 |
#
|
| 7 |
# GNU Radio is free software; you can redistribute it and/or modify
|
| 8 |
# it under the terms of the GNU General Public License as published by
|
| 9 |
# the Free Software Foundation; either asversion 3, or (at your option)
|
| 10 |
# any later version.
|
| 11 |
#
|
| 12 |
# GNU Radio is distributed in the hope that it will be useful,
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
# GNU General Public License for more details.
|
| 16 |
#
|
| 17 |
# You should have received a copy of the GNU General Public License
|
| 18 |
# along with GNU Radio; see the file COPYING. If not, write to
|
| 19 |
# the Free Software Foundation, Inc., 51 Franklin Street,
|
| 20 |
# Boston, MA 02110-1301, USA.
|
| 21 |
|
| 22 |
import sys |
| 23 |
from common import * |
| 24 |
|
| 25 |
########################################################################
|
| 26 |
# Template for raw text data describing registers
|
| 27 |
# name addr[bit range inclusive] default optional enums
|
| 28 |
########################################################################
|
| 29 |
REGS_DATA_TMPL="""\
|
| 30 |
result 0[0:11] 0
|
| 31 |
mod 0[12] 0
|
| 32 |
chn 0[13] 0
|
| 33 |
"""
|
| 34 |
|
| 35 |
########################################################################
|
| 36 |
# Header and Source templates below
|
| 37 |
########################################################################
|
| 38 |
HEADER_TEXT="""
|
| 39 |
#import time
|
| 40 |
|
| 41 |
/***********************************************************************
|
| 42 |
* This file was generated by $file on $time.strftime("%c")
|
| 43 |
**********************************************************************/
|
| 44 |
|
| 45 |
\#ifndef INCLUDED_AD7922_REGS_HPP
|
| 46 |
\#define INCLUDED_AD7922_REGS_HPP
|
| 47 |
|
| 48 |
\#include <boost/cstdint.hpp>
|
| 49 |
|
| 50 |
struct ad7922_regs_t{
|
| 51 |
#for $reg in $regs
|
| 52 |
#if $reg.get_enums()
|
| 53 |
enum $(reg.get_name())_t{
|
| 54 |
#for $i, $enum in enumerate($reg.get_enums())
|
| 55 |
#set $end_comma = ',' if $i < len($reg.get_enums())-1 else ''
|
| 56 |
$(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma
|
| 57 |
#end for
|
| 58 |
} $reg.get_name();
|
| 59 |
#else
|
| 60 |
boost::$reg.get_stdint_type() $reg.get_name();
|
| 61 |
#end if
|
| 62 |
#end for
|
| 63 |
|
| 64 |
ad7922_regs_t(void){
|
| 65 |
#for $reg in $regs
|
| 66 |
$reg.get_name() = $reg.get_default();
|
| 67 |
#end for
|
| 68 |
}
|
| 69 |
|
| 70 |
boost::uint16_t get_reg(void){
|
| 71 |
boost::uint16_t reg = 0;
|
| 72 |
#for $reg in filter(lambda r: r.get_addr() == 0, $regs)
|
| 73 |
reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
|
| 74 |
#end for
|
| 75 |
return reg;
|
| 76 |
}
|
| 77 |
|
| 78 |
void set_reg(boost::uint16_t reg){
|
| 79 |
#for $reg in filter(lambda r: r.get_addr() == 0, $regs)
|
| 80 |
$reg.get_name() = (reg >> $reg.get_shift()) & $reg.get_mask();
|
| 81 |
#end for
|
| 82 |
}
|
| 83 |
|
| 84 |
};
|
| 85 |
|
| 86 |
\#endif /* INCLUDED_AD7922_REGS_HPP */
|
| 87 |
"""
|
| 88 |
|
| 89 |
if __name__ == '__main__': |
| 90 |
regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines())
|
| 91 |
open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) |