from hwlib.hcdc.globals \ import CTX, GLProp,HCDCSubset from hwlib.block import Block,BlockType ana_props = util.make_ana_props(enums.RangeType.HIGH,\ glb.CTX.get(glb.GLProp.CURRENT_INTERVAL, 'tile_out', \ "*","*",None)) tile_out = Block('tile_out',type=BlockType.BUS) \ .set_comp_modes(["*"], \ HCDCSubset.all_subsets()) \ .set_scale_modes("*",["*"], \ HCDCSubset.all_subsets()) \ .add_outputs(props.CURRENT,["out"]) \ .add_inputs(props.CURRENT,["in"]) \ .set_op("*","out",ops.Var("in")) \ .set_props("*","*",["out","in"], ana_props) \ .set_coeff("*","*","out",1.0) \ .check() ana_props = util.make_ana_props(enums.RangeType.HIGH,\ CTX.get(GLProp.CURRENT_INTERVAL, 'tile_in', \ "*","*",None)) tile_in = Block('tile_in',type=BlockType.BUS) \ .set_comp_modes(["*"], \ HCDCSubset.all_subsets()) \ .set_scale_modes("*",["*"], \ HCDCSubset.all_subsets()) \
"*","*",'in')) props_in.set_physical(True) props_out = util.make_ana_props(enums.RangeType.MED,\ glb.CTX.get(glb.GLProp.CURRENT_INTERVAL, 'ext_chip_analog_in', \ "*","*",'out')) coeff = glb.CTX.get(glb.GLProp.COEFF,"ext_chip_analog_in", "*","*","out") block_analog_in = Block('ext_chip_analog_in') \ .set_comp_modes(["*"], \ glb.HCDCSubset.all_subsets()) \ .set_scale_modes("*",["*"], \ glb.HCDCSubset.all_subsets()) \ .add_outputs(props.CURRENT,["out"]) \ .add_inputs(props.CURRENT,["in"]) \ .set_op("*","out",ops.Var("in")) \ .set_props("*","*",["in"],props_in) \ .set_props("*","*",["out"], props_out) \ .set_coeff("*","*","out",coeff) \ .check() # DUE DAC -> VTOI coeff = glb.CTX.get(glb.GLProp.COEFF,"ext_chip_in", "*","*","out") props_in = util.make_dig_props(enums.RangeType.MED, \ glb.CTX.get( glb.GLProp.DIGITAL_INTERVAL, \ 'ext_chip_in', \
get_prop = lambda p: glb.CTX.get(p, fanout.name, '*', mode, None) ana_props = util.make_ana_props( rng, get_prop(glb.GLProp.CURRENT_INTERVAL)) fanout\ .set_coeff(comp_mode,rng,"out0",1.0) \ .set_coeff(comp_mode,rng,"out1",1.0) \ .set_coeff(comp_mode,rng,"out2",1.0) fanout\ .set_props(comp_mode,rng,["out0","out1","out2","in"], ana_props) fanout.check() block = Block('fanout',type=BlockType.COPIER) \ .set_comp_modes(get_comp_modes(), glb.HCDCSubset.all_subsets()) \ .add_outputs(props.CURRENT,["out1","out2","out0"]) \ .add_inputs(props.CURRENT,["in"]) do_sign = lambda mode: ops.Var("in") \ if mode == enums.SignType.POS \ else ops.Mult(ops.Var("in"),ops.Const(-1)) for mode in get_comp_modes(): sign0, sign1, sign2 = mode block.set_op(mode, "out0", do_sign(sign0)) block.set_op(mode, "out1", do_sign(sign1)) block.set_op(mode, "out2", do_sign(sign2)) scale_model(block)
dig_props.set_constant() dig_props.set_resolution(get_prop(glb.GLProp.DIGITAL_RESOLUTION)) mult.set_props("vga",mode,["in0"], util.make_ana_props(in0rng, \ get_prop(glb.GLProp.CURRENT_INTERVAL) )) mult.set_props("vga",mode,["in1"], util.make_ana_props(enums.RangeType.MED, \ get_prop(glb.GLProp.CURRENT_INTERVAL) )) mult.set_props("vga", mode, ["coeff"], dig_props) mult.set_props("vga",mode,["out"], util.make_ana_props(outrng, \ get_prop(glb.GLProp.CURRENT_INTERVAL) )) mult.set_coeff("vga", mode, 'out', scf) block = Block('multiplier') \ .set_comp_modes(["mul","vga"], glb.HCDCSubset.all_subsets()) \ .add_inputs(props.CURRENT,["in0","in1"]) \ .add_inputs(props.DIGITAL,["coeff"]) \ .add_outputs(props.CURRENT,["out"]) \ .set_op("mul","out",ops.Mult(ops.Var("in0"),ops.Var("in1"))) \ .set_op("vga","out",ops.Mult(ops.Var("coeff"),ops.Var("in0"))) scale_model(block) block.check()
integ.set_props(comp_mode, scale_mode, ["out"], analog_out) scf_inout = outrng.coeff() / inrng.coeff() # alteration: initial condition, is not scaled scf_ic = outrng.coeff() * 2.0 integ.set_coeff(comp_mode, scale_mode, "out", scf_inout, handle=':z\'') integ.set_coeff(comp_mode, scale_mode, "out", scf_ic, ':z[0]') integ.set_coeff(comp_mode, scale_mode, "out", 1.0, handle=':z') integ.set_coeff(comp_mode, scale_mode, "out", 1.0) block = Block('integrator',) \ .set_comp_modes(get_comp_modes(),glb.HCDCSubset.all_subsets()) \ .add_inputs(props.CURRENT,["in","ic"]) \ .add_outputs(props.CURRENT,["out"]) \ .set_op(enums.SignType.POS,"out", ops.Integ(ops.Var("in"), ops.Var("ic"), handle=':z' ) ) \ .set_op(enums.SignType.NEG,"out", ops.Integ(ops.Mult(ops.Const(-1),ops.Var("in")), \ ops.Var("ic"), handle=':z') ) scale_model(block) block.check()
digital_props = util.make_dig_props( enums.RangeType.MED, get_prop(glb.GLProp.DIGITAL_INTERVAL), get_prop(glb.GLProp.DIGITAL_QUANTIZE)) ana_props = util.make_ana_props(rng, get_prop(glb.GLProp.CURRENT_INTERVAL)) digital_props.set_continuous(0, get_prop(glb.GLProp.MAX_FREQ)) digital_props.set_resolution(get_prop(glb.GLProp.DIGITAL_RESOLUTION)) digital_props.set_coverage(get_prop(glb.GLProp.DIGITAL_COVERAGE)) dac.set_coeff("*", mode, 'out', coeff) dac.set_props("*", mode, ["in"], digital_props) dac.set_props("*", mode, ["out"], ana_props) dac = Block('tile_dac',type=BlockType.DAC) \ .set_comp_modes(["*"], \ glb.HCDCSubset.all_subsets()) \ .add_outputs(props.CURRENT,["out"]) \ .add_inputs(props.DIGITAL,["in"]) \ .set_op("*","out",ops.Var("in")) dac_scale_model(dac) dac.check() def adc_get_modes(): return [enums.RangeType.HIGH, enums.RangeType.MED] def adc_is_standard(mode): return mode == enums.RangeType.MED def adc_scale_model(adc):
import ops.op as ops def mkdig(port): dig= util.make_dig_props(enums.RangeType.MED,\ glb.CTX.get(glb.GLProp.DIGITAL_INTERVAL, "lut","*","*",None), glb.CTX.get(glb.GLProp.DIGITAL_QUANTIZE, "lut","*","*",None) ) dig.set_continuous(0,glb.CTX.get(glb.GLProp.MAX_FREQ, \ "lut","*","*",None)) dig.set_coverage(glb.CTX.get(glb.GLProp.DIGITAL_COVERAGE, "lut","*","*",port)) return dig block = Block("lut") \ .add_inputs(props.DIGITAL,["in"]) \ .add_outputs(props.DIGITAL,["out"]) \ .set_comp_modes(["*"], \ glb.HCDCSubset.all_subsets()) \ .set_scale_modes("*",["*"], \ glb.HCDCSubset.all_subsets()) \ block.set_props("*","*",["in"], mkdig("in")) block.set_props("*","*",["out"], mkdig("out")) block.set_op("*","out",ops.Func(["in"],None)) \ .check()