aboutsummaryrefslogtreecommitdiffstats
path: root/host/apps/omap_debug/usrp1-e-spi.c
blob: a79d74b186c34925ff00bae625cbd48b8cd628e5 (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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <linux/ioctl.h>

#include "usrp1_e.h"

// Usage: usrp1_e_spi w|rb slave data

int main(int argc, char *argv[])
{
	int fp, slave, data, ret;
	struct usrp_e_spi spi_dat;

	if (argc < 4) {
		printf("Usage: usrp1_e_spi w|rb slave data\n");
		exit(-1);
	}

	slave = atoi(argv[2]);
	data = atoi(argv[3]);

	fp = open("/dev/usrp1_e0", O_RDWR);
	printf("fp = %d\n", fp);

	spi_dat.slave = slave;
	spi_dat.data = data;
	spi_dat.length = 2;
	spi_dat.flags = 0;

	if (*argv[1] == 'r') {
		spi_dat.readback = 1;
		ret = ioctl(fp, USRP_E_SPI, &spi_dat);
		printf("Data returned = %d\n", ret);
	} else {
		spi_dat.readback = 0;
		ioctl(fp, USRP_E_SPI, &spi_dat);
	}
}