Skip to content

Commit

Permalink
Merge pull request #21 from telegraphic/master
Browse files Browse the repository at this point in the history
Adding in a gbe core config and setGain on ADC
  • Loading branch information
jack-h committed Jan 6, 2020
2 parents 7f8bb67 + 3be6e59 commit 6b5a018
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from register import Register
from sbram import Sbram
from snap import Snap
from snapadc import SnapAdc
from tengbe import TenGbe
import progska
import skarab_fileops

# BEGIN VERSION CHECK
Expand Down
20 changes: 13 additions & 7 deletions src/gbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def __init__(self, parent, name, address, length_bytes, device_info=None):
self.mac = None
self.ip_address = None
self.port = None
self.gateway = None
self.subnet_mask = None
self.fullname = self.parent.host + ':' + self.name
self.block_info = device_info
self.process_device_info(device_info)
Expand Down Expand Up @@ -101,17 +103,21 @@ def process_device_info(self, device_info):
'have mac, ip and port.' % self.fullname)
self.setup(mac, ip_address, port)

def setup(self, mac, ipaddress, port):
def setup(self, mac, ipaddress, port, gateway=None, subnet_mask=None):
"""
Set up the MAC, IP and port for this interface
:param mac: String or Integer input
:param ipaddress: String or Integer input
:param mac: String or Integer input, MAC address (e.g. '02:00:00:00:00:01')
:param ipaddress: String or Integer input, IP address (eg '10.0.0.1')
:param port: String or Integer input
"""
self.mac = Mac(mac)
self.ip_address = IpAddress(ipaddress)
self.port = port if isinstance(port, int) else int(port)
:param gateway: String or Integer input, an IP address
:param subnet_mask: string or integer, subnet mask (e.g. '255.255.255.0')
"""
self.mac = Mac(mac)
self.ip_address = IpAddress(ipaddress)
self.port = port if isinstance(port, int) else int(port)
self.gateway = None if gateway is None else IpAddress(gateway)
self.subnet_mask = None if subnet_mask is None else IpAddress(subnet_mask)

def post_create_update(self, raw_device_info):
"""
Expand Down
37 changes: 36 additions & 1 deletion src/snapadc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


# Some codes and docstrings are copied from https://github.com/UCBerkeleySETI/snap_control
class SNAPADC(object):
class SnapAdc(object):

RESOLUTION = 8

Expand Down Expand Up @@ -202,6 +202,41 @@ def selectADC(self, chipSel=None):
else:
raise ValueError("Invalid parameter")

def setGain(self, gains, use_linear_step=False, fine_gains=None, fgain_cfg=False):
""" Set the coarse gain of the ADC channels
Args:
gains (list): List of gains, e.g. [1, 2, 3, 4]
use_linear_step (bool): Defaults to use dB steps for values.
fine_gains (list): Fine gain values to set
fgain_cfg (bool): If fine gains are to be used, set this to True
Notes:
Coarse gain control (parameters in dB). Input gain must be a list of
integers. Coarse gain range for HMCAD1511: 0dB ~ 12dB
E.g.
cGain([1,5,9,12]) # Quad channel mode in dB step
cGain([32,50],use_linear_step=True) # Dual channel mode in x step
cGain([10], fgain_cfg=True) # Single channel mode in dB
# step, with fine gain enabled
Coarse gain options when by default use_linear_step=False:
0 dB, 1 dB, 2 dB, 3 dB, 4 dB, 5 dB, 6 dB,
7 dB, 8 dB, 9 dB, 10 dB, 11 dB and 12 dB
Coarse gain options when use_linear_step=True:
1x, 1.25x, 2x, 2.5x, 4x, 5x, 8x,
10x, 12.5x, 16x, 20x, 25x, 32x, 50x
TODO: Test + improve support for fine gain control
"""

self.adc.cGain(gains, cgain_cfg=use_linear_step, fgain_cfg=fgain_cfg)

if fine_gains is not None:
n_channels = len(gains)
self.adc.fGain(fine_gains, n_channels)

def setDemux(self, numChannel=1):
"""
when mode==0: numChannel=4
Expand Down
66 changes: 50 additions & 16 deletions src/tengbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,56 @@ def read_rxsnap(self):
"""
return self.snaps['rx'].read(timeout=10)['data']

# def fabric_start(self):
# """
# Setup the interface by writing to the fabric directly, bypassing tap.
# :param self:
# :return:
# """
# if self.tap_running():
# log_runtime_error(
# LOGGER, 'TAP running on %s, stop tap before '
# 'accessing fabric directly.' % self.name)
# mac_location = 0x00
# ip_location = 0x10
# port_location = 0x22
# self.parent.write(self.name, self.mac.packed(), mac_location)
# self.parent.write(self.name, self.ip_address.packed(), ip_location)
# # self.parent.write_int(self.name, self.port, offset = port_location)
def configure_core(self):
"""
Setup the interface by writing to the fabric directly, bypassing tap.
:param self:
:return:
Core offset notes:
0x00 - 0x07: My MAC address
0x08 - 0x0b: Not used
0x0c - 0x0f: Gateway addr
0x10 - 0x13: my IP addr
0x14 - 0x17: Not assigned
0x18 - 0x1b: Buffer sizes
0x1c - 0x1f: Not assigned
0x20 : soft reset (bit 0)
0x21 : fabric enable (bit 0)
0x22 - 0x23: fabric port
0x24 - 0x27: XAUI status (bit 2,3,4,5=lane sync, bit6=chan_bond)
0x28 - 0x2b: PHY config
0x28 : RX_eq_mix
0x29 : RX_eq_pol
0x2a : TX_preemph
0x2b : TX_diff_ctrl
0x38 - 0x3b: subnet mask
0x1000 : CPU TX buffer
0x2000 : CPU RX buffer
0x3000 : ARP tables start
"""

gateway = 1 if self.gateway is None else self.gateway.ip_int

ctrl_pack = struct.pack('>QLLLLLLBBH',
self.mac.mac_int,
0, # Not assigned
gateway,
self.ip_address.ip_int,
0, # Not assigned
0, # Buffer sozes
0, # Not assigned
0, # Soft reset
1, # Fabric enable
self.port)

self.parent.blindwrite(self.name, ctrl_pack, offset=0)

if self.subnet_mask is not None:
self.parent.blindwrite(self.name, self.subnet_mask.packed(), offset=0x38)

def dhcp_start(self):
"""
Expand Down

0 comments on commit 6b5a018

Please sign in to comment.