Skip to content
Snippets Groups Projects
Commit 0132a082 authored by Paulus Kruger's avatar Paulus Kruger
Browse files

RCU multiple switches added for 32 channels

parent 66405527
Branches
No related tags found
No related merge requests found
Pipeline #21382 passed
...@@ -4,7 +4,7 @@ description: "1234" ...@@ -4,7 +4,7 @@ description: "1234"
drivers: drivers:
- name: I2C1 #TCA9548 - name: I2C1 #TCA9548
type: i2c_switch type: i2c_switch
devreg: [0x70] devreg: [0x70,0x71,0x72,0x73]
parameters: [1] #I2C port number parameters: [1] #I2C port number
- name: I2C_RCU - name: I2C_RCU
type: i2c_array #An array of similar devices connected to an I2C switch type: i2c_array #An array of similar devices connected to an I2C switch
......
...@@ -47,6 +47,10 @@ drivers: ...@@ -47,6 +47,10 @@ drivers:
type: gpio type: gpio
parameters: [19,26] parameters: [19,26]
- name: GPIO2
type: gpio
parameters: [11,13]
#This is the I2C devices in the RCU #This is the I2C devices in the RCU
device_registers: device_registers:
......
...@@ -33,10 +33,11 @@ class i2c_array(i2c_dev): ...@@ -33,10 +33,11 @@ class i2c_array(i2c_dev):
def SetSwitchMask(self,mask): def SetSwitchMask(self,mask):
m=0; m=0;
self.conf['parentcls'].ClearNewChannel();
for RCUi in range(self.N): for RCUi in range(self.N):
if (mask[RCUi]) and (self.I2Cmask[RCUi]<=self.I2Ccut): if (mask[RCUi]) and (self.I2Cmask[RCUi]<=self.I2Ccut):
m|=1<<self.RCU_Switch1[RCUi]; self.conf['parentcls'].AddNewChannel(self.RCU_Switch1[RCUi]);
self.conf['parentcls'].SetChannel(m); self.conf['parentcls'].UpdateNewChannel();
def SetGetVarValueMask(self,var1,data,mask,getalso=True): def SetGetVarValueMask(self,var1,data,mask,getalso=True):
Step,Step2=GetSteps(var1); Step,Step2=GetSteps(var1);
......
...@@ -6,26 +6,54 @@ from .i2c import i2c ...@@ -6,26 +6,54 @@ from .i2c import i2c
class i2c_switch(i2c): class i2c_switch(i2c):
def __init__(self,config): def __init__(self,config):
i2c.__init__(self,config) i2c.__init__(self,config)
self.SWaddr=config['devreg'][0]['addr'] # self.SWaddr=config['devreg'][0]['addr']
self.CurrentChannel=0 self.SWcnt=len(config['devreg']);
self.NoSwitch=self.SWaddr==0; self.SWaddrs=[config['devreg'][x]['addr'] for x in range(self.SWcnt)];
logging.info("i2c switch at address "+str(self.SWaddr)) self.CurrentChannel=[-1 for x in range(self.SWcnt)];
self.NoSwitch=self.SWcnt==0;
S='';
for x in range(self.SWcnt): S+=str(self.SWaddrs[x])+",";
logging.info("i2c switch at address "+S)
if self.NoSwitch: if self.NoSwitch:
logging.warn("i2c switch disabled!") logging.warn("i2c switch disabled!")
def SetSW1(self,channelbit): def SetSW1(self,channelbit):
channel=(0 if (channelbit>5) else 1<<(channelbit)) #LTS # channel=(0 if (channelbit>5) else 1<<(channelbit)) #LTS
if (channel)==self.CurrentChannel: return True; if self.NoSwitch: return True;
logging.debug("SetChannelbit=%i" % channelbit) SWn=channelbit>>3;
self.CurrentChannel=channel channel=1<<(channelbit & 0x07)
return (True if self.NoSwitch else self.i2csetget(self.SWaddr,[channel])) for x in range(self.SWcnt):
if x==SWn:
if (channel)!=self.CurrentChannel[x]:
self.CurrentChannel[x]=channel
logging.debug("SetChannel addr %i = val %i" % (SWn,channel));
if not(self.i2csetget(self.SWaddrs[x],[channel])): return False;
else:
if self.CurrentChannel[x]!=0:
logging.debug("SetChannel addr %i = val %i" % (x,0));
self.CurrentChannel[x]=0
if not(self.i2csetget(self.SWaddrs[x],[0])): return False;
return True
def SetChannel(self,channel): def ClearNewChannel(self):
channel&=0x3F;#LTS self.newChannel=[0 for x in self.SWaddrs];
if (channel)==self.CurrentChannel: return True;
logging.debug("SetChannel=%i" % channel) def AddNewChannel(self,channelbit):
self.CurrentChannel=channel SWn=channelbit>>3;
return (True if self.NoSwitch else self.i2csetget(self.SWaddr,[channel])) channel=1<<(channelbit & 0x07)
self.newChannel[SWn]|=channel;
def UpdateNewChannel(self):
# channel&=0x3F;#LTS
if self.NoSwitch: return True;
for x in range(self.SWcnt):
if self.newChannel[x]!=self.CurrentChannel[x]:
self.CurrentChannel[x]=self.newChannel[x];
logging.debug("SetChannel2 addr %i = val %i" % (x,self.newChannel[x]));
if not(self.i2csetget(self.SWaddrs[x],[self.newChannel[x]])): return False;
# logging.debug("SetChannel=%i" % channel)
# self.CurrentChannel=channel
return True
# def I2Ccallback(self,RCU,addr,data,reg=None,read=0): # def I2Ccallback(self,RCU,addr,data,reg=None,read=0):
# self.callback1(addr,data,reg,read) # self.callback1(addr,data,reg,read)
from test_common import * from test_common import *
RCUs=[0,1,2,3];
RCUs=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31];
connect() connect()
setRCUmask(RCUs) setRCUmask(RCUs)
def wait(var1="RECVTR_translator_busy_R"): #def wait(var1="RECVTR_translator_busy_R"):
for x in range(20): # for x in range(20):#
busy=get_value(var1) # busy=get_value(var1)
# print(busy) # print(busy)
if not(busy): break # if not(busy): break
time.sleep(0.1) # time.sleep(0.1)
print("Time=",x*0.1,"s") # print("Time=",x*0.1,"s")
#callmethod("RCU_off") #callmethod("RCU_off")
#wait() #wait()
#exit() #exit()
#time.sleep(2) #time.sleep(2)
callmethod("RCU_on") callmethod("RCU_on")
wait() #wait()
#callmethod("RCU_on") #callmethod("RCU_on")
#time.sleep(1) #time.sleep(1)
#callmethod("ADC_on") #callmethod("ADC_on")
......
#from gpiozero import LED,Button
import RPi.GPIO as GPIO
#SCL=3
#SDA=2
#PIN=13
PIN=11
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN,GPIO.OUT)
GPIO.output(PIN,1)
#print("SDA ",GPIO.input(SDA))
#print("SCL ",GPIO.input(SCL))
GPIO.cleanup()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment