summaryrefslogtreecommitdiffstats
path: root/host/usrp_e_utils/usrp-e-debug-pins.c
blob: 570ae63d8093de2fab304d45c5508b2dafd796a8 (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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>

#include <linux/usrp_e.h>
#include "e100_regs.hpp"

// Usage: usrp_e_gpio <string>

static int fp;

static int read_reg(__u16 reg)
{
	int ret;
	struct usrp_e_ctl16 d;

	d.offset = reg;
	d.count = 1;
	ret = ioctl(fp, USRP_E_READ_CTL16, &d);
	return d.buf[0];
}

static void write_reg(__u16 reg, __u16 val)
{
	int ret;
	struct usrp_e_ctl16 d;

	d.offset = reg;
	d.count = 1;
	d.buf[0] = val;
	ret = ioctl(fp, USRP_E_WRITE_CTL16, &d);
}

int main(int argc, char *argv[])
{
	int test;

	test = 0;
	if (argc < 2) {
		printf("%s 0|1|off\n", argv[0]);
		return -1;
	}

        fp = open("/dev/usrp_e0", O_RDWR);
        printf("fp = %d\n", fp);
	if (fp < 0) {
		perror("Open failed");
		return -1;
	}

	if (strcmp(argv[1], "0") == 0) {
		printf("Selected 0 based on %s\n", argv[1]);
		write_reg(E100_REG_GPIO_TX_DDR, 0xFFFF);
		write_reg(E100_REG_GPIO_RX_DDR, 0xFFFF);
		write_reg(E100_REG_GPIO_TX_SEL, 0x0);
		write_reg(E100_REG_GPIO_RX_SEL, 0x0);
		write_reg(E100_REG_GPIO_TX_DBG, 0xFFFF);
		write_reg(E100_REG_GPIO_RX_DBG, 0xFFFF);
	} else if (strcmp(argv[1], "1") == 0) {
		printf("Selected 1 based on %s\n", argv[1]);
		write_reg(E100_REG_GPIO_TX_DDR, 0xFFFF);
		write_reg(E100_REG_GPIO_RX_DDR, 0xFFFF);
		write_reg(E100_REG_GPIO_TX_SEL, 0xFFFF);
		write_reg(E100_REG_GPIO_RX_SEL, 0xFFFF);
		write_reg(E100_REG_GPIO_TX_DBG, 0xFFFF);
		write_reg(E100_REG_GPIO_RX_DBG, 0xFFFF);
	} else {
		printf("Selected off based on %s\n", argv[1]);
		write_reg(E100_REG_GPIO_TX_DDR, 0x0);
		write_reg(E100_REG_GPIO_RX_DDR, 0x0);
	}

	return 0;
}