From 5463912c324639791b354dea0d6af5e42c1eae77 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 24 Mar 2010 12:00:05 -0400 Subject: Start applying order through Makefile. --- host/apps/omap_debug/Makefile | 1 + 1 file changed, 1 insertion(+) create mode 100644 host/apps/omap_debug/Makefile (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile new file mode 100644 index 000000000..5616a7355 --- /dev/null +++ b/host/apps/omap_debug/Makefile @@ -0,0 +1 @@ +usrp-e-spi : usrp-e-spi.c -- cgit v1.2.3 From 4f5cd64188c7e2b5490d910d5e86301c053960ea Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 24 Mar 2010 15:49:08 -0400 Subject: Makefile and usrp-e-spi edits, add i2c test program. --- host/apps/omap_debug/Makefile | 10 ++++++ host/apps/omap_debug/usrp-e-i2c.c | 71 +++++++++++++++++++++++++++++++++++++++ host/apps/omap_debug/usrp-e-spi.c | 4 ++- 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 host/apps/omap_debug/usrp-e-i2c.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 5616a7355..07545a639 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1 +1,11 @@ +CFLAGS=-Wall + +all : usrp-e-spi usrp-e-i2c + usrp-e-spi : usrp-e-spi.c + +usrp-e-i2c : usrp-e-i2c.c + +clean : + rm -f usrp-e-spi + rm -f usrp-e-i2c diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c new file mode 100644 index 000000000..dce1ae153 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include + +#include "usrp1_e.h" + +// Usage: usrp_e_i2c w address data0 data1 data 2 .... +// Usage: usrp_e_i2c r address count + +int main(int argc, char *argv[]) +{ + int fp, ret, i; + struct usrp_e_i2c *i2c_msg; + int direction, address, count; + + if (argc < 3) { + printf("Usage: usrp1_e_i2c w address data0 data1 data2 ...\n"); + printf("Usage: usrp1_e_i2c r address count\n"); + exit(-1); + } + + if (strcmp(argv[1], "r") == 0) { + direction = 0; + } else if (strcmp(argv[1], "w") == 0) { + direction = 1; + } else { + return -1; + } + + address = atoi(argv[2]); + + fp = open("/dev/usrp1_e0", O_RDWR); + printf("fp = %d\n", fp); + + if (direction) { + count = argc - 2; + } else { + count = atoi(argv[3]); + } + + i2c_msg = malloc(sizeof(i2c_msg) + count * sizeof(char)); + + i2c_msg->addr = address; + i2c_msg->len = count; + + if (direction) { + // Write + + for (i=0; idata[i] = atoi(argv[3+i]); + } + + ret = ioctl(fp, USRP_E_I2C_WRITE, i2c_msg); + printf("Return value from i2c_write ioctl: %d\n", ret); + } else { + // Read + + ret = ioctl(fp, USRP_E_I2C_READ, i2c_msg); + + printf("Ioctl: %d Data read :", ret); + for (i=0; idata[i]); + } + printf("/n"); + + } + return 0; +} diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index a79d74b18..e10e72b80 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "usrp1_e.h" @@ -37,4 +37,6 @@ int main(int argc, char *argv[]) spi_dat.readback = 0; ioctl(fp, USRP_E_SPI, &spi_dat); } + + return 0; } -- cgit v1.2.3 From 717a6acd2b0687348c492cbf2e0813ffd63d847a Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 25 Mar 2010 20:43:59 +0000 Subject: Update read/write test program to new header name and add to Makefile. --- host/apps/omap_debug/Makefile | 6 +++++- host/apps/omap_debug/usrp-e-rw.c | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 07545a639..34446ccc3 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,11 +1,15 @@ CFLAGS=-Wall -all : usrp-e-spi usrp-e-i2c +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-spi : usrp-e-spi.c usrp-e-i2c : usrp-e-i2c.c +usrp-e-rw : usrp-e-rw.c + gcc -o $@ $< -lpthread clean : rm -f usrp-e-spi rm -f usrp-e-i2c + rm -f usrp-e-rw + diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c index cd7fbe4dd..5607166b0 100644 --- a/host/apps/omap_debug/usrp-e-rw.c +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -3,6 +3,7 @@ #include #include #include +#include struct pkt { int checksum; @@ -74,11 +75,10 @@ static void *write_thread(void *threadid) int main(int argc, char *argv[]) { - int ret; pthread_t tx, rx; long int t; - fp = open("/dev/usrp1_e0", O_RDWR); + fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); if (pthread_create(&rx, NULL, read_thread, (void *) t)) { -- cgit v1.2.3 From 84df070f371b989ef51b6f2d04c131b34308e5e9 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 26 Mar 2010 15:22:12 +0000 Subject: Add test program to send characters to the wishbone uart. --- host/apps/omap_debug/Makefile | 6 +++++- host/apps/omap_debug/usrp-e-uart.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 host/apps/omap_debug/usrp-e-uart.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 34446ccc3..13b834e28 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -all : usrp-e-spi usrp-e-i2c usrp-e-rw +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-spi : usrp-e-spi.c @@ -8,8 +8,12 @@ usrp-e-i2c : usrp-e-i2c.c usrp-e-rw : usrp-e-rw.c gcc -o $@ $< -lpthread + +usrp-e-uart : usrp-e-uart.c + clean : rm -f usrp-e-spi rm -f usrp-e-i2c rm -f usrp-e-rw + rm -f usrp-e-uart diff --git a/host/apps/omap_debug/usrp-e-uart.c b/host/apps/omap_debug/usrp-e-uart.c new file mode 100644 index 000000000..92f89f45c --- /dev/null +++ b/host/apps/omap_debug/usrp-e-uart.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include + +#include "usrp_e.h" + +// Usage: usrp_e_uart + +#define UART_WRITE_ADDR ((1<<6) + 16) + +int main(int argc, char *argv[]) +{ + int fp, i, ret; + struct usrp_e_ctl16 d; + char *str = argv[1]; + + if (argc < 2) { + printf("Usage: usrp_e_uart n"); + exit(-1); + } + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + for (i=0; i Date: Fri, 2 Apr 2010 19:49:45 +0000 Subject: Convert to use register include file. Fix peek/poke16 program. Add program to cycle through LED's and test buttons. Only pushbuttons tested at the moment. --- host/apps/omap_debug/Makefile | 14 +++++++-- host/apps/omap_debug/usrp-e-button.c | 56 +++++++++++++++++++++++++++++++++++ host/apps/omap_debug/usrp-e-ctl.c | 20 ++++++------- host/apps/omap_debug/usrp-e-led.c | 35 ++++++++++++++++++++++ host/apps/omap_debug/usrp-e-uart | Bin 0 -> 7143 bytes 5 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-button.c create mode 100644 host/apps/omap_debug/usrp-e-led.c create mode 100755 host/apps/omap_debug/usrp-e-uart (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 13b834e28..f292379f4 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ -CFLAGS=-Wall +CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-spi : usrp-e-spi.c @@ -11,9 +11,17 @@ usrp-e-rw : usrp-e-rw.c usrp-e-uart : usrp-e-uart.c +usrp-e-led : usrp-e-led.c + +usrp-e-ctl : usrp-e-ctl.c + +usrp-e-button : usrp-e-button.c + clean : rm -f usrp-e-spi rm -f usrp-e-i2c rm -f usrp-e-rw rm -f usrp-e-uart - + rm -f usrp-e-led + rm -f usrp-e-ctl + rm -f usrp-e-button diff --git a/host/apps/omap_debug/usrp-e-button.c b/host/apps/omap_debug/usrp-e-button.c new file mode 100644 index 000000000..fca501833 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-button.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "usrp_e.h" +#include "usrp_e_regs.hpp" + +// Usage: usrp_e_uart + +#define PB1 (1<<8) +#define PB2 (1<<9) +#define PB3 (1<<10) +#define P1 (0) +#define P2 (0xFF) +#define P3 (0xAA) +#define P4 (0x55) + +int main(int argc, char *argv[]) +{ + int fp, ret; + struct usrp_e_ctl16 d; + int pb1=0, pb2=0, pb3=0, p1=0, p2=0, p3=0, p4=0; + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + d.offset = 6; + d.count = 1; + + do { + ret = ioctl(fp, USRP_E_READ_CTL16, &d); + if (d.buf[0] & PB1) { + pb1 = 1; + printf("Pushbutton 1 hit\n"); + } + + if (d.buf[0] & PB2) { + pb2 = 1; + printf("Pushbutton 2 hit\n"); + } + + if (d.buf[0] & PB3) { + pb3 = 1; + printf("Pushbutton 3 hit\n"); + } + + sleep(1); + + } while (!(pb1 && pb2 && pb3)); + + return 0; +} diff --git a/host/apps/omap_debug/usrp-e-ctl.c b/host/apps/omap_debug/usrp-e-ctl.c index 045e7ce19..501a4870e 100644 --- a/host/apps/omap_debug/usrp-e-ctl.c +++ b/host/apps/omap_debug/usrp-e-ctl.c @@ -2,44 +2,44 @@ #include #include #include -#include +#include -#include "usrp1_e.h" +#include "usrp_e.h" -// Usage: usrp1_e_ctl w|r offset number_of_values val1 val2 .... +// Usage: usrp_e_ctl w|r offset number_of_values val1 val2 .... int main(int argc, char *argv[]) { int fp, i, cnt, ret; - struct usrp1_e_ctl *ctl_data; + struct usrp_e_ctl16 *ctl_data; if (argc < 4) { - printf("Usage: usrp1_e_ctl w|r offset number_of_values val1 val2 ....\n"); + printf("Usage: usrp_e_ctl w|r offset number_of_values val1 val2 ....\n"); exit(-1); } cnt = atoi(argv[3]); - ctl_data = malloc(sizeof(struct usrp1_e_ctl) + cnt*2); + ctl_data = malloc(sizeof(struct usrp_e_ctl16) + cnt*2); ctl_data->offset = atoi(argv[2]); ctl_data->count = cnt; - printf("Sizeof usrp1_e_ctl struct = %d\n", sizeof(struct usrp1_e_ctl)); + printf("Sizeof usrp1_e_ctl struct = %d\n", sizeof(struct usrp_e_ctl16)); - fp = open("/dev/usrp1_e0", O_RDWR); + fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); if (*argv[1] == 'w') { for (i=0; ibuf[i] = atoi(argv[4+i]); - ret = ioctl(fp, USRP1_E_WRITE_CTL, ctl_data); + ret = ioctl(fp, USRP_E_WRITE_CTL16, ctl_data); printf("Return value from write ioctl = %d\n", ret); } if (*argv[1] == 'r') { - ret = ioctl(fp, USRP1_E_READ_CTL, ctl_data); + ret = ioctl(fp, USRP_E_READ_CTL16, ctl_data); printf("Return value from write ioctl = %d\n", ret); for (i=0; icount; i++) { diff --git a/host/apps/omap_debug/usrp-e-led.c b/host/apps/omap_debug/usrp-e-led.c new file mode 100644 index 000000000..159251c8a --- /dev/null +++ b/host/apps/omap_debug/usrp-e-led.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "usrp_e.h" +#include "usrp_e_regs.hpp" + +// Usage: usrp_e_uart + + +int main(int argc, char *argv[]) +{ + int fp, i, ret; + struct usrp_e_ctl16 d; + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + d.offset = 4; + d.count = 1; + + while (1) { + for (i=0; i<8; i++) { + d.buf[0] = i; + ret = ioctl(fp, USRP_E_WRITE_CTL16, &d); + sleep(1); + } + } + + return 0; +} diff --git a/host/apps/omap_debug/usrp-e-uart b/host/apps/omap_debug/usrp-e-uart new file mode 100755 index 000000000..5781f0db2 Binary files /dev/null and b/host/apps/omap_debug/usrp-e-uart differ -- cgit v1.2.3 From ea28c75555b989407d182225febffad8d2a64d1e Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Sat, 3 Apr 2010 15:25:37 +0000 Subject: Add program to read from serial port and print to screen. (works) --- host/apps/omap_debug/Makefile | 5 +++- host/apps/omap_debug/usrp-e-uart-rx.c | 53 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 host/apps/omap_debug/usrp-e-uart-rx.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index f292379f4..4779969de 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx usrp-e-spi : usrp-e-spi.c @@ -11,6 +11,8 @@ usrp-e-rw : usrp-e-rw.c usrp-e-uart : usrp-e-uart.c +usrp-e-uart-rx : usrp-e-uart-rx.c + usrp-e-led : usrp-e-led.c usrp-e-ctl : usrp-e-ctl.c @@ -22,6 +24,7 @@ clean : rm -f usrp-e-i2c rm -f usrp-e-rw rm -f usrp-e-uart + rm -f usrp-e-uart-rx rm -f usrp-e-led rm -f usrp-e-ctl rm -f usrp-e-button diff --git a/host/apps/omap_debug/usrp-e-uart-rx.c b/host/apps/omap_debug/usrp-e-uart-rx.c new file mode 100644 index 000000000..24b417980 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-uart-rx.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include + +#include "usrp_e.h" +#include "usrp_e_regs.hpp" + +// Usage: usrp_e_uart + + +int main(int argc, char *argv[]) +{ + int fp, ret; + struct usrp_e_ctl16 d; + __u16 clkdiv; + + if (argc == 0) { + printf("Usage: usrp-e-uart-rx \n"); + printf("clkdiv = 278 is 230.4k \n"); + printf("clkdiv = 556 is 115.2k \n"); + exit(-1); + } + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + if (argc == 2) { + clkdiv = atoi(argv[1]); + d.offset = UE_REG_UART_CLKDIV; + d.count = 1; + d.buf[0] = clkdiv; + ret = ioctl(fp, USRP_E_WRITE_CTL16, &d); + } + + while(1) { + d.offset = UE_REG_UART_RXLEVEL; + d.count = 1; + ret = ioctl(fp, USRP_E_READ_CTL16, &d); + + if (d.buf[0] > 0) { + d.offset = UE_REG_UART_RXCHAR; + d.count = 1; + ret = ioctl(fp, USRP_E_READ_CTL16, &d); + printf("%c", d.buf[0]); + fflush(stdout); + } + } + + return 0; +} -- cgit v1.2.3 From b0316af8ebc713afaddc5b6ded5c0304353a7ab6 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Sat, 3 Apr 2010 16:59:44 +0000 Subject: Attempt to make scripts run inside and outside GHQ. When at GHQ: export GHQ=1 export GHQ_USER="something that can log in to astro" --- host/apps/omap_debug/Makefile | 5 ++++- host/apps/omap_debug/fetch-bin.sh | 6 +++++- host/apps/omap_debug/fetch-kernel.sh | 5 ++++- host/apps/omap_debug/fetch-module.sh | 7 +++++-- host/apps/omap_debug/fetch-u-boot.sh | 5 ++++- 5 files changed, 22 insertions(+), 6 deletions(-) (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 4779969de..cd95d36fc 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-spi : usrp-e-spi.c @@ -19,6 +19,8 @@ usrp-e-ctl : usrp-e-ctl.c usrp-e-button : usrp-e-button.c +fpga-downloader : fpga-downloader.cc + clean : rm -f usrp-e-spi rm -f usrp-e-i2c @@ -28,3 +30,4 @@ clean : rm -f usrp-e-led rm -f usrp-e-ctl rm -f usrp-e-button + rm -f fpga-downloader diff --git a/host/apps/omap_debug/fetch-bin.sh b/host/apps/omap_debug/fetch-bin.sh index beff7ffcd..d1502f95c 100755 --- a/host/apps/omap_debug/fetch-bin.sh +++ b/host/apps/omap_debug/fetch-bin.sh @@ -1,2 +1,6 @@ -scp balister@astro:/workspace/usrp1-e-dev/u1e.bin . +if [ $GHQ ]; then + scp $GHQ_USER@astro:/workspace/usrp1-e-dev/u1e.bin . +else + scp -P 8822 balister@192.168.1.10:src/git/fpgapriv/usrp2/top/u1e/build/u1e.bin . +fi sync diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh index 7023f5d28..f32666adf 100755 --- a/host/apps/omap_debug/fetch-kernel.sh +++ b/host/apps/omap_debug/fetch-kernel.sh @@ -1,3 +1,6 @@ -scp balister@192.168.1.167:src/git/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage +if [ $GHQ]; then + scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage +else + scp balister@192.168.1.167:src/git/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage sync diff --git a/host/apps/omap_debug/fetch-module.sh b/host/apps/omap_debug/fetch-module.sh index 45cf1f052..52fbd4040 100755 --- a/host/apps/omap_debug/fetch-module.sh +++ b/host/apps/omap_debug/fetch-module.sh @@ -1,3 +1,6 @@ -scp balister@192.168.1.167:src/git/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc -scp balister@192.168.1.167:src/git/kernel_usrp/include/linux/usrp_e.h . +if [ $GHQ ]; then + scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc +else + scp balister@192.168.1.167:src/git/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc +fi sync diff --git a/host/apps/omap_debug/fetch-u-boot.sh b/host/apps/omap_debug/fetch-u-boot.sh index 63d4edcf2..a2a488fb2 100755 --- a/host/apps/omap_debug/fetch-u-boot.sh +++ b/host/apps/omap_debug/fetch-u-boot.sh @@ -1,3 +1,6 @@ -scp balister@astro:/workspace/usrp1-e-dev/u-boot-overo/u-boot.bin /media/mmcblk0p1/ +if [ $GHQ ]; then + scp $GHQ_USER@astro:/workspace/usrp1-e-dev/u-boot-overo/u-boot.bin /media/mmcblk0p1/ +else + scp balister@192.168.1.167:src/git/u-boot/u-boot.bin /media/mmcblk0p1/ sync -- cgit v1.2.3 From 50780640a1b9ed6abb2abebbc727ce19711fbcb4 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 9 Apr 2010 21:41:37 +0000 Subject: Test program to verify GPIO on daughterboards. For success, connect gpios on TX to corresponding ones on RX. --- host/apps/omap_debug/Makefile | 5 +- host/apps/omap_debug/set_debug_pins.py | 13 +++--- host/apps/omap_debug/usrp-e-gpio.c | 83 ++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-gpio.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index cd95d36fc..31229d45c 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-spi : usrp-e-spi.c @@ -21,6 +21,8 @@ usrp-e-button : usrp-e-button.c fpga-downloader : fpga-downloader.cc +usrp-e-gpio : usrp-e-gpio.c + clean : rm -f usrp-e-spi rm -f usrp-e-i2c @@ -31,3 +33,4 @@ clean : rm -f usrp-e-ctl rm -f usrp-e-button rm -f fpga-downloader + rm -f usrp-e-gpio diff --git a/host/apps/omap_debug/set_debug_pins.py b/host/apps/omap_debug/set_debug_pins.py index fdd085c9e..0f9ecd7b9 100755 --- a/host/apps/omap_debug/set_debug_pins.py +++ b/host/apps/omap_debug/set_debug_pins.py @@ -3,12 +3,12 @@ import os # Memory Map -misc_base = 0 << 7 -uart_base = 1 << 7 -spi_base = 2 << 7 -i2c_base = 3 << 7 -gpio_base = 4 << 7 -settings_base = 5 << 7 +misc_base = 0 +uart_base = 1 +spi_base = 2 +i2c_base = 3 +gpio_base = 4 * 128 +settings_base = 5 # GPIO offset gpio_pins = 0 @@ -32,3 +32,4 @@ set_reg(gpio_base+gpio_ctrl_lo, 0xAAAA) set_reg(gpio_base+gpio_ctrl_lo+2, 0xAAAA) set_reg(gpio_base+gpio_ctrl_hi, 0xAAAA) set_reg(gpio_base+gpio_ctrl_hi+2, 0xAAAA) + 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 +#include +#include +#include +#include +#include +#include + +#include "usrp_e.h" +#include "usrp_e_regs.hpp" + +// Usage: usrp_e_gpio + +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; +} -- cgit v1.2.3 From 43db7fd7ffb542d55d59368b62a27cffe03cba67 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 20 Apr 2010 15:54:37 +0000 Subject: Add program to setup debug pins. Add script to reload fpga and module. --- host/apps/omap_debug/Makefile | 4 +- host/apps/omap_debug/reload-fpga.sh | 7 +++ host/apps/omap_debug/usrp-e-debug-pins.c | 73 ++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 host/apps/omap_debug/reload-fpga.sh create mode 100644 host/apps/omap_debug/usrp-e-debug-pins.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 31229d45c..61f659b3e 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-spi : usrp-e-spi.c @@ -23,6 +23,7 @@ fpga-downloader : fpga-downloader.cc usrp-e-gpio : usrp-e-gpio.c +usrp-e-debug-pins : usrp-e-debug-pins.c clean : rm -f usrp-e-spi rm -f usrp-e-i2c @@ -34,3 +35,4 @@ clean : rm -f usrp-e-button rm -f fpga-downloader rm -f usrp-e-gpio + rm -f usrp-e-debug-pins diff --git a/host/apps/omap_debug/reload-fpga.sh b/host/apps/omap_debug/reload-fpga.sh new file mode 100755 index 000000000..2754718a4 --- /dev/null +++ b/host/apps/omap_debug/reload-fpga.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +rmmod usrp_e +fpga-downloader /home/root/u1e.bin +modprobe usrp_e +usrp-e-debug-pins 1 + diff --git a/host/apps/omap_debug/usrp-e-debug-pins.c b/host/apps/omap_debug/usrp-e-debug-pins.c new file mode 100644 index 000000000..d4e3f5223 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-debug-pins.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "usrp_e.h" +#include "usrp_e_regs.hpp" + +// Usage: usrp_e_gpio + +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]); + } + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + if (strcmp(argv[1], "0") == 0) { + printf("Selected 0 based on %s\n", argv[1]); + write_reg(UE_REG_GPIO_TX_DDR, 0xFFFF); + write_reg(UE_REG_GPIO_RX_DDR, 0xFFFF); + write_reg(UE_REG_GPIO_TX_SEL, 0x0); + write_reg(UE_REG_GPIO_RX_SEL, 0x0); + write_reg(UE_REG_GPIO_TX_DBG, 0xFFFF); + write_reg(UE_REG_GPIO_RX_DBG, 0xFFFF); + } else if (strcmp(argv[1], "1") == 0) { + printf("Selected 1 based on %s\n", argv[1]); + write_reg(UE_REG_GPIO_TX_DDR, 0xFFFF); + write_reg(UE_REG_GPIO_RX_DDR, 0xFFFF); + write_reg(UE_REG_GPIO_TX_SEL, 0xFFFF); + write_reg(UE_REG_GPIO_RX_SEL, 0xFFFF); + write_reg(UE_REG_GPIO_TX_DBG, 0xFFFF); + write_reg(UE_REG_GPIO_RX_DBG, 0xFFFF); + } else { + printf("Selected off based on %s\n", argv[1]); + write_reg(UE_REG_GPIO_TX_DDR, 0x0); + write_reg(UE_REG_GPIO_RX_DDR, 0x0); + } + + return 0; +} -- cgit v1.2.3 From f5b6776a0b642c0357fbecdead9d2b1ac6ece3d3 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 23 Apr 2010 14:04:37 +0000 Subject: Updates to test programs. --- host/apps/omap_debug/Makefile | 6 +- host/apps/omap_debug/usrp-e-rw-random.c | 147 ++++++++++++++++++++++++++++++++ host/apps/omap_debug/usrp-e-rw.c | 42 ++++++--- 3 files changed, 181 insertions(+), 14 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-rw-random.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 61f659b3e..b00210c4f 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-spi : usrp-e-spi.c @@ -9,6 +9,9 @@ usrp-e-i2c : usrp-e-i2c.c usrp-e-rw : usrp-e-rw.c gcc -o $@ $< -lpthread +usrp-e-rw-random : usrp-e-rw-random.c + gcc -o $@ $< -lpthread + usrp-e-uart : usrp-e-uart.c usrp-e-uart-rx : usrp-e-uart-rx.c @@ -28,6 +31,7 @@ clean : rm -f usrp-e-spi rm -f usrp-e-i2c rm -f usrp-e-rw + rm -f usrp-e-rw-random rm -f usrp-e-uart rm -f usrp-e-uart-rx rm -f usrp-e-led diff --git a/host/apps/omap_debug/usrp-e-rw-random.c b/host/apps/omap_debug/usrp-e-rw-random.c new file mode 100644 index 000000000..67d6ca803 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-rw-random.c @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1014 +static int packet_data_length; + +struct pkt { + int checksum; + int seq_num; + int len; + short data[]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i < p->len; i++) + sum += p->data[i]; + + sum += p->seq_num; + + return sum; +} + +int randN(int n) +{ + long tmp; + + tmp = rand() % n; + + return tmp; +} + +static void *read_thread(void *threadid) +{ + int cnt, prev_seq_num; + struct usrp_transfer_frame *rx_data; + struct pkt *p; + + printf("Greetings from the reading thread!\n"); + + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1014 * 2)); + rx_data = malloc(2048); + p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); + //p = &(rx_data->buf[0]); + printf("Address of rx_data = %p, p = %p\n", rx_data, p); + printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); + printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + + prev_seq_num = 0; + + while (1) { + + cnt = read(fp, rx_data, 2048); +// printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); +// printf("p->seq_num = %d\n", p->seq_num); + + if (p->seq_num != prev_seq_num + 1) + printf("Sequence number fail, current = %d, previous = %d\n", + p->seq_num, prev_seq_num); + prev_seq_num = p->seq_num; + + if (calc_checksum(p) != p->checksum) + printf("Checksum fail packet = %d, expected = %d\n", + calc_checksum(p), p->checksum); +// printf("\n"); + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt, pkt_cnt; + struct usrp_transfer_frame *tx_data; + struct pkt *p; + + printf("Greetings from the write thread!\n"); + + // Allocate max length buffer for frame + tx_data = malloc(2048); + p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); + printf("Address of tx_data = %p, p = %p\n", tx_data, p); + + printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); + + for (i=0; i < 1014; i++) +// p->data[i] = random() >> 16; + p->data[i] = i; + + tx_data->flags = 0xdeadbeef; + tx_data->len = 8 + packet_data_length * 2; + + printf("tx_data->len = %d\n", tx_data->len); + + seq_number = 1; + + while (1) { + pkt_cnt = randN(16); + for (i = 0; i < pkt_cnt; i++) { + p->seq_num = seq_number++; + p->len = randN(1013) + 1; + p->checksum = calc_checksum(p); + tx_data->len = 12 + p->len * 2; + cnt = write(fp, tx_data, 2048); + } + sleep(random() >> 31); + } +} + + +int main(int argc, char *argv[]) +{ + pthread_t tx, rx; + long int t; + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + if (pthread_create(&rx, NULL, read_thread, (void *) t)) { + printf("Failed to create rx thread\n"); + exit(-1); + } + + sleep(1); + + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { + printf("Failed to create tx thread\n"); + exit(-1); + } + + sleep(10000); + + printf("Done sleeping\n"); +} diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c index 5fd73e9b6..edfcea92a 100644 --- a/host/apps/omap_debug/usrp-e-rw.c +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -7,13 +7,13 @@ #include #include "usrp_e.h" -#define PKT_DATA_LENGTH 30 // max length #define PKT_DATA_LENGTH 1016 +static int packet_data_length; struct pkt { int checksum; int seq_num; - short data[PKT_DATA_LENGTH]; + short data[]; }; static int fp; @@ -25,7 +25,7 @@ static int calc_checksum(struct pkt *p) i = 0; sum = 0; - for (i=0; idata[i]; sum += p->seq_num; @@ -41,20 +41,24 @@ static void *read_thread(void *threadid) printf("Greetings from the reading thread!\n"); - rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1016 * 2)); p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); //p = &(rx_data->buf[0]); printf("Address of rx_data = %p, p = %p\n", rx_data, p); printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); - printf("sizeof rx data = %X\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); prev_seq_num = 0; while (1) { cnt = read(fp, rx_data, 2048); - printf("Packet received, flags = %X, len = %X\n", rx_data->flags, rx_data->len); - printf("p->seq_num = %d\n", p->seq_num); + if (cnt < 0) + printf("Error returned from read: %d\n", cnt); + +// printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); +// printf("p->seq_num = %d\n", p->seq_num); if (p->seq_num != prev_seq_num + 1) printf("Sequence number fail, current = %X, previous = %X\n", @@ -64,7 +68,7 @@ static void *read_thread(void *threadid) if (calc_checksum(p) != p->checksum) printf("Checksum fail packet = %X, expected = %X\n", calc_checksum(p), p->checksum); - printf("\n"); +// printf("\n"); } } @@ -77,26 +81,31 @@ static void *write_thread(void *threadid) printf("Greetings from the write thread!\n"); - tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (packet_data_length * 2)); p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); printf("Address of tx_data = %p, p = %p\n", tx_data, p); - printf("sizeof tx data = %X\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); - for (i=0; idata[i] = random() >> 16; p->data[i] = i; tx_data->flags = 0xdeadbeef; - tx_data->len = 8 + PKT_DATA_LENGTH * 2; + tx_data->len = 8 + packet_data_length * 2; + + printf("tx_data->len = %d\n", tx_data->len); seq_number = 1; while (1) { +// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); p->seq_num = seq_number++; p->checksum = calc_checksum(p); cnt = write(fp, tx_data, 2048); - sleep(1); + if (cnt < 0) + printf("Error returned from write: %d\n", cnt); + // sleep(1); } } @@ -106,6 +115,13 @@ int main(int argc, char *argv[]) pthread_t tx, rx; long int t; + if (argc < 2) { + printf("%s data_size\n", argv[0]); + return -1; + } + + packet_data_length = atoi(argv[1]); + fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); -- cgit v1.2.3 From 245b46da0b603e3c12c56fdad782ff884b2a6432 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 27 Apr 2010 08:18:24 +0000 Subject: Add program to exercise interface using internal fpga data source and data sink. --- host/apps/omap_debug/Makefile | 6 +- host/apps/omap_debug/usrp-e-fpga-rw.c | 167 ++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 host/apps/omap_debug/usrp-e-fpga-rw.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index b00210c4f..f48eb9539 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw usrp-e-spi : usrp-e-spi.c @@ -9,6 +9,9 @@ usrp-e-i2c : usrp-e-i2c.c usrp-e-rw : usrp-e-rw.c gcc -o $@ $< -lpthread +usrp-e-fpga-rw : usrp-e-fpga-rw.c + gcc -o $@ $< -lpthread + usrp-e-rw-random : usrp-e-rw-random.c gcc -o $@ $< -lpthread @@ -31,6 +34,7 @@ clean : rm -f usrp-e-spi rm -f usrp-e-i2c rm -f usrp-e-rw + rm -f usrp-e-fpga-rw rm -f usrp-e-rw-random rm -f usrp-e-uart rm -f usrp-e-uart-rx diff --git a/host/apps/omap_debug/usrp-e-fpga-rw.c b/host/apps/omap_debug/usrp-e-fpga-rw.c new file mode 100644 index 000000000..455657203 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-fpga-rw.c @@ -0,0 +1,167 @@ +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1016 +static int packet_data_length; + +struct pkt { + int checksum; + int seq_num; + short data[]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i < packet_data_length; i++) + sum += p->data[i]; + + sum += p->seq_num; + + return sum; +} + +static void *read_thread(void *threadid) +{ + int cnt, prev_seq_num; + struct usrp_transfer_frame *rx_data; + struct pkt *p; + + printf("Greetings from the reading thread!\n"); + + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1016 * 2)); + p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); + //p = &(rx_data->buf[0]); + printf("Address of rx_data = %p, p = %p\n", rx_data, p); + printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); + printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + + prev_seq_num = 0; + + while (1) { + + cnt = read(fp, rx_data, 2048); + if (cnt < 0) + printf("Error returned from read: %d\n", cnt); + +// printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); +// printf("p->seq_num = %d\n", p->seq_num); + + if (p->seq_num != prev_seq_num + 1) + printf("Sequence number fail, current = %X, previous = %X\n", + p->seq_num, prev_seq_num); + prev_seq_num = p->seq_num; + + if (calc_checksum(p) != p->checksum) + printf("Checksum fail packet = %X, expected = %X\n", + calc_checksum(p), p->checksum); +// printf("\n"); + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt; + struct usrp_transfer_frame *tx_data; + struct pkt *p; + + printf("Greetings from the write thread!\n"); + + tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (packet_data_length * 2)); + p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); + printf("Address of tx_data = %p, p = %p\n", tx_data, p); + + printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); + + for (i=0; i < packet_data_length; i++) +// p->data[i] = random() >> 16; + p->data[i] = i; + + tx_data->flags = 0; + tx_data->len = 8 + packet_data_length * 2; + + printf("tx_data->len = %d\n", tx_data->len); + + seq_number = 1; + + while (1) { +// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); + p->seq_num = seq_number++; + p->checksum = calc_checksum(p); + cnt = write(fp, tx_data, 2048); + if (cnt < 0) + printf("Error returned from write: %d\n", cnt); +// sleep(1); + } +} + + +int main(int argc, char *argv[]) +{ + pthread_t tx, rx; + long int t; + int fpga_config_flag ,decimation; + struct usrp_e_ctl16 d; + + if (argc < 4) { + printf("%s t|w|rw decimation data_size\n", argv[0]); + return -1; + } + + decimation = atoi(argv[2]); + packet_data_length = atoi(argv[3]); + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + fpga_config_flag = 0; + if (strcmp(argv[1], "w") == 0) + fpga_config_flag |= (1 << 15); + else if (strcmp(argv[1], "r") == 0) + fpga_config_flag |= (1 << 14); + else if (strcmp(argv[1], "rw") == 0) + fpga_config_flag |= ((1 << 15) | (1 << 14)); + + fpga_config_flag |= decimation; + + d.offset = 14; + d.count = 1; + d.buf[0] = fpga_config_flag; + ioctl(fp, USRP_E_WRITE_CTL16, &d); + + sleep(1); // in case the kernel threads need time to start. FIXME if so + + if (fpga_config_flag & (1 << 14)) { + if (pthread_create(&rx, NULL, read_thread, (void *) t)) { + printf("Failed to create rx thread\n"); + exit(-1); + } + } + + sleep(1); + + if (fpga_config_flag & (1 << 15)) { + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { + printf("Failed to create tx thread\n"); + exit(-1); + } + } + + sleep(10000); + + printf("Done sleeping\n"); +} -- cgit v1.2.3 From f2454f90023552c00b5b25aca4e8eaa8d46c0751 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 28 Apr 2010 13:07:22 +0000 Subject: Various updates to test programs. --- host/apps/omap_debug/Makefile | 5 ++- host/apps/omap_debug/usrp-e-fpga-rw.c | 32 ++++++++++++++----- host/apps/omap_debug/usrp-e-lb-test.c | 58 +++++++++++++++++++++++++++++++++++ host/apps/omap_debug/usrp_e.h | 6 ++++ 4 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-lb-test.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index f48eb9539..14be592ff 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw usrp-e-lb-test usrp-e-spi : usrp-e-spi.c @@ -29,6 +29,8 @@ fpga-downloader : fpga-downloader.cc usrp-e-gpio : usrp-e-gpio.c +usrp-e-lb-test : usrp-e-lb-test.c + usrp-e-debug-pins : usrp-e-debug-pins.c clean : rm -f usrp-e-spi @@ -44,3 +46,4 @@ clean : rm -f fpga-downloader rm -f usrp-e-gpio rm -f usrp-e-debug-pins + rm -f usrp-e-lb-test diff --git a/host/apps/omap_debug/usrp-e-fpga-rw.c b/host/apps/omap_debug/usrp-e-fpga-rw.c index 455657203..f3fa1499a 100644 --- a/host/apps/omap_debug/usrp-e-fpga-rw.c +++ b/host/apps/omap_debug/usrp-e-fpga-rw.c @@ -38,6 +38,8 @@ static void *read_thread(void *threadid) int cnt, prev_seq_num; struct usrp_transfer_frame *rx_data; struct pkt *p; + int rx_pkt_cnt; + int i; printf("Greetings from the reading thread!\n"); @@ -51,23 +53,39 @@ static void *read_thread(void *threadid) prev_seq_num = 0; + rx_pkt_cnt = 0; + while (1) { cnt = read(fp, rx_data, 2048); if (cnt < 0) printf("Error returned from read: %d\n", cnt); + rx_pkt_cnt++; + + if (rx_pkt_cnt == 512) { + printf("."); + fflush(stdout); + rx_pkt_cnt = 0; + } + if (rx_data->flags & RB_OVERRUN) + printf("RX ring buffer overrun occurred at packet %d\n", rx_pkt_cnt); + +// for (i = 0; i < 10; i++) +// printf(" %d", p->data[i]); +// printf("\n"); + // printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); // printf("p->seq_num = %d\n", p->seq_num); - if (p->seq_num != prev_seq_num + 1) - printf("Sequence number fail, current = %X, previous = %X\n", - p->seq_num, prev_seq_num); - prev_seq_num = p->seq_num; +// if (p->seq_num != prev_seq_num + 1) +// printf("Sequence number fail, current = %X, previous = %X\n", +// p->seq_num, prev_seq_num); +// prev_seq_num = p->seq_num; - if (calc_checksum(p) != p->checksum) - printf("Checksum fail packet = %X, expected = %X\n", - calc_checksum(p), p->checksum); +// if (calc_checksum(p) != p->checksum) +// printf("Checksum fail packet = %X, expected = %X\n", +// calc_checksum(p), p->checksum); // printf("\n"); } diff --git a/host/apps/omap_debug/usrp-e-lb-test.c b/host/apps/omap_debug/usrp-e-lb-test.c new file mode 100644 index 000000000..675de8622 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-lb-test.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1016 + +int main(int argc, char *argv[]) +{ + struct usrp_transfer_frame *tx_data, *rx_data; + int i, fp, packet_data_length, cnt; + struct usrp_e_ctl16 d; + + if (argc < 2) { + printf("%s data_size (in bytes < 2040)\n", argv[0]); + return -1; + } + + packet_data_length = atoi(argv[1]); + + fp = open("/dev/usrp_e0", O_RDWR); + + d.offset = 14; + d.count = 1; + d.buf[0] = (1 << 13); + ioctl(fp, USRP_E_WRITE_CTL16, &d); + + tx_data = malloc(2048); + rx_data = malloc(2048); + + tx_data->flags = 0; + tx_data->len = sizeof(struct usrp_transfer_frame) + packet_data_length; + + while (1) { + + for (i = 0; i < packet_data_length; i++) { + tx_data->buf[i] = random() >> 24; + + } + + cnt = write(fp, tx_data, 2048); + cnt = read(fp, rx_data, 2048); + + if (tx_data->len != rx_data->len) + printf("Bad frame length sent %d, read %d\n", tx_data->len, rx_data->len); + + for (i = 0; i < packet_data_length; i++) { + if (tx_data->buf[i] != rx_data->buf[i]) + printf("Bad data at %d, sent %d, received %d\n", i, tx_data->buf[i], rx_data->buf[i]); + } + printf("---------------------------------------------------\n"); + sleep(1); + } +} diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h index 48a3201cb..d4132021f 100644 --- a/host/apps/omap_debug/usrp_e.h +++ b/host/apps/omap_debug/usrp_e.h @@ -1,3 +1,4 @@ + /* * Copyright (C) 2010 Ettus Research, LLC * @@ -77,6 +78,11 @@ struct usrp_transfer_frame { __u8 buf[]; }; +// Flag defines +#define RB_USER (1 << 0) +#define RB_KERNEL (1 << 1) +#define RB_OVERRUN (1 << 2) + struct ring_buffer_entry { unsigned long dma_addr; struct usrp_transfer_frame *frame_addr; -- cgit v1.2.3 From 8df3a38c3be477a02c4b9d636a3ddd647e55e4a5 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 7 May 2010 15:45:31 -0400 Subject: First pass at data transfer program that uses CRC. --- host/apps/omap_debug/Makefile | 6 +- host/apps/omap_debug/usrp-e-crc-rw.c | 195 +++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 host/apps/omap_debug/usrp-e-crc-rw.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 14be592ff..9b590b9f7 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw usrp-e-lb-test +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw usrp-e-lb-test usrp-e-crc-rw usrp-e-spi : usrp-e-spi.c @@ -15,6 +15,9 @@ usrp-e-fpga-rw : usrp-e-fpga-rw.c usrp-e-rw-random : usrp-e-rw-random.c gcc -o $@ $< -lpthread +usrp-e-crc-rw : usrp-e-crc-rw.c + gcc -o $@ $< -lpthread + usrp-e-uart : usrp-e-uart.c usrp-e-uart-rx : usrp-e-uart-rx.c @@ -47,3 +50,4 @@ clean : rm -f usrp-e-gpio rm -f usrp-e-debug-pins rm -f usrp-e-lb-test + rm -f usrp-e-crc-rw diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c new file mode 100644 index 000000000..1f23c8d54 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -0,0 +1,195 @@ +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1016 +static int packet_data_length; + +static int fp; +static u_int32_t crc_tab[256]; + +// CRC code from http://www.koders.com/c/fid699AFE0A656F0022C9D6B9D1743E697B69CE5815.aspx +// GPLv2 + +static u_int32_t chksum_crc32_gentab(void) +{ + unsigned long crc, poly; + unsigned long i, j; + + poly = 0xEDB88320L; + + for (i = 0; i < 256; i++) { + crc = i; + for (j = 8; j > 0; j--) { + if (crc & 1) { + crc = (crc >> 1) ^ poly; + } else { + crc >>= 1; + } + } + crc_tab[i] = crc; + } +} + +static void *read_thread(void *threadid) +{ + int cnt; + struct usrp_transfer_frame *rx_data; + int rx_pkt_cnt; + int i; + unsigned long crc; + unsigned int rx_crc; + + printf("Greetings from the reading thread!\n"); + + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(2048); + + rx_pkt_cnt = 0; + + while (1) { + + cnt = read(fp, rx_data, 2048); + if (cnt < 0) + printf("Error returned from read: %d\n", cnt); + + rx_pkt_cnt++; + + if (rx_pkt_cnt == 512) { + printf("."); + fflush(stdout); + rx_pkt_cnt = 0; + } + + if (rx_data->flags & RB_OVERRUN) + printf("O"); + + crc = 0xFFFFFFFF; + for (i = 0; i < rx_data->len - 4; i++) { + crc = ((crc >> 8) & 0x00FFFFFF) ^ + crc_tab[(crc ^ rx_data->buf[i]) & 0xFF]; + } + + rx_crc = *((int *) &rx_data[rx_data->len - 4]); + + if (rx_crc != (crc & 0xFFFFFFFF)) { + printf("CRC Error, sent: %d, rx: %d\n", + rx_crc, (crc & 0xFFFFFFFF)); + } + + } +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt, tx_pkt_cnt; + int tx_len; + unsigned long crc; + struct usrp_transfer_frame *tx_data; + struct pkt *p; + + printf("Greetings from the write thread!\n"); + + tx_data = malloc(2048); + + while (1) { + + tx_pkt_cnt++; + if (tx_pkt_cnt == 512) { + printf("."); + fflush(stdout); + } + if (tx_pkt_cnt == 1024) { + printf("'"); + fflush(stdout); + } + if (tx_pkt_cnt == 1536) { + printf(":"); + fflush(stdout); + tx_pkt_cnt = 0; + } + + tx_len = 2048 - sizeof(struct usrp_transfer_frame) - sizeof(int); + crc = 0xFFFFFFFF; + for (i = 0; i < tx_len; i++) { + tx_data->buf[i] = rand() & 0xFF; + + crc = ((crc >> 8) & 0x00FFFFFF) ^ + crc_tab[(crc ^ tx_data->buf[i]) & 0xFF]; + + } + *((int *) &tx_data[tx_len]) = crc; + + cnt = write(fp, tx_data, 2048); + if (cnt < 0) + printf("Error returned from write: %d\n", cnt); +// sleep(1); + } +} + + +int main(int argc, char *argv[]) +{ + pthread_t tx, rx; + long int t; + int fpga_config_flag ,decimation; + struct usrp_e_ctl16 d; + struct sched_param s = { + .sched_priority = 1 + }; + + if (argc < 4) { + printf("%s t|w|rw decimation data_size\n", argv[0]); + return -1; + } + + decimation = atoi(argv[2]); + packet_data_length = atoi(argv[3]); + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + fpga_config_flag = 0; + if (strcmp(argv[1], "w") == 0) + fpga_config_flag |= (1 << 15); + else if (strcmp(argv[1], "r") == 0) + fpga_config_flag |= (1 << 14); + else if (strcmp(argv[1], "rw") == 0) + fpga_config_flag |= ((1 << 15) | (1 << 14)); + + fpga_config_flag |= decimation; + + d.offset = 14; + d.count = 1; + d.buf[0] = fpga_config_flag; + ioctl(fp, USRP_E_WRITE_CTL16, &d); + + sleep(1); // in case the kernel threads need time to start. FIXME if so + + sched_setscheduler(0, SCHED_RR, &s); + + if (fpga_config_flag & (1 << 14)) { + if (pthread_create(&rx, NULL, read_thread, (void *) t)) { + printf("Failed to create rx thread\n"); + exit(-1); + } + } + + sleep(1); + + if (fpga_config_flag & (1 << 15)) { + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { + printf("Failed to create tx thread\n"); + exit(-1); + } + } + + sleep(10000); + + printf("Done sleeping\n"); +} -- cgit v1.2.3 From 019be7444989b977de9e94677bc259bad9eb6843 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Mon, 10 May 2010 21:43:43 -0400 Subject: Add program to do initial configuration of the clkgen chip. --- host/apps/omap_debug/Makefile | 5 +- host/apps/omap_debug/clkgen-config.cc | 294 ++++++++++++++++++++++++++++++++++ 2 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 host/apps/omap_debug/clkgen-config.cc (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 9b590b9f7..e2aa384f2 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw usrp-e-lb-test usrp-e-crc-rw +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw usrp-e-lb-test usrp-e-crc-rw clkgen-config usrp-e-spi : usrp-e-spi.c @@ -30,6 +30,8 @@ usrp-e-button : usrp-e-button.c fpga-downloader : fpga-downloader.cc +clkgen-config : clkgen-config.cc + usrp-e-gpio : usrp-e-gpio.c usrp-e-lb-test : usrp-e-lb-test.c @@ -51,3 +53,4 @@ clean : rm -f usrp-e-debug-pins rm -f usrp-e-lb-test rm -f usrp-e-crc-rw + rm -f clkgen-config diff --git a/host/apps/omap_debug/clkgen-config.cc b/host/apps/omap_debug/clkgen-config.cc new file mode 100644 index 000000000..c21f54a60 --- /dev/null +++ b/host/apps/omap_debug/clkgen-config.cc @@ -0,0 +1,294 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc. + * + * This file is part of UHD + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + + +// Programming data for clock gen chip +static const unsigned int config_data[] = { + 0x000024, + 0x023201, + 0x000081, + 0x000400, + 0x00104c, + 0x001101, + 0x001200, + 0x001300, + 0x001414, + 0x001500, + 0x001604, + 0x001704, + 0x001807, + 0x001900, + 0x001a32, + 0x001b12, + 0x001c44, + 0x001d00, + 0x001e00, + 0x00f062, + 0x00f162, + 0x00f262, + 0x00f362, + 0x00f462, + 0x00f562, + 0x00f662, + 0x00f762, + 0x00f862, + 0x00f962, + 0x00fa62, + 0x00fb62, + 0x00fc00, + 0x00fd00, + 0x019021, + 0x019100, + 0x019200, + 0x019333, + 0x019400, + 0x019500, + 0x019611, + 0x019700, + 0x019800, + 0x019900, + 0x019a00, + 0x019b00, + 0x01e003, + 0x01e102, + 0x023000, + 0x023201, + 0x0b0201, + 0x0b0300, + 0x001fff, + 0x0a0000, + 0x0a0100, + 0x0a0200, + 0x0a0302, + 0x0a0400, + 0x0a0504, + 0x0a060e, + 0x0a0700, + 0x0a0810, + 0x0a090e, + 0x0a0a00, + 0x0a0bf0, + 0x0a0c0b, + 0x0a0d01, + 0x0a0e90, + 0x0a0f01, + 0x0a1001, + 0x0a11e0, + 0x0a1201, + 0x0a1302, + 0x0a1430, + 0x0a1580, + 0x0a16ff, + 0x023201, + 0x0b0301, + 0x023201, +}; + + +const unsigned int CLKGEN_SELECT = 145; + + +enum gpio_direction {IN, OUT}; + +class gpio { + public: + + gpio(unsigned int gpio_num, gpio_direction pin_direction, bool close_action); + ~gpio(); + + bool get_value(); + void set_value(bool state); + + private: + + unsigned int gpio_num; + + std::stringstream base_path; + std::fstream value_file; + std::fstream direction_file; + bool close_action; // True set to input and release, false do nothing +}; + +class spidev { + public: + + spidev(std::string dev_name); + ~spidev(); + + void send(char *wbuf, char *rbuf, unsigned int nbytes); + + private: + + int fd; + +}; + +gpio::gpio(unsigned int _gpio_num, gpio_direction pin_direction, bool close_action) +{ + std::fstream export_file; + + gpio_num = _gpio_num; + + export_file.open("/sys/class/gpio/export", std::ios::out); + if (!export_file.is_open()) ///\todo Poor error handling + std::cout << "Failed to open gpio export file." << std::endl; + + export_file << gpio_num << std::endl; + + base_path << "/sys/class/gpio/gpio" << gpio_num << std::flush; + + std::string direction_file_name; + + direction_file_name = base_path.str() + "/direction"; + + direction_file.open(direction_file_name.c_str()); + if (!direction_file.is_open()) + std::cout << "Failed to open direction file." << std::endl; + if (pin_direction == OUT) + direction_file << "out" << std::endl; + else + direction_file << "in" << std::endl; + + std::string value_file_name; + + value_file_name = base_path.str() + "/value"; + + value_file.open(value_file_name.c_str(), std::ios_base::in | std::ios_base::out); + if (!value_file.is_open()) + std::cout << "Failed to open value file." << std::endl; +} + +bool gpio::get_value() +{ + + std::string val; + + std::getline(value_file, val); + value_file.seekg(0); + + if (val == "0") + return false; + else if (val == "1") + return true; + else + std::cout << "Data read from value file|" << val << "|" << std::endl; + + return false; +} + +void gpio::set_value(bool state) +{ + + if (state) + value_file << "1" << std::endl; + else + value_file << "0" << std::endl; +} + +gpio::~gpio() +{ + if (close_action) { + std::fstream unexport_file; + + direction_file << "in" << std::endl; + + unexport_file.open("/sys/class/gpio/unexport", std::ios::out); + if (!unexport_file.is_open()) ///\todo Poor error handling + std::cout << "Failed to open gpio export file." << std::endl; + + unexport_file << gpio_num << std::endl; + + } + +} + +spidev::spidev(std::string fname) +{ + int ret; + int mode = 0; + int speed = 12000000; + int bits = 32; + + fd = open(fname.c_str(), O_RDWR); + + ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); + ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); + ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); +} + + +spidev::~spidev() +{ + close(fd); +} + +void spidev::send(char *buf, char *rbuf, unsigned int nbytes) +{ + int ret; + + struct spi_ioc_transfer tr; + tr.tx_buf = (unsigned long) buf; + tr.rx_buf = (unsigned long) rbuf; + tr.len = nbytes; + tr.delay_usecs = 0; + tr.speed_hz = 12000000; + tr.bits_per_word = 32; + + ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); + +} + +static void send_config_to_clkgen(gpio &chip_select, const unsigned int data[], unsigned int data_size) +{ + spidev spi("/dev/spidev1.0"); + unsigned int rbuf; + + for (unsigned int i = 0; i < data_size; i++) { + + chip_select.set_value(1); + spi.send((char *)&data[i], (char *)&rbuf, 4); + chip_select.set_value(0); + + }; +} + +int main(int argc, char *argv[]) +{ + + gpio clkgen_select(CLKGEN_SELECT, OUT, true); + + send_config_to_clkgen(clkgen_select, config_data, sizeof(config_data)/sizeof(unsigned int)); +} + -- cgit v1.2.3 From 88b2a958f0a3a593230ca6b17e7c4aac3fba35e7 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 19 May 2010 13:21:45 -0400 Subject: Rename test program to match FPGA bin file name and add data rate calculation. --- host/apps/omap_debug/Makefile | 6 +- host/apps/omap_debug/usrp-e-fpga-rw.c | 207 ------------------------------- host/apps/omap_debug/usrp-e-timed.c | 227 ++++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+), 210 deletions(-) delete mode 100644 host/apps/omap_debug/usrp-e-fpga-rw.c create mode 100644 host/apps/omap_debug/usrp-e-timed.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index e2aa384f2..40e04e377 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-fpga-rw usrp-e-lb-test usrp-e-crc-rw clkgen-config +all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config usrp-e-spi : usrp-e-spi.c @@ -9,7 +9,7 @@ usrp-e-i2c : usrp-e-i2c.c usrp-e-rw : usrp-e-rw.c gcc -o $@ $< -lpthread -usrp-e-fpga-rw : usrp-e-fpga-rw.c +usrp-e-timed : usrp-e-timed.c gcc -o $@ $< -lpthread usrp-e-rw-random : usrp-e-rw-random.c @@ -41,7 +41,7 @@ clean : rm -f usrp-e-spi rm -f usrp-e-i2c rm -f usrp-e-rw - rm -f usrp-e-fpga-rw + rm -f usrp-e-timed rm -f usrp-e-rw-random rm -f usrp-e-uart rm -f usrp-e-uart-rx diff --git a/host/apps/omap_debug/usrp-e-fpga-rw.c b/host/apps/omap_debug/usrp-e-fpga-rw.c deleted file mode 100644 index 6b585913e..000000000 --- a/host/apps/omap_debug/usrp-e-fpga-rw.c +++ /dev/null @@ -1,207 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "usrp_e.h" - -// max length #define PKT_DATA_LENGTH 1016 -static int packet_data_length; - -struct pkt { - int checksum; - int seq_num; - short data[]; -}; - -static int fp; - -static int calc_checksum(struct pkt *p) -{ - int i, sum; - - i = 0; - sum = 0; - - for (i=0; i < packet_data_length; i++) - sum += p->data[i]; - - sum += p->seq_num; - - return sum; -} - -static void *read_thread(void *threadid) -{ - int cnt, prev_seq_num; - struct usrp_transfer_frame *rx_data; - struct pkt *p; - int rx_pkt_cnt; - int i; - - printf("Greetings from the reading thread!\n"); - - // IMPORTANT: must assume max length packet from fpga - rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1016 * 2)); - p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); - //p = &(rx_data->buf[0]); - printf("Address of rx_data = %p, p = %p\n", rx_data, p); - printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); - printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); - - prev_seq_num = 0; - - rx_pkt_cnt = 0; - - while (1) { - - cnt = read(fp, rx_data, 2048); - if (cnt < 0) - printf("Error returned from read: %d\n", cnt); - rx_pkt_cnt++; - - if (rx_pkt_cnt == 512) { - printf("."); - fflush(stdout); - rx_pkt_cnt = 0; - } - - if (rx_data->flags & RB_OVERRUN) - printf("O"); - -// for (i = 0; i < 10; i++) -// printf(" %d", p->data[i]); -// printf("\n"); - -// printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); -// printf("p->seq_num = %d\n", p->seq_num); - -// if (p->seq_num != prev_seq_num + 1) -// printf("Sequence number fail, current = %X, previous = %X\n", -// p->seq_num, prev_seq_num); -// prev_seq_num = p->seq_num; - -// if (calc_checksum(p) != p->checksum) -// printf("Checksum fail packet = %X, expected = %X\n", -// calc_checksum(p), p->checksum); -// printf("\n"); - } - -} - -static void *write_thread(void *threadid) -{ - int seq_number, i, cnt, tx_pkt_cnt; - struct usrp_transfer_frame *tx_data; - struct pkt *p; - - printf("Greetings from the write thread!\n"); - - tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (packet_data_length * 2)); - p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); - printf("Address of tx_data = %p, p = %p\n", tx_data, p); - - printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); - - for (i=0; i < packet_data_length; i++) -// p->data[i] = random() >> 16; - p->data[i] = i; - - tx_data->flags = 0; - tx_data->len = 8 + packet_data_length * 2; - - printf("tx_data->len = %d\n", tx_data->len); - - seq_number = 1; - tx_pkt_cnt = 0; - - while (1) { - - tx_pkt_cnt++; - if (tx_pkt_cnt == 512) { - printf("."); - fflush(stdout); - } - if (tx_pkt_cnt == 1024) { - printf("'"); - fflush(stdout); - } - if (tx_pkt_cnt == 1536) { - printf(":"); - fflush(stdout); - tx_pkt_cnt = 0; - } - -// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); - p->seq_num = seq_number++; - p->checksum = calc_checksum(p); - cnt = write(fp, tx_data, 2048); - if (cnt < 0) - printf("Error returned from write: %d\n", cnt); -// sleep(1); - } -} - - -int main(int argc, char *argv[]) -{ - pthread_t tx, rx; - long int t; - int fpga_config_flag ,decimation; - struct usrp_e_ctl16 d; - struct sched_param s = { - .sched_priority = 1 - }; - - if (argc < 4) { - printf("%s t|w|rw decimation data_size\n", argv[0]); - return -1; - } - - decimation = atoi(argv[2]); - packet_data_length = atoi(argv[3]); - - fp = open("/dev/usrp_e0", O_RDWR); - printf("fp = %d\n", fp); - - fpga_config_flag = 0; - if (strcmp(argv[1], "w") == 0) - fpga_config_flag |= (1 << 15); - else if (strcmp(argv[1], "r") == 0) - fpga_config_flag |= (1 << 14); - else if (strcmp(argv[1], "rw") == 0) - fpga_config_flag |= ((1 << 15) | (1 << 14)); - - fpga_config_flag |= decimation; - - d.offset = 14; - d.count = 1; - d.buf[0] = fpga_config_flag; - ioctl(fp, USRP_E_WRITE_CTL16, &d); - - sleep(1); // in case the kernel threads need time to start. FIXME if so - - sched_setscheduler(0, SCHED_RR, &s); - - if (fpga_config_flag & (1 << 14)) { - if (pthread_create(&rx, NULL, read_thread, (void *) t)) { - printf("Failed to create rx thread\n"); - exit(-1); - } - } - - sleep(1); - - if (fpga_config_flag & (1 << 15)) { - if (pthread_create(&tx, NULL, write_thread, (void *) t)) { - printf("Failed to create tx thread\n"); - exit(-1); - } - } - - sleep(10000); - - printf("Done sleeping\n"); -} diff --git a/host/apps/omap_debug/usrp-e-timed.c b/host/apps/omap_debug/usrp-e-timed.c new file mode 100644 index 000000000..69e6c07ca --- /dev/null +++ b/host/apps/omap_debug/usrp-e-timed.c @@ -0,0 +1,227 @@ +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1016 +static int packet_data_length; + +struct pkt { + int checksum; + int seq_num; + short data[]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i < packet_data_length; i++) + sum += p->data[i]; + + sum += p->seq_num; + + return sum; +} + +static void *read_thread(void *threadid) +{ + int cnt, prev_seq_num; + struct usrp_transfer_frame *rx_data; + struct pkt *p; + int rx_pkt_cnt; + int i; + unsigned long bytes_transfered, elapsed_seconds; + struct timeval start_time, finish_time; + + printf("Greetings from the reading thread!\n"); + + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1016 * 2)); + p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); + //p = &(rx_data->buf[0]); + printf("Address of rx_data = %p, p = %p\n", rx_data, p); + printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); + printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + + prev_seq_num = 0; + + rx_pkt_cnt = 0; + + while (1) { + + cnt = read(fp, rx_data, 2048); + if (cnt < 0) + printf("Error returned from read: %d\n", cnt); + rx_pkt_cnt++; + +#if 0 + if (rx_pkt_cnt == 512) { + printf("."); + fflush(stdout); + rx_pkt_cnt = 0; + } +#endif + + if (rx_data->flags & RB_OVERRUN) + printf("O"); + + bytes_transfered += rx_data->len; + + if (bytes_transfered > (100 * 1000000)) { + gettimeofday(&finish_time, NULL); + elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; + + printf("RX data transfer rate = %f K Bps\n", + (float) bytes_transfered / (float) elapsed_seconds / 1000); + + + start_time = finish_time; + bytes_transfered = 0; + } + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt, tx_pkt_cnt; + struct usrp_transfer_frame *tx_data; + struct pkt *p; + unsigned long bytes_transfered, elapsed_seconds; + struct timeval start_time, finish_time; + + printf("Greetings from the write thread!\n"); + + tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (packet_data_length * 2)); + p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); + printf("Address of tx_data = %p, p = %p\n", tx_data, p); + + printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); + + for (i=0; i < packet_data_length; i++) +// p->data[i] = random() >> 16; + p->data[i] = i; + + tx_data->flags = 0; + tx_data->len = 8 + packet_data_length * 2; + + printf("tx_data->len = %d\n", tx_data->len); + + seq_number = 1; + tx_pkt_cnt = 0; + + while (1) { + + tx_pkt_cnt++; + +#if 0 + if (tx_pkt_cnt == 512) { + printf("."); + fflush(stdout); + } + if (tx_pkt_cnt == 1024) { + printf("'"); + fflush(stdout); + } + if (tx_pkt_cnt == 1536) { + printf(":"); + fflush(stdout); + tx_pkt_cnt = 0; + } +#endif + +// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); + p->seq_num = seq_number++; + p->checksum = calc_checksum(p); + cnt = write(fp, tx_data, 2048); + if (cnt < 0) + printf("Error returned from write: %d\n", cnt); + + bytes_transfered += tx_data->len; + + if (bytes_transfered > (100 * 1000000)) { + gettimeofday(&finish_time, NULL); + elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; + + printf("TX data transfer rate = %f K Bps\n", + (float) bytes_transfered / (float) elapsed_seconds / 1000); + + + start_time = finish_time; + bytes_transfered = 0; + } +// sleep(1); + } +} + + +int main(int argc, char *argv[]) +{ + pthread_t tx, rx; + long int t; + int fpga_config_flag ,decimation; + struct usrp_e_ctl16 d; + struct sched_param s = { + .sched_priority = 1 + }; + + if (argc < 4) { + printf("%s t|w|rw decimation data_size\n", argv[0]); + return -1; + } + + decimation = atoi(argv[2]); + packet_data_length = atoi(argv[3]); + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + fpga_config_flag = 0; + if (strcmp(argv[1], "w") == 0) + fpga_config_flag |= (1 << 15); + else if (strcmp(argv[1], "r") == 0) + fpga_config_flag |= (1 << 14); + else if (strcmp(argv[1], "rw") == 0) + fpga_config_flag |= ((1 << 15) | (1 << 14)); + + fpga_config_flag |= decimation; + + d.offset = 14; + d.count = 1; + d.buf[0] = fpga_config_flag; + ioctl(fp, USRP_E_WRITE_CTL16, &d); + + sleep(1); // in case the kernel threads need time to start. FIXME if so + + sched_setscheduler(0, SCHED_RR, &s); + + if (fpga_config_flag & (1 << 14)) { + if (pthread_create(&rx, NULL, read_thread, (void *) t)) { + printf("Failed to create rx thread\n"); + exit(-1); + } + } + + sleep(1); + + if (fpga_config_flag & (1 << 15)) { + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { + printf("Failed to create tx thread\n"); + exit(-1); + } + } + + sleep(10000); + + printf("Done sleeping\n"); +} -- cgit v1.2.3 From fe753af7e62e55668cb331b7b74ea14d6e45a0ec Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 19 May 2010 22:25:29 +0000 Subject: Use better optimization settings. --- host/apps/omap_debug/Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 40e04e377..295d40979 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,4 +1,5 @@ -CFLAGS=-Wall -I../../lib/usrp/usrp_e/ +CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 +CXXFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config @@ -7,16 +8,16 @@ usrp-e-spi : usrp-e-spi.c usrp-e-i2c : usrp-e-i2c.c usrp-e-rw : usrp-e-rw.c - gcc -o $@ $< -lpthread + gcc -o $@ $< -lpthread ${CFLAGS} usrp-e-timed : usrp-e-timed.c - gcc -o $@ $< -lpthread + gcc -o $@ $< -lpthread ${CFLAGS} usrp-e-rw-random : usrp-e-rw-random.c - gcc -o $@ $< -lpthread + gcc -o $@ $< -lpthread ${CFLAGS} usrp-e-crc-rw : usrp-e-crc-rw.c - gcc -o $@ $< -lpthread + gcc -o $@ $< -lpthread ${CFLAGS} usrp-e-uart : usrp-e-uart.c -- cgit v1.2.3 From 64276eabd8d88f7d72763f8b500c13a9a689cd21 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 20 May 2010 15:10:32 +0000 Subject: Rename loopback test program to match bin file name. --- host/apps/omap_debug/Makefile | 6 +- host/apps/omap_debug/usrp-e-loopback.c | 176 +++++++++++++++++++++++++++++++++ host/apps/omap_debug/usrp-e-rw.c | 176 --------------------------------- 3 files changed, 179 insertions(+), 179 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-loopback.c delete mode 100644 host/apps/omap_debug/usrp-e-rw.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 295d40979..17a3858cf 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,13 +1,13 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 CXXFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 -all : usrp-e-spi usrp-e-i2c usrp-e-rw usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config +all : usrp-e-spi usrp-e-i2c usrp-e-loopback usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config usrp-e-spi : usrp-e-spi.c usrp-e-i2c : usrp-e-i2c.c -usrp-e-rw : usrp-e-rw.c +usrp-e-loopback : usrp-e-loopback.c gcc -o $@ $< -lpthread ${CFLAGS} usrp-e-timed : usrp-e-timed.c @@ -41,7 +41,7 @@ usrp-e-debug-pins : usrp-e-debug-pins.c clean : rm -f usrp-e-spi rm -f usrp-e-i2c - rm -f usrp-e-rw + rm -f usrp-e-loopback rm -f usrp-e-timed rm -f usrp-e-rw-random rm -f usrp-e-uart diff --git a/host/apps/omap_debug/usrp-e-loopback.c b/host/apps/omap_debug/usrp-e-loopback.c new file mode 100644 index 000000000..798bc4b45 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-loopback.c @@ -0,0 +1,176 @@ +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1016 +static int packet_data_length; + +struct pkt { + int checksum; + int seq_num; + short data[]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i < packet_data_length; i++) + sum += p->data[i]; + + sum += p->seq_num; + + return sum; +} + +static void *read_thread(void *threadid) +{ + int cnt, prev_seq_num, pkt_count; + struct usrp_transfer_frame *rx_data; + struct pkt *p; + unsigned long bytes_transfered, elapsed_seconds; + struct timeval start_time, finish_time; + + printf("Greetings from the reading thread!\n"); + + bytes_transfered = 0; + gettimeofday(&start_time, NULL); + + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1016 * 2)); + p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); + //p = &(rx_data->buf[0]); + printf("Address of rx_data = %p, p = %p\n", rx_data, p); + printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); + printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + + prev_seq_num = 0; + pkt_count = 0; + + while (1) { + + cnt = read(fp, rx_data, 2048); + if (cnt < 0) + printf("Error returned from read: %d\n", cnt); + +// printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); +// printf("p->seq_num = %d\n", p->seq_num); + + + pkt_count++; + + if (p->seq_num != prev_seq_num + 1) + printf("Sequence number fail, current = %X, previous = %X, pkt_count = %d\n", + p->seq_num, prev_seq_num, pkt_count); + prev_seq_num = p->seq_num; + + if (calc_checksum(p) != p->checksum) + printf("Checksum fail packet = %X, expected = %X, pkt_count = %d\n", + calc_checksum(p), p->checksum, pkt_count); + + + bytes_transfered += rx_data->len; + + if (bytes_transfered > (100 * 1000000)) { + gettimeofday(&finish_time, NULL); + elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; + + printf("RX data transfer rate = %f K Samples/second\n", + (float) bytes_transfered / (float) elapsed_seconds / 250); + + + start_time = finish_time; + bytes_transfered = 0; + } + + +// printf("."); +// fflush(stdout); +// printf("\n"); + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt; + struct usrp_transfer_frame *tx_data; + struct pkt *p; + + printf("Greetings from the write thread!\n"); + + tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (packet_data_length * 2)); + p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); + printf("Address of tx_data = %p, p = %p\n", tx_data, p); + + printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); + + for (i=0; i < packet_data_length; i++) +// p->data[i] = random() >> 16; + p->data[i] = i; + + tx_data->flags = 0xdeadbeef; + tx_data->len = 8 + packet_data_length * 2; + + printf("tx_data->len = %d\n", tx_data->len); + + seq_number = 1; + + while (1) { +// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); + p->seq_num = seq_number++; + p->checksum = calc_checksum(p); + cnt = write(fp, tx_data, 2048); + if (cnt < 0) + printf("Error returned from write: %d\n", cnt); +// sleep(1); + } +} + + +int main(int argc, char *argv[]) +{ + pthread_t tx, rx; + long int t; + struct sched_param s = { + .sched_priority = 1 + }; + + if (argc < 2) { + printf("%s data_size\n", argv[0]); + return -1; + } + + packet_data_length = atoi(argv[1]); + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + sched_setscheduler(0, SCHED_RR, &s); + + if (pthread_create(&rx, NULL, read_thread, (void *) t)) { + printf("Failed to create rx thread\n"); + exit(-1); + } + + sleep(1); + + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { + printf("Failed to create tx thread\n"); + exit(-1); + } + + sleep(10000); + + printf("Done sleeping\n"); +} diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c deleted file mode 100644 index 798bc4b45..000000000 --- a/host/apps/omap_debug/usrp-e-rw.c +++ /dev/null @@ -1,176 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "usrp_e.h" - -// max length #define PKT_DATA_LENGTH 1016 -static int packet_data_length; - -struct pkt { - int checksum; - int seq_num; - short data[]; -}; - -static int fp; - -static int calc_checksum(struct pkt *p) -{ - int i, sum; - - i = 0; - sum = 0; - - for (i=0; i < packet_data_length; i++) - sum += p->data[i]; - - sum += p->seq_num; - - return sum; -} - -static void *read_thread(void *threadid) -{ - int cnt, prev_seq_num, pkt_count; - struct usrp_transfer_frame *rx_data; - struct pkt *p; - unsigned long bytes_transfered, elapsed_seconds; - struct timeval start_time, finish_time; - - printf("Greetings from the reading thread!\n"); - - bytes_transfered = 0; - gettimeofday(&start_time, NULL); - - // IMPORTANT: must assume max length packet from fpga - rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1016 * 2)); - p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); - //p = &(rx_data->buf[0]); - printf("Address of rx_data = %p, p = %p\n", rx_data, p); - printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); - printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); - - prev_seq_num = 0; - pkt_count = 0; - - while (1) { - - cnt = read(fp, rx_data, 2048); - if (cnt < 0) - printf("Error returned from read: %d\n", cnt); - -// printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); -// printf("p->seq_num = %d\n", p->seq_num); - - - pkt_count++; - - if (p->seq_num != prev_seq_num + 1) - printf("Sequence number fail, current = %X, previous = %X, pkt_count = %d\n", - p->seq_num, prev_seq_num, pkt_count); - prev_seq_num = p->seq_num; - - if (calc_checksum(p) != p->checksum) - printf("Checksum fail packet = %X, expected = %X, pkt_count = %d\n", - calc_checksum(p), p->checksum, pkt_count); - - - bytes_transfered += rx_data->len; - - if (bytes_transfered > (100 * 1000000)) { - gettimeofday(&finish_time, NULL); - elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; - - printf("RX data transfer rate = %f K Samples/second\n", - (float) bytes_transfered / (float) elapsed_seconds / 250); - - - start_time = finish_time; - bytes_transfered = 0; - } - - -// printf("."); -// fflush(stdout); -// printf("\n"); - } - -} - -static void *write_thread(void *threadid) -{ - int seq_number, i, cnt; - struct usrp_transfer_frame *tx_data; - struct pkt *p; - - printf("Greetings from the write thread!\n"); - - tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (packet_data_length * 2)); - p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); - printf("Address of tx_data = %p, p = %p\n", tx_data, p); - - printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); - - for (i=0; i < packet_data_length; i++) -// p->data[i] = random() >> 16; - p->data[i] = i; - - tx_data->flags = 0xdeadbeef; - tx_data->len = 8 + packet_data_length * 2; - - printf("tx_data->len = %d\n", tx_data->len); - - seq_number = 1; - - while (1) { -// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); - p->seq_num = seq_number++; - p->checksum = calc_checksum(p); - cnt = write(fp, tx_data, 2048); - if (cnt < 0) - printf("Error returned from write: %d\n", cnt); -// sleep(1); - } -} - - -int main(int argc, char *argv[]) -{ - pthread_t tx, rx; - long int t; - struct sched_param s = { - .sched_priority = 1 - }; - - if (argc < 2) { - printf("%s data_size\n", argv[0]); - return -1; - } - - packet_data_length = atoi(argv[1]); - - fp = open("/dev/usrp_e0", O_RDWR); - printf("fp = %d\n", fp); - - sched_setscheduler(0, SCHED_RR, &s); - - if (pthread_create(&rx, NULL, read_thread, (void *) t)) { - printf("Failed to create rx thread\n"); - exit(-1); - } - - sleep(1); - - if (pthread_create(&tx, NULL, write_thread, (void *) t)) { - printf("Failed to create tx thread\n"); - exit(-1); - } - - sleep(10000); - - printf("Done sleeping\n"); -} -- cgit v1.2.3 From 617488fd6a4f6a2efa0c966a07d6ac1b6201c3aa Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Mon, 7 Jun 2010 14:46:14 +0000 Subject: Rename loopback of random length packets test program so we know it needs loopback fpga image. Needs debug. --- host/apps/omap_debug/Makefile | 4 +- host/apps/omap_debug/usrp-e-random-loopback.c | 149 ++++++++++++++++++++++++++ host/apps/omap_debug/usrp-e-rw-random.c | 149 -------------------------- 3 files changed, 151 insertions(+), 151 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-random-loopback.c delete mode 100644 host/apps/omap_debug/usrp-e-rw-random.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index 17a3858cf..c11609bdd 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,7 +1,7 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 CXXFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 -all : usrp-e-spi usrp-e-i2c usrp-e-loopback usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-rw-random usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config +all : usrp-e-spi usrp-e-i2c usrp-e-loopback usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-random-loopback usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config usrp-e-spi : usrp-e-spi.c @@ -13,7 +13,7 @@ usrp-e-loopback : usrp-e-loopback.c usrp-e-timed : usrp-e-timed.c gcc -o $@ $< -lpthread ${CFLAGS} -usrp-e-rw-random : usrp-e-rw-random.c +usrp-e-random-loopback : usrp-e-random-loopback.c gcc -o $@ $< -lpthread ${CFLAGS} usrp-e-crc-rw : usrp-e-crc-rw.c diff --git a/host/apps/omap_debug/usrp-e-random-loopback.c b/host/apps/omap_debug/usrp-e-random-loopback.c new file mode 100644 index 000000000..5960b8fbd --- /dev/null +++ b/host/apps/omap_debug/usrp-e-random-loopback.c @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1014 +static int packet_data_length; + +struct pkt { + int checksum; + int seq_num; + int len; + short data[]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i < p->len; i++) + sum += p->data[i]; + + sum += p->seq_num; + + return sum; +} + +int randN(int n) +{ + long tmp; + + tmp = rand() % n; + + return tmp; +} + +static void *read_thread(void *threadid) +{ + int cnt, prev_seq_num; + struct usrp_transfer_frame *rx_data; + struct pkt *p; + + printf("Greetings from the reading thread!\n"); + + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1014 * 2)); + rx_data = malloc(2048); + p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); + //p = &(rx_data->buf[0]); + printf("Address of rx_data = %p, p = %p\n", rx_data, p); + printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); + printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + + prev_seq_num = 0; + + while (1) { + + cnt = read(fp, rx_data, 2048); +// printf("Packet received, status = %X, len = %d\n", rx_data->status, rx_data->len); +// printf("p->seq_num = %d\n", p->seq_num); + + if (p->seq_num != prev_seq_num + 1) + printf("Sequence number fail, current = %d, previous = %d\n", + p->seq_num, prev_seq_num); + prev_seq_num = p->seq_num; + + if (calc_checksum(p) != p->checksum) + printf("Checksum fail packet = %d, expected = %d\n", + calc_checksum(p), p->checksum); + printf("."); + fflush(stdout); +// printf("\n"); + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt, pkt_cnt; + struct usrp_transfer_frame *tx_data; + struct pkt *p; + + printf("Greetings from the write thread!\n"); + + // Allocate max length buffer for frame + tx_data = malloc(2048); + p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); + printf("Address of tx_data = %p, p = %p\n", tx_data, p); + + printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); + + for (i=0; i < 1014; i++) +// p->data[i] = random() >> 16; + p->data[i] = i; + + tx_data->status = 0xdeadbeef; + tx_data->len = 8 + packet_data_length * 2; + + printf("tx_data->len = %d\n", tx_data->len); + + seq_number = 1; + + while (1) { + pkt_cnt = randN(16); + for (i = 0; i < pkt_cnt; i++) { + p->seq_num = seq_number++; + p->len = randN(1013) + 1; + p->checksum = calc_checksum(p); + tx_data->len = 12 + p->len * 2; + cnt = write(fp, tx_data, tx_data->len + 8); + } + sleep(random() >> 31); + } +} + + +int main(int argc, char *argv[]) +{ + pthread_t tx, rx; + long int t; + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + if (pthread_create(&rx, NULL, read_thread, (void *) t)) { + printf("Failed to create rx thread\n"); + exit(-1); + } + + sleep(1); + + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { + printf("Failed to create tx thread\n"); + exit(-1); + } + + sleep(1000000000); + + printf("Done sleeping\n"); +} diff --git a/host/apps/omap_debug/usrp-e-rw-random.c b/host/apps/omap_debug/usrp-e-rw-random.c deleted file mode 100644 index 5960b8fbd..000000000 --- a/host/apps/omap_debug/usrp-e-rw-random.c +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "usrp_e.h" - -// max length #define PKT_DATA_LENGTH 1014 -static int packet_data_length; - -struct pkt { - int checksum; - int seq_num; - int len; - short data[]; -}; - -static int fp; - -static int calc_checksum(struct pkt *p) -{ - int i, sum; - - i = 0; - sum = 0; - - for (i=0; i < p->len; i++) - sum += p->data[i]; - - sum += p->seq_num; - - return sum; -} - -int randN(int n) -{ - long tmp; - - tmp = rand() % n; - - return tmp; -} - -static void *read_thread(void *threadid) -{ - int cnt, prev_seq_num; - struct usrp_transfer_frame *rx_data; - struct pkt *p; - - printf("Greetings from the reading thread!\n"); - - // IMPORTANT: must assume max length packet from fpga - rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1014 * 2)); - rx_data = malloc(2048); - p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); - //p = &(rx_data->buf[0]); - printf("Address of rx_data = %p, p = %p\n", rx_data, p); - printf("offsetof = %d\n", offsetof(struct usrp_transfer_frame, buf)); - printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); - - prev_seq_num = 0; - - while (1) { - - cnt = read(fp, rx_data, 2048); -// printf("Packet received, status = %X, len = %d\n", rx_data->status, rx_data->len); -// printf("p->seq_num = %d\n", p->seq_num); - - if (p->seq_num != prev_seq_num + 1) - printf("Sequence number fail, current = %d, previous = %d\n", - p->seq_num, prev_seq_num); - prev_seq_num = p->seq_num; - - if (calc_checksum(p) != p->checksum) - printf("Checksum fail packet = %d, expected = %d\n", - calc_checksum(p), p->checksum); - printf("."); - fflush(stdout); -// printf("\n"); - } - -} - -static void *write_thread(void *threadid) -{ - int seq_number, i, cnt, pkt_cnt; - struct usrp_transfer_frame *tx_data; - struct pkt *p; - - printf("Greetings from the write thread!\n"); - - // Allocate max length buffer for frame - tx_data = malloc(2048); - p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); - printf("Address of tx_data = %p, p = %p\n", tx_data, p); - - printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); - - for (i=0; i < 1014; i++) -// p->data[i] = random() >> 16; - p->data[i] = i; - - tx_data->status = 0xdeadbeef; - tx_data->len = 8 + packet_data_length * 2; - - printf("tx_data->len = %d\n", tx_data->len); - - seq_number = 1; - - while (1) { - pkt_cnt = randN(16); - for (i = 0; i < pkt_cnt; i++) { - p->seq_num = seq_number++; - p->len = randN(1013) + 1; - p->checksum = calc_checksum(p); - tx_data->len = 12 + p->len * 2; - cnt = write(fp, tx_data, tx_data->len + 8); - } - sleep(random() >> 31); - } -} - - -int main(int argc, char *argv[]) -{ - pthread_t tx, rx; - long int t; - - fp = open("/dev/usrp_e0", O_RDWR); - printf("fp = %d\n", fp); - - if (pthread_create(&rx, NULL, read_thread, (void *) t)) { - printf("Failed to create rx thread\n"); - exit(-1); - } - - sleep(1); - - if (pthread_create(&tx, NULL, write_thread, (void *) t)) { - printf("Failed to create tx thread\n"); - exit(-1); - } - - sleep(1000000000); - - printf("Done sleeping\n"); -} -- cgit v1.2.3 From cb92934527964b8fda924925dbc12b18d5ae7fad Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 11 Aug 2010 01:05:47 +0000 Subject: Loopback test now supports variable size and works with mmapable ring buffer. --- host/apps/omap_debug/Makefile | 6 +- host/apps/omap_debug/usrp-e-loopback.c | 39 ++++-- host/apps/omap_debug/usrp-e-mm-loopback.c | 194 ++++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+), 12 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-mm-loopback.c (limited to 'host/apps/omap_debug/Makefile') diff --git a/host/apps/omap_debug/Makefile b/host/apps/omap_debug/Makefile index c11609bdd..46d4714a8 100644 --- a/host/apps/omap_debug/Makefile +++ b/host/apps/omap_debug/Makefile @@ -1,7 +1,7 @@ CFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 CXXFLAGS=-Wall -I../../lib/usrp/usrp_e/ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -O3 -all : usrp-e-spi usrp-e-i2c usrp-e-loopback usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-random-loopback usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config +all : usrp-e-spi usrp-e-i2c usrp-e-loopback usrp-e-mm-loopback usrp-e-uart usrp-e-led usrp-e-ctl usrp-e-button usrp-e-uart-rx fpga-downloader usrp-e-gpio usrp-e-debug-pins usrp-e-random-loopback usrp-e-timed usrp-e-lb-test usrp-e-crc-rw clkgen-config usrp-e-spi : usrp-e-spi.c @@ -10,6 +10,9 @@ usrp-e-i2c : usrp-e-i2c.c usrp-e-loopback : usrp-e-loopback.c gcc -o $@ $< -lpthread ${CFLAGS} +usrp-e-mm-loopback : usrp-e-mm-loopback.c + gcc -o $@ $< -lpthread ${CFLAGS} + usrp-e-timed : usrp-e-timed.c gcc -o $@ $< -lpthread ${CFLAGS} @@ -42,6 +45,7 @@ clean : rm -f usrp-e-spi rm -f usrp-e-i2c rm -f usrp-e-loopback + rm -f usrp-e-mm-loopback rm -f usrp-e-timed rm -f usrp-e-rw-random rm -f usrp-e-uart diff --git a/host/apps/omap_debug/usrp-e-loopback.c b/host/apps/omap_debug/usrp-e-loopback.c index 929d65604..c463e774d 100644 --- a/host/apps/omap_debug/usrp-e-loopback.c +++ b/host/apps/omap_debug/usrp-e-loopback.c @@ -14,6 +14,7 @@ static int error; struct pkt { int checksum; int seq_num; + int len; short data[]; }; @@ -26,10 +27,11 @@ static int calc_checksum(struct pkt *p) i = 0; sum = 0; - for (i=0; i < packet_data_length; i++) + for (i=0; i < p->len; i++) sum += p->data[i]; sum += p->seq_num; + sum += p->len; return sum; } @@ -48,7 +50,7 @@ static void *read_thread(void *threadid) gettimeofday(&start_time, NULL); // IMPORTANT: must assume max length packet from fpga - rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (1016 * 2)); + rx_data = malloc(2048); p = (struct pkt *) ((void *)rx_data + offsetof(struct usrp_transfer_frame, buf)); //p = &(rx_data->buf[0]); printf("Address of rx_data = %p, p = %p\n", rx_data, p); @@ -60,14 +62,16 @@ static void *read_thread(void *threadid) seq_num_failure = 0; while (1) { - cnt = read(fp, rx_data, 2048); if (cnt < 0) printf("Error returned from read: %d, sequence number = %d\n", cnt, p->seq_num); // printf("Packet received, status = %X, len = %d\n", rx_data->status, rx_data->len); -// printf("p->seq_num = %d\n", p->seq_num); +// printf("p->seq_num = %d, p->len = %d\n", p->seq_num, p->len); + + if (rx_data->len != (p->len*2 + 12)) + printf("rx_data->len = %d, p->len*2 + 12 = %d\n", rx_data->len, p->len*2 + 12); pkt_count++; @@ -83,8 +87,8 @@ static void *read_thread(void *threadid) prev_seq_num = p->seq_num; if (calc_checksum(p) != p->checksum) { - printf("Checksum fail packet = %X, expected = %X, pkt_count = %d\n", - calc_checksum(p), p->checksum, pkt_count); + printf("Cksum fail rx = %X, tx = %X, dif = %d, count = %d, len = %d, rx->len = %d\n", + calc_checksum(p), p->checksum, p->checksum - calc_checksum(p), pkt_count, p->len, rx_data->len); error = 1; } @@ -112,24 +116,23 @@ static void *read_thread(void *threadid) static void *write_thread(void *threadid) { - int seq_number, i, cnt; + int seq_number, i, cnt, data_length; struct usrp_transfer_frame *tx_data; struct pkt *p; printf("Greetings from the write thread!\n"); - tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + (packet_data_length * 2)); + tx_data = malloc(2048); p = (struct pkt *) ((void *)tx_data + offsetof(struct usrp_transfer_frame, buf)); printf("Address of tx_data = %p, p = %p\n", tx_data, p); printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); - for (i=0; i < packet_data_length; i++) + for (i=0; i < 2048; i++) // p->data[i] = random() >> 16; p->data[i] = i; tx_data->status = 0xdeadbeef; - tx_data->len = 8 + packet_data_length * 2; printf("tx_data->len = %d\n", tx_data->len); @@ -137,9 +140,23 @@ static void *write_thread(void *threadid) while (1) { // printf("tx status = %X, len = %d\n", tx_data->status, tx_data->len); + if (packet_data_length > 0) + data_length = packet_data_length; + else + data_length = (random() & 0x1ff) + (1004 - 512); + +// printf("data_length = %d\n", data_length); + p->seq_num = seq_number++; + p->len = data_length; p->checksum = calc_checksum(p); - cnt = write(fp, tx_data, 2048); + tx_data->len = 12 + p->len * 2; + +// printf("tx status = %X, len = %d, p->len = %d\n", tx_data->status, tx_data->len, p->len); + + cnt = write(fp, tx_data, sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + 2 * p->len); +// cnt = write(fp, tx_data, 2048); + if (cnt < 0) printf("Error returned from write: %d\n", cnt); // sleep(1); diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c new file mode 100644 index 000000000..d11cf7d09 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "usrp_e.h" + +// max length #define PKT_DATA_LENGTH 1016 +static int packet_data_length; +static int error; + +struct pkt { + int len; + int checksum; + int seq_num; + short data[]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i < p->len; i++) + sum += p->data[i]; + + sum += p->seq_num; + sum += p->len; + + return sum; +} + +static void *read_thread(void *threadid) +{ + char *rx_data; + int cnt, prev_seq_num, pkt_count, seq_num_failure; + struct pkt *p; + unsigned long bytes_transfered, elapsed_seconds; + struct timeval start_time, finish_time; + + printf("Greetings from the reading thread!\n"); + + bytes_transfered = 0; + gettimeofday(&start_time, NULL); + + // IMPORTANT: must assume max length packet from fpga + rx_data = malloc(2048); + p = (struct pkt *) ((void *)rx_data); + + prev_seq_num = 0; + pkt_count = 0; + seq_num_failure = 0; + + while (1) { + + cnt = read(fp, rx_data, 2048); + if (cnt < 0) + printf("Error returned from read: %d, sequence number = %d\n", cnt, p->seq_num); + +// printf("p->seq_num = %d\n", p->seq_num); + + + pkt_count++; + + if (p->seq_num != prev_seq_num + 1) { + printf("Sequence number fail, current = %d, previous = %d, pkt_count = %d\n", + p->seq_num, prev_seq_num, pkt_count); + + seq_num_failure ++; + if (seq_num_failure > 2) + error = 1; + } + + prev_seq_num = p->seq_num; + + if (calc_checksum(p) != p->checksum) { + printf("Checksum fail packet = %X, expected = %X, pkt_count = %d\n", + calc_checksum(p), p->checksum, pkt_count); + error = 1; + } + + bytes_transfered += cnt; + + if (bytes_transfered > (100 * 1000000)) { + gettimeofday(&finish_time, NULL); + elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; + + printf("RX data transfer rate = %f K Samples/second\n", + (float) bytes_transfered / (float) elapsed_seconds / 4000); + + + start_time = finish_time; + bytes_transfered = 0; + } + + +// printf("."); +// fflush(stdout); +// printf("\n"); + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt; + void *tx_data; + struct pkt *p; + + printf("Greetings from the write thread!\n"); + + tx_data = malloc(2048); + p = (struct pkt *) ((void *)tx_data); + + for (i=0; i < packet_data_length; i++) +// p->data[i] = random() >> 16; + p->data[i] = i; + + seq_number = 1; + + while (1) { + p->seq_num = seq_number++; + + if (packet_data_length > 0) + p->len = packet_data_length; + else + p->len = (random() & 0x1ff) + (1004 - 512); + + p->checksum = calc_checksum(p); + + cnt = write(fp, tx_data, p->len * 2 + 12); + if (cnt < 0) + printf("Error returned from write: %d\n", cnt); +// sleep(1); + } +} + + +int main(int argc, char *argv[]) +{ + pthread_t tx, rx; + long int t; + struct sched_param s = { + .sched_priority = 1 + }; + void *rb; + struct usrp_transfer_frame *tx_rb, *rx_rb; + + if (argc < 2) { + printf("%s data_size\n", argv[0]); + return -1; + } + + packet_data_length = atoi(argv[1]); + + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); + + rb = mmap(0, 202 * 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fp, 0); + if (!rb) { + printf("mmap failed\n"); + exit; + } + + + sched_setscheduler(0, SCHED_RR, &s); + error = 0; + +#if 1 + if (pthread_create(&rx, NULL, read_thread, (void *) t)) { + printf("Failed to create rx thread\n"); + exit(-1); + } + + sleep(1); +#endif + + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { + printf("Failed to create tx thread\n"); + exit(-1); + } + +// while (!error) + sleep(1000000000); + + printf("Done sleeping\n"); +} -- cgit v1.2.3