Python Model for discussion

Hardware Architectures Document
Please debate the content of Volume 3 here!
User avatar
Ian McIntosh
SJTAG Chair
Posts: 504
Joined: Mon Nov 05, 2007 11:49 pm
Location: Leonardo, UK

Python Model for discussion

Post by Ian McIntosh »

At the September 13, 2010 meeting, Brad presented and described this (incomplete) model in Python:

Code: Select all

import bitstring

class model:
	def __init__(self):
		pass
	
class ChainTypes:
	{UNDEFINED, STATIC_PATH, DYNAMIC_PATH, EXTERNAL_PATH, TAP_INTERFACE} = range(5)
	
class ScanChainSegment(object):
	def __init__(self, input, output, type=ChainTypes.UNDEFINED):
		self.input = input
		self.output = output
		self.type = type
		
	def drlength(self):
		return 0
	
	def irlength(self):
		return 0
	
	def scandr(self, parent):
		pass
	
	def scanir(self, parent):
		pass
	
	def scanCallback(self, vector):
		"""
		This callback is used by the called layers closer to output to register
		their vector patterns as part of the scan that must take place.
		Look at StaticPath class to see how this is called following the work
		done by the scandr() or scanir() methods.
		"""
		pass

class StaticPath(ScanChainSegment):
	def __init__(self, input, output):
		ScanChainSegment.__init__(self, input, output, type=ChainTypes.STATIC_PATH)
		self.entityCount = 0
		self.entityList = []
		
	def drlength(self):
		len = 0
		for e in self.entityList:
			len += e.drlength()
		return len
	
	def irlength(self):
		len = 0
		for e in self.entityList:
			len += e.irlength()
		return len
	
	def scandr(self, parent):
		self.vector = BitString()
		for e in self.entityList:
			e.scandr(self)
		parent.scanCallback(self.vector)
		
	def scanir(self, parent):
		self.vector = BitString()
		for e in self.entityList:
			e.scanir(self)
		parent.scanCallback(self.vector)
		
	def scanCallback(self, vector):
		self.vector.append(vector)
		
class BypassElement(object):
	def __init__(self):
		self.isResynchronized = False
		self.isParked = True
		self.parkValue = 0
		self.scanChain = None
		
class Register(object):
	def __init__(self):
		self.vector = BitString()
		
class BScanDevice(ScanChainSegment):
	def __init__(self, name, input, output):
		ScanChainSegment.__init__(self, input, output, type=ChainTypes.DYNAMIC_PATH)
		# State Properties
		self.name = name
		self.registerList = [] # DR Registers
		self.currentDR = self.registerList[0]
		self.ir = BitString()
		self.vector = BitString()
		
	def drlength(self):
		if self.output is not None:
			return length(self.currentDR.vector) + self.output.drlength()
		else:
			return length(self.currentDR.vector)
	
	def irlength(self):
		if self.output is not None:
			return length(self.ir) + self.output.irlength()
		else:
			return length(self.ir)
	
	def scandr(self, parent):
		self.vector = self.currentDR.vector
		if self.output is not None:
			self.output.scandr(self)
		parent.scanCallback(self.vector)
		
	def scanir(self, parent):
		self.vector = self.ir
		if self.output is not None:
			self.output.scanir(self)
		parent.scanCallback(self.vector)
		
	def scanCallback(self, vector):
		self.vector.append(vector)
				
class Linker(BScanDevice):
	def __init__(self, name, input, output):
		BScanDevice.__init__(self, name, input, output)
		# Structural Properties
		self.bypassElementCount = 0
		self.bypassElements = []
		self.tapInterface = input
		
		# Addressing Properties
		self.selectionProtocol = ScanPathLinker(self)
				
	def drlength(self):
		len = 0
		for b in self.bypassElements:
			if b.scanChain is not None:
				len += b.scanChain.drlength()
		if self.output is not None:
			return length(self.currentDR.vector) + self.output.drlength() + len
		else:
			return length(self.currentDR.vector) + len
	
	def irlength(self):
		len = 0
		for b in self.bypassElements:
			if b.scanChain is not None:
				len += b.scanChain.irlength()
		if self.output is not None:
			return length(self.ir) + self.output.irlength() + len
		else:
			return length(self.ir) + len
	
	def scandr(self, parent):
		self.vector = self.currentDR.vector
		for b in self.bypassElements:
			if b.scanChain is not None:
				b.scanChain.scandr(self)
		if self.output is not None:
			self.output.scandr(self)
		parent.scanCallback(self.vector)
		
	def scanir(self, parent):
		self.vector = self.ir
		for b in self.bypassElements:
			if b.scanChain is not None:
				b.scanChain.scanir(self)
		if self.output is not None:
			self.output.scanir(self)
		parent.scanCallback(self.vector)
		
	def scanCallback(self, vector):
		self.vector.append(vector)
It is not intended to be working Python code, but a representation that can act as a catalyst for further discussion of the concepts or as a prompt for alternative representations.
Ian McIntosh
Testability Lead
Leonardo UK