Revision 4f5cd641
| b/host/apps/omap_debug/Makefile | ||
|---|---|---|
| 1 |
CFLAGS=-Wall |
|
| 2 |
|
|
| 3 |
all : usrp-e-spi usrp-e-i2c |
|
| 4 |
|
|
| 1 | 5 |
usrp-e-spi : usrp-e-spi.c |
| 6 |
|
|
| 7 |
usrp-e-i2c : usrp-e-i2c.c |
|
| 8 |
|
|
| 9 |
clean : |
|
| 10 |
rm -f usrp-e-spi |
|
| 11 |
rm -f usrp-e-i2c |
|
| b/host/apps/omap_debug/usrp-e-i2c.c | ||
|---|---|---|
| 1 |
#include <stdio.h> |
|
| 2 |
#include <stdlib.h> |
|
| 3 |
#include <string.h> |
|
| 4 |
#include <sys/types.h> |
|
| 5 |
#include <fcntl.h> |
|
| 6 |
#include <sys/ioctl.h> |
|
| 7 |
|
|
| 8 |
#include "usrp1_e.h" |
|
| 9 |
|
|
| 10 |
// Usage: usrp_e_i2c w address data0 data1 data 2 .... |
|
| 11 |
// Usage: usrp_e_i2c r address count |
|
| 12 |
|
|
| 13 |
int main(int argc, char *argv[]) |
|
| 14 |
{
|
|
| 15 |
int fp, ret, i; |
|
| 16 |
struct usrp_e_i2c *i2c_msg; |
|
| 17 |
int direction, address, count; |
|
| 18 |
|
|
| 19 |
if (argc < 3) {
|
|
| 20 |
printf("Usage: usrp1_e_i2c w address data0 data1 data2 ...\n");
|
|
| 21 |
printf("Usage: usrp1_e_i2c r address count\n");
|
|
| 22 |
exit(-1); |
|
| 23 |
} |
|
| 24 |
|
|
| 25 |
if (strcmp(argv[1], "r") == 0) {
|
|
| 26 |
direction = 0; |
|
| 27 |
} else if (strcmp(argv[1], "w") == 0) {
|
|
| 28 |
direction = 1; |
|
| 29 |
} else {
|
|
| 30 |
return -1; |
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
address = atoi(argv[2]); |
|
| 34 |
|
|
| 35 |
fp = open("/dev/usrp1_e0", O_RDWR);
|
|
| 36 |
printf("fp = %d\n", fp);
|
|
| 37 |
|
|
| 38 |
if (direction) {
|
|
| 39 |
count = argc - 2; |
|
| 40 |
} else {
|
|
| 41 |
count = atoi(argv[3]); |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
i2c_msg = malloc(sizeof(i2c_msg) + count * sizeof(char)); |
|
| 45 |
|
|
| 46 |
i2c_msg->addr = address; |
|
| 47 |
i2c_msg->len = count; |
|
| 48 |
|
|
| 49 |
if (direction) {
|
|
| 50 |
// Write |
|
| 51 |
|
|
| 52 |
for (i=0; i<count; i++) {
|
|
| 53 |
i2c_msg->data[i] = atoi(argv[3+i]); |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
ret = ioctl(fp, USRP_E_I2C_WRITE, i2c_msg); |
|
| 57 |
printf("Return value from i2c_write ioctl: %d\n", ret);
|
|
| 58 |
} else {
|
|
| 59 |
// Read |
|
| 60 |
|
|
| 61 |
ret = ioctl(fp, USRP_E_I2C_READ, i2c_msg); |
|
| 62 |
|
|
| 63 |
printf("Ioctl: %d Data read :", ret);
|
|
| 64 |
for (i=0; i<count; i++) {
|
|
| 65 |
printf(" %X", i2c_msg->data[i]);
|
|
| 66 |
} |
|
| 67 |
printf("/n");
|
|
| 68 |
|
|
| 69 |
} |
|
| 70 |
return 0; |
|
| 71 |
} |
|
| b/host/apps/omap_debug/usrp-e-spi.c | ||
|---|---|---|
| 2 | 2 |
#include <stdlib.h> |
| 3 | 3 |
#include <sys/types.h> |
| 4 | 4 |
#include <fcntl.h> |
| 5 |
#include <linux/ioctl.h>
|
|
| 5 |
#include <sys/ioctl.h>
|
|
| 6 | 6 |
|
| 7 | 7 |
#include "usrp1_e.h" |
| 8 | 8 |
|
| ... | ... | |
| 37 | 37 |
spi_dat.readback = 0; |
| 38 | 38 |
ioctl(fp, USRP_E_SPI, &spi_dat); |
| 39 | 39 |
} |
| 40 |
|
|
| 41 |
return 0; |
|
| 40 | 42 |
} |
Also available in: Unified diff