summaryrefslogtreecommitdiffstats
path: root/host/utils/usrp-e-spi.c
blob: 5203f56a880376b248594c1267dc65f3dabde321 (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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ioctl.h>

#include <linux/usrp_e.h>

// Usage: usrp_e_spi w|rb slave data

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

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

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

	printf("Data = %X\n", data);

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

//	sleep(1);


	spi_dat.slave = slave;
	spi_dat.data = data;
	spi_dat.length = length;
	spi_dat.flags = UE_SPI_PUSH_FALL | UE_SPI_LATCH_RISE;

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

	return 0;
}