Exemplo n.º 1
0
	def __init__(self, deviceName, logger=None):

		XMLDeviceReader.__init__(self, os.path.join(os.path.dirname(__file__), 'data', deviceName + '.xml'), logger)
		self.name = deviceName
		self.id = DeviceIdentifier(self.name.lower())
		self.graph = nx.DiGraph()

		self.log.info("STMClockReader: Parsing '{}'".format(self.id.string))

		rccName = "RCC-STM32F100_rcc_v1_0_Modes"
		self.rcc = XMLDeviceReader(os.path.join(os.path.dirname(__file__), 'data', rccName + '.xml'), logger)

		self.parameters = []
		for parameter in self.rcc.query("//RefParameter"):
			p = STMXMLParameter(parameter.attrib)

			p.values = [STMXMLValue(c.attrib) for c in parameter.getchildren() if c.tag == 'PossibleValue']
			p.conditions = [STMXMLCondition(c.attrib) for c in parameter.getchildren() if c.tag == 'Condition']

			self.parameters.append(p)
			# self.log.debug("STMClockReader: {}".format(p))

		self.elements = []
		self.connections = []

		# read all elements and connections
		for element in self.query("//Element"):
			e = STMClockElement(element.attrib)
			# only store the ids of the in and outputs for now
			e.outputs = [c.get('to') for c in element.getchildren() if c.tag == 'Output']
			e.inputs = [c.get('from') for c in element.getchildren() if c.tag == 'Input']
			e.conditions = [c.attrib for c in element.getchildren() if c.tag == 'Condition']
			if 'refParameter' in e.attributes:
				e.parameters = [p for p in self.parameters if p.name == e.attributes['refParameter']]

			# create the connections
			for c in [c.attrib for c in element.getchildren() if c.tag in ['Input', 'Output']]:
				conn = STMClockConnection(e, c)
				if conn not in self.connections:
					self.connections.append(conn)

			self.elements.append(e)

		for signal in self.query("//Signals/Signal"):
			param = signal.get('refParameter')
			if param is not None and param != "":
				conn = [c for c in self.connections if c.id == signal.get('id')][0]
				conn.attributes['refParameter'] = param

		# connect the element input and outputs with the actual object, not just the id string
		for element in self.elements:
			inputs = []
			outputs = []
			for i in element.inputs:
				inputs.extend([e for e in self.elements if e.id == i])
			for o in element.outputs:
				outputs.extend([e for e in self.elements if e.id == o])
			element.inputs = inputs
			element.outputs = outputs
			self.log.debug("STMClockReader: {}".format(element))



			for p in element.parameters:
				# self.graph.add_edge(element, p)
				# for v in p.values:
				# 	self.graph.add_edge(p, v)
				# for c in p.conditions:
				# 	self.graph.add_edge(p, c)

				if 'IP' in p.attributes:
					for ip in p.attributes['IP'].split(','):
						e = STMClockElement({'id': ip, 'type': "ip"})
						# self.graph.add_edge(e, element)

			for i in element.inputs:
				self.graph.add_edge(i, element)
			for o in element.outputs:
				self.graph.add_edge(element, o)

		for conn in self.connections:
			if 'refParameter' in conn.attributes:
				conn.parameters = [p for p in self.parameters if p.name == conn.attributes['refParameter']]

			conn.begin = filter(lambda e: e.id == conn.begin, self.elements)[0]
			conn.end = filter(lambda e: e.id == conn.end, self.elements)[0]
			self.log.debug("STMClockReader: {}".format(conn))

		"""
		# find the SYSCLK connection
		sysClk = filter(lambda c: c.id == 'SYSCLK', self.connections)[0]

		# find the clock tree elements
		systemClockSink = sysClk.begin.getChildren()
		# and the system clock elements
		systemClockSource = sysClk.end.getParents()

		print '\n### SytemClock ###'
		for e in clockTree:
			print e

		print '\n### Sources ###'

		for e in systemClock:
			print e

		# simple filtering now possible

		self.sinks = filter(lambda e: len(e.outputs) == 0, self.elements)

		for e in self.elements:
			print e

		self.sources = []
		for s in filter(lambda e: len(e.inputs) == 0, self.elements):
			self.sources.extend(self._parseSource(s))

		print '\n### Sources ###'
		for s in self.sources:
			print s



		self.pll = {'name': 'Pll', 'inputs': [], 'multiplier':'2:16'}
		# find the PLL Multiplier connection
		pllMul = filter(lambda c: c.id == 'PLLMUL', self.elements)[0]


		print '\n### Pll ###'
		pllMulPaths = pllMul.getParentPaths()
		pllInputs = []
		for path in pllMulPaths:
			print [p.id for p in path]
			sources = self._parseSource(path[-1])
			for source in sources:
				input = {'name': source['name']}
				divisor = filter(lambda c: c.type == 'devisor', path)[0]
				print divisor.parameters
		"""

		# nx.draw_graphviz(self.graph)
		# plt.savefig("path.png")
		nx.write_dot(self.graph,'file.dot')
Exemplo n.º 2
0
    def __init__(self, deviceName, logger=None):

        XMLDeviceReader.__init__(
            self,
            os.path.join(os.path.dirname(__file__), 'data',
                         deviceName + '.xml'), logger)
        self.name = deviceName
        self.id = DeviceIdentifier(self.name.lower())
        self.graph = nx.DiGraph()

        self.log.info("STMClockReader: Parsing '{}'".format(self.id.string))

        rccName = "RCC-STM32F100_rcc_v1_0_Modes"
        self.rcc = XMLDeviceReader(
            os.path.join(os.path.dirname(__file__), 'data', rccName + '.xml'),
            logger)

        self.parameters = []
        for parameter in self.rcc.query("//RefParameter"):
            p = STMXMLParameter(parameter.attrib)

            p.values = [
                STMXMLValue(c.attrib) for c in parameter.getchildren()
                if c.tag == 'PossibleValue'
            ]
            p.conditions = [
                STMXMLCondition(c.attrib) for c in parameter.getchildren()
                if c.tag == 'Condition'
            ]

            self.parameters.append(p)
            # self.log.debug("STMClockReader: {}".format(p))

        self.elements = []
        self.connections = []

        # read all elements and connections
        for element in self.query("//Element"):
            e = STMClockElement(element.attrib)
            # only store the ids of the in and outputs for now
            e.outputs = [
                c.get('to') for c in element.getchildren() if c.tag == 'Output'
            ]
            e.inputs = [
                c.get('from') for c in element.getchildren()
                if c.tag == 'Input'
            ]
            e.conditions = [
                c.attrib for c in element.getchildren() if c.tag == 'Condition'
            ]
            if 'refParameter' in e.attributes:
                e.parameters = [
                    p for p in self.parameters
                    if p.name == e.attributes['refParameter']
                ]

            # create the connections
            for c in [
                    c.attrib for c in element.getchildren()
                    if c.tag in ['Input', 'Output']
            ]:
                conn = STMClockConnection(e, c)
                if conn not in self.connections:
                    self.connections.append(conn)

            self.elements.append(e)

        for signal in self.query("//Signals/Signal"):
            param = signal.get('refParameter')
            if param is not None and param != "":
                conn = [
                    c for c in self.connections if c.id == signal.get('id')
                ][0]
                conn.attributes['refParameter'] = param

        # connect the element input and outputs with the actual object, not just the id string
        for element in self.elements:
            inputs = []
            outputs = []
            for i in element.inputs:
                inputs.extend([e for e in self.elements if e.id == i])
            for o in element.outputs:
                outputs.extend([e for e in self.elements if e.id == o])
            element.inputs = inputs
            element.outputs = outputs
            self.log.debug("STMClockReader: {}".format(element))

            for p in element.parameters:
                # self.graph.add_edge(element, p)
                # for v in p.values:
                # 	self.graph.add_edge(p, v)
                # for c in p.conditions:
                # 	self.graph.add_edge(p, c)

                if 'IP' in p.attributes:
                    for ip in p.attributes['IP'].split(','):
                        e = STMClockElement({'id': ip, 'type': "ip"})
                        # self.graph.add_edge(e, element)

            for i in element.inputs:
                self.graph.add_edge(i, element)
            for o in element.outputs:
                self.graph.add_edge(element, o)

        for conn in self.connections:
            if 'refParameter' in conn.attributes:
                conn.parameters = [
                    p for p in self.parameters
                    if p.name == conn.attributes['refParameter']
                ]

            conn.begin = filter(lambda e: e.id == conn.begin, self.elements)[0]
            conn.end = filter(lambda e: e.id == conn.end, self.elements)[0]
            self.log.debug("STMClockReader: {}".format(conn))
        """
		# find the SYSCLK connection
		sysClk = filter(lambda c: c.id == 'SYSCLK', self.connections)[0]

		# find the clock tree elements
		systemClockSink = sysClk.begin.getChildren()
		# and the system clock elements
		systemClockSource = sysClk.end.getParents()

		print '\n### SytemClock ###'
		for e in clockTree:
			print e

		print '\n### Sources ###'

		for e in systemClock:
			print e

		# simple filtering now possible

		self.sinks = filter(lambda e: len(e.outputs) == 0, self.elements)

		for e in self.elements:
			print e

		self.sources = []
		for s in filter(lambda e: len(e.inputs) == 0, self.elements):
			self.sources.extend(self._parseSource(s))

		print '\n### Sources ###'
		for s in self.sources:
			print s



		self.pll = {'name': 'Pll', 'inputs': [], 'multiplier':'2:16'}
		# find the PLL Multiplier connection
		pllMul = filter(lambda c: c.id == 'PLLMUL', self.elements)[0]


		print '\n### Pll ###'
		pllMulPaths = pllMul.getParentPaths()
		pllInputs = []
		for path in pllMulPaths:
			print [p.id for p in path]
			sources = self._parseSource(path[-1])
			for source in sources:
				input = {'name': source['name']}
				divisor = filter(lambda c: c.type == 'devisor', path)[0]
				print divisor.parameters
		"""

        # nx.draw_graphviz(self.graph)
        # plt.savefig("path.png")
        nx.write_dot(self.graph, 'file.dot')