summaryrefslogtreecommitdiff
path: root/usrp/host/swig/util.py
blob: 089bcaaac2ed314d39c8a52a140241ff9e13884f (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# utilities

from usrp_prims import *

def setup (which_board = 0):
    if not usrp_load_standard_bits (which_board, False):
        raise RuntimeError, "usrp_load_standard_bits"
    dev = usrp_find_device (which_board)
    if not dev:
        raise RuntimeError, "usrp_find_device"
    u = usrp_open_cmd_interface (dev)
    if not u:
        raise RuntimeError, "usrp_open_cmd_interface"

    # FIXME setup high speed paths, Aux ADC Clock, ...

    # usrp_9862_write (u, 0, 35, 0x1)     # aux ADC clock = CLK/4
    # usrp_9862_write (u, 1, 35, 0x1)

    return u

def write_slot_oe (u, slot, value, mask):
    assert 0 <= slot and slot < 4
    return usrp_write_fpga_reg (u, slot + FR_OE_0,
                                ((mask & 0xffff) << 16) | (value & 0xffff))

def write_slot_io (u, slot, value, mask):
    assert 0 <= slot and slot < 4
    return usrp_write_fpga_reg (u, slot + FR_IO_0,
                                ((mask & 0xffff) << 16) | (value & 0xffff))


# ----------------------------------------------------------------


def ramp_aux_dac (u, which_codec, which_dac):
    if not (which_codec == 0 or which_codec == 1):
        raise AssertionError
    if not (which_dac >= 0 and which_dac < 4):
        raise AssertionError
    try:
        if which_dac == 3:                  # sigma delta output
            sigma_delta_loop (u, which_codec)
        else:
            aux_dac_loop (u, which_codec, which_dac)
    except KeyboardInterrupt:
        return

def sigma_delta_loop (u, which_codec):
    counter = 0
    while True:
        usrp_9862_write (u, which_codec, 43, counter >> 4)
        usrp_9862_write (u, which_codec, 42, (counter & 0xf) << 4)
        # counter += 1 FIXME
        counter += 4
        if counter > 0xfff:
            counter = 0

def aux_dac_loop (u, which_codec, which_dac):
    reg = 36 + which_dac                # Aux DAC A,B,C
    counter = 0
    while True:
        usrp_9862_write (u, which_codec, reg, counter)
        counter += 1
        if counter > 0xff:
            counter = 0


def read_aux_adc_loop (u, slot, which_adc):
    while True:
        v = usrp_read_aux_adc (u, slot, which_adc)
        print "%3d  %5.3f" % (v, v * 3.3 / 1024)

def ramp_io_port (u, slot):
    counter = 0
    try:
        while True:
            write_slot_io (u, slot, counter, 0xffff)
            counter += 1
            if counter > 0xffff:
                counter = 0
    except KeyboardInterrupt:
        return

def walk_io_port (u, slot):
    bit = 1
    try:
        while True:
            write_slot_io (u, slot, bit, 0xffff)
            bit = (bit << 1) & 0xffff
            if bit == 0:
                bit = 1
    except KeyboardInterrupt:
        return