aboutsummaryrefslogtreecommitdiffstats
path: root/host/apps/omap_debug/usrp-e-gpio.c
diff options
context:
space:
mode:
authorPhilip Balister <philip@opensdr.com>2010-04-09 21:41:37 +0000
committerPhilip Balister <philip@opensdr.com>2010-04-09 21:41:37 +0000
commit50780640a1b9ed6abb2abebbc727ce19711fbcb4 (patch)
tree06f3cbd552e9aafd69830fd98f2fcba77f0ce096 /host/apps/omap_debug/usrp-e-gpio.c
parentb0316af8ebc713afaddc5b6ded5c0304353a7ab6 (diff)
downloaduhd-50780640a1b9ed6abb2abebbc727ce19711fbcb4.tar.gz
uhd-50780640a1b9ed6abb2abebbc727ce19711fbcb4.tar.bz2
uhd-50780640a1b9ed6abb2abebbc727ce19711fbcb4.zip
Test program to verify GPIO on daughterboards. For success, connect gpios on
TX to corresponding ones on RX.
Diffstat (limited to 'host/apps/omap_debug/usrp-e-gpio.c')
-rw-r--r--host/apps/omap_debug/usrp-e-gpio.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/host/apps/omap_debug/usrp-e-gpio.c b/host/apps/omap_debug/usrp-e-gpio.c
new file mode 100644
index 000000000..adef877d3
--- /dev/null
+++ b/host/apps/omap_debug/usrp-e-gpio.c
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/ioctl.h>
+
+#include "usrp_e.h"
+#include "usrp_e_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 i, test, data_in;
+
+ test = 0;
+ if (argc > 1)
+ test = 1;
+
+ fp = open("/dev/usrp_e0", O_RDWR);
+ printf("fp = %d\n", fp);
+
+ write_reg(UE_REG_GPIO_TX_DDR, 0x0);
+ write_reg(UE_REG_GPIO_RX_DDR, 0xFFFF);
+
+ for (i=0; i < 16; i++) {
+ write_reg(UE_REG_GPIO_RX_IO, 1 << i);
+ sleep(1);
+ if (test) {
+ data_in = read_reg(UE_REG_GPIO_TX_IO);
+ if (data_in != (1 << i))
+ printf("Read failed, wrote: %X read: %X\n", \
+ 1 << i, data_in);
+ }
+ }
+
+ write_reg(UE_REG_GPIO_RX_DDR, 0x0);
+ write_reg(UE_REG_GPIO_TX_DDR, 0xFFFF);
+
+ sleep(1);
+
+ for (i=0; i < 16; i++) {
+ write_reg(UE_REG_GPIO_TX_IO, 1 << i);
+ sleep(1);
+ if (test) {
+ data_in = read_reg(UE_REG_GPIO_RX_IO);
+ if (data_in != (1 << i))
+ printf("Read failed, wrote: %X read: %X\n", \
+ 1 << i, data_in);
+ }
+ }
+
+ write_reg(UE_REG_GPIO_RX_DDR, 0x0);
+ write_reg(UE_REG_GPIO_TX_DDR, 0x0);
+
+ return 0;
+}