Commit aa853387 authored by Paolo Baesso's avatar Paolo Baesso

Merge branch 'master' into documentation

Hopefully all right.
parents 7049685f 816f2e27
......@@ -13,8 +13,8 @@ from si5345 import si5345 # Library for clock chip
from AD5665R import AD5665R # Library for DAC
from PCA9539PW import PCA9539PW # Library for serial line expander
from I2CDISP import CFA632 #Library for display
from I2CDISP import LCD09052 #Library for display
from TLU_powermodule import PWRLED
from ATSHA204A import ATSHA204A
class TLU:
"""docstring for TLU"""
......@@ -58,6 +58,13 @@ class TLU:
enableCore= True #Only need to run this once, after power-up
self.enableCore()
####### EEPROM AX3 testing
self.ax3eeprom= ATSHA204A(self.TLU_I2C, 0x64)
print "shiftR\tdatBit\tcrcBit\tcrcReg \n", self.ax3eeprom._CalculateCrc([255, 12, 54, 28, 134, 89], 3)
self.ax3eeprom._wake(True, True)
print self.ax3eeprom._GetCommandPacketSize(8)
#self.eepromAX3read()
####### EEPROM AX3 testing end
# Instantiate clock chip and configure it (if necessary)
#self.zeClock=si5345(self.TLU_I2C, 0x68)
......@@ -105,8 +112,7 @@ class TLU:
self.IC7.setOutputs(1, 0xB0)# If output, set to XX
#Instantiate Display
#self.DISP=CFA632(self.TLU_I2C, 0x2A) #
self.DISP=LCD09052(self.TLU_I2C, 0x3A) #
self.DISP=CFA632(self.TLU_I2C, 0x2A) #
#Instantiate Power/Led Module
dac_addr_module= int(parsed_cfg.get(section_name, "I2C_DACModule_Addr"), 16)
......@@ -118,31 +124,26 @@ class TLU:
self.pwdled.setVch(1, 0.9, True)
self.pwdled.setVch(2, 0.8, True)
self.pwdled.setVch(3, 0.1, True)
self.pwdled.setIndicatorRGB(1, [0, 0, 1])
self.pwdled.setIndicatorRGB(2, [0, 0, 1])
self.pwdled.setIndicatorRGB(3, [0, 0, 1])
self.pwdled.setIndicatorRGB(4, [0, 0, 1])
self.pwdled.setIndicatorRGB(5, [0, 0, 1])
self.pwdled.setIndicatorRGB(6, [0, 0, 1])
self.pwdled.setIndicatorRGB(7, [0, 0, 1])
self.pwdled.setIndicatorRGB(8, [0, 0, 1])
self.pwdled.setIndicatorRGB(9, [0, 0, 1])
self.pwdled.setIndicatorRGB(10, [0, 0, 1])
self.pwdled.setIndicatorRGB(11, [0, 0, 1])
#self.pwdled.setIndicatorRGB(1, [0, 0, 1])
#self.pwdled.setIndicatorRGB(2, [0, 0, 1])
#self.pwdled.setIndicatorRGB(3, [0, 0, 1])
#self.pwdled.setIndicatorRGB(4, [0, 0, 1])
#self.pwdled.setIndicatorRGB(5, [0, 0, 1])
#self.pwdled.setIndicatorRGB(6, [0, 0, 1])
#self.pwdled.setIndicatorRGB(7, [0, 0, 1])
#self.pwdled.setIndicatorRGB(8, [0, 0, 1])
#self.pwdled.setIndicatorRGB(9, [0, 0, 1])
#self.pwdled.setIndicatorRGB(10, [0, 0, 1])
#self.pwdled.setIndicatorRGB(11, [0, 0, 1])
self.pwdled.allGreen()
#time.sleep(0.5)
#self.pwdled.allRed()
#time.sleep(0.5)
self.pwdled.allBlue()
#time.sleep(0.5)
self.pwdled.allBlack()
#self.pwdled.allWhite()
#time.sleep(0.5)
#self.pwdled.kitt()
self.pwdled.kitt()
self.pwdled.allBlack()
##################################################################################################################################
##################################################################################################################################
def DUTOutputs_old(self, dutN, enable=False, verbose=False):
......@@ -235,6 +236,23 @@ class TLU:
self.IC7.setOutputs(bank, newStatus)
return newStatus
def eepromAX3read(self):
mystop=True
print " Reading AX3 eeprom (not working 100% yet):"
myslave= 0x64
self.TLU_I2C.write(myslave, [0x02, 0x00])
nwords= 5
res= self.TLU_I2C.read( myslave, nwords)
print "\tAX3 awake: ", res
mystop=True
nwords= 7
#mycmd= [0x03, 0x07, 0x02, 0x00, 0x00, 0x00, 0x1e, 0x2d]#conf 0?
mycmd= [0x03, 0x07, 0x02, 0x00, 0x01, 0x00, 0x17, 0xad]#conf 1 <<< seems to reply with correct error code (0)
#mycmd= [0x03, 0x07, 0x02, 0x02, 0x00, 0x00, 0x1d, 0xa8]#data 0?
self.TLU_I2C.write(myslave, mycmd, mystop)
res= self.TLU_I2C.read( myslave, nwords)
print "\tAX3 EEPROM: ", res
def enableClkLEMO(self, enable= False, verbose= False):
## Enable or disable the output clock to the differential LEMO output
bank=1
......
# -*- coding: utf-8 -*-
import uhal
from I2CuHal import I2CCore
import StringIO
import math
class ADN2814ACPZ:
#Class to configure the ADN2814 clock and data recovery chip (CDR)
# The I2C address can either be 0x40 or 0x60
def __init__(self, i2c, slaveaddr=0x40):
self.i2c = i2c
self.slaveaddr = slaveaddr
self.regDictionary= {'freq0': 0x0, 'freq1': 0x1, 'freq2': 0x2, 'rate': 0x3, 'misc': 0x4, 'ctrla': 0x8, 'ctrlb': 0x9, 'ctrlc': 0x11}
def writeReg(self, regN, regContent, verbose=False):
#Basic functionality to write to register.
regContent= regContent & 0xFF
mystop=True
cmd= [regN, regContent]
self.i2c.write( self.slaveaddr, cmd, mystop)
def readReg(self, regN, nwords, verbose=False):
#Basic functionality to read from register.
mystop=False
self.i2c.write( self.slaveaddr, [regN], mystop)
res= self.i2c.read( self.slaveaddr, nwords)
return res
def readf0(self, verbose=False):
res= self.readReg(self.regDictionary['freq0'], 1, False)
if verbose:
print "\tfreq0 is", res[0]
return res[0]
def readf1(self, verbose=False):
res= self.readReg(self.regDictionary['freq1'], 1, False)
if verbose:
print "\tfreq1 is", res[0]
return res[0]
def readf2(self, verbose=False):
res= self.readReg(self.regDictionary['freq2'], 1, False)
if verbose:
print "\tfreq2 is", res[0]
return res[0]
def readFrequency(self, verbose=False):
# write 1 to CTRLA[1]
# reset MISC[2] by writing a 1 followed by a 0 to CTRLB[3]
# read back MISC[2], if 0 the measurement is not complete (typ 80 ms). If 1 the data rate can be read by reading FREQ[22:0]
# read FREQ2, FREQ1, FREQ0
# rate= (FREQ[22:0]xFrefclk)/2^(14+SEL_RATE)
return
def readLOLstatus(self, verbose=False):
# return the status of the LOL bit MISC[3] and the STATIC LOL MISC[4]
# the STATIC LOL is asserted if a LOL condition occurred and remains asserted
# until cleared by writing 1 followed by 0 to the CTRLB[6] bit
misc= self.readReg(self.regDictionary['misc'], 1, False)[0]
staticLOL= (misc & 0x10000) >> 4
LOL= (misc & 0x1000) >> 3
if verbose:
print "MISC=", misc, "LOL=", LOL, "StaticLOL=", staticLOL
return [LOL, staticLOL]
def readRate(self, verbose=False):
rate_msb= self.readReg(self.regDictionary['rate'], 1, False)[0]
rate_lsb= self.readReg(self.regDictionary['misc'], 1, False)[0]
rate_lsb= 0x1 & rate_lsb
rate= (rate_msb << 1) | rate_lsb
if verbose:
print "\tcoarse rate is", rate
return rate
def _writeCTRLA(self, fRef, dataRatio, measureDataRate, lockToRef, verbose=False):
#write content to register CTRLA:
# fRef: reference frequency in MHz; range is [10 : 160]
# dataRatio: integer in range [0 : 8] equal to Data Rate/Div_FREF Ratio
# measureDataRate: set to 1 to measure data rate
# lockToRef= 0 > lock to input data; 1 > lock to reference clock
regContent= 0x0
if fRef < 10:
print "fRef must be comprised between 10 and 160. Coherced to 10"
fRef = 10
if fRef > 160:
print "fRef must be comprised between 10 and 160. Coherced to 160"
fRef = 160
fRefRange={
10<= fRef <20 : 0x00,
20<= fRef <40 : 0x01,
40<= fRef <80 : 0x02,
80<= fRef <=160 : 0x03,
}[1]
fRefRange= fRefRange << 6
regContent= regContent | fRefRange
if ((1 <= dataRatio <= 256) & (isinstance(dataRatio, (int, long) )) ):
ratioValue= math.log(dataRatio, 2)
ratioValue= int(ratioValue)
else:
print " dataRatio should be an integer in the form 2^n with 0<= n <= 8. Coherced to 0"
ratioValue= 0
if verbose:
print "\tratioValue=", ratioValue
ratioValue = ratioValue << 2
regContent= regContent | ratioValue
measureDataRate= (measureDataRate & 0x1) << 1
lockToRef= lockToRef & 0x1
regContent= regContent | measureDataRate | lockToRef
self.writeReg( self.regDictionary['ctrla'], regContent, verbose=False)
return
def _writeCTRLB(self, confLOL, rstMisc4, systemReset, rstMisc2, verbose=False):
#write content to register CTRLB:
# confLOL=0 > LOL pin normal operation; 1 > LOL pin is static LOL
# rstMisc4= Write a 1 followed by 0 to reset MISC[4] (staticLOL)
# systemReset= Write 1 followed by 0 to reset ADN2814
# rsttMisc2= Write a 1 followed by 0 to reset MISC[2] (data read measure complete)
regContent= 0x0
confLOL= (confLOL & 0x1) << 7
rstMisc4= (rstMisc4 & 0x1) << 6
systemReset= (systemReset & 0x1) << 5
rstMisc2= (rstMisc2 & 0x1) << 3
regContent= regContent | confLOL | rstMisc4 | systemReset | rstMisc2
self.writeReg( self.regDictionary['ctrlb'], regContent, verbose=False)
return
def _writeCTRLC(self, confLOS, squelch, outBoost, verbose=False):
#write content to register CTRLC:
# confLOS= 0 > active high LOS; 1 > active low LOS
# squelch= 0 > squelch CLK and DATA; 1 > squelch CLK or DATA
# outBoost= 0 > default swing; boost output swing
regContent= 0x0
confLOS= (confLOS & 0x1) << 2
squelch= (squelch & 0x1) << 1
outBoost= (outBoost & 0x1)
regContent= regContent | confLOS | squelch | outBoost
self.writeReg( self.regDictionary['ctrlc'], regContent, verbose=False)
return
# -*- coding: utf-8 -*-
import uhal
from I2CuHal import I2CCore
import StringIO
import numpy as np
class ATSHA204A:
#Class for Atmel ATSHA204A eeprom
def __init__(self, i2c, slaveaddr= 0x64):
self.i2c = i2c
self.slaveaddr = slaveaddr
#Slot size, in bytes.
self.SLOT_SIZE_BYTES = 32;
#Word size, in bytes. This is the base unit for all reads and writes.
self.WORD_SIZE_BYTES = 4;
#Maximum word offset per slot
self.MAX_WORD_OFFSET = 7;
#Size of the configuration zone, in bytes
self.CONFIGURATION_ZONE_SIZE_BYTES = 88;
#Number of slots in the configuration zone
self.CONFIGURATION_ZONE_SIZE_SLOTS = 3;
#Slot 3 in the configuration zone is only 24 bytes rather than 32, so the max word offset is limited to 5.
self.CONFIGURATION_ZONE_SLOT_2_MAX_WORD_OFFSET = 5;
#Size of the OTP zone, in bytes
self.OTP_ZONE_SIZE_BYTES = 64;
#Number of slots in the OTP zone
self.OTP_ZONE_SIZE_SLOTS = 2;
#Size of the data zone, in bytes
self.DATA_ZONE_SIZE_BYTES = 512;
#Number of slots in the data zone
self.DATA_ZONE_SIZE_SLOTS = 16;
#The data slot used for module configuration data
self.DATA_ZONE_SLOT_MODULE_CONFIGURATION = 0;
#Byte index of the OTP mode byte within its configuration word.
self.OTP_MODE_WORD_BYTE_INDEX = 2;
#-------------------------------------------------------------------------------------------------
# Command packets and I/O
#-------------------------------------------------------------------------------------------------
#Command execution status response block size
self.STATUS_RESPONSE_BLOCK_SIZE_BYTES = 4;
#Byte index of count in response block
self.STATUS_RESPONSE_COUNT_BYTE_INDEX = 0;
#Byte index of status code in response block
self.STATUS_RESPONSE_STATUS_BYTE_INDEX = 1;
#Checksum size
self.CHECKSUM_LENGTH_BYTES = 2;
#Index of the count byte in a command packet
self.COMMAND_PACKET_COUNT_BYTE_INDEX = 0;
#Size of count in a command packet
self.COMMAND_PACKET_COUNT_SIZE_BYTES = 1;
#Index of the opcode byte in a command packet
self.COMMAND_PACKET_OPCODE_BYTE_INDEX = 1;
#Size of the opcode byte in a command packet
self.COMMAND_PACKET_OPCODE_LENGTH_BYTES = 1;
#Index of param 1 in a command packet
self.COMMAND_PACKET_PARAM1_BYTE_INDEX = 2;
#Size of param 1 in a command packet
self.COMMAND_PACKET_PARAM1_SIZE_BYTES = 1;
#Index of param 2 in a command packet
self.COMMAND_PACKET_PARAM2_BYTE_INDEX = 3;
#Size of param 2 in a command packet
self.COMMAND_PACKET_PARAM2_SIZE_BYTES = 2;
def _CalculateCrc(self, pData, dataLengthBytes):
# Calculate a CRC-16 used when communicating with the device. Code taken from Atmel's library.
#The Atmel documentation only specifies that the CRC algorithm used on the ATSHA204A is CRC-16 with polynomial
#0x8005; compared to a standard CRC-16, however, the used algorithm doesn't use remainder reflection.
#@param pData The data to calculate the CRC for
#@param dataLengthBytes The number of bytes to process
#@return The CRC
polynomial = 0x8005
crcRegister = 0
if not pData:
print "_CalculateCrc: No data to process"
return 0
for counter in range(0, dataLengthBytes):
shiftRegister= 0x01
for iShift in range(0, 8):
if (pData[counter] & shiftRegister) :
dataBit= 1
else:
dataBit=0
crcBit= ((crcRegister) >> 15)
crcRegister <<= 1
crcRegister= crcRegister & 0xffff
#print shiftRegister, "\t", dataBit, "\t", crcBit, "\t", crcRegister
shiftRegister= shiftRegister << 1
if (dataBit != crcBit):
#print "poly"
crcRegister ^= polynomial;
return crcRegister
def _wake(self, verifyDeviceIsAtmelAtsha204a, debug):
dummyWriteData = 0x00
mystop=True
self.i2c.write( self.slaveaddr, [dummyWriteData], mystop)
if (verifyDeviceIsAtmelAtsha204a):
expectedStatusBlock= [ 0x04, 0x11, 0x33, 0x43 ];
nwords= 4
res= self.i2c.read( self.slaveaddr, nwords)
if (res != expectedStatusBlock):
print "Attempt to awake Atmel ATSHA204A failed"
print res
def _GetCommandPacketSize(self, additionalDataLengthBytes):
packetSizeBytes = self.COMMAND_PACKET_COUNT_SIZE_BYTES + self.COMMAND_PACKET_OPCODE_LENGTH_BYTES \
+ self.COMMAND_PACKET_PARAM1_SIZE_BYTES + self.COMMAND_PACKET_PARAM2_SIZE_BYTES \
+ additionalDataLengthBytes + self.CHECKSUM_LENGTH_BYTES;
return packetSizeBytes
# -*- coding: utf-8 -*-
import uhal
from I2CuHal import I2CCore
import StringIO
class PCA9548ADW:
#Class to configure the I2C multiplexer
def __init__(self, i2c, slaveaddr=0x74):
self.i2c = i2c
self.slaveaddr = slaveaddr
def disableAllChannels(self, verbose=False):
#Disable all channels so that none of the MUX outputs is visible
# to the upstream I2C bus
mystop=True
cmd= [0x0]
self.i2c.write( self.slaveaddr, cmd, mystop)
def getChannelStatus(self, verbose=False):
#Basic functionality to read the status of the control register and determine
# which channel is currently enabled.
mystop=False
cmd= []
self.i2c.write( self.slaveaddr, cmd, mystop)
res= self.i2c.read( self.slaveaddr, 1)
return res[0]
def setActiveChannel(self, channel, verbose=False):
#Basic functionality to activate one channel
# In principle multiple channels can be active at the same time (see
# function "setMultipleChannels")
if (channel < 0) | (channel > 7):
print "PCA9539PW - ERROR: channel number should be in range [0:7]"
return
mystop=True
cmd= [0x1 << channel]
#print "\tChannel is ", channel, "we write ", cmd
self.i2c.write( self.slaveaddr, cmd, mystop)
def setMultipleChannels(self, channels, verbose=False):
#Basic functionality to activate multiple channels
# channels is a byte: each bit set to one will set the corresponding channels
# as active. The slave connected to that channel will be visible on the I2C bus.
# NOTE: this can lead to address clashes!
channels = channels & 0xFF
mystop=True
cmd= [channels]
#print "\tChannel is ", channel, "we write ", cmd
self.i2c.write( self.slaveaddr, cmd, mystop)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment