Пример #1
0
def main(filename):
    with open(filename) as f:
        text = f.read()
        parser = bsdl.bsdlParser()
        ast = parser.parse(text,
                           "bsdl_description",
                           semantics=BsdlSemantics(),
                           parseinfo=False)
        print(json.dumps(ast.asjson()))
Пример #2
0
    def map_string(self, ast):
        """
        When a PIN_MAP is encountered, parse out pins and store them for later conversion
        """
        parser = bsdl.bsdlParser()
        ast = parser.parse(''.join(ast), "port_map")
        for item in ast:
            for pin in item['pin_list']:
                if int(pin) in self._pin_map.keys():
                    raise Exception('Pin {} already in pin list?! BSDL is malformed. (pin name: {})'.format(pin, item['port_name']))

                self._pin_map[int(pin)] = item['port_name']
        return ast
Пример #3
0
def main():
    parser = argparse.ArgumentParser(description='Parse a BSDL file and generate a pin map CSV from it for use with Allegro.')
    parser.add_argument('-o', '--output', type=str, required=False, help='File to write to (default: stdout)', default='/dev/stdout')
    parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose logging')
    parser.add_argument('filename', type=str, help='BSDL file to parse')
    args = parser.parse_args()

    # Set up logging.
    if args.verbose:
        log_level = logging.DEBUG
    else:
        log_level = logging.INFO

    logging.basicConfig(format='%(asctime)s - %(name)s:%(levelname)s:%(message)s', datefmt='%m/%d/%Y %H:%M:%S', level=log_level)

    logging.debug('Input file: {}'.format(args.filename))

    # Open the BSDL and turn it into a Python object
    with open(args.filename) as f:
        text = f.read()
        parser = bsdl.bsdlParser()
        semantics = CSVPinConvertSemantics()

        # Walk the AST, and collect a pin map from it.
        ast = parser.parse(text, 'bsdl_description', semantics=semantics, parseinfo=False)

    logging.debug('Finished parsing BSDL. There are {} pins. Port vector length is {}. Generating pinmap.'.format(len(semantics._pin_map.keys()), semantics._port_vec_length))

    output_pin_map = []

    for pin_mapping in sorted(semantics._pin_map.items()):
        port_attrs = semantics._port_map.get(pin_mapping[1], {})
        logging.debug('Pin {} Port {}, attributes: {}'.format(pin_mapping[0], pin_mapping[1], port_attrs))
        port_dir = _direction_mapping.get(port_attrs.get('direction', 'passive'), 'Passive')
        pin_name = pin_mapping[1]
        if port_attrs.get('nr_pins', 1) != 1:
            pin_name = '{}{}'.format(pin_name, port_attrs['next_pin'])
            port_attrs['next_pin'] += 1
        output_pin_map.append({'Number': pin_mapping[0], 'Name': pin_name, 'Type' : port_dir, 'Shape': 'Short'})

    with open(args.output, 'wt+') as outf:
        writer = csv.DictWriter(outf, fieldnames=['Number', 'Name', 'Type', 'Shape'], dialect='excel')

        writer.writeheader()
        for mapping in output_pin_map:
            writer.writerow(mapping)
Пример #4
0
	def __init__(self, bsdlfile, pins):
		parser = bsdl.bsdlParser()
		self.bsd_data = parser.parse(open(bsdlfile).read(), "bsdl_description", semantics=BsdlSemantics(), parseinfo=False)
		self.dr_scan_len = int(self.bsd_data["boundary_scan_register_description"]["fixed_boundary_stmts"]["boundary_length"])
		self.ir_scan_len = int(self.bsd_data["instruction_register_description"]["instruction_length"])

		led_a_pin = "IO64"
		led_b_pin = "IO48"
		pos_out_led_green = self.get_pin_pos(led_a_pin, "OUTPUT3")
		pos_out_led_yellow = self.get_pin_pos(led_b_pin, "OUTPUT3")

		self.fill_instructions()
		print(self.instructions)

		self.testpins = pins

		self.sample = DataSerializer()
		self.sample.add_data_block(self.ir_scan_len, self.instructions["SAMPLE"])
		self.sample.add_data_block(self.ir_scan_len, self.instructions["SAMPLE"])

		self.extest = DataSerializer()
		self.extest.add_data_block(self.ir_scan_len, self.instructions["EXTEST"])
		self.extest.add_data_block(self.ir_scan_len, self.instructions["EXTEST"])

		self.testdata = DataSerializer()

		self.result_mask = DataSerializer()

		self.expected_result = DataSerializer()

		self.testcon = DataSerializer()
		self.testcon.add_data_block(self.ir_scan_len, self.instructions["SAMPLE"])
		self.testcon.add_data_block(self.ir_scan_len, self.instructions["EXTEST"])

		self.led_green_on = DataSerializer()
		self.led_green_on.add_data_block(self.dr_scan_len, 0)
		self.led_green_on.add_data_block(self.dr_scan_len, 1 << pos_out_led_green)
Пример #5
0
 def grouped_port_identification(self, ast):
     parser = bsdl.bsdlParser()
     ast = parser.parse(''.join(ast), "group_table")
     return ast
Пример #6
0
 def map_string(self, ast):
     parser = bsdl.bsdlParser()
     ast = parser.parse(''.join(ast), "port_map")
     return ast
Пример #7
0
def main(filename):
    with open(filename) as f:
        text = f.read()
        parser = bsdl.bsdlParser()
        ast = parser.parse(text, "bsdl_description", semantics=BsdlSemantics(), parseinfo=False)
        print(json.dumps(ast.asjson()))
Пример #8
0
 def grouped_port_identification(self, ast):
     parser = bsdl.bsdlParser()
     ast = parser.parse(''.join(ast), "group_table")
     return ast
Пример #9
0
 def map_string(self, ast):
     parser = bsdl.bsdlParser()
     ast = parser.parse(''.join(ast), "port_map")
     return ast