root / host / lib / ic_reg_maps / gen_adf4360_regs.py @ 6b015b1c
History | View | Annotate | Download (4.73 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 |
########################################################################
|
| 31 |
## address 0
|
| 32 |
########################################################################
|
| 33 |
core_power_level 0[2:3] 0 5ma, 10ma, 15ma, 20ma
|
| 34 |
counter_operation 0[4] 0 normal, reset
|
| 35 |
muxout_control 0[5:7] 0 3state, dld, ndiv, dvdd, rdiv, nchan_od_ld, sdo, dgnd
|
| 36 |
phase_detector_polarity 0[8] 0 neg, pos
|
| 37 |
charge_pump_output 0[9] 0 normal, 3state
|
| 38 |
cp_gain_0 0[10] 0 set1, set2
|
| 39 |
mute_till_ld 0[11] 0 dis, enb
|
| 40 |
output_power_level 0[12:13] 0 3_5ma, 5_0ma, 7_5ma, 11_0ma
|
| 41 |
#set $current_setting_enums = ', '.join(map(lambda x: x+"ma", "0_31 0_62 0_93 1_25 1_56 1_87 2_18 2_50".split()))
|
| 42 |
current_setting1 0[14:16] 0 $current_setting_enums
|
| 43 |
current_setting2 0[17:19] 0 $current_setting_enums
|
| 44 |
power_down 0[20:21] 0 normal_op=0, async_pd=1, sync_pd=3
|
| 45 |
prescaler_value 0[22:23] 0 8_9, 16_17, 32_33
|
| 46 |
########################################################################
|
| 47 |
## address 2
|
| 48 |
########################################################################
|
| 49 |
a_counter 2[2:6] 0
|
| 50 |
b_counter 2[8:20] 0
|
| 51 |
cp_gain_1 2[21] 0 set1, set2
|
| 52 |
divide_by_2_output 2[22] 0 fund, div2
|
| 53 |
divide_by_2_prescaler 2[23] 0 fund, div2
|
| 54 |
########################################################################
|
| 55 |
## address 1
|
| 56 |
########################################################################
|
| 57 |
r_counter 1[2:15] 0
|
| 58 |
ablpw 1[16:17] 0 3_0ns, 1_3ns, 6_0ns
|
| 59 |
lock_detect_precision 1[18] 0 3cycles, 5cycles
|
| 60 |
test_mode_bit 1[19] 0
|
| 61 |
band_select_clock_div 1[20:21] 0 1, 2, 4, 8
|
| 62 |
"""
|
| 63 |
|
| 64 |
########################################################################
|
| 65 |
# Header and Source templates below
|
| 66 |
########################################################################
|
| 67 |
HEADER_TEXT="""
|
| 68 |
#import time
|
| 69 |
|
| 70 |
/***********************************************************************
|
| 71 |
* This file was generated by $file on $time.strftime("%c")
|
| 72 |
**********************************************************************/
|
| 73 |
|
| 74 |
\#ifndef INCLUDED_ADF4360_REGS_HPP
|
| 75 |
\#define INCLUDED_ADF4360_REGS_HPP
|
| 76 |
|
| 77 |
\#include <boost/cstdint.hpp>
|
| 78 |
|
| 79 |
struct adf4360_regs_t{
|
| 80 |
#for $reg in $regs
|
| 81 |
#if $reg.get_enums()
|
| 82 |
enum $(reg.get_name())_t{
|
| 83 |
#for $i, $enum in enumerate($reg.get_enums())
|
| 84 |
#set $end_comma = ',' if $i < len($reg.get_enums())-1 else ''
|
| 85 |
$(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma
|
| 86 |
#end for
|
| 87 |
} $reg.get_name();
|
| 88 |
#else
|
| 89 |
boost::$reg.get_stdint_type() $reg.get_name();
|
| 90 |
#end if
|
| 91 |
#end for
|
| 92 |
|
| 93 |
adf4360_regs_t(void){
|
| 94 |
#for $reg in $regs
|
| 95 |
$reg.get_name() = $reg.get_default();
|
| 96 |
#end for
|
| 97 |
}
|
| 98 |
|
| 99 |
enum addr_t{
|
| 100 |
ADDR_CONTROL = 0,
|
| 101 |
ADDR_NCOUNTER = 2,
|
| 102 |
ADDR_RCOUNTER = 1
|
| 103 |
};
|
| 104 |
|
| 105 |
boost::uint32_t get_reg(addr_t addr){
|
| 106 |
boost::uint32_t reg = addr & 0x3;
|
| 107 |
switch(addr){
|
| 108 |
#for $addr in (0, 1, 2)
|
| 109 |
case $addr:
|
| 110 |
#for $reg in filter(lambda r: r.get_addr() == addr, $regs)
|
| 111 |
reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
|
| 112 |
#end for
|
| 113 |
break;
|
| 114 |
#end for
|
| 115 |
}
|
| 116 |
return reg;
|
| 117 |
}
|
| 118 |
};
|
| 119 |
|
| 120 |
\#endif /* INCLUDED_ADF4360_REGS_HPP */
|
| 121 |
"""
|
| 122 |
|
| 123 |
if __name__ == '__main__': |
| 124 |
regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines())
|
| 125 |
open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) |