Exemple #1
0
	def getPortCounts(self, port):
		template = "@HHH"
		n = struct.calcsize(template)
		data = struct.pack(template, 0x07, n, port)
		self.__socket.send(data);

		template = "@HQQQ"
		n = struct.calcsize(template)
		data = self.__socket.recv(n);
		length, tx, rx, rxBad = struct.unpack(template, data)		
		tx = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(tx, 48)))
		rx = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(rx, 48)))
		rxBad = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(rxBad, 48)))
		return (tx, rx, rxBad)
Exemple #2
0
	def __setAD5533Channel(self, portID, slaveID, channelID, value, forceAccess=False):
		cacheKey = (portID, slaveID, channelID)
		if not forceAccess:
			try:
				lastValue = self.__ad5553ConfigCache[cacheKey]
				if value == lastValue:
					return 0
			except KeyError:
				pass
		
		whichDAC = channelID / 32
		channel = channelID % 32
		whichDAC = 1 - whichDAC # Wrong decoding in ad5535.vhd
		dacBits = bitarray_utils.intToBin(whichDAC, 1) + bitarray_utils.intToBin(channel, 5) + bitarray_utils.intToBin(value, 14) + bitarray('0000')
		dacBytes = bytearray(dacBits.tobytes())
		self.sendCommand(portID, slaveID, 0x01, dacBytes)
		self.__ad5553ConfigCache[cacheKey] = value
		return 0
Exemple #3
0
	def __getCurrentFrameID(self):
		activePorts = self.getActivePorts()
		if activePorts == []:
			raise ErrorNoFEB()

		portID = min(activePorts)
		gray = self.readFEBDConfig(portID, 0, 0, 7)
		timeTag = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(gray, 46)))
		frameID = timeTag / 1024
		return frameID
Exemple #4
0
	def getFEBDCount1(self, portID, slaveID):
		mtx = self.readFEBDConfig(portID, slaveID, 1, 0)
		mrx = self.readFEBDConfig(portID, slaveID, 1, 1)
		mrxBad = self.readFEBDConfig(portID, slaveID, 1, 2)

		slaveOn = self.readFEBDConfig(portID, slaveID, 0, 12) != 0x0

		stx = self.readFEBDConfig(portID, slaveID, 1, 3)
		srx = self.readFEBDConfig(portID, slaveID, 1, 4)
		srxBad = self.readFEBDConfig(portID, slaveID, 1, 5)
		
		mtx = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(mtx, 48)))
		mrx = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(mrx, 48)))
		mrxBad = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(mrxBad, 48)))
		stx = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(stx, 48)))
		srx = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(srx, 48)))
		srxBad = bitarray_utils.binToInt(bitarray_utils.grayToBin(bitarray_utils.intToBin(srxBad, 48)))
		return (mtx, mrx, mrxBad, slaveOn, stx, srx, srxBad)
Exemple #5
0
 def setValue(self, key, value):
     b = intToBin(value, len(self.__fields[key]))
     self.setBits(key, b)
Exemple #6
0
 def setValue(self, key, value):
     key = key.lower()
     b = intToBin(value, len(self.fields[key]))
     self.setBits(key, b)
Exemple #7
0
	def ___doAsicCommand(self, portID, slaveID, chipID, command, value=None, channel=None, forceAccess=False):
		commandInfo = {
		#	commandID 	: (code,   ch,   read, data length)
			"wrChCfg"	: (0b0000, True, False, 125),
			"rdChCfg"	: (0b0001, True, True, 125),
			"wrGlobalCfg" 	: (0b1000, False, False, 184),
			"rdGlobalCfg" 	: (0b1001, False, True, 184)
		}
	
		commandCode, isChannel, isRead, dataLength = commandInfo[command]

		cacheKey = (command[2:], portID, slaveID, chipID, channel)
		if not forceAccess:
			# Let's see if we have this in cache
			if not isRead:
				try:
					lastValue = self.__asicConfigCache[cacheKey]
					if value == lastValue:
						return (0, None)
				except KeyError:
					pass
			else:
				try:
					lastValue = self.__asicConfigCache[cacheKey]
					return (0, lastValue)
				except KeyError:
					pass


		ccBits = bitarray_utils.intToBin(commandCode, 4)

		if isChannel:
			ccBits += bitarray_utils.intToBin(channel, 7)

		if not isRead:
			assert len(value) == dataLength
			ccBits += value

		nBytes = int(math.ceil(len(ccBits) / 8.0))
		paddedValue = ccBits + bitarray([ False for x in range((nBytes * 8) - dataLength) ])
		byteX = [ ord(x) for x in paddedValue.tobytes() ]		
		
		if isRead:
			bitsToRead = dataLength
		else:
			bitsToRead = 0

		nBitsToWrite= len(ccBits)
		cmd = [ chipID, nBitsToWrite, bitsToRead] + byteX
		cmd = bytearray(cmd)

		reply = self.sendCommand(portID, slaveID, 0x00, cmd)
		if len(reply) < 2: raise tofpet2.ConfigurationErrorBadReply(2, len(reply))
		status = reply[1]
			
		if status == 0xE3:
			raise tofpet2.ConfigurationErrorBadAck(portID, slaveID, chipID, 0)
		elif status == 0xE4:
			raise tofpet2.ConfigurationErrorBadCRC(portID, slaveID, chipID )
		elif status == 0xE5:
			raise tofpet2.ConfigurationErrorBadAck(portID, slaveID, chipID, 1)
		elif status != 0x00:
			raise tofpet2.ConfigurationErrorGeneric(portID, slaveID, chipID , status)

		if isRead:
			expectedBytes = math.ceil(dataLength/8)
			if len(reply) < (2+expectedBytes): 
				print len(reply), (2+expectedBytes)
				raise tofpet2.ConfigurationErrorBadReply(2+expectedBytes, len(reply))
			reply = str(reply[2:])
			data = bitarray()
			data.frombytes(reply)
			value = data[0:dataLength]
			self.__asicConfigCache[cacheKey] = bitarray(value)
			return (status, value)
		else:
			# Check what we wrote
			readCommand = 'rd' + command[2:]
			readStatus, readValue = self.__doAsicCommand(portID, slaveID, chipID, readCommand, channel=channel, forceAccess=True)
			if readValue != value:
				raise tofpet2.ConfigurationErrorBadRead(portID, slaveID, chipID, value, readValue)

			return (status, None)