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

Merge branch 'new_apsct' into 'master'

New apsct branch merge

See merge request !20
parents 689ae6ef d9325265
No related branches found
No related tags found
1 merge request!20New apsct branch merge
Pipeline #46961 passed
1. Make dynamic tunnel from pi to local machine (kruger@dop416 in this example)
On LCU: (pi can not ssh to LCU, so we need reverse ssh)
ssh -R 20222:dop416:22 pi@10.99.0.101
then on pi: (dynamic tunnel)
ssh kruger@localhost -p 20222 -D 1080
2. Configure git to use tunnel
git config http.proxy socks5h://localhost:1080
\ No newline at end of file
......@@ -9,17 +9,21 @@ drivers:
type: i2c_dev #I2C devices
parent: I2C
status: APSCTTR_I2C_error
- name: SPIbb1
type: spibitbang2 #SPI bitbang via GPIO expander: CLK, SDI,SDO,CS
- name: SPIbb1
type: spibitbang3 #SPI bitbang via GPIO expander: CLK, SDI,SDO,CS
parent: I2C_CLK
devreg: [IO1.GPIO1,IO1.GPIO1,IO1.GPIO1,IO1.GPIO1]
parameters: [4,7,5,6]
- name: SPIbb2
type: spibitbang2 #SPI bitbang via GPIO expander: CLK, SDI,SDO,CS
type: spibitbang3 #SPI bitbang via GPIO expander: CLK, SDI,SDO,CS
parent: I2C_CLK
devreg: [IO2.GPIO1,IO2.GPIO1,IO2.GPIO1,IO2.GPIO1]
parameters: [4,7,5,6]
- name: LMP_GPIO
type: gpio_id
parameters: [21,20,16,12,7,8]
#This is the I2C devices in the RCU
device_registers:
- name: IO
......@@ -44,8 +48,12 @@ device_registers:
description: Input/Ouput port 2
address: [1,3] #Read / Write address different
store: True
- name: POL1
address: 4
- name: POL2
address: 5
- name: PLL2
- name: PLL2 #200MHz on IO1
driver: SPIbb1
registers:
- name: PLL_stat
......@@ -129,6 +137,14 @@ variables:
dtype: boolean
dim: 1
- name: LMP_ID
driver: LMP_GPIO
devreg: ROM.ID #this is ignored
width: 6
rw: ro
dtype: uint8
- name: APSCT_PCB_ID
description: Unique PCB ID
driver: I2C_CLK
......@@ -210,23 +226,52 @@ variables:
bitoffset: 3
width: 1
- name: APSCT_PLL_200MHz_locked_SPI
description: 0x81=locked
- name: APSCT_PLL_200MHz_lol
rw: ro
dtype: boolean
convert_unit: bool_invert
monitor: true
driver: I2C_CLK
devreg: PLL2.PLL_stat
width: 8
devreg: IO2.GPIO2
bitoffset: 4
width: 1
- name: APSCT_PLL_160MHz_lol
rw: ro
dtype: uint8
debug: True
dtype: boolean
convert_unit: bool_invert
monitor: true
driver: I2C_CLK
devreg: IO2.GPIO2
bitoffset: 5
width: 1
- name: APSCT_PLL_160MHz_locked_SPI
description: 0x81=locked
- name: APSCT_PLL_clr_lol
rw: rw
dtype: boolean
# monitor: true
driver: I2C_CLK
devreg: PLL1.PLL_stat
width: 8
rw: ro
dtype: uint8
debug: True
devreg: IO1.GPIO2
bitoffset: 4
width: 1
# - name: APSCT_PLL_200MHz_locked_SPI
# description: 0x81=locked
# driver: I2C_CLK
# devreg: PLL2.PLL_stat
# width: 8
# rw: ro
# dtype: uint8
# debug: True
# - name: APSCT_PLL_160MHz_locked_SPI
# description: 0x81=locked
# driver: I2C_CLK
# devreg: PLL1.PLL_stat
# width: 8
# rw: ro
# dtype: uint8
# debug: True
# - name: [APSCT_PLL_r3,APSCT_PLL_r5,APSCT_PLL_r6]
# driver: I2C_CLK
......@@ -297,6 +342,7 @@ methods:
- APSCT_PCB_version : Update
- APSCT_PCB_number : Update
- APSCT_PWR_on: Update
- LMP_ID: Update
- APSCT_PWR_PLL_200MHz_on: Update
- APSCT_PLL_200MHz_locked: Update
- APSCT_PLL_200MHz_error: Update
......@@ -304,24 +350,41 @@ methods:
- APSCT_PLL_160MHz_locked: Update
- APSCT_PLL_160MHz_error: Update
- APSCT_PPS_ignore : Update
- APSCT_PLL_clr_lol: Update
- APSCT_PLL_200MHz_lol: Update
- APSCT_PLL_160MHz_lol: Update
# - name: APSCT_clr_lol
# driver: I2C_CLK
# description: Clear lock-off-lock
# instructions:
# - APSCTTR_I2C_error : 0
- name: APSCT_200MHz_on
driver: I2C_CLK
description: Configure clock. Monitored using APSCT_PWR_on, APSCT_PLL_error and APSCT_PLL_locked
instructions:
- APSCTTR_I2C_error : 0
- IO1.POL1: 0
- IO1.POL2: 0
- IO2.POL1: 0
- IO2.POL2: 0
- IO1.CONF1: 0x2C #0010 1100 PPS/PWR output, SCLK,CS,SDI
- IO1.CONF2: 0x00
- IO2.CONF1: 0x2C #0010 1100 PPS/PWR output, SCLK,CS,SDI
- IO2.CONF2: 0x03 #
- IO2.CONF2: 0xFF #
- IO1.GPIO1: 0x42 #0100 0010 high:200MHz PLL enable, CS high
- IO1.GPIO2: 0xF8 #PWR enable ##Check if not 4??
# - IO1.GPIO2: 0xF8 #PWR enable ##Check if not 4??
- IO1.GPIO2: 0x28 #PWR enable
- IO2.GPIO1: 0x00 #All low
- IO2.GPIO2: 0x00 #All low (just inputs)
# - IO2.GPIO2: 0x00 #All low (just inputs)
- WAIT: 200
- APSCT_PLL200_setup: 0
- WAIT: 200 #ms to wait before checking lock
- APSCT_PLL_clr_lol: 1
- WAIT: 10 #ms
- APSCT_PLL_clr_lol: 0
- APSCTTR_Update: 0 #refresh all settings
- name: APSCT_160MHz_on
......@@ -329,18 +392,25 @@ methods:
description: Configure clock. Monitored using APSCT_PWR_on, APSCT_PLL_error and APSCT_PLL_locked
instructions:
- APSCTTR_I2C_error : 0
- IO1.POL1: 0
- IO1.POL2: 0
- IO2.POL1: 0
- IO2.POL2: 0
- IO1.CONF1: 0x2C #0010 1100 PPS/PWR output, SCLK,CS,SDI
- IO1.CONF2: 0x00
- IO2.CONF1: 0x2C #0010 1100 PPS/PWR output, SCLK,CS,SDI
- IO2.CONF2: 0x03 #
- IO2.CONF2: 0xFF #
- IO1.GPIO1: 0x00
- IO1.GPIO2: 0x08 #PWR enable ##Check if not 4??
- IO2.GPIO1: 0x42 #0100 0010 high:160MHz PLL enable, CS high
- IO2.GPIO2: 0x00 #All low (just inputs)
# - IO2.GPIO2: 0x00 #All low (just inputs)
- WAIT: 200
- APSCT_PLL160_setup: 0
- WAIT: 200 #ms to wait before checking lock
- APSCT_PLL_clr_lol: 1
- WAIT: 10 #ms
- APSCT_PLL_clr_lol: 0
- APSCTTR_Update: 0 #refresh all settings
- name: APSCT_off
......@@ -358,45 +428,50 @@ methods:
driver: I2C_CLK
debug: true
instructions:
# - PLL2.0x03: 0x08 #Set power, this is default
- PLL2.0x04: 0xCF #
- PLL2.0x05: 0x97 #was 97, set lock time = =x17?
- PLL2.0x06: 0x10
- PLL2.0x07: 0x04 #Stop R divider
- PLL2.0x08: 0x01 #Set R divider
- PLL2.0x07: 0x00 #Start R divider
- PLL2.0x09: 0x10 #Stop N divider
- PLL2.0x0A: 0x14 #Set N divider=20, 200MHz/20=10MHz = input clock
- PLL2.0x09: 0x00 #Start N divider
- PLL2.0x0D: 0x01 #Divider output 1=1
- PLL2.0x0F: 0x01 #Divider output 2=1
- PLL2.0x11: 0x01 #Divider output 3=1
- PLL2.0x13: 0x01 #Divider output 4=1
- PLL2.0x04: 0x01 #div a
- PLL2.0x05: 0x00 #div b, high
- PLL2.0x06: 0x14 #dib b, low
- PLL2.0x07: 0x00 # No LOR
- PLL2.0x08: 0x3B # Charge pump normal + Status bit
- PLL2.0x09: 0x30 # Charge pump current
- PLL2.0x0A: 0x00 # Fixed Divide 1
- PLL2.0x0B: 0x00
- PLL2.0x0C: 0x01
- PLL2.0x45: 0x00 # CLK2 as feedback clock input
- PLL2.0x3d: 0x08 # OUT0 ON LVDS Standard
- PLL2.0x3e: 0x0a # OUT1 OFF
- PLL2.0x3f: 0x0a # OUT2 OFF
- PLL2.0x40: 0x03 # OUT3 OFF
- PLL2.0x41: 0x02 # OUT4 ON LVDS Standard
- PLL2.0x4b: 0x80 # OUT0 bypass divider
- PLL2.0x4d: 0x80 # OUT1 bypass divider
- PLL2.0x4f: 0x80 # OUT2 bypass divider
- PLL2.0x51: 0x80 # OUT3 bypass divider
- PLL2.0x53: 0x80 # OUT4 bypass divider
- PLL2.0x5a: 0x0f # Update registers
- name: APSCT_PLL160_setup
driver: I2C_CLK
debug: true
instructions:
# - PLL1.0x03: 0x08 #Set power, this is default
- PLL1.0x04: 0xCF #
- PLL1.0x05: 0x97 #was 97, set lock time = =x17?
- PLL1.0x06: 0x10
- PLL1.0x07: 0x04 #Stop R divider
- PLL1.0x08: 0x01 #Set R divider
- PLL1.0x07: 0x00 #Start R divider
- PLL1.0x09: 0x10 #Stop N divider
- PLL1.0x0A: 0x10 #Set N divider=16, 160MHz/16=10MHz = input clock
- PLL1.0x09: 0x00 #Start N divider
- PLL1.0x0D: 0x01 #Divider output 1=1
- PLL1.0x0F: 0x01 #Divider output 2=1
- PLL1.0x11: 0x01 #Divider output 3=1
- PLL1.0x13: 0x01 #Divider output 4=1
- PLL1.0x04: 0x01 #div a
- PLL1.0x05: 0x00 #div b, high
- PLL1.0x06: 0x10 #dib b, low
- PLL1.0x07: 0x00 # No LOR
- PLL1.0x08: 0x3B # Charge pump normal + Status bit
- PLL1.0x09: 0x30 # Charge pump current
- PLL1.0x0A: 0x00 # Fixed Divide 1
- PLL1.0x0B: 0x00
- PLL1.0x0C: 0x01
- PLL1.0x45: 0x00 # CLK2 as feedback clock input
- PLL1.0x3d: 0x08 # OUT0 ON LVDS Standard
- PLL1.0x3e: 0x0a # OUT1 OFF
- PLL1.0x3f: 0x0a # OUT2 OFF
- PLL1.0x40: 0x03 # OUT3 OFF
- PLL1.0x41: 0x02 # OUT4 ON LVDS Standard
- PLL1.0x4b: 0x80 # OUT0 bypass divider
- PLL1.0x4d: 0x80 # OUT1 bypass divider
- PLL1.0x4f: 0x80 # OUT2 bypass divider
- PLL1.0x51: 0x80 # OUT3 bypass divider
- PLL1.0x53: 0x80 # OUT4 bypass divider
- PLL1.0x5a: 0x0f # Update registers
......@@ -52,6 +52,10 @@ drivers:
type: gpio
parameters: [11,13]
- name: I2C_reset_GPIO
type: gpio
parameters: [15,15]
#This is the I2C devices in the RCU
device_registers:
......@@ -266,6 +270,15 @@ variables:
dtype: boolean
dim: 2
- name: UNB2_I2C_reset
driver: I2C_reset_GPIO
mask: UNB2_mask
width: 1
rw: rw
dtype: boolean
dim: 2
# convert_unit: bool_invert
- name: UNB2_Front_Panel_LED_colour
description: bit 0=Red, 1=Blue, 2=Green
mask: UNB2_mask
......@@ -483,7 +496,8 @@ methods:
debug: True
instructions:
- UNB2TR_I2C_error: 0
- UNB2_I2C_enabled: 1 #Make sure I2C switches are enabled
- UNB2_I2C_enabled: 1 #Make sure UNB2 I2C switches are enabled
- UNB2_I2C_reset: 1 #Make sure APSCT I2C switches are enabled
- UNB2_PCB_ID: Update
- UNB2_PCB_version: Update
- UNB2_PCB_number: Update
......
......@@ -11,24 +11,24 @@ class gpio(hwdev):
self.pins=config['parameters']
self.Npins=len(self.pins);
GPIO.setmode(GPIO.BCM)
self.state=[0 for pin in self.pins]
logging.info(str(("gpio, Pins=",self.state)));
# self.state=[0 for pin in self.pins]
# logging.info(str(("gpio, Pins=",self.state)));
for i,pin in enumerate(self.pins):
GPIO.setup(pin,GPIO.OUT)
# for i,pin in enumerate(self.pins):
# GPIO.setup(pin,GPIO.IN)
# self.state=[GPIO.input(pin) for pin in self.pins]
# logging.info(str(("gpio, Pins=",self.state)));
self.state=[GPIO.input(pin) for pin in self.pins]
logging.info(str((config['name']," gpio, Pins=",self.state)));
def OPCUASetVariable(self,varid,var1,data,mask):
logging.info("Set gpio");
if len(mask)!=self.Npins:
logging.warning("Wrong mask length");
if len(mask)>0: logging.warning("GPIO Wrong mask length %i,%i"%(len(mask),self.Npins));
mask=[True]*self.Npins;
if len(data)!=self.Npins:
if len(data)==1: data=[data[0]]*self.Npins;
else:
logging.warning("Wrong data length");
logging.warning("GPIO Wrong data length");
return []
for i,pin in enumerate(self.pins):
if mask[i]:
......
#import numpy as np
from .hwdev import hwdev;
import logging
import RPi.GPIO as GPIO
from pypcc.queuetypes import *
class gpio_id(hwdev):
def __init__(self,config):
hwdev.__init__(self,config);
self.pins=config['parameters']
self.Npins=len(self.pins);
GPIO.setmode(GPIO.BCM)
for i,pin in enumerate(self.pins):
GPIO.setup(pin,GPIO.IN)
logging.info(str((config['name']," gpio, value=",self.get_value())));
def get_value(self):
value=0;
for pin in self.pins:
value=2*value+1 if GPIO.input(pin) else 2*value
return value
def OPCUASetVariable(self,varid,var1,data,mask):
return []
def OPCUAReadVariable(self,varid,var1,mask):
value=self.get_value()
logging.info(" gpio, value=%i"%value);
Data=OPCUAset(varid,InstType.varSet,[value],mask.copy())
return [Data]
from enum import Enum
import logging
import numpy as np
from .hwdev import hwdev
class SPIBB_pins(Enum):
CLK = 0
SDI = 1
SDO = 2
CS = 3
class spibitbang3(hwdev):
def __init__(self,config):
hwdev.__init__(self,config)
def i2csetget(self,addr,data,reg=None,read=0):
if read==0: return self.SetSPIbb(reg,data)
elif read==1: return self.GetSPIbb(reg,data)
else: logging.warn("Not implemented!")
return False;
def SetSPIbb(self,address,value):
CSdev=self.conf['devreg'][SPIBB_pins.CS.value]
CSpin=self.conf['parameters'][SPIBB_pins.CS.value]
SDIdev=self.conf['devreg'][SPIBB_pins.SDI.value]
SDIpin=self.conf['parameters'][SPIBB_pins.SDI.value]
CLKdev=self.conf['devreg'][SPIBB_pins.CLK.value]
CLKpin=self.conf['parameters'][SPIBB_pins.CLK.value]
logging.info(str(("SPIbb3 set",address,value)))
SetI2C=self.conf['parentcls'].SetVarValue
ADC_bytes = 0x00
ADC_rw = 0x00 # 0 for write, 1 for read
data2 = ( ADC_rw << 23 ) + ( ADC_bytes << 21 ) + ( address << 8 ) + value[0]
bit_array = "{0:{fill}24b}".format(data2, fill='0')
# print(bit_array)
# SetI2C(CSdev,1,CSpin,[1]) #disable
if not(SetI2C(CSdev,1,CSpin,[0])): return False #enable
for bit in bit_array:
SetI2C(SDIdev,1,SDIpin,[int(bit)])
SetI2C(CLKdev,1,CLKpin,[1])
SetI2C(CLKdev,1,CLKpin,[0])
SetI2C(CSdev,1,CSpin,[1]) #disable
# SetI2C(SDOdev,1,SDOpin,[1]) #high when finished
return True;
def GetSPIbb(self,reg_address,value):
CSdev=self.conf['devreg'][SPIBB_pins.CS.value]
CSpin=self.conf['parameters'][SPIBB_pins.CS.value]
SDOdev=self.conf['devreg'][SPIBB_pins.SDO.value]
SDOpin=self.conf['parameters'][SPIBB_pins.SDO.value]
SDIdev=self.conf['devreg'][SPIBB_pins.SDI.value]
SDIpin=self.conf['parameters'][SPIBB_pins.SDI.value]
CLKdev=self.conf['devreg'][SPIBB_pins.CLK.value]
CLKpin=self.conf['parameters'][SPIBB_pins.CLK.value]
logging.info(str(("SPIbb2 get",reg_address)))
SetI2C=self.conf['parentcls'].SetVarValue
GetI2C=self.conf['parentcls'].GetVarValue
ADC_bytes = 0x00
# ADC_rw = 0x01 # 0 for write, 1 for read
#data = (reg_address << 1) + 1 #was 7??
ADC_rw = 0x01 # 0 for write, 1 for read
data = ( ADC_rw << 15) + ( ADC_bytes << 13 ) + reg_address
SetI2C(CSdev,1,CSpin,[1]) #disable
SetI2C(CSdev,1,CSpin,[0]) #enable
bit_array = "{0:{fill}16b}".format(data, fill='0')
for bit in bit_array:
SetI2C(SDIdev,1,SDIpin,[int(bit)])
SetI2C(CLKdev,1,CLKpin,[0])
SetI2C(CLKdev,1,CLKpin,[1])
# print("read byte")
a=[0]
N=1 #len(value)
ret_value=[0]
for i in range(N): value[i]=0
for cnt in range(8*(ADC_bytes+1)):
SetI2C(CLKdev,1,CLKpin,[0])
SetI2C(CLKdev,1,CLKpin,[1]) #read after rising
GetI2C(SDOdev,1,SDOpin,ret_value)
# for i in range(N): value[i]=(value[i]<<1)+ ret_value[i]
for i in range(N):
if ret_value is None: value[i]=None
elif not value[i] is None: value[i]=(value[i]<<1)+ ret_value[i]
SetI2C(CLKdev,1,CLKpin,[0])
SetI2C(CSdev,1,CSpin,[1]) #disable
return True;
import logging
import argparse
from pypcc.opcuaserv import opcuaserv
from pypcc.opcuaserv import i2client
from pypcc.opcuaserv import yamlreader
#from opcuaserv import pypcc2
from pypcc.i2cserv import i2cthread
import threading
import time
import sys
import signal
from importlib_metadata import metadata
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--simulator", help="Do not connect to I2c, but simulate behaviour.", action="store_true")
......@@ -30,6 +26,14 @@ args = parser.parse_args()
#}
#configure_logger(logstash_host=args.loghost,level=args.loglevel, log_extra=log_extra)
logging.getLogger().setLevel(args.loglevel)
git_hash=metadata("pypcc")["Summary"]
logging.info("Git Hash="+git_hash)
from pypcc.opcuaserv import opcuaserv
from pypcc.opcuaserv import i2client
from pypcc.opcuaserv import yamlreader
#from opcuaserv import pypcc2
from pypcc.i2cserv import i2cthread
RunTimer=True;
def signal_handler(sig, frame):
......@@ -64,6 +68,7 @@ configs=[]
if not(args.test):
handler=opcuaserv.InitServer(port=args.port)
logging.info("Load OPCUA variables & start i2c listing thread")
opcuaserv.AddVarR("pypcc_git_hash",git_hash,[],False)
for i,name in enumerate(I2Cports):
RCU_I2C=I2Cclients[i]
RCU_conf=yamlreader.yamlreader(RCU_I2C,yamlfile=name)
......
from test_common import *
from time import sleep
connect("opc.tcp://localhost:4843/")
if True:
print("Switch off")
callmethod("APSCT_off")
sleep(0.5)
wait_not_busy("APSCTTR_translator_busy_R",timeout_sec=3)
if True:
print("Setup 160MHz")
callmethod("APSCT_160MHz_on")
sleep(0.5)
wait_not_busy("APSCTTR_translator_busy_R",timeout_sec=3)
if False:
print("Setup 200MHz")
callmethod("APSCT_200MHz_on")
sleep(0.5)
wait_not_busy("APSCTTR_translator_busy_R",timeout_sec=3)
if False:
print("Get monitor values")
set_value("APSCTTR_monitor_rate_RW",1)
sleep(3)
set_value("APSCTTR_monitor_rate_RW",30)
names=get_all_variables()
for name in names:
att=get_value(name)
print(name,[att])
disconnect();
from test_common import *
connect("opc.tcp://localhost:4840/")
print(get_value("pypcc_git_hash"))
disconnect();
......@@ -41,6 +41,16 @@ def set_value(name,value,tp=None):
else:
var1.set_value(value,tp)
def get_all_variables():
vars0=[]
obj0=root.get_child(["0:Objects"])
for nodeid in obj0.get_children():
ch = client.get_node(nodeid)
name=ch.get_display_name().Text
if ch.get_node_class()==ua.NodeClass.Variable:
vars0.append(name)
return vars0
def get_debug_value(name):
var1 = root.get_child(["0:Objects", "2:DEBUG", "2:"+name])
......
import setuptools
import subprocess
def _get_version_hash():
"""Talk to git and find out the tag/hash of our latest commit"""
try:
p = subprocess.Popen(["git", "rev-parse","HEAD"],
# p = subprocess.Popen(["git", "log","-1","--format='%H'"],
stdout=subprocess.PIPE)
except EnvironmentError:
print("Couldn't run git to get a version number for setup.py")
return
ver = p.communicate()[0]
ver=ver.strip()
ver=str(ver)[2:-1]
print("Git hash=",ver)
return ver
#with open('requirements.txt') as f:
# required = f.read().splitlines()
# Requires: setup.cfg
setuptools.setup(install_requires=["asyncua",
setuptools.setup(description=_get_version_hash(),
install_requires=["asyncua",
"numpy",
"recordclass",
"pyyaml",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment