def find_stvars(var, expr, stvars, ics): def visit(e): return find_stvars(var, e, stvars, ics) if expr.op == op.OpType.INTEG: handle = expr.handle key = "%s%s" % (var, handle) ics[key] = expr.init_cond.value stvars[key] = visit(expr.deriv) return op.Var(key) elif expr.op == op.OpType.ADD: return op.Add(visit(expr.arg1), visit(expr.arg2)) elif expr.op == op.OpType.MULT: return op.Mult(visit(expr.arg1), visit(expr.arg2)) elif expr.op == op.OpType.VAR or \ expr.op == op.OpType.EXTVAR or \ expr.op == op.OpType.CONST: return expr elif expr.op == op.OpType.EMIT: return op.Emit(visit(expr.arg(0)))
def expr(self, port, biases={}, inject=True): naked_expr = self._exprs[port] if not inject: return naked_expr repl = {} for inj_port, value in self._injs.items(): bias = 0.0 if not port in biases else biases[port] var = ops.Var(inj_port) if port in biases: var = ops.Add(var, \ ops.Const(biases[port])) e = ops.Mult(ops.Const(value), var) repl[inj_port] = e inj_out = self._injs['out'] e = ops.Mult(ops.Const(inj_out), naked_expr.substitute(repl)) if 'out' in biases: e = ops.Add(ops.Const(biases['out']), e) return e
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', \ "*","*",'in'), \
def lark_to_ast(node, lambda_impls, handle_enumerator): def recurse(ch): return lark_to_ast(ch,lambda_impls, \ handle_enumerator) n = len(node.children) if node.data == "neg": report(n == 1, "negation operation takes one argument") expr = recurse(node.children[0]) if (expr.op == op.OpType.CONST): return op.Const(-1 * expr.value) else: return op.Mult(op.Const(-1), expr) if node.data == "func": report(n > 0, "function name not specified") func_name = node.children[0] report(func_name.type == "NAME", "expected Token.NAME") arguments = recurse(node.children[1]) if not isinstance(arguments, list): arguments = [arguments] return function_to_ast(func_name.value,arguments, \ lambda_impls, handle_enumerator=handle_enumerator) if node.data == "number": number = node.children[0] report(number.type == "NUMBER", "expected Token.NUMBER") value = float(number.value) return op.Const(value) if node.data == "var": report(n == 1, "variable must have token") var_name = node.children[0] report(var_name.type == "NAME", "expected Token.NAME") return op.Var(var_name.value) if node.data == "sub": report(n == 2, "only binary subtraction are supported") e1 = recurse(node.children[0]) e2 = recurse(node.children[1]) return op.Add(e1, op.Mult(op.Const(-1), e2)) if node.data == "add": report(n == 2, "only binary adds are supported") e1 = recurse(node.children[0]) e2 = recurse(node.children[1]) return op.Add(e1, e2) if node.data == "mul": report(n == 2, "only binary mults are supported") e1 = recurse(node.children[0]) e2 = recurse(node.children[1]) return op.Mult(e1, e2) if node.data == "div": report(n == 2, "only binary div are supported") e1 = recurse(node.children[0]) e2 = recurse(node.children[1]) return op.Div(e1, e2) if node.data == "pow": report(n == 2, "only binary div are supported") e1 = recurse(node.children[0]) e2 = recurse(node.children[1]) return op.Pow(e1, e2) if node.data == "lst": e1 = recurse(node.children[0]) e2 = recurse(node.children[1]) if not isinstance(e1, list): e1 = [e1] e1.append(e2) return e1 else: raise Exception("unknown operator: %s" % node.data)
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()