Пример #1
0
 def connectPorts(self, source, sourcePort, target, targetPort, enableProbe = True):
     """Connects two specified components on the specified ports. The references of the components and the ports to be connected
        are required. Moreover, if specified, a probe is introduced on the connection, i.e., the source component is connected to the target
        port of the probe and the target component is connected to the initiator port of the probe"""
     #check if ports are already connected
     key = (sourcePort.name(),targetPort.name())
     if self.__probes.has_key(key):
         return
     if ComponentManager.areConnected(self, source, sourcePort, target, targetPort):
         return
     
     if enableProbe:
         #instantiate the probe
         probeInst = self.__probeClass('probe_'+str(self.__probeID))
         self.__probeID = self.__probeID + 1
         probeInPort = helper.getTLMInPort(probeInst)
         if len(probeInPort) != 1:
             raise exceptions.Exception('The probe must have exactly one target port')
         probeOutPort = helper.getTLMOutPort(probeInst)
         if len(probeOutPort) != 1:
             raise exceptions.Exception('The probe must have exactly one initiator port')
         #interconnect the components
         ComponentManager.connectPorts(self, source, sourcePort, probeInst, probeInPort[0])
         ComponentManager.connectPorts(self, probeInst, probeOutPort[0], target, targetPort)
         #keep track of the connected probe
         key = (sourcePort.name(), targetPort.name())
         self.__probes[key] = ProbeConnectionNode(probeInst, source.name(), sourcePort.name(), target.name(), targetPort.name()) 
         return probeInst
     else:
         ComponentManager.connectPorts(self, source, sourcePort, target, targetPort)
Пример #2
0
    def connect(self, source, target):
        """Connects the source component with target; in case only one initiator port is present in source and one target port in target
        these two ports are connected, otherwise the user is requested to specify the correct ports by using the connectPortsByPathName method. 
        Note that source and target must represent the instances of the components that we wish to connect together, not their names
        """
        
        #check if source and target are SystemC components
        if not helper.isSystemCComponent(source):
            exceptions.Exception(str(source) + ' is not a SystemC component')        
        if not helper.isSystemCComponent(target):
            exceptions.Exception(str(target) + ' is not a SystemC component')        
        
        # First of all I get all the initiator ports from source and all the target ports from target
        sourcePorts = helper.getTLMOutPort(source)
        targetPorts = helper.getTLMInPort(target)

        # check if ports are already connected. TODO improve check considering single and multi_pass_through ports
        candidates = []
        for srcPort in sourcePorts:
            for trgPort in targetPorts:
                if not self.areConnected(source, srcPort.name(), target, trgPort.name()):
                    candidates.append((srcPort,trgPort))
        
        #connect if possible
        if len(candidates) == 0:
            raise exceptions.Exception('Found no possible connections among ' +
                  str(source) + ' and ' + str(target))
        elif len(candidates) > 1:
            errorString = 'There are too many possible connections among' + str(source) + ' and ' + str(target)
            errorString = errorString + 'The candidates sourcePort, targetPort are:'
            for candTemp in candidates:
                errorString = errorString + candTemp[0][1] + ' -> ' + candTemp[1][1]
            errorString = errorString + 'Please call connectPortsByPathName or connectPorts specifying ' + 'the ports you wish to connect'
            raise exceptions.Exception(errorString)
        else: #connect the two identified ports
            print('Connecting ' + source.name() + ' and ' + target.name() +
                  ' repectively using ports ' + candidates[0][0].name() + ' and ' + candidates[0][1].name())
            self.connectPorts(source, candidates[0][0], target, candidates[0][1])