From be576635cbba32bec56974fc24f5ae859f6722da Mon Sep 17 00:00:00 2001 From: Matt Ettus Date: Mon, 22 Feb 2010 16:44:15 -0800 Subject: place to put omap tools --- host/apps/omap_debug/README | 1 + 1 file changed, 1 insertion(+) create mode 100644 host/apps/omap_debug/README (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/README b/host/apps/omap_debug/README new file mode 100644 index 000000000..bbe0c2cc4 --- /dev/null +++ b/host/apps/omap_debug/README @@ -0,0 +1 @@ +OMAP development tools go here -- cgit v1.2.3 From fa35b710c09d7cb4a410313fd24d0ea2aa4172a3 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 23 Feb 2010 02:06:59 +0000 Subject: Initial checkin of u1e testing code. Some of these may not be really useful anymore. --- host/apps/omap_debug/fpga-downloader.cc | 251 ++++++++++++++++++++++++++++++++ host/apps/omap_debug/test.c | 34 +++++ host/apps/omap_debug/u1e-read-stream.c | 21 +++ host/apps/omap_debug/usrp1-e-ctl.c | 52 +++++++ host/apps/omap_debug/usrp1-e-ram.c | 25 ++++ host/apps/omap_debug/usrp1-e-read.c | 18 +++ host/apps/omap_debug/usrp1-e-write.c | 21 +++ 7 files changed, 422 insertions(+) create mode 100644 host/apps/omap_debug/fpga-downloader.cc create mode 100644 host/apps/omap_debug/test.c create mode 100644 host/apps/omap_debug/u1e-read-stream.c create mode 100644 host/apps/omap_debug/usrp1-e-ctl.c create mode 100644 host/apps/omap_debug/usrp1-e-ram.c create mode 100644 host/apps/omap_debug/usrp1-e-read.c create mode 100644 host/apps/omap_debug/usrp1-e-write.c (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fpga-downloader.cc b/host/apps/omap_debug/fpga-downloader.cc new file mode 100644 index 000000000..fb96b64a3 --- /dev/null +++ b/host/apps/omap_debug/fpga-downloader.cc @@ -0,0 +1,251 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * 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 + +/* + * Configuration connections + * + * CCK - MCSPI1_CLK + * DIN - MCSPI1_MOSI + * PROG_B - GPIO_175 - output (change mux) + * DONE - GPIO_173 - input (change mux) + * INIT_B - GPIO_114 - input (change mux) + * +*/ + +const unsigned int PROG_B = 175; +const unsigned int DONE = 173; +const unsigned int INIT_B = 114; + +static std::string bit_file = "safe_u1e.bin"; + +const int BUF_SIZE = 4096; + +enum gpio_direction {IN, OUT}; + +class gpio { + public: + + gpio(unsigned int gpio_num, gpio_direction pin_direction); + + bool get_value(); + void set_value(bool state); + + private: + + std::stringstream base_path; + std::fstream value_file; +}; + +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) +{ + std::fstream export_file; + + 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::fstream direction_file; + 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; +} + +static void prepare_fpga_for_configuration(gpio &prog, gpio &init) +{ + + prog.set_value(true); + prog.set_value(false); + prog.set_value(true); + +#if 0 + bool ready_to_program(false); + unsigned int count(0); + do { + ready_to_program = init.get_value(); + count++; + + sleep(1); + } while (count < 10 && !ready_to_program); + + if (count == 10) { + std::cout << "FPGA not ready for programming." << std::endl; + exit(-1); + } +#endif +} + +spidev::spidev(std::string fname) +{ + int ret; + int mode = 0; + int speed = 12000000; + int bits = 8; + + 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 = 48000000; + tr.bits_per_word = 8; + + ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); + +} + +static void send_file_to_fpga(std::string &file_name, gpio &error, gpio &done) +{ + std::ifstream bitstream; + + std::cout << "File name - " << file_name.c_str() << std::endl; + + bitstream.open(file_name.c_str(), std::ios::binary); + if (!bitstream.is_open()) + std::cout << "File " << file_name << " not opened succesfully." << std::endl; + + spidev spi("/dev/spidev1.0"); + char buf[BUF_SIZE]; + char rbuf[BUF_SIZE]; + + do { + bitstream.read(buf, BUF_SIZE); + spi.send(buf, rbuf, bitstream.gcount()); + + if (error.get_value()) + std::cout << "INIT_B went high, error occured." << std::endl; + + if (!done.get_value()) + std::cout << "Configuration complete." << std::endl; + + } while (bitstream.gcount() == BUF_SIZE); +} + +int main(int argc, char *argv[]) +{ + + gpio gpio_prog_b(PROG_B, OUT); + gpio gpio_init_b(INIT_B, IN); + gpio gpio_done (DONE, IN); + + if (argc == 2) + bit_file = argv[1]; + + std::cout << "FPGA config file: " << bit_file << std::endl; + + prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b); + + std::cout << "Done = " << gpio_done.get_value() << std::endl; + + send_file_to_fpga(bit_file, gpio_init_b, gpio_done); +} + diff --git a/host/apps/omap_debug/test.c b/host/apps/omap_debug/test.c new file mode 100644 index 000000000..36f4d700a --- /dev/null +++ b/host/apps/omap_debug/test.c @@ -0,0 +1,34 @@ +#include + +void +main() +{ + int x; + char *y; + long long z; + + x = 0x01020304; + z = 0x0102030405060708LL; + + printf("%x\n",x); + y = (char *)&x; + printf("%x\n",y[0]); + printf("%x\n",y[1]); + printf("%x\n",y[2]); + printf("%x\n",y[3]); + + printf("Printing z ...\n"); + printf("%llx\n",z); + printf("Printing z done\n"); + + y = (char *)&z; + printf("%x\n",y[0]); + printf("%x\n",y[1]); + printf("%x\n",y[2]); + printf("%x\n",y[3]); + printf("%x\n",y[4]); + printf("%x\n",y[5]); + printf("%x\n",y[6]); + printf("%x\n",y[7]); +} + diff --git a/host/apps/omap_debug/u1e-read-stream.c b/host/apps/omap_debug/u1e-read-stream.c new file mode 100644 index 000000000..4e4c21d9e --- /dev/null +++ b/host/apps/omap_debug/u1e-read-stream.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int main(int rgc, char *argv[]) +{ + int fp, cnt, n; + short buf[1024]; + + n = 0; + + fp = open("/dev/usrp1_e0", O_RDONLY); + printf("fp = %d\n", fp); + + do { + cnt = read(fp, buf, 2048); + n++; +// printf("Bytes read - %d\n", cnt); + } while(n < 10*512); + printf("Data - %hX\n", buf[0]); +} diff --git a/host/apps/omap_debug/usrp1-e-ctl.c b/host/apps/omap_debug/usrp1-e-ctl.c new file mode 100644 index 000000000..045e7ce19 --- /dev/null +++ b/host/apps/omap_debug/usrp1-e-ctl.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +#include "usrp1_e.h" + +// Usage: usrp1_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; + + if (argc < 4) { + printf("Usage: usrp1_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->offset = atoi(argv[2]); + ctl_data->count = cnt; + + printf("Sizeof usrp1_e_ctl struct = %d\n", sizeof(struct usrp1_e_ctl)); + + fp = open("/dev/usrp1_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); + printf("Return value from write ioctl = %d\n", ret); + } + + if (*argv[1] == 'r') { + ret = ioctl(fp, USRP1_E_READ_CTL, ctl_data); + printf("Return value from write ioctl = %d\n", ret); + + for (i=0; icount; i++) { + if (!(i%8)) + printf("\nData at %4d :", i); + printf(" %5d", ctl_data->buf[i]); + } + printf("\n"); + } +} diff --git a/host/apps/omap_debug/usrp1-e-ram.c b/host/apps/omap_debug/usrp1-e-ram.c new file mode 100644 index 000000000..d548f7ccd --- /dev/null +++ b/host/apps/omap_debug/usrp1-e-ram.c @@ -0,0 +1,25 @@ +#include +#include +#include + +int main(int rgc, char *argv[]) +{ + int fp, i, cnt; + unsigned short buf[1024]; + unsigned short buf_rb[1024]; + + fp = open("/dev/usrp1_e0", O_RDWR); + printf("fp = %d\n", fp); + + for (i=0; i<1024; i++) + buf[i] = i*256; + write(fp, buf, 2048); + read(fp, buf_rb, 2048); + + printf("Read back %hX %hX\n", buf_rb[0], buf_rb[1]); + + for (i=0; i<1024; i++) { + if (buf[i] != buf_rb[i]) + printf("Read - %hX, expected - %hX\n", buf_rb[i], buf[i]); + } +} diff --git a/host/apps/omap_debug/usrp1-e-read.c b/host/apps/omap_debug/usrp1-e-read.c new file mode 100644 index 000000000..c28f018d5 --- /dev/null +++ b/host/apps/omap_debug/usrp1-e-read.c @@ -0,0 +1,18 @@ +#include +#include +#include + +int main(int rgc, char *argv[]) +{ + int fp, cnt; + short buf[1024]; + + fp = open("/dev/usrp1_e0", O_RDONLY); + printf("fp = %d\n", fp); + + do { + cnt = read(fp, buf, 2048); +// printf("Bytes read - %d\n", cnt); + } while(1); + printf("Data - %hX\n", buf[0]); +} diff --git a/host/apps/omap_debug/usrp1-e-write.c b/host/apps/omap_debug/usrp1-e-write.c new file mode 100644 index 000000000..f29cc7032 --- /dev/null +++ b/host/apps/omap_debug/usrp1-e-write.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int main(int rgc, char *argv[]) +{ + int fp, i, cnt; + short buf[1024]; + + fp = open("/dev/usrp1_e0", O_WRONLY); + printf("fp = %d\n", fp); + + for (i=0; i<1024; i++) { + buf[i] = i; + } + + do { + cnt = write(fp, buf, 2048); + printf("Bytes written - %d\n", cnt); + } while (1); +} -- cgit v1.2.3 From 1e49264f713701a89fb2bc079344273df5a94c06 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 23 Feb 2010 02:09:51 +0000 Subject: Initial checkin of useful shell scripts. --- host/apps/omap_debug/fetch-bin.sh | 1 + host/apps/omap_debug/fetch-kernel.sh | 2 ++ host/apps/omap_debug/fetch-module.sh | 1 + 3 files changed, 4 insertions(+) create mode 100755 host/apps/omap_debug/fetch-bin.sh create mode 100755 host/apps/omap_debug/fetch-kernel.sh create mode 100755 host/apps/omap_debug/fetch-module.sh (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-bin.sh b/host/apps/omap_debug/fetch-bin.sh new file mode 100755 index 000000000..9fb09a10d --- /dev/null +++ b/host/apps/omap_debug/fetch-bin.sh @@ -0,0 +1 @@ +scp balister@192.168.1.182:Download/u1e.bin . diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh new file mode 100755 index 000000000..e3bc1b0ad --- /dev/null +++ b/host/apps/omap_debug/fetch-kernel.sh @@ -0,0 +1,2 @@ +scp balister@192.168.1.182:src/git/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage + diff --git a/host/apps/omap_debug/fetch-module.sh b/host/apps/omap_debug/fetch-module.sh new file mode 100755 index 000000000..95140df15 --- /dev/null +++ b/host/apps/omap_debug/fetch-module.sh @@ -0,0 +1 @@ +scp balister@192.168.1.182:src/git/kernel_usrp/drivers/misc/usrp1_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc -- cgit v1.2.3 From ba0bbdb3ca3815ca45766cc5f2d06a4d12810f0f Mon Sep 17 00:00:00 2001 From: Matt Ettus Date: Mon, 22 Feb 2010 18:37:29 -0800 Subject: first cut at automatically setting the debug pins --- host/apps/omap_debug/set_debug_pins.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 host/apps/omap_debug/set_debug_pins.py (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/set_debug_pins.py b/host/apps/omap_debug/set_debug_pins.py new file mode 100755 index 000000000..982c290ef --- /dev/null +++ b/host/apps/omap_debug/set_debug_pins.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +import os + +# Memory Map +misc_base = 0 +uart_base = 1 +spi_base = 2 +i2c_base = 3 +gpio_base = 4 +settings_base = 5 + +# GPIO offset +gpio_pins = 0 +gpio_ddr = 4 +gpio_ctrl_lo = 8 +gpio_ctrl_hi = 12 + +def set_reg(reg, val): + os.system("usrp1-e-ctl w %d 1 %d" % (reg,val)) + +def get_reg(reg): + fin,fout = os.popen4("usrp1-e-ctl r %d 1" % (reg,)) + print fout.read() + +# Set DDRs to output +set_reg(gpio_base+gpio_ddr, 0xFFFF) +set_reg(gpio_base+gpio_ddr+2, 0xFFFF) + +# Set CTRL to Debug #0 ( A is for debug 0, F is for debug 1 ) +set_reg(gpio_base+ctrl_lo, 0xAAAA) +set_reg(gpio_base+ctrl_lo+2, 0xAAAA) +set_reg(gpio_base+ctrl_hi, 0xAAAA) +set_reg(gpio_base+ctrl_hi+2, 0xAAAA) -- cgit v1.2.3 From 3cd7bc9be6420623eb7803e490b39ecc75d83ed9 Mon Sep 17 00:00:00 2001 From: Matt Ettus Date: Mon, 22 Feb 2010 18:43:16 -0800 Subject: full neame --- host/apps/omap_debug/set_debug_pins.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/set_debug_pins.py b/host/apps/omap_debug/set_debug_pins.py index 982c290ef..d67cc3e58 100755 --- a/host/apps/omap_debug/set_debug_pins.py +++ b/host/apps/omap_debug/set_debug_pins.py @@ -28,7 +28,7 @@ set_reg(gpio_base+gpio_ddr, 0xFFFF) set_reg(gpio_base+gpio_ddr+2, 0xFFFF) # Set CTRL to Debug #0 ( A is for debug 0, F is for debug 1 ) -set_reg(gpio_base+ctrl_lo, 0xAAAA) -set_reg(gpio_base+ctrl_lo+2, 0xAAAA) -set_reg(gpio_base+ctrl_hi, 0xAAAA) -set_reg(gpio_base+ctrl_hi+2, 0xAAAA) +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) -- cgit v1.2.3 From f6ec1e45117f5794facd1cd8e11cbfacabdeb166 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Feb 2010 02:18:54 +0000 Subject: Commit wip. Programs that fetch OS code sync now. --- host/apps/omap_debug/fetch-bin.sh | 1 + host/apps/omap_debug/fetch-kernel.sh | 1 + host/apps/omap_debug/fetch-module.sh | 1 + host/apps/omap_debug/set_debug_pins.py | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-bin.sh b/host/apps/omap_debug/fetch-bin.sh index 9fb09a10d..1ceec4fd2 100755 --- a/host/apps/omap_debug/fetch-bin.sh +++ b/host/apps/omap_debug/fetch-bin.sh @@ -1 +1,2 @@ scp balister@192.168.1.182:Download/u1e.bin . +sync diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh index e3bc1b0ad..08b470e9b 100755 --- a/host/apps/omap_debug/fetch-kernel.sh +++ b/host/apps/omap_debug/fetch-kernel.sh @@ -1,2 +1,3 @@ scp balister@192.168.1.182: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 95140df15..6511958f9 100755 --- a/host/apps/omap_debug/fetch-module.sh +++ b/host/apps/omap_debug/fetch-module.sh @@ -1 +1,2 @@ scp balister@192.168.1.182:src/git/kernel_usrp/drivers/misc/usrp1_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc +sync diff --git a/host/apps/omap_debug/set_debug_pins.py b/host/apps/omap_debug/set_debug_pins.py index d67cc3e58..bedabc20c 100755 --- a/host/apps/omap_debug/set_debug_pins.py +++ b/host/apps/omap_debug/set_debug_pins.py @@ -17,10 +17,10 @@ gpio_ctrl_lo = 8 gpio_ctrl_hi = 12 def set_reg(reg, val): - os.system("usrp1-e-ctl w %d 1 %d" % (reg,val)) + os.system("./usrp1-e-ctl w %d 1 %d" % (reg,val)) def get_reg(reg): - fin,fout = os.popen4("usrp1-e-ctl r %d 1" % (reg,)) + fin,fout = os.popen4("./usrp1-e-ctl r %d 1" % (reg,)) print fout.read() # Set DDRs to output -- cgit v1.2.3 From e273ea92d83d46ca350ac07e3d836a4d99b106c2 Mon Sep 17 00:00:00 2001 From: Matt Ettus Date: Mon, 8 Mar 2010 16:13:06 -0800 Subject: proper flags bits --- host/apps/omap_debug/set_debug_pins.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/set_debug_pins.py b/host/apps/omap_debug/set_debug_pins.py index d67cc3e58..20071db6b 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 -uart_base = 1 -spi_base = 2 -i2c_base = 3 -gpio_base = 4 -settings_base = 5 +misc_base = 0 << 7 +uart_base = 1 << 7 +spi_base = 2 << 7 +i2c_base = 3 << 7 +gpio_base = 4 << 7 +settings_base = 5 << 7 # GPIO offset gpio_pins = 0 -- cgit v1.2.3 From 3137e2ca001176c4ffc12e091530fe23c82974b6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 23 Mar 2010 13:38:46 +0000 Subject: Commit random test code. Unfiltered commit of test code I am accumlating on my ewewoneee. Most of this should go away before release. --- host/apps/omap_debug/fetch-bin.sh | 2 +- host/apps/omap_debug/fetch-kernel.sh | 2 +- host/apps/omap_debug/fetch-module.sh | 3 +- host/apps/omap_debug/fetch-u-boot.sh | 3 ++ host/apps/omap_debug/usrp1-e-rw.c | 97 ++++++++++++++++++++++++++++++++++++ host/apps/omap_debug/usrp1-e-spi.c | 40 +++++++++++++++ host/apps/omap_debug/usrp1-e-write.c | 4 +- host/apps/omap_debug/usrp1_e.h | 56 +++++++++++++++++++++ host/apps/omap_debug/write-eeprom.sh | 92 ++++++++++++++++++++++++++++++++++ 9 files changed, 294 insertions(+), 5 deletions(-) create mode 100755 host/apps/omap_debug/fetch-u-boot.sh create mode 100644 host/apps/omap_debug/usrp1-e-rw.c create mode 100644 host/apps/omap_debug/usrp1-e-spi.c create mode 100644 host/apps/omap_debug/usrp1_e.h create mode 100755 host/apps/omap_debug/write-eeprom.sh (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-bin.sh b/host/apps/omap_debug/fetch-bin.sh index 1ceec4fd2..beff7ffcd 100755 --- a/host/apps/omap_debug/fetch-bin.sh +++ b/host/apps/omap_debug/fetch-bin.sh @@ -1,2 +1,2 @@ -scp balister@192.168.1.182:Download/u1e.bin . +scp balister@astro:/workspace/usrp1-e-dev/u1e.bin . sync diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh index 08b470e9b..7023f5d28 100755 --- a/host/apps/omap_debug/fetch-kernel.sh +++ b/host/apps/omap_debug/fetch-kernel.sh @@ -1,3 +1,3 @@ -scp balister@192.168.1.182:src/git/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage +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 6511958f9..101ea9aef 100755 --- a/host/apps/omap_debug/fetch-module.sh +++ b/host/apps/omap_debug/fetch-module.sh @@ -1,2 +1,3 @@ -scp balister@192.168.1.182:src/git/kernel_usrp/drivers/misc/usrp1_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc +scp balister@192.168.1.167:src/git/kernel_usrp/drivers/misc/usrp1_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc +scp balister@192.168.1.167:src/git/kernel_usrp/include/linux/usrp1_e.h . sync diff --git a/host/apps/omap_debug/fetch-u-boot.sh b/host/apps/omap_debug/fetch-u-boot.sh new file mode 100755 index 000000000..63d4edcf2 --- /dev/null +++ b/host/apps/omap_debug/fetch-u-boot.sh @@ -0,0 +1,3 @@ +scp balister@astro:/workspace/usrp1-e-dev/u-boot-overo/u-boot.bin /media/mmcblk0p1/ +sync + diff --git a/host/apps/omap_debug/usrp1-e-rw.c b/host/apps/omap_debug/usrp1-e-rw.c new file mode 100644 index 000000000..cd7fbe4dd --- /dev/null +++ b/host/apps/omap_debug/usrp1-e-rw.c @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include + +struct pkt { + int checksum; + int seq_num; + short data[1020]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i<1020; i++) + sum += p->data[i]; + + sum += p->seq_num; + + return sum; +} + +static void *read_thread(void *threadid) +{ + int cnt, prev_seq_num; + struct pkt rx_data; + + printf("Greetings from the reading thread!\n"); + + prev_seq_num = 0; + + while (1) { + cnt = read(fp, &rx_data, 2048); + + if (rx_data.seq_num != prev_seq_num + 1) + printf("Sequence number fail, current = %d, previous = %d\n", + rx_data.seq_num, prev_seq_num); + prev_seq_num = rx_data.seq_num; + + if (calc_checksum(&rx_data) != rx_data.checksum) + printf("Checksum fail packet = %d, expected = %d\n", + calc_checksum(&rx_data), rx_data.checksum); + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt; + struct pkt tx_data; + + printf("Greetings from the write thread!\n"); + + for (i=0; i<1020; i++) + tx_data.data[i] = random() >> 16; + + + seq_number = 1; + + while (1) { + tx_data.seq_num = seq_number++; + tx_data.checksum = calc_checksum(&tx_data); + cnt = write(fp, &tx_data, 2048); + } +} + + +int main(int argc, char *argv[]) +{ + int ret; + pthread_t tx, rx; + long int t; + + fp = open("/dev/usrp1_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); + } + + 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/usrp1-e-spi.c b/host/apps/omap_debug/usrp1-e-spi.c new file mode 100644 index 000000000..a79d74b18 --- /dev/null +++ b/host/apps/omap_debug/usrp1-e-spi.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#include "usrp1_e.h" + +// Usage: usrp1_e_spi w|rb slave data + +int main(int argc, char *argv[]) +{ + int fp, slave, data, ret; + struct usrp_e_spi spi_dat; + + if (argc < 4) { + printf("Usage: usrp1_e_spi w|rb slave data\n"); + exit(-1); + } + + slave = atoi(argv[2]); + data = atoi(argv[3]); + + fp = open("/dev/usrp1_e0", O_RDWR); + printf("fp = %d\n", fp); + + spi_dat.slave = slave; + spi_dat.data = data; + spi_dat.length = 2; + spi_dat.flags = 0; + + if (*argv[1] == 'r') { + spi_dat.readback = 1; + ret = ioctl(fp, USRP_E_SPI, &spi_dat); + printf("Data returned = %d\n", ret); + } else { + spi_dat.readback = 0; + ioctl(fp, USRP_E_SPI, &spi_dat); + } +} diff --git a/host/apps/omap_debug/usrp1-e-write.c b/host/apps/omap_debug/usrp1-e-write.c index f29cc7032..903c0071f 100644 --- a/host/apps/omap_debug/usrp1-e-write.c +++ b/host/apps/omap_debug/usrp1-e-write.c @@ -14,8 +14,8 @@ int main(int rgc, char *argv[]) buf[i] = i; } - do { +// do { cnt = write(fp, buf, 2048); printf("Bytes written - %d\n", cnt); - } while (1); +// } while (1); } diff --git a/host/apps/omap_debug/usrp1_e.h b/host/apps/omap_debug/usrp1_e.h new file mode 100644 index 000000000..b49b526dc --- /dev/null +++ b/host/apps/omap_debug/usrp1_e.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2010 Ettus Research, LLC + * + * Written by Philip Balister + * + * This program 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 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __USRP_E_H +#define __USRP_E_H + +#include +#include + +struct usrp1_e_ctl { + __u32 offset; + __u32 count; + __u16 buf[]; +}; + +// SPI interface + +#define UE_SPI_TXONLY 0 +#define UE_SPI_TXRX 1 + +// Defines for spi ctrl register +#define UE_SPI_CTRL_ASS (1<<13) +#define UE_SPI_CTRL_IE (1<<12) +#define UE_SPI_CTRL_LSB (1<<11) +#define UE_SPI_CTRL_TXNEG (1<<10) +#define UE_SPI_CTRL_RXNEG (1<<9) +#define UE_SPI_CTRL_GO_BSY (1<<8) +#define UE_SPI_CTRL_CHAR_LEN_MASK 0x7f + +#define UE_SPI_PUSH_RISE 0 +#define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG +#define UE_SPI_LATCH_RISE 0 +#define UE_SPI_LATCH_FALL UE_SPI_CTRL_RXNEG + +struct usrp_e_spi { + __u8 readback; + __u32 slave; + __u32 data; + __u32 length; + __u32 flags; +}; + +#define USRP_E_IOC_MAGIC 'u' +#define USRP_E_WRITE_CTL _IOW(USRP_E_IOC_MAGIC, 0x20, struct usrp1_e_ctl) +#define USRP_E_READ_CTL _IOWR(USRP_E_IOC_MAGIC, 0x21, struct usrp1_e_ctl) +#define USRP_E_SPI _IOW(USRP_E_IOC_MAGIC, 0x22, struct usrp_e_spi) + +#endif diff --git a/host/apps/omap_debug/write-eeprom.sh b/host/apps/omap_debug/write-eeprom.sh new file mode 100755 index 000000000..301b06f07 --- /dev/null +++ b/host/apps/omap_debug/write-eeprom.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +if [ $# -ne 3 ] && [ $# -ne 5 ]; +then + echo "Usage:" + echo "" + echo "writeprom.sh deviceid rev fab_rev [envvar envsetting]" + echo + echo " deviceid - expansion board device number from table:" + echo + echo " Summit 0x01" + echo " Tobi 0x02" + echo " Tobi Duo 0x03" + echo " Palo35 0x04" + echo " Palo43 0x05" + echo " Chestnut43 0x06" + echo " Pinto 0x07" + echo + echo " rev - board revision (e.g. 0x00)" + echo " fab_rev - revision marking from pcb (e.g. R2411)" + echo " envvar - optional u-boot env variable name" + echo " (e.g. dvimode)" + echo " envsetting - optional u-boot env variable setting" + echo " (e.g. 1024x768MR-16@60)" + exit 1 +fi + +fabrevision=$3 +if [ ${#fabrevision} -ge 8 ]; then + echo "Error: fab revision string must less than 8 characters" + exit 1 +fi + +envvar=$4 +if [ ${#envar} -ge 16 ]; then + echo "Error: environment variable name string must less than 16 characters" + exit 1 +fi + +envsetting=$5 +if [ ${#ensetting} -ge 64 ]; then + echo "Error: environment setting string must less than 64 characters" + exit 1 +fi + +bus=3 +device=0x51 +vendorid=0x03 + +i2cset -y $bus $device 0x00 0x00 +i2cset -y $bus $device 0x01 $vendorid +i2cset -y $bus $device 0x02 0x00 +i2cset -y $bus $device 0x03 $1 +i2cset -y $bus $device 0x04 $2 +i2cset -y $bus $device 0x05 00 + +let i=6 +hexdumpargs="'${#fabrevision}/1 \"0x%02x \"'" +command="echo -n \"$fabrevision\" | hexdump -e $hexdumpargs" +hex=$(eval $command) +for character in $hex; do + i2cset -y $bus $device $i $character + let i=$i+1 +done +i2cset -y $bus $device $i 0x00 + +if [ $# -eq 5 ] +then + i2cset -y $bus $device 0x05 0x01 + + let i=14 + hexdumpargs="'${#envvar}/1 \"0x%02x \"'" + command="echo -n \"$envvar\" | hexdump -e $hexdumpargs" + hex=$(eval $command) + for character in $hex; do + i2cset -y $bus $device $i $character + let i=$i+1 + done + i2cset -y $bus $device $i 0x00 + + let i=30 + hexdumpargs="'${#envsetting}/1 \"0x%02x \"'" + command="echo -n \"$envsetting\" | hexdump -e $hexdumpargs" + hex=$(eval $command) + for character in $hex; do + i2cset -y $bus $device $i $character + let i=$i+1 + done + i2cset -y $bus $device $i 0x00 +fi + + -- cgit v1.2.3 From 4e5429b2839115235c7be778fe334479b833f128 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 24 Mar 2010 11:33:02 -0400 Subject: Start renaming stuff in line with product name USRP Embedded. --- host/apps/omap_debug/usrp-e-ctl.c | 52 +++++++++++++++++++ host/apps/omap_debug/usrp-e-ram.c | 25 ++++++++++ host/apps/omap_debug/usrp-e-read.c | 18 +++++++ host/apps/omap_debug/usrp-e-rw.c | 97 ++++++++++++++++++++++++++++++++++++ host/apps/omap_debug/usrp-e-spi.c | 40 +++++++++++++++ host/apps/omap_debug/usrp-e-write.c | 21 ++++++++ host/apps/omap_debug/usrp1-e-ctl.c | 52 ------------------- host/apps/omap_debug/usrp1-e-ram.c | 25 ---------- host/apps/omap_debug/usrp1-e-read.c | 18 ------- host/apps/omap_debug/usrp1-e-rw.c | 97 ------------------------------------ host/apps/omap_debug/usrp1-e-spi.c | 40 --------------- host/apps/omap_debug/usrp1-e-write.c | 21 -------- 12 files changed, 253 insertions(+), 253 deletions(-) create mode 100644 host/apps/omap_debug/usrp-e-ctl.c create mode 100644 host/apps/omap_debug/usrp-e-ram.c create mode 100644 host/apps/omap_debug/usrp-e-read.c create mode 100644 host/apps/omap_debug/usrp-e-rw.c create mode 100644 host/apps/omap_debug/usrp-e-spi.c create mode 100644 host/apps/omap_debug/usrp-e-write.c delete mode 100644 host/apps/omap_debug/usrp1-e-ctl.c delete mode 100644 host/apps/omap_debug/usrp1-e-ram.c delete mode 100644 host/apps/omap_debug/usrp1-e-read.c delete mode 100644 host/apps/omap_debug/usrp1-e-rw.c delete mode 100644 host/apps/omap_debug/usrp1-e-spi.c delete mode 100644 host/apps/omap_debug/usrp1-e-write.c (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-ctl.c b/host/apps/omap_debug/usrp-e-ctl.c new file mode 100644 index 000000000..045e7ce19 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-ctl.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +#include "usrp1_e.h" + +// Usage: usrp1_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; + + if (argc < 4) { + printf("Usage: usrp1_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->offset = atoi(argv[2]); + ctl_data->count = cnt; + + printf("Sizeof usrp1_e_ctl struct = %d\n", sizeof(struct usrp1_e_ctl)); + + fp = open("/dev/usrp1_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); + printf("Return value from write ioctl = %d\n", ret); + } + + if (*argv[1] == 'r') { + ret = ioctl(fp, USRP1_E_READ_CTL, ctl_data); + printf("Return value from write ioctl = %d\n", ret); + + for (i=0; icount; i++) { + if (!(i%8)) + printf("\nData at %4d :", i); + printf(" %5d", ctl_data->buf[i]); + } + printf("\n"); + } +} diff --git a/host/apps/omap_debug/usrp-e-ram.c b/host/apps/omap_debug/usrp-e-ram.c new file mode 100644 index 000000000..d548f7ccd --- /dev/null +++ b/host/apps/omap_debug/usrp-e-ram.c @@ -0,0 +1,25 @@ +#include +#include +#include + +int main(int rgc, char *argv[]) +{ + int fp, i, cnt; + unsigned short buf[1024]; + unsigned short buf_rb[1024]; + + fp = open("/dev/usrp1_e0", O_RDWR); + printf("fp = %d\n", fp); + + for (i=0; i<1024; i++) + buf[i] = i*256; + write(fp, buf, 2048); + read(fp, buf_rb, 2048); + + printf("Read back %hX %hX\n", buf_rb[0], buf_rb[1]); + + for (i=0; i<1024; i++) { + if (buf[i] != buf_rb[i]) + printf("Read - %hX, expected - %hX\n", buf_rb[i], buf[i]); + } +} diff --git a/host/apps/omap_debug/usrp-e-read.c b/host/apps/omap_debug/usrp-e-read.c new file mode 100644 index 000000000..c28f018d5 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-read.c @@ -0,0 +1,18 @@ +#include +#include +#include + +int main(int rgc, char *argv[]) +{ + int fp, cnt; + short buf[1024]; + + fp = open("/dev/usrp1_e0", O_RDONLY); + printf("fp = %d\n", fp); + + do { + cnt = read(fp, buf, 2048); +// printf("Bytes read - %d\n", cnt); + } while(1); + printf("Data - %hX\n", buf[0]); +} diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c new file mode 100644 index 000000000..cd7fbe4dd --- /dev/null +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include + +struct pkt { + int checksum; + int seq_num; + short data[1020]; +}; + +static int fp; + +static int calc_checksum(struct pkt *p) +{ + int i, sum; + + i = 0; + sum = 0; + + for (i=0; i<1020; i++) + sum += p->data[i]; + + sum += p->seq_num; + + return sum; +} + +static void *read_thread(void *threadid) +{ + int cnt, prev_seq_num; + struct pkt rx_data; + + printf("Greetings from the reading thread!\n"); + + prev_seq_num = 0; + + while (1) { + cnt = read(fp, &rx_data, 2048); + + if (rx_data.seq_num != prev_seq_num + 1) + printf("Sequence number fail, current = %d, previous = %d\n", + rx_data.seq_num, prev_seq_num); + prev_seq_num = rx_data.seq_num; + + if (calc_checksum(&rx_data) != rx_data.checksum) + printf("Checksum fail packet = %d, expected = %d\n", + calc_checksum(&rx_data), rx_data.checksum); + } + +} + +static void *write_thread(void *threadid) +{ + int seq_number, i, cnt; + struct pkt tx_data; + + printf("Greetings from the write thread!\n"); + + for (i=0; i<1020; i++) + tx_data.data[i] = random() >> 16; + + + seq_number = 1; + + while (1) { + tx_data.seq_num = seq_number++; + tx_data.checksum = calc_checksum(&tx_data); + cnt = write(fp, &tx_data, 2048); + } +} + + +int main(int argc, char *argv[]) +{ + int ret; + pthread_t tx, rx; + long int t; + + fp = open("/dev/usrp1_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); + } + + 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-spi.c b/host/apps/omap_debug/usrp-e-spi.c new file mode 100644 index 000000000..a79d74b18 --- /dev/null +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#include "usrp1_e.h" + +// Usage: usrp1_e_spi w|rb slave data + +int main(int argc, char *argv[]) +{ + int fp, slave, data, ret; + struct usrp_e_spi spi_dat; + + if (argc < 4) { + printf("Usage: usrp1_e_spi w|rb slave data\n"); + exit(-1); + } + + slave = atoi(argv[2]); + data = atoi(argv[3]); + + fp = open("/dev/usrp1_e0", O_RDWR); + printf("fp = %d\n", fp); + + spi_dat.slave = slave; + spi_dat.data = data; + spi_dat.length = 2; + spi_dat.flags = 0; + + if (*argv[1] == 'r') { + spi_dat.readback = 1; + ret = ioctl(fp, USRP_E_SPI, &spi_dat); + printf("Data returned = %d\n", ret); + } else { + spi_dat.readback = 0; + ioctl(fp, USRP_E_SPI, &spi_dat); + } +} diff --git a/host/apps/omap_debug/usrp-e-write.c b/host/apps/omap_debug/usrp-e-write.c new file mode 100644 index 000000000..903c0071f --- /dev/null +++ b/host/apps/omap_debug/usrp-e-write.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int main(int rgc, char *argv[]) +{ + int fp, i, cnt; + short buf[1024]; + + fp = open("/dev/usrp1_e0", O_WRONLY); + printf("fp = %d\n", fp); + + for (i=0; i<1024; i++) { + buf[i] = i; + } + +// do { + cnt = write(fp, buf, 2048); + printf("Bytes written - %d\n", cnt); +// } while (1); +} diff --git a/host/apps/omap_debug/usrp1-e-ctl.c b/host/apps/omap_debug/usrp1-e-ctl.c deleted file mode 100644 index 045e7ce19..000000000 --- a/host/apps/omap_debug/usrp1-e-ctl.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -#include -#include - -#include "usrp1_e.h" - -// Usage: usrp1_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; - - if (argc < 4) { - printf("Usage: usrp1_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->offset = atoi(argv[2]); - ctl_data->count = cnt; - - printf("Sizeof usrp1_e_ctl struct = %d\n", sizeof(struct usrp1_e_ctl)); - - fp = open("/dev/usrp1_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); - printf("Return value from write ioctl = %d\n", ret); - } - - if (*argv[1] == 'r') { - ret = ioctl(fp, USRP1_E_READ_CTL, ctl_data); - printf("Return value from write ioctl = %d\n", ret); - - for (i=0; icount; i++) { - if (!(i%8)) - printf("\nData at %4d :", i); - printf(" %5d", ctl_data->buf[i]); - } - printf("\n"); - } -} diff --git a/host/apps/omap_debug/usrp1-e-ram.c b/host/apps/omap_debug/usrp1-e-ram.c deleted file mode 100644 index d548f7ccd..000000000 --- a/host/apps/omap_debug/usrp1-e-ram.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -int main(int rgc, char *argv[]) -{ - int fp, i, cnt; - unsigned short buf[1024]; - unsigned short buf_rb[1024]; - - fp = open("/dev/usrp1_e0", O_RDWR); - printf("fp = %d\n", fp); - - for (i=0; i<1024; i++) - buf[i] = i*256; - write(fp, buf, 2048); - read(fp, buf_rb, 2048); - - printf("Read back %hX %hX\n", buf_rb[0], buf_rb[1]); - - for (i=0; i<1024; i++) { - if (buf[i] != buf_rb[i]) - printf("Read - %hX, expected - %hX\n", buf_rb[i], buf[i]); - } -} diff --git a/host/apps/omap_debug/usrp1-e-read.c b/host/apps/omap_debug/usrp1-e-read.c deleted file mode 100644 index c28f018d5..000000000 --- a/host/apps/omap_debug/usrp1-e-read.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -int main(int rgc, char *argv[]) -{ - int fp, cnt; - short buf[1024]; - - fp = open("/dev/usrp1_e0", O_RDONLY); - printf("fp = %d\n", fp); - - do { - cnt = read(fp, buf, 2048); -// printf("Bytes read - %d\n", cnt); - } while(1); - printf("Data - %hX\n", buf[0]); -} diff --git a/host/apps/omap_debug/usrp1-e-rw.c b/host/apps/omap_debug/usrp1-e-rw.c deleted file mode 100644 index cd7fbe4dd..000000000 --- a/host/apps/omap_debug/usrp1-e-rw.c +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include -#include -#include -#include - -struct pkt { - int checksum; - int seq_num; - short data[1020]; -}; - -static int fp; - -static int calc_checksum(struct pkt *p) -{ - int i, sum; - - i = 0; - sum = 0; - - for (i=0; i<1020; i++) - sum += p->data[i]; - - sum += p->seq_num; - - return sum; -} - -static void *read_thread(void *threadid) -{ - int cnt, prev_seq_num; - struct pkt rx_data; - - printf("Greetings from the reading thread!\n"); - - prev_seq_num = 0; - - while (1) { - cnt = read(fp, &rx_data, 2048); - - if (rx_data.seq_num != prev_seq_num + 1) - printf("Sequence number fail, current = %d, previous = %d\n", - rx_data.seq_num, prev_seq_num); - prev_seq_num = rx_data.seq_num; - - if (calc_checksum(&rx_data) != rx_data.checksum) - printf("Checksum fail packet = %d, expected = %d\n", - calc_checksum(&rx_data), rx_data.checksum); - } - -} - -static void *write_thread(void *threadid) -{ - int seq_number, i, cnt; - struct pkt tx_data; - - printf("Greetings from the write thread!\n"); - - for (i=0; i<1020; i++) - tx_data.data[i] = random() >> 16; - - - seq_number = 1; - - while (1) { - tx_data.seq_num = seq_number++; - tx_data.checksum = calc_checksum(&tx_data); - cnt = write(fp, &tx_data, 2048); - } -} - - -int main(int argc, char *argv[]) -{ - int ret; - pthread_t tx, rx; - long int t; - - fp = open("/dev/usrp1_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); - } - - 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/usrp1-e-spi.c b/host/apps/omap_debug/usrp1-e-spi.c deleted file mode 100644 index a79d74b18..000000000 --- a/host/apps/omap_debug/usrp1-e-spi.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include -#include - -#include "usrp1_e.h" - -// Usage: usrp1_e_spi w|rb slave data - -int main(int argc, char *argv[]) -{ - int fp, slave, data, ret; - struct usrp_e_spi spi_dat; - - if (argc < 4) { - printf("Usage: usrp1_e_spi w|rb slave data\n"); - exit(-1); - } - - slave = atoi(argv[2]); - data = atoi(argv[3]); - - fp = open("/dev/usrp1_e0", O_RDWR); - printf("fp = %d\n", fp); - - spi_dat.slave = slave; - spi_dat.data = data; - spi_dat.length = 2; - spi_dat.flags = 0; - - if (*argv[1] == 'r') { - spi_dat.readback = 1; - ret = ioctl(fp, USRP_E_SPI, &spi_dat); - printf("Data returned = %d\n", ret); - } else { - spi_dat.readback = 0; - ioctl(fp, USRP_E_SPI, &spi_dat); - } -} diff --git a/host/apps/omap_debug/usrp1-e-write.c b/host/apps/omap_debug/usrp1-e-write.c deleted file mode 100644 index 903c0071f..000000000 --- a/host/apps/omap_debug/usrp1-e-write.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -int main(int rgc, char *argv[]) -{ - int fp, i, cnt; - short buf[1024]; - - fp = open("/dev/usrp1_e0", O_WRONLY); - printf("fp = %d\n", fp); - - for (i=0; i<1024; i++) { - buf[i] = i; - } - -// do { - cnt = write(fp, buf, 2048); - printf("Bytes written - %d\n", cnt); -// } while (1); -} -- cgit v1.2.3 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') 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 550bf3230aa1a5e7236d5bdb64a77c4ae1acea66 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Mar 2010 16:57:48 +0000 Subject: Update usrp1_e.h header file to match kernel driver. --- host/apps/omap_debug/usrp1_e.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp1_e.h b/host/apps/omap_debug/usrp1_e.h index b49b526dc..b34446b01 100644 --- a/host/apps/omap_debug/usrp1_e.h +++ b/host/apps/omap_debug/usrp1_e.h @@ -15,10 +15,16 @@ #include #include -struct usrp1_e_ctl { +struct usrp1_e_ctl16 { __u32 offset; __u32 count; - __u16 buf[]; + __u16 buf[20]; +}; + +struct usrp1_e_ctl32 { + __u32 offset; + __u32 count; + __u32 buf[10]; }; // SPI interface @@ -48,9 +54,19 @@ struct usrp_e_spi { __u32 flags; }; +struct usrp_e_i2c { + __u8 addr; + __u32 len; + __u8 data[]; +}; + #define USRP_E_IOC_MAGIC 'u' -#define USRP_E_WRITE_CTL _IOW(USRP_E_IOC_MAGIC, 0x20, struct usrp1_e_ctl) -#define USRP_E_READ_CTL _IOWR(USRP_E_IOC_MAGIC, 0x21, struct usrp1_e_ctl) -#define USRP_E_SPI _IOW(USRP_E_IOC_MAGIC, 0x22, struct usrp_e_spi) +#define USRP_E_WRITE_CTL16 _IOW(USRP_E_IOC_MAGIC, 0x20, struct usrp1_e_ctl16) +#define USRP_E_READ_CTL16 _IOWR(USRP_E_IOC_MAGIC, 0x21, struct usrp1_e_ctl16) +#define USRP_E_WRITE_CTL32 _IOW(USRP_E_IOC_MAGIC, 0x22, struct usrp1_e_ctl32) +#define USRP_E_READ_CTL32 _IOWR(USRP_E_IOC_MAGIC, 0x23, struct usrp1_e_ctl32) +#define USRP_E_SPI _IOW(USRP_E_IOC_MAGIC, 0x24, struct usrp_e_spi) +#define USRP_E_I2C_READ _IOR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) +#define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) #endif -- 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') 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 28e5e0740a8fc3c7233a1bd5cc6bbc897c586da6 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 25 Mar 2010 17:42:36 +0000 Subject: Updates for header file change from usrp1_e.h to usrp_e.h. --- host/apps/omap_debug/fetch-module.sh | 4 +- host/apps/omap_debug/usrp-e-i2c.c | 8 ++-- host/apps/omap_debug/usrp-e-spi.c | 8 ++-- host/apps/omap_debug/usrp1_e.h | 72 ------------------------------------ host/apps/omap_debug/usrp_e.h | 72 ++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 host/apps/omap_debug/usrp1_e.h create mode 100644 host/apps/omap_debug/usrp_e.h (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-module.sh b/host/apps/omap_debug/fetch-module.sh index 101ea9aef..45cf1f052 100755 --- a/host/apps/omap_debug/fetch-module.sh +++ b/host/apps/omap_debug/fetch-module.sh @@ -1,3 +1,3 @@ -scp balister@192.168.1.167:src/git/kernel_usrp/drivers/misc/usrp1_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc -scp balister@192.168.1.167:src/git/kernel_usrp/include/linux/usrp1_e.h . +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 . sync diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c index dce1ae153..417d6d580 100644 --- a/host/apps/omap_debug/usrp-e-i2c.c +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -5,7 +5,7 @@ #include #include -#include "usrp1_e.h" +#include "usrp_e.h" // Usage: usrp_e_i2c w address data0 data1 data 2 .... // Usage: usrp_e_i2c r address count @@ -17,8 +17,8 @@ int main(int argc, char *argv[]) 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"); + printf("Usage: usrp_e_i2c w address data0 data1 data2 ...\n"); + printf("Usage: usrp_e_i2c r address count\n"); exit(-1); } @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) address = atoi(argv[2]); - fp = open("/dev/usrp1_e0", O_RDWR); + fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); if (direction) { diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index e10e72b80..1af47b172 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -4,9 +4,9 @@ #include #include -#include "usrp1_e.h" +#include "usrp_e.h" -// Usage: usrp1_e_spi w|rb slave data +// Usage: usrp_e_spi w|rb slave data int main(int argc, char *argv[]) { @@ -14,14 +14,14 @@ int main(int argc, char *argv[]) struct usrp_e_spi spi_dat; if (argc < 4) { - printf("Usage: usrp1_e_spi w|rb slave data\n"); + printf("Usage: usrp_e_spi w|rb slave data\n"); exit(-1); } slave = atoi(argv[2]); data = atoi(argv[3]); - fp = open("/dev/usrp1_e0", O_RDWR); + fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); spi_dat.slave = slave; diff --git a/host/apps/omap_debug/usrp1_e.h b/host/apps/omap_debug/usrp1_e.h deleted file mode 100644 index b34446b01..000000000 --- a/host/apps/omap_debug/usrp1_e.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2010 Ettus Research, LLC - * - * Written by Philip Balister - * - * This program 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 2 of the License, or - * (at your option) any later version. - */ - -#ifndef __USRP_E_H -#define __USRP_E_H - -#include -#include - -struct usrp1_e_ctl16 { - __u32 offset; - __u32 count; - __u16 buf[20]; -}; - -struct usrp1_e_ctl32 { - __u32 offset; - __u32 count; - __u32 buf[10]; -}; - -// SPI interface - -#define UE_SPI_TXONLY 0 -#define UE_SPI_TXRX 1 - -// Defines for spi ctrl register -#define UE_SPI_CTRL_ASS (1<<13) -#define UE_SPI_CTRL_IE (1<<12) -#define UE_SPI_CTRL_LSB (1<<11) -#define UE_SPI_CTRL_TXNEG (1<<10) -#define UE_SPI_CTRL_RXNEG (1<<9) -#define UE_SPI_CTRL_GO_BSY (1<<8) -#define UE_SPI_CTRL_CHAR_LEN_MASK 0x7f - -#define UE_SPI_PUSH_RISE 0 -#define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG -#define UE_SPI_LATCH_RISE 0 -#define UE_SPI_LATCH_FALL UE_SPI_CTRL_RXNEG - -struct usrp_e_spi { - __u8 readback; - __u32 slave; - __u32 data; - __u32 length; - __u32 flags; -}; - -struct usrp_e_i2c { - __u8 addr; - __u32 len; - __u8 data[]; -}; - -#define USRP_E_IOC_MAGIC 'u' -#define USRP_E_WRITE_CTL16 _IOW(USRP_E_IOC_MAGIC, 0x20, struct usrp1_e_ctl16) -#define USRP_E_READ_CTL16 _IOWR(USRP_E_IOC_MAGIC, 0x21, struct usrp1_e_ctl16) -#define USRP_E_WRITE_CTL32 _IOW(USRP_E_IOC_MAGIC, 0x22, struct usrp1_e_ctl32) -#define USRP_E_READ_CTL32 _IOWR(USRP_E_IOC_MAGIC, 0x23, struct usrp1_e_ctl32) -#define USRP_E_SPI _IOW(USRP_E_IOC_MAGIC, 0x24, struct usrp_e_spi) -#define USRP_E_I2C_READ _IOR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) -#define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) - -#endif diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h new file mode 100644 index 000000000..aa8ef3d57 --- /dev/null +++ b/host/apps/omap_debug/usrp_e.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2010 Ettus Research, LLC + * + * Written by Philip Balister + * + * This program 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 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __USRP_E_H +#define __USRP_E_H + +#include +#include + +struct usrp_e_ctl16 { + __u32 offset; + __u32 count; + __u16 buf[20]; +}; + +struct usrp_e_ctl32 { + __u32 offset; + __u32 count; + __u32 buf[10]; +}; + +// SPI interface + +#define UE_SPI_TXONLY 0 +#define UE_SPI_TXRX 1 + +// Defines for spi ctrl register +#define UE_SPI_CTRL_ASS (1<<13) +#define UE_SPI_CTRL_IE (1<<12) +#define UE_SPI_CTRL_LSB (1<<11) +#define UE_SPI_CTRL_TXNEG (1<<10) +#define UE_SPI_CTRL_RXNEG (1<<9) +#define UE_SPI_CTRL_GO_BSY (1<<8) +#define UE_SPI_CTRL_CHAR_LEN_MASK 0x7f + +#define UE_SPI_PUSH_RISE 0 +#define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG +#define UE_SPI_LATCH_RISE 0 +#define UE_SPI_LATCH_FALL UE_SPI_CTRL_RXNEG + +struct usrp_e_spi { + __u8 readback; + __u32 slave; + __u32 data; + __u32 length; + __u32 flags; +}; + +struct usrp_e_i2c { + __u8 addr; + __u32 len; + __u8 data[]; +}; + +#define USRP_E_IOC_MAGIC 'u' +#define USRP_E_WRITE_CTL16 _IOW(USRP_E_IOC_MAGIC, 0x20, struct usrp_e_ctl16) +#define USRP_E_READ_CTL16 _IOWR(USRP_E_IOC_MAGIC, 0x21, struct usrp_e_ctl16) +#define USRP_E_WRITE_CTL32 _IOW(USRP_E_IOC_MAGIC, 0x22, struct usrp_e_ctl32) +#define USRP_E_READ_CTL32 _IOWR(USRP_E_IOC_MAGIC, 0x23, struct usrp_e_ctl32) +#define USRP_E_SPI _IOW(USRP_E_IOC_MAGIC, 0x24, struct usrp_e_spi) +#define USRP_E_I2C_READ _IOR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) +#define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) + +#endif -- 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') 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') 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, 26 Mar 2010 19:04:18 +0000 Subject: Working version. --- host/apps/omap_debug/usrp-e-uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-uart.c b/host/apps/omap_debug/usrp-e-uart.c index 92f89f45c..239df9444 100644 --- a/host/apps/omap_debug/usrp-e-uart.c +++ b/host/apps/omap_debug/usrp-e-uart.c @@ -9,7 +9,7 @@ // Usage: usrp_e_uart -#define UART_WRITE_ADDR ((1<<6) + 16) +#define UART_WRITE_ADDR (0x80 + 12) int main(int argc, char *argv[]) { -- cgit v1.2.3 From 930755fce1e5d22a5ede0459dccd6c9501fc642c Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Mon, 29 Mar 2010 13:30:17 +0000 Subject: Minor fixes. --- host/apps/omap_debug/usrp-e-i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c index 417d6d580..19d64731b 100644 --- a/host/apps/omap_debug/usrp-e-i2c.c +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) printf("fp = %d\n", fp); if (direction) { - count = argc - 2; + count = argc - 3; } else { count = atoi(argv[3]); } @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) for (i=0; idata[i]); } - printf("/n"); + printf("\n"); } return 0; -- cgit v1.2.3 From 3e01c94fe0c690293f13a09666deb79fcb6af58c Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 1 Apr 2010 12:44:55 +0000 Subject: Spi word length is in bits, not bytes. --- host/apps/omap_debug/usrp-e-spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index 1af47b172..f7131bbe3 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) spi_dat.slave = slave; spi_dat.data = data; - spi_dat.length = 2; + spi_dat.length = 32; spi_dat.flags = 0; if (*argv[1] == 'r') { -- cgit v1.2.3 From 9b30d7293f93ec340c23448147c425c398c01db4 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 1 Apr 2010 19:27:59 +0000 Subject: Allow variable length spi messages. --- host/apps/omap_debug/usrp-e-spi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index f7131bbe3..de1409647 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -10,23 +10,24 @@ int main(int argc, char *argv[]) { - int fp, slave, data, ret; + int fp, slave, length, data, ret; struct usrp_e_spi spi_dat; - if (argc < 4) { - printf("Usage: usrp_e_spi w|rb slave data\n"); + if (argc < 5) { + printf("Usage: usrp_e_spi w|rb slave transfer_length data\n"); exit(-1); } slave = atoi(argv[2]); - data = atoi(argv[3]); + length = atoi(argv[3]); + data = atoi(argv[4]); fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); spi_dat.slave = slave; spi_dat.data = data; - spi_dat.length = 32; + spi_dat.length = length; spi_dat.flags = 0; if (*argv[1] == 'r') { -- cgit v1.2.3 From 80b2b928df6e3c1caf68dee199593a0af1cb91ae Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 2 Apr 2010 12:33:37 +0000 Subject: Handle 32 bit data to spi controller. --- host/apps/omap_debug/usrp-e-spi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index de1409647..f693d7db1 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -10,7 +10,8 @@ int main(int argc, char *argv[]) { - int fp, slave, length, data, ret; + int fp, slave, length, ret; + unsigned int data; struct usrp_e_spi spi_dat; if (argc < 5) { @@ -20,7 +21,9 @@ int main(int argc, char *argv[]) slave = atoi(argv[2]); length = atoi(argv[3]); - data = atoi(argv[4]); + data = atoll(argv[4]); + + printf("Data = %X\n", data); fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); -- cgit v1.2.3 From d8052db8e5614935241a4824a3f9711bfe34507d Mon Sep 17 00:00:00 2001 From: Philip Balister 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') 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 5d7a5e66c05290c5e3957457680313a2e427af08 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 2 Apr 2010 21:16:13 +0000 Subject: Don't need to use malloc to get the correct sized struct anymore. --- host/apps/omap_debug/usrp-e-ctl.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-ctl.c b/host/apps/omap_debug/usrp-e-ctl.c index 501a4870e..69c48ee6f 100644 --- a/host/apps/omap_debug/usrp-e-ctl.c +++ b/host/apps/omap_debug/usrp-e-ctl.c @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { int fp, i, cnt, ret; - struct usrp_e_ctl16 *ctl_data; + struct usrp_e_ctl16 ctl_data; if (argc < 4) { printf("Usage: usrp_e_ctl w|r offset number_of_values val1 val2 ....\n"); @@ -20,32 +20,28 @@ int main(int argc, char *argv[]) cnt = atoi(argv[3]); - 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 usrp_e_ctl16)); + ctl_data.offset = atoi(argv[2]); + ctl_data.count = cnt; 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]); + ctl_data.buf[i] = atoi(argv[4+i]); - ret = ioctl(fp, USRP_E_WRITE_CTL16, 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, USRP_E_READ_CTL16, 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++) { + for (i=0; ibuf[i]); + printf(" %5d", ctl_data.buf[i]); } printf("\n"); } -- cgit v1.2.3 From d4e9f3629021736b1330b4a9f22ee60336a53e0e Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 2 Apr 2010 21:58:55 +0000 Subject: Update to use register definitions from header file. --- host/apps/omap_debug/usrp-e-button.c | 2 +- host/apps/omap_debug/usrp-e-led.c | 2 +- host/apps/omap_debug/usrp-e-uart.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-button.c b/host/apps/omap_debug/usrp-e-button.c index fca501833..f13291491 100644 --- a/host/apps/omap_debug/usrp-e-button.c +++ b/host/apps/omap_debug/usrp-e-button.c @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); - d.offset = 6; + d.offset = UE_REG_MISC_SW; d.count = 1; do { diff --git a/host/apps/omap_debug/usrp-e-led.c b/host/apps/omap_debug/usrp-e-led.c index 159251c8a..d1b6c8996 100644 --- a/host/apps/omap_debug/usrp-e-led.c +++ b/host/apps/omap_debug/usrp-e-led.c @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); - d.offset = 4; + d.offset = UE_REG_MISC_BASE; d.count = 1; while (1) { diff --git a/host/apps/omap_debug/usrp-e-uart.c b/host/apps/omap_debug/usrp-e-uart.c index 239df9444..b0b14626a 100644 --- a/host/apps/omap_debug/usrp-e-uart.c +++ b/host/apps/omap_debug/usrp-e-uart.c @@ -6,10 +6,10 @@ #include #include "usrp_e.h" +#include "usrp_e_regs.hpp" // Usage: usrp_e_uart -#define UART_WRITE_ADDR (0x80 + 12) int main(int argc, char *argv[]) { @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) printf("fp = %d\n", fp); for (i=0; i Date: Sat, 3 Apr 2010 14:54:54 +0000 Subject: Yes, I am an idiot. --- host/apps/omap_debug/usrp-e-uart | Bin 7143 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 host/apps/omap_debug/usrp-e-uart (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-uart b/host/apps/omap_debug/usrp-e-uart deleted file mode 100755 index 5781f0db2..000000000 Binary files a/host/apps/omap_debug/usrp-e-uart and /dev/null differ -- cgit v1.2.3 From 317fc2d16288dcc621761a88119f279e1cfeafd6 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Sat, 3 Apr 2010 14:55:16 +0000 Subject: Add ability to change uart baud rate. (works) --- host/apps/omap_debug/usrp-e-uart.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-uart.c b/host/apps/omap_debug/usrp-e-uart.c index b0b14626a..2956c407f 100644 --- a/host/apps/omap_debug/usrp-e-uart.c +++ b/host/apps/omap_debug/usrp-e-uart.c @@ -16,15 +16,26 @@ int main(int argc, char *argv[]) int fp, i, ret; struct usrp_e_ctl16 d; char *str = argv[1]; + __u16 clkdiv; if (argc < 2) { - printf("Usage: usrp_e_uart n"); + printf("Usage: usrp_e_uart \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 == 3) { + clkdiv = atoi(argv[2]); + d.offset = UE_REG_UART_CLKDIV; + d.count = 1; + d.buf[0] = clkdiv; + ret = ioctl(fp, USRP_E_WRITE_CTL16, &d); + } + for (i=0; i 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') 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') 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') 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 b59c54e334dfc1c6ab7da81c62038444f93efe61 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 13 Apr 2010 16:37:22 +0000 Subject: Fix typo. --- host/apps/omap_debug/fetch-kernel.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh index f32666adf..a3cddb339 100755 --- a/host/apps/omap_debug/fetch-kernel.sh +++ b/host/apps/omap_debug/fetch-kernel.sh @@ -2,5 +2,6 @@ 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 +fi sync -- cgit v1.2.3 From 839d9c39542db356ad1b955e3a3d9e7aabb071bc Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 16 Apr 2010 12:58:42 +0000 Subject: pulled in master and got usrp-e code compiling --- host/apps/omap_debug/fetch-kernel.sh | 2 +- host/apps/omap_debug/fetch-module.sh | 2 +- host/lib/CMakeLists.txt | 3 +- host/lib/usrp/usrp_e/dboard_iface.cpp | 218 ++++++++++++++++++++++++++++++ host/lib/usrp/usrp_e/dboard_impl.cpp | 6 +- host/lib/usrp/usrp_e/dboard_interface.cpp | 212 ----------------------------- host/lib/usrp/usrp_e/mboard_impl.cpp | 4 +- host/lib/usrp/usrp_e/usrp_e_iface.cpp | 135 ++++++++++++++++++ host/lib/usrp/usrp_e/usrp_e_iface.hpp | 97 +++++++++++++ host/lib/usrp/usrp_e/usrp_e_impl.cpp | 89 ++---------- host/lib/usrp/usrp_e/usrp_e_impl.hpp | 26 +--- 11 files changed, 478 insertions(+), 316 deletions(-) create mode 100644 host/lib/usrp/usrp_e/dboard_iface.cpp delete mode 100644 host/lib/usrp/usrp_e/dboard_interface.cpp create mode 100644 host/lib/usrp/usrp_e/usrp_e_iface.cpp create mode 100644 host/lib/usrp/usrp_e/usrp_e_iface.hpp (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh index a3cddb339..f25f139fa 100755 --- a/host/apps/omap_debug/fetch-kernel.sh +++ b/host/apps/omap_debug/fetch-kernel.sh @@ -1,4 +1,4 @@ -if [ $GHQ]; then +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 diff --git a/host/apps/omap_debug/fetch-module.sh b/host/apps/omap_debug/fetch-module.sh index 52fbd4040..0957ad7b4 100755 --- a/host/apps/omap_debug/fetch-module.sh +++ b/host/apps/omap_debug/fetch-module.sh @@ -1,5 +1,5 @@ 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 + scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.34-rc1/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 diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index dfcb88ec9..ff7f2c0df 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -138,11 +138,12 @@ IF(HAVE_USRP_E_REQUIRED_HEADERS) MESSAGE(STATUS " Building usrp-e support.") LIST(APPEND libuhd_sources usrp/usrp_e/dboard_impl.cpp - usrp/usrp_e/dboard_interface.cpp + usrp/usrp_e/dboard_iface.cpp usrp/usrp_e/dsp_impl.cpp usrp/usrp_e/fpga-downloader.cc usrp/usrp_e/mboard_impl.cpp usrp/usrp_e/usrp_e_impl.cpp + usrp/usrp_e/usrp_e_iface.cpp ) ELSE(HAVE_USRP_E_REQUIRED_HEADERS) MESSAGE(STATUS " Skipping usrp-e support.") diff --git a/host/lib/usrp/usrp_e/dboard_iface.cpp b/host/lib/usrp/usrp_e/dboard_iface.cpp new file mode 100644 index 000000000..12e8fe206 --- /dev/null +++ b/host/lib/usrp/usrp_e/dboard_iface.cpp @@ -0,0 +1,218 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see . +// + +#include "usrp_e_iface.hpp" +#include "usrp_e_regs.hpp" +#include +#include +#include +#include +#include //i2c and spi constants + +using namespace uhd::usrp; + +class usrp_e_dboard_iface : public dboard_iface{ +public: + usrp_e_dboard_iface(usrp_e_iface::sptr iface); + ~usrp_e_dboard_iface(void); + + void write_aux_dac(unit_t, int, float); + float read_aux_adc(unit_t, int); + + void set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); + void set_gpio_ddr(unit_t, boost::uint16_t); + boost::uint16_t read_gpio(unit_t); + + void write_i2c(int, const byte_vector_t &); + byte_vector_t read_i2c(int, size_t); + + void write_spi( + unit_t unit, + const spi_config_t &config, + boost::uint32_t data, + size_t num_bits + ); + + boost::uint32_t read_write_spi( + unit_t unit, + const spi_config_t &config, + boost::uint32_t data, + size_t num_bits + ); + + double get_clock_rate(unit_t); + void set_clock_enabled(unit_t, bool); + +private: + usrp_e_iface::sptr _iface; +}; + +/*********************************************************************** + * Make Function + **********************************************************************/ +dboard_iface::sptr make_usrp_e_dboard_iface(usrp_e_iface::sptr iface){ + return dboard_iface::sptr(new usrp_e_dboard_iface(iface)); +} + +/*********************************************************************** + * Structors + **********************************************************************/ +usrp_e_dboard_iface::usrp_e_dboard_iface(usrp_e_iface::sptr iface){ + _iface = iface; +} + +usrp_e_dboard_iface::~usrp_e_dboard_iface(void){ + /* NOP */ +} + +/*********************************************************************** + * Clock Rates + **********************************************************************/ +double usrp_e_dboard_iface::get_clock_rate(unit_t){ + throw std::runtime_error("not implemented"); +} + +void usrp_e_dboard_iface::set_clock_enabled(unit_t, bool){ + throw std::runtime_error("not implemented"); +} + +/*********************************************************************** + * GPIO + **********************************************************************/ +void usrp_e_dboard_iface::set_gpio_ddr(unit_t bank, boost::uint16_t value){ + //define mapping of gpio bank to register address + static const uhd::dict bank_to_addr = boost::assign::map_list_of + (UNIT_RX, UE_REG_GPIO_RX_DDR) + (UNIT_TX, UE_REG_GPIO_TX_DDR) + ; + _iface->poke16(bank_to_addr[bank], value); +} + +boost::uint16_t usrp_e_dboard_iface::read_gpio(unit_t bank){ + //define mapping of gpio bank to register address + static const uhd::dict bank_to_addr = boost::assign::map_list_of + (UNIT_RX, UE_REG_GPIO_RX_IO) + (UNIT_TX, UE_REG_GPIO_TX_IO) + ; + return _iface->peek16(bank_to_addr[bank]); +} + +void usrp_e_dboard_iface::set_atr_reg(unit_t bank, atr_reg_t atr, boost::uint16_t value){ + //define mapping of bank to atr regs to register address + static const uhd::dict< + unit_t, uhd::dict + > bank_to_atr_to_addr = boost::assign::map_list_of + (UNIT_RX, boost::assign::map_list_of + (ATR_REG_IDLE, UE_REG_ATR_IDLE_RXSIDE) + (ATR_REG_TX_ONLY, UE_REG_ATR_INTX_RXSIDE) + (ATR_REG_RX_ONLY, UE_REG_ATR_INRX_RXSIDE) + (ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_RXSIDE) + ) + (UNIT_TX, boost::assign::map_list_of + (ATR_REG_IDLE, UE_REG_ATR_IDLE_TXSIDE) + (ATR_REG_TX_ONLY, UE_REG_ATR_INTX_TXSIDE) + (ATR_REG_RX_ONLY, UE_REG_ATR_INRX_TXSIDE) + (ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_TXSIDE) + ) + ; + _iface->poke16(bank_to_atr_to_addr[bank][atr], value); +} + +/*********************************************************************** + * SPI + **********************************************************************/ +/*! + * Static function to convert a unit type to a spi slave device number. + * \param unit the dboard interface unit type enum + * \return the slave device number + */ +static boost::uint32_t unit_to_otw_spi_dev(dboard_iface::unit_t unit){ + switch(unit){ + case dboard_iface::UNIT_TX: return UE_SPI_CTRL_TXNEG; + case dboard_iface::UNIT_RX: return UE_SPI_CTRL_RXNEG; + } + throw std::invalid_argument("unknown unit type"); +} + +void usrp_e_dboard_iface::write_spi( + unit_t unit, + const spi_config_t &config, + boost::uint32_t data, + size_t num_bits +){ + _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, false /*no rb*/); +} + +boost::uint32_t usrp_e_dboard_iface::read_write_spi( + unit_t unit, + const spi_config_t &config, + boost::uint32_t data, + size_t num_bits +){ + return _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, true /*rb*/); +} + +/*********************************************************************** + * I2C + **********************************************************************/ +static const size_t max_i2c_data_bytes = 10; + +void usrp_e_dboard_iface::write_i2c(int i2c_addr, const byte_vector_t &buf){ + //allocate some memory for this transaction + ASSERT_THROW(buf.size() <= max_i2c_data_bytes); + boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes]; + + //load the data struct + usrp_e_i2c &data = reinterpret_cast(mem); + data.addr = i2c_addr; + data.len = buf.size(); + std::copy(buf.begin(), buf.end(), data.data); + + //call the spi ioctl + _iface->ioctl(USRP_E_I2C_WRITE, &data); +} + +dboard_iface::byte_vector_t usrp_e_dboard_iface::read_i2c(int i2c_addr, size_t num_bytes){ + //allocate some memory for this transaction + ASSERT_THROW(num_bytes <= max_i2c_data_bytes); + boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes]; + + //load the data struct + usrp_e_i2c &data = reinterpret_cast(mem); + data.addr = i2c_addr; + data.len = num_bytes; + + //call the spi ioctl + _iface->ioctl(USRP_E_I2C_READ, &data); + + //unload the data + byte_vector_t ret(data.len); + ASSERT_THROW(ret.size() == num_bytes); + std::copy(data.data, data.data+ret.size(), ret.begin()); + return ret; +} + +/*********************************************************************** + * Aux DAX/ADC + **********************************************************************/ +void usrp_e_dboard_iface::write_aux_dac(dboard_iface::unit_t unit, int which, float value){ + throw std::runtime_error("not implemented"); +} + +float usrp_e_dboard_iface::read_aux_adc(dboard_iface::unit_t unit, int which){ + throw std::runtime_error("not implemented"); +} diff --git a/host/lib/usrp/usrp_e/dboard_impl.cpp b/host/lib/usrp/usrp_e/dboard_impl.cpp index 7c87361e0..df0f1d9a9 100644 --- a/host/lib/usrp/usrp_e/dboard_impl.cpp +++ b/host/lib/usrp/usrp_e/dboard_impl.cpp @@ -28,11 +28,11 @@ void usrp_e_impl::dboard_init(void){ dboard_id_t tx_dboard_id = dboard_id::NONE; //create a new dboard interface and manager - dboard_interface::sptr dboard_interface( - make_usrp_e_dboard_interface(this) + dboard_iface::sptr dboard_iface( + make_usrp_e_dboard_iface(_iface) ); _dboard_manager = dboard_manager::make( - rx_dboard_id, tx_dboard_id, dboard_interface + rx_dboard_id, tx_dboard_id, dboard_iface ); //setup the dboard proxies diff --git a/host/lib/usrp/usrp_e/dboard_interface.cpp b/host/lib/usrp/usrp_e/dboard_interface.cpp deleted file mode 100644 index 47948f3d0..000000000 --- a/host/lib/usrp/usrp_e/dboard_interface.cpp +++ /dev/null @@ -1,212 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 this program. If not, see . -// - -#include "usrp_e_impl.hpp" -#include "usrp_e_regs.hpp" -#include -#include -#include -#include //std::copy -#include - -using namespace uhd::usrp; - -class usrp_e_dboard_interface : public dboard_interface{ -public: - usrp_e_dboard_interface(usrp_e_impl *impl); - ~usrp_e_dboard_interface(void); - - void write_aux_dac(unit_type_t, int, int); - int read_aux_adc(unit_type_t, int); - - void set_atr_reg(gpio_bank_t, atr_reg_t, boost::uint16_t); - void set_gpio_ddr(gpio_bank_t, boost::uint16_t); - boost::uint16_t read_gpio(gpio_bank_t); - - void write_i2c(int, const byte_vector_t &); - byte_vector_t read_i2c(int, size_t); - - double get_rx_clock_rate(void); - double get_tx_clock_rate(void); - -private: - byte_vector_t transact_spi( - spi_dev_t dev, - spi_edge_t edge, - const byte_vector_t &buf, - bool readback - ); - - usrp_e_impl *_impl; -}; - -/*********************************************************************** - * Make Function - **********************************************************************/ -dboard_interface::sptr make_usrp_e_dboard_interface(usrp_e_impl *impl){ - return dboard_interface::sptr(new usrp_e_dboard_interface(impl)); -} - -/*********************************************************************** - * Structors - **********************************************************************/ -usrp_e_dboard_interface::usrp_e_dboard_interface(usrp_e_impl *impl){ - _impl = impl; -} - -usrp_e_dboard_interface::~usrp_e_dboard_interface(void){ - /* NOP */ -} - -/*********************************************************************** - * Clock Rates - **********************************************************************/ -double usrp_e_dboard_interface::get_rx_clock_rate(void){ - throw std::runtime_error("not implemented"); -} - -double usrp_e_dboard_interface::get_tx_clock_rate(void){ - throw std::runtime_error("not implemented"); -} - -/*********************************************************************** - * GPIO - **********************************************************************/ -void usrp_e_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value){ - //define mapping of gpio bank to register address - static const uhd::dict bank_to_addr = boost::assign::map_list_of - (GPIO_BANK_RX, UE_REG_GPIO_RX_DDR) - (GPIO_BANK_TX, UE_REG_GPIO_TX_DDR) - ; - _impl->poke16(bank_to_addr[bank], value); -} - -boost::uint16_t usrp_e_dboard_interface::read_gpio(gpio_bank_t bank){ - //define mapping of gpio bank to register address - static const uhd::dict bank_to_addr = boost::assign::map_list_of - (GPIO_BANK_RX, UE_REG_GPIO_RX_IO) - (GPIO_BANK_TX, UE_REG_GPIO_TX_IO) - ; - return _impl->peek16(bank_to_addr[bank]); -} - -void usrp_e_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t atr, boost::uint16_t value){ - //define mapping of bank to atr regs to register address - static const uhd::dict< - gpio_bank_t, uhd::dict - > bank_to_atr_to_addr = boost::assign::map_list_of - (GPIO_BANK_RX, boost::assign::map_list_of - (ATR_REG_IDLE, UE_REG_ATR_IDLE_RXSIDE) - (ATR_REG_TX_ONLY, UE_REG_ATR_INTX_RXSIDE) - (ATR_REG_RX_ONLY, UE_REG_ATR_INRX_RXSIDE) - (ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_RXSIDE) - ) - (GPIO_BANK_TX, boost::assign::map_list_of - (ATR_REG_IDLE, UE_REG_ATR_IDLE_TXSIDE) - (ATR_REG_TX_ONLY, UE_REG_ATR_INTX_TXSIDE) - (ATR_REG_RX_ONLY, UE_REG_ATR_INRX_TXSIDE) - (ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_TXSIDE) - ) - ; - _impl->poke16(bank_to_atr_to_addr[bank][atr], value); -} - -/*********************************************************************** - * SPI - **********************************************************************/ -dboard_interface::byte_vector_t usrp_e_dboard_interface::transact_spi( - spi_dev_t dev, - spi_edge_t edge, - const byte_vector_t &buf, - bool readback -){ - //load data struct - usrp_e_spi data; - data.readback = (readback)? UE_SPI_TXRX : UE_SPI_TXONLY; - data.slave = (dev == SPI_DEV_RX)? UE_SPI_CTRL_RXNEG : UE_SPI_CTRL_TXNEG; - data.length = buf.size() * 8; //bytes to bits - boost::uint8_t *data_bytes = reinterpret_cast(&data.data); - - //load the data - ASSERT_THROW(buf.size() <= sizeof(data.data)); - std::copy(buf.begin(), buf.end(), data_bytes); - - //load the flags - data.flags = 0; - data.flags |= (edge == SPI_EDGE_RISE)? UE_SPI_LATCH_RISE : UE_SPI_LATCH_FALL; - data.flags |= (edge == SPI_EDGE_RISE)? UE_SPI_PUSH_RISE : UE_SPI_PUSH_FALL; - - //call the spi ioctl - _impl->ioctl(USRP_E_SPI, &data); - - //unload the data - byte_vector_t ret(data.length/8); //bits to bytes - ASSERT_THROW(ret.size() <= sizeof(data.data)); - std::copy(data_bytes, data_bytes+ret.size(), ret.begin()); - return ret; -} - -/*********************************************************************** - * I2C - **********************************************************************/ -static const size_t max_i2c_data_bytes = 10; - -void usrp_e_dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){ - //allocate some memory for this transaction - ASSERT_THROW(buf.size() <= max_i2c_data_bytes); - boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes]; - - //load the data struct - usrp_e_i2c &data = reinterpret_cast(mem); - data.addr = i2c_addr; - data.len = buf.size(); - std::copy(buf.begin(), buf.end(), data.data); - - //call the spi ioctl - _impl->ioctl(USRP_E_I2C_WRITE, &data); -} - -dboard_interface::byte_vector_t usrp_e_dboard_interface::read_i2c(int i2c_addr, size_t num_bytes){ - //allocate some memory for this transaction - ASSERT_THROW(num_bytes <= max_i2c_data_bytes); - boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes]; - - //load the data struct - usrp_e_i2c &data = reinterpret_cast(mem); - data.addr = i2c_addr; - data.len = num_bytes; - - //call the spi ioctl - _impl->ioctl(USRP_E_I2C_READ, &data); - - //unload the data - byte_vector_t ret(data.len); - ASSERT_THROW(ret.size() == num_bytes); - std::copy(data.data, data.data+ret.size(), ret.begin()); - return ret; -} - -/*********************************************************************** - * Aux DAX/ADC - **********************************************************************/ -void usrp_e_dboard_interface::write_aux_dac(dboard_interface::unit_type_t unit, int which, int value){ - throw std::runtime_error("not implemented"); -} - -int usrp_e_dboard_interface::read_aux_adc(dboard_interface::unit_type_t unit, int which){ - throw std::runtime_error("not implemented"); -} diff --git a/host/lib/usrp/usrp_e/mboard_impl.cpp b/host/lib/usrp/usrp_e/mboard_impl.cpp index ba15c394d..2d225c6ea 100644 --- a/host/lib/usrp/usrp_e/mboard_impl.cpp +++ b/host/lib/usrp/usrp_e/mboard_impl.cpp @@ -75,8 +75,8 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){ val = prop_names_t(1, ""); //vector of size 1 with empty string return; - case MBOARD_PROP_CLOCK_RATE: - //val = TODO probably remove this property + case MBOARD_PROP_STREAM_CMD: + //val = TODO return; case MBOARD_PROP_RX_DSP: diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.cpp b/host/lib/usrp/usrp_e/usrp_e_iface.cpp new file mode 100644 index 000000000..d4c988211 --- /dev/null +++ b/host/lib/usrp/usrp_e/usrp_e_iface.cpp @@ -0,0 +1,135 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see . +// + +#include "usrp_e_iface.hpp" +#include //ioctl +#include //ioctl structures and constants +#include +#include + +class usrp_e_iface_impl : public usrp_e_iface{ +public: + + /******************************************************************* + * Structors + ******************************************************************/ + usrp_e_iface_impl(int node_fd){ + _node_fd = node_fd; + } + + ~usrp_e_iface_impl(void){ + /* NOP */ + } + + /******************************************************************* + * IOCTL: provides the communication base for all other calls + ******************************************************************/ + void ioctl(int request, void *mem){ + if (::ioctl(_node_fd, request, mem) < 0){ + throw std::runtime_error(str( + boost::format("ioctl failed with request %d") % request + )); + } + } + + /******************************************************************* + * Peek and Poke + ******************************************************************/ + void poke32(boost::uint32_t addr, boost::uint32_t value){ + //load the data struct + usrp_e_ctl32 data; + data.offset = addr; + data.count = 1; + data.buf[0] = value; + + //call the ioctl + this->ioctl(USRP_E_WRITE_CTL32, &data); + } + + void poke16(boost::uint32_t addr, boost::uint16_t value){ + //load the data struct + usrp_e_ctl16 data; + data.offset = addr; + data.count = 1; + data.buf[0] = value; + + //call the ioctl + this->ioctl(USRP_E_WRITE_CTL16, &data); + } + + boost::uint32_t peek32(boost::uint32_t addr){ + //load the data struct + usrp_e_ctl32 data; + data.offset = addr; + data.count = 1; + + //call the ioctl + this->ioctl(USRP_E_READ_CTL32, &data); + + return data.buf[0]; + } + + boost::uint16_t peek16(boost::uint32_t addr){ + //load the data struct + usrp_e_ctl16 data; + data.offset = addr; + data.count = 1; + + //call the ioctl + this->ioctl(USRP_E_READ_CTL16, &data); + + return data.buf[0]; + } + + /******************************************************************* + * SPI + ******************************************************************/ + boost::uint32_t transact_spi( + int which_slave, + const uhd::usrp::spi_config_t &config, + boost::uint32_t bits, + size_t num_bits, + bool readback + ){ + //load data struct + usrp_e_spi data; + data.readback = (readback)? UE_SPI_TXRX : UE_SPI_TXONLY; + data.slave = which_slave; + data.length = num_bits; + data.data = bits; + + //load the flags + data.flags = 0; + data.flags |= (config.miso_edge == uhd::usrp::spi_config_t::EDGE_RISE)? UE_SPI_LATCH_RISE : UE_SPI_LATCH_FALL; + data.flags |= (config.mosi_edge == uhd::usrp::spi_config_t::EDGE_RISE)? UE_SPI_PUSH_FALL : UE_SPI_PUSH_RISE; + + //call the spi ioctl + this->ioctl(USRP_E_SPI, &data); + + //unload the data + return data.data; + } + +private: int _node_fd; +}; + +/*********************************************************************** + * Public Make Function + **********************************************************************/ +usrp_e_iface::sptr usrp_e_iface::make(int node_fd){ + return sptr(new usrp_e_iface_impl(node_fd)); +} diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.hpp b/host/lib/usrp/usrp_e/usrp_e_iface.hpp new file mode 100644 index 000000000..4fc3bb33d --- /dev/null +++ b/host/lib/usrp/usrp_e/usrp_e_iface.hpp @@ -0,0 +1,97 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 this program. If not, see . +// + +#ifndef INCLUDED_USRP_E_IFACE_HPP +#define INCLUDED_USRP_E_IFACE_HPP + +#include +#include //spi config +#include +#include +#include + +/*! + * The usrp-e interface class: + * Provides a set of functions to implementation layer. + * Including spi, peek, poke, control... + */ +class usrp_e_iface : boost::noncopyable{ +public: + typedef boost::shared_ptr sptr; + + /*! + * Make a new usrp-e interface with the control transport. + * \param node_fd the file descriptor for the kernel module node + * \return a new usrp-e interface object + */ + static sptr make(int node_fd); + + /*! + * Perform an ioctl call on the device node file descriptor. + * This will throw when the internal ioctl call fails. + * \param request the control word + * \param mem pointer to some memory + */ + virtual void ioctl(int request, void *mem) = 0; + + /*! + * Write a register (32 bits) + * \param addr the address + * \param data the 32bit data + */ + virtual void poke32(boost::uint32_t addr, boost::uint32_t data) = 0; + + /*! + * Read a register (32 bits) + * \param addr the address + * \return the 32bit data + */ + virtual boost::uint32_t peek32(boost::uint32_t addr) = 0; + + /*! + * Write a register (16 bits) + * \param addr the address + * \param data the 16bit data + */ + virtual void poke16(boost::uint32_t addr, boost::uint16_t data) = 0; + + /*! + * Read a register (16 bits) + * \param addr the address + * \return the 16bit data + */ + virtual boost::uint16_t peek16(boost::uint32_t addr) = 0; + + /*! + * Perform an spi transaction. + * \param which_slave the slave device number + * \param config spi config args + * \param data the bits to write + * \param num_bits how many bits in data + * \param readback true to readback a value + * \return spi data if readback set + */ + virtual boost::uint32_t transact_spi( + int which_slave, + const uhd::usrp::spi_config_t &config, + boost::uint32_t data, + size_t num_bits, + bool readback + ) = 0; +}; + +#endif /* INCLUDED_USRP_E_IFACE_HPP */ diff --git a/host/lib/usrp/usrp_e/usrp_e_impl.cpp b/host/lib/usrp/usrp_e/usrp_e_impl.cpp index 3fefd6787..4d08210e2 100644 --- a/host/lib/usrp/usrp_e/usrp_e_impl.cpp +++ b/host/lib/usrp/usrp_e/usrp_e_impl.cpp @@ -22,8 +22,6 @@ #include #include #include //open -#include //ioctl -#include using namespace uhd; using namespace uhd::usrp; @@ -43,30 +41,24 @@ static std::string abs_path(const std::string &file_path){ /*********************************************************************** * Discovery **********************************************************************/ -device_addrs_t usrp_e::find(const device_addr_t &device_addr){ +device_addrs_t usrp_e::find(const device_addr_t &hint){ device_addrs_t usrp_e_addrs; - //if a node was provided, use it and only it - if (device_addr.has_key("node")){ - if (not fs::exists(device_addr["node"])) return usrp_e_addrs; + //device node not provided, assume its 0 + if (not hint.has_key("node")){ + device_addr_t new_addr = hint; + new_addr["node"] = "/dev/usrp_e0"; + return usrp_e::find(new_addr); + } + + //use the given device node name + if (fs::exists(hint["node"])){ device_addr_t new_addr; new_addr["name"] = "USRP-E"; - new_addr["node"] = abs_path(device_addr["node"]); + new_addr["node"] = abs_path(hint["node"]); usrp_e_addrs.push_back(new_addr); } - //otherwise look for a few nodes at small indexes - else{ - for(size_t i = 0; i < 5; i++){ - std::string node = str(boost::format("/dev/usrp1_e%d") % i); - if (not fs::exists(node)) continue; - device_addr_t new_addr; - new_addr["name"] = "USRP-E"; - new_addr["node"] = abs_path(node); - usrp_e_addrs.push_back(new_addr); - } - } - return usrp_e_addrs; } @@ -88,6 +80,8 @@ usrp_e_impl::usrp_e_impl(const std::string &node){ )); } + _iface = usrp_e_iface::make(_node_fd); + //initialize the mboard mboard_init(); @@ -104,63 +98,6 @@ usrp_e_impl::~usrp_e_impl(void){ ::close(_node_fd); } -/*********************************************************************** - * Misc Methods - **********************************************************************/ -void usrp_e_impl::ioctl(int request, void *mem){ - if (::ioctl(_node_fd, request, mem) < 0){ - throw std::runtime_error(str( - boost::format("ioctl failed with request %d") % request - )); - } -} - -void usrp_e_impl::poke32(boost::uint32_t addr, boost::uint32_t value){ - //load the data struct - usrp_e_ctl32 data; - data.offset = addr; - data.count = 1; - data.buf[0] = value; - - //call the ioctl - this->ioctl(USRP_E_WRITE_CTL32, &data); -} - -void usrp_e_impl::poke16(boost::uint32_t addr, boost::uint16_t value){ - //load the data struct - usrp_e_ctl16 data; - data.offset = addr; - data.count = 1; - data.buf[0] = value; - - //call the ioctl - this->ioctl(USRP_E_WRITE_CTL16, &data); -} - -boost::uint32_t usrp_e_impl::peek32(boost::uint32_t addr){ - //load the data struct - usrp_e_ctl32 data; - data.offset = addr; - data.count = 1; - - //call the ioctl - this->ioctl(USRP_E_READ_CTL32, &data); - - return data.buf[0]; -} - -boost::uint16_t usrp_e_impl::peek16(boost::uint32_t addr){ - //load the data struct - usrp_e_ctl16 data; - data.offset = addr; - data.count = 1; - - //call the ioctl - this->ioctl(USRP_E_READ_CTL16, &data); - - return data.buf[0]; -} - /*********************************************************************** * Device Get **********************************************************************/ diff --git a/host/lib/usrp/usrp_e/usrp_e_impl.hpp b/host/lib/usrp/usrp_e/usrp_e_impl.hpp index 21023ae55..08ace2ffb 100644 --- a/host/lib/usrp/usrp_e/usrp_e_impl.hpp +++ b/host/lib/usrp/usrp_e/usrp_e_impl.hpp @@ -15,21 +15,20 @@ // along with this program. If not, see . // -#include +#include "usrp_e_iface.hpp" #include +#include #include #ifndef INCLUDED_USRP_E_IMPL_HPP #define INCLUDED_USRP_E_IMPL_HPP -class usrp_e_impl; // dummy class declaration - /*! - * Make a usrp_e dboard interface. - * \param impl a pointer to the usrp_e impl object + * Make a usrp-e dboard interface. + * \param iface the usrp-e interface object * \return a sptr to a new dboard interface */ -uhd::usrp::dboard_interface::sptr make_usrp_e_dboard_interface(usrp_e_impl *impl); +uhd::usrp::dboard_iface::sptr make_usrp_e_dboard_iface(usrp_e_iface::sptr iface); /*! * Simple wax obj proxy class: @@ -84,22 +83,9 @@ public: size_t send(const boost::asio::const_buffer &, const uhd::tx_metadata_t &, const uhd::io_type_t &); size_t recv(const boost::asio::mutable_buffer &, uhd::rx_metadata_t &, const uhd::io_type_t &); - /*! - * Perform an ioctl call on the device node file descriptor. - * This will throw when the internal ioctl call fails. - * \param request the control word - * \param mem pointer to some memory - */ - void ioctl(int request, void *mem); - - //peekers and pokers - void poke32(boost::uint32_t addr, boost::uint32_t value); - void poke16(boost::uint32_t addr, boost::uint16_t value); - boost::uint32_t peek32(boost::uint32_t addr); - boost::uint16_t peek16(boost::uint32_t addr); - private: static const size_t _max_num_samples = 2048/sizeof(boost::uint32_t); + usrp_e_iface::sptr _iface; int _node_fd; uhd::clock_config_t _clock_config; -- cgit v1.2.3 From de668d9924b6176e8296dee5929aab1e37374d8b Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 20 Apr 2010 21:46:51 +0000 Subject: Add scripts to read and write board id info into usrp e id eeprom --- host/apps/omap_debug/read_board_id.sh | 10 ++++++++++ host/apps/omap_debug/write_board_id.sh | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100755 host/apps/omap_debug/read_board_id.sh create mode 100755 host/apps/omap_debug/write_board_id.sh (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/read_board_id.sh b/host/apps/omap_debug/read_board_id.sh new file mode 100755 index 000000000..96081f219 --- /dev/null +++ b/host/apps/omap_debug/read_board_id.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +i2cget -y 3 0x51 0x00 b +i2cget -y 3 0x51 0x01 b +i2cget -y 3 0x51 0x02 b +i2cget -y 3 0x51 0x03 b +i2cget -y 3 0x51 0x04 b +i2cget -y 3 0x51 0x05 b + + diff --git a/host/apps/omap_debug/write_board_id.sh b/host/apps/omap_debug/write_board_id.sh new file mode 100755 index 000000000..139394a4c --- /dev/null +++ b/host/apps/omap_debug/write_board_id.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +i2cset -y 3 0x51 0x00 0x00 +i2cset -y 3 0x51 0x01 0x03 +i2cset -y 3 0x51 0x02 0x00 +i2cset -y 3 0x51 0x03 0x00 +i2cset -y 3 0x51 0x04 0x01 +i2cset -y 3 0x51 0x05 0x00 + + -- cgit v1.2.3 From bbfb3a7a9554c06fd54c3c572eb9a716627cc50c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 20 Apr 2010 11:06:28 +0000 Subject: Fix script to write board id eeprom. --- host/apps/omap_debug/write_board_id.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/write_board_id.sh b/host/apps/omap_debug/write_board_id.sh index 139394a4c..067269c64 100755 --- a/host/apps/omap_debug/write_board_id.sh +++ b/host/apps/omap_debug/write_board_id.sh @@ -3,8 +3,8 @@ i2cset -y 3 0x51 0x00 0x00 i2cset -y 3 0x51 0x01 0x03 i2cset -y 3 0x51 0x02 0x00 -i2cset -y 3 0x51 0x03 0x00 -i2cset -y 3 0x51 0x04 0x01 +i2cset -y 3 0x51 0x03 0x01 +i2cset -y 3 0x51 0x04 0x00 i2cset -y 3 0x51 0x05 0x00 -- cgit v1.2.3 From 0e11c5ddbcee0ca6afaf06920764a05d046df358 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 20 Apr 2010 11:07:05 +0000 Subject: Fix silly typo in script. --- host/apps/omap_debug/fetch-u-boot.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-u-boot.sh b/host/apps/omap_debug/fetch-u-boot.sh index a2a488fb2..5309364b8 100755 --- a/host/apps/omap_debug/fetch-u-boot.sh +++ b/host/apps/omap_debug/fetch-u-boot.sh @@ -2,5 +2,6 @@ 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/ +fi sync -- cgit v1.2.3 From dfd5bed2b32131cd398a5daae184cec81488b5de Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 20 Apr 2010 13:33:32 +0000 Subject: Always put new bin file in /home/root. --- host/apps/omap_debug/fetch-bin.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-bin.sh b/host/apps/omap_debug/fetch-bin.sh index d1502f95c..019ddaaf2 100755 --- a/host/apps/omap_debug/fetch-bin.sh +++ b/host/apps/omap_debug/fetch-bin.sh @@ -1,6 +1,6 @@ if [ $GHQ ]; then - scp $GHQ_USER@astro:/workspace/usrp1-e-dev/u1e.bin . + scp $GHQ_USER@astro:/workspace/usrp1-e-dev/u1e.bin /home/root else - scp -P 8822 balister@192.168.1.10:src/git/fpgapriv/usrp2/top/u1e/build/u1e.bin . + scp -P 8822 balister@192.168.1.10:src/git/fpgapriv/usrp2/top/u1e/build/u1e.bin /home/root fi sync -- cgit v1.2.3 From 29a3b01fb48d1c10f489103b9012b14be6f1553d Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 20 Apr 2010 13:34:24 +0000 Subject: usrp-e-i2c always uses hex arguments. --- host/apps/omap_debug/usrp-e-i2c.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c index 19d64731b..c8fcc3f98 100644 --- a/host/apps/omap_debug/usrp-e-i2c.c +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -12,13 +12,14 @@ int main(int argc, char *argv[]) { - int fp, ret, i; + int fp, ret, i, tmp; struct usrp_e_i2c *i2c_msg; int direction, address, count; if (argc < 3) { - printf("Usage: usrp_e_i2c w address data0 data1 data2 ...\n"); - printf("Usage: usrp_e_i2c r address count\n"); + printf("Usage: usrp-e-i2c w address data0 data1 data2 ...\n"); + printf("Usage: usrp-e-i2c r address count\n"); + printf("All addresses and data in hex.\n"); exit(-1); } @@ -30,7 +31,8 @@ int main(int argc, char *argv[]) return -1; } - address = atoi(argv[2]); + sscanf(argv[2], "%X", &address); + printf("Address = %X\n", address); fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); @@ -38,8 +40,9 @@ int main(int argc, char *argv[]) if (direction) { count = argc - 3; } else { - count = atoi(argv[3]); + sscanf(argv[3], "%X", &count); } + printf("Count = %X\n", count); i2c_msg = malloc(sizeof(i2c_msg) + count * sizeof(char)); @@ -50,7 +53,8 @@ int main(int argc, char *argv[]) // Write for (i=0; idata[i] = atoi(argv[3+i]); + sscanf(argv[3+i], "%X", &tmp); + i2c_msg->data[i] = tmp; } ret = ioctl(fp, USRP_E_I2C_WRITE, i2c_msg); -- cgit v1.2.3 From c05fc634407741ce202cccc0781e937897c51361 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 20 Apr 2010 13:35:00 +0000 Subject: usrp-e-spi: change active edges around. --- host/apps/omap_debug/usrp-e-spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index f693d7db1..caa36b3f1 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) spi_dat.slave = slave; spi_dat.data = data; spi_dat.length = length; - spi_dat.flags = 0; + spi_dat.flags = UE_SPI_PUSH_FALL | UE_SPI_LATCH_RISE; if (*argv[1] == 'r') { spi_dat.readback = 1; -- cgit v1.2.3 From 4e4d8556a43f7f054e760b66749c034aa5741a7f Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 20 Apr 2010 15:53:07 +0000 Subject: Initialize data array to help show when reads fail. Report return value from ioctl --- host/apps/omap_debug/usrp-e-i2c.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c index c8fcc3f98..575430f84 100644 --- a/host/apps/omap_debug/usrp-e-i2c.c +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -49,6 +49,10 @@ int main(int argc, char *argv[]) i2c_msg->addr = address; i2c_msg->len = count; + for (i = 0; i < count; i++) { + i2c_msg->data[i] = i; + } + if (direction) { // Write @@ -63,6 +67,7 @@ int main(int argc, char *argv[]) // Read ret = ioctl(fp, USRP_E_I2C_READ, i2c_msg); + printf("Return value from i2c_read ioctl: %d\n", ret); printf("Ioctl: %d Data read :", ret); for (i=0; i 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') 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 eb2f38d4af5345a64cd1feb92fa5cb44433d037b Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 22 Apr 2010 15:41:42 +0000 Subject: Update transfer test program to use usrp_transfer_frame struct. --- host/apps/omap_debug/usrp-e-rw.c | 64 +++++++++++++++++++++++++++++----------- host/apps/omap_debug/usrp_e.h | 13 ++++++++ 2 files changed, 60 insertions(+), 17 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c index 5607166b0..5fd73e9b6 100644 --- a/host/apps/omap_debug/usrp-e-rw.c +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -4,11 +4,16 @@ #include #include #include +#include +#include "usrp_e.h" + +#define PKT_DATA_LENGTH 30 +// max length #define PKT_DATA_LENGTH 1016 struct pkt { int checksum; int seq_num; - short data[1020]; + short data[PKT_DATA_LENGTH]; }; static int fp; @@ -20,7 +25,7 @@ static int calc_checksum(struct pkt *p) i = 0; sum = 0; - for (i=0; i<1020; i++) + for (i=0; idata[i]; sum += p->seq_num; @@ -31,23 +36,35 @@ static int calc_checksum(struct pkt *p) static void *read_thread(void *threadid) { int cnt, prev_seq_num; - struct pkt rx_data; + struct usrp_transfer_frame *rx_data; + struct pkt *p; printf("Greetings from the reading thread!\n"); + rx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + 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)); + prev_seq_num = 0; while (1) { - cnt = read(fp, &rx_data, 2048); - if (rx_data.seq_num != prev_seq_num + 1) - printf("Sequence number fail, current = %d, previous = %d\n", - rx_data.seq_num, prev_seq_num); - prev_seq_num = rx_data.seq_num; + 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 (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(&rx_data) != rx_data.checksum) - printf("Checksum fail packet = %d, expected = %d\n", - calc_checksum(&rx_data), rx_data.checksum); + if (calc_checksum(p) != p->checksum) + printf("Checksum fail packet = %X, expected = %X\n", + calc_checksum(p), p->checksum); + printf("\n"); } } @@ -55,20 +72,31 @@ static void *read_thread(void *threadid) static void *write_thread(void *threadid) { int seq_number, i, cnt; - struct pkt tx_data; + struct usrp_transfer_frame *tx_data; + struct pkt *p; printf("Greetings from the write thread!\n"); - for (i=0; i<1020; i++) - tx_data.data[i] = random() >> 16; + tx_data = malloc(sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); + 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)); + + for (i=0; idata[i] = random() >> 16; + p->data[i] = i; + + tx_data->flags = 0xdeadbeef; + tx_data->len = 8 + PKT_DATA_LENGTH * 2; seq_number = 1; while (1) { - tx_data.seq_num = seq_number++; - tx_data.checksum = calc_checksum(&tx_data); - cnt = write(fp, &tx_data, 2048); + p->seq_num = seq_number++; + p->checksum = calc_checksum(p); + cnt = write(fp, tx_data, 2048); + sleep(1); } } @@ -86,6 +114,8 @@ int main(int argc, char *argv[]) exit(-1); } + sleep(1); + if (pthread_create(&tx, NULL, write_thread, (void *) t)) { printf("Failed to create tx thread\n"); exit(-1); diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h index aa8ef3d57..48a3201cb 100644 --- a/host/apps/omap_debug/usrp_e.h +++ b/host/apps/omap_debug/usrp_e.h @@ -69,4 +69,17 @@ struct usrp_e_i2c { #define USRP_E_I2C_READ _IOR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) #define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) +// Data transfer frame definition + +struct usrp_transfer_frame { + __u32 flags; + __u32 len; + __u8 buf[]; +}; + +struct ring_buffer_entry { + unsigned long dma_addr; + struct usrp_transfer_frame *frame_addr; +}; + #endif -- 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') 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 7953156249776ce7d45bb2a24c8ac88edb644c64 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 27 Apr 2010 08:17:46 +0000 Subject: Send only required number of bytes. Do it for longer. --- host/apps/omap_debug/usrp-e-rw-random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-rw-random.c b/host/apps/omap_debug/usrp-e-rw-random.c index 67d6ca803..c6a838067 100644 --- a/host/apps/omap_debug/usrp-e-rw-random.c +++ b/host/apps/omap_debug/usrp-e-rw-random.c @@ -114,7 +114,7 @@ static void *write_thread(void *threadid) p->len = randN(1013) + 1; p->checksum = calc_checksum(p); tx_data->len = 12 + p->len * 2; - cnt = write(fp, tx_data, 2048); + cnt = write(fp, tx_data, tx_data->len + 8); } sleep(random() >> 31); } @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) exit(-1); } - sleep(10000); + sleep(1000000000); printf("Done sleeping\n"); } -- 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') 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') 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 2de179640be9d897a63f7423f6e04399394abb8b Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 29 Apr 2010 05:26:29 +0000 Subject: Add script to setup board id info in eeprom. --- host/apps/omap_debug/setup-board-id-eeprom.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 host/apps/omap_debug/setup-board-id-eeprom.sh (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/setup-board-id-eeprom.sh b/host/apps/omap_debug/setup-board-id-eeprom.sh new file mode 100755 index 000000000..4dba1cce5 --- /dev/null +++ b/host/apps/omap_debug/setup-board-id-eeprom.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +i2cset -y 3 0x51 0x00 0x00 +i2cset -y 3 0x51 0x01 0x03 +i2cset -y 3 0x51 0x02 0x00 +i2cset -y 3 0x51 0x03 0x01 +i2cset -y 3 0x51 0x04 0x01 +i2cset -y 3 0x51 0x05 0x00 +i2cset -y 3 0x51 0x06 0x00 + +i2cget -y 3 0x51 0 b +i2cget -y 3 0x51 1 b +i2cget -y 3 0x51 2 b +i2cget -y 3 0x51 3 b +i2cget -y 3 0x51 4 b +i2cget -y 3 0x51 5 b +i2cget -y 3 0x51 6 b -- cgit v1.2.3 From e526627270cf2846d0cba0d30a5947621c545be1 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Sun, 2 May 2010 08:52:36 +0000 Subject: Update IP address for my home desktop. Change module version to 2.6.33. --- host/apps/omap_debug/fetch-kernel.sh | 2 +- host/apps/omap_debug/fetch-module.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh index f25f139fa..ce420f3d2 100755 --- a/host/apps/omap_debug/fetch-kernel.sh +++ b/host/apps/omap_debug/fetch-kernel.sh @@ -1,7 +1,7 @@ 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 + scp balister@192.168.1.10:src/git/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage fi sync diff --git a/host/apps/omap_debug/fetch-module.sh b/host/apps/omap_debug/fetch-module.sh index 0957ad7b4..e23289050 100755 --- a/host/apps/omap_debug/fetch-module.sh +++ b/host/apps/omap_debug/fetch-module.sh @@ -1,6 +1,6 @@ if [ $GHQ ]; then - scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.34-rc1/kernel/drivers/misc + scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33/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 + scp balister@192.168.1.10:src/git/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc fi sync -- cgit v1.2.3 From 084459a16892c393af08b674ea1df7777e47423a Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Sun, 2 May 2010 08:53:32 +0000 Subject: Change overrun indication. New progress indicator. Turn on RT scheduler for user space. --- host/apps/omap_debug/usrp-e-fpga-rw.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-fpga-rw.c b/host/apps/omap_debug/usrp-e-fpga-rw.c index f3fa1499a..6b585913e 100644 --- a/host/apps/omap_debug/usrp-e-fpga-rw.c +++ b/host/apps/omap_debug/usrp-e-fpga-rw.c @@ -69,7 +69,7 @@ static void *read_thread(void *threadid) } if (rx_data->flags & RB_OVERRUN) - printf("RX ring buffer overrun occurred at packet %d\n", rx_pkt_cnt); + printf("O"); // for (i = 0; i < 10; i++) // printf(" %d", p->data[i]); @@ -93,7 +93,7 @@ static void *read_thread(void *threadid) static void *write_thread(void *threadid) { - int seq_number, i, cnt; + int seq_number, i, cnt, tx_pkt_cnt; struct usrp_transfer_frame *tx_data; struct pkt *p; @@ -115,8 +115,25 @@ static void *write_thread(void *threadid) 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); @@ -134,6 +151,9 @@ int main(int argc, char *argv[]) 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]); @@ -163,6 +183,8 @@ int main(int argc, char *argv[]) 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"); -- cgit v1.2.3 From a8f284d03d061a2fb9a6daf6e6bc2493daccd5d4 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Mon, 3 May 2010 12:44:41 +0000 Subject: Add a hack to work around a driver race. Remove when teh driver is fixed. --- host/apps/omap_debug/usrp-e-spi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index caa36b3f1..264231731 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -28,6 +28,8 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); + sleep(1); // HACK HACK + spi_dat.slave = slave; spi_dat.data = data; spi_dat.length = length; -- cgit v1.2.3 From 4c4e0f48534a735cc7f5780f4483871264a880ad Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Mon, 3 May 2010 12:51:02 +0000 Subject: Add hack to work around driver race. --- host/apps/omap_debug/usrp-e-i2c.c | 3 +++ host/apps/omap_debug/usrp-e-spi.c | 1 + 2 files changed, 4 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c index 575430f84..57a3f4739 100644 --- a/host/apps/omap_debug/usrp-e-i2c.c +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,8 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); + sleep(1); + if (direction) { count = argc - 3; } else { diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index 264231731..47ee9369c 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include -- cgit v1.2.3 From 31d4e1362cd222c688a3bfd3b528a2de51a4b03b Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Mon, 3 May 2010 22:36:24 +0000 Subject: Update path to put module in. --- host/apps/omap_debug/fetch-module.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fetch-module.sh b/host/apps/omap_debug/fetch-module.sh index e23289050..ec28989bd 100755 --- a/host/apps/omap_debug/fetch-module.sh +++ b/host/apps/omap_debug/fetch-module.sh @@ -1,6 +1,6 @@ if [ $GHQ ]; then scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33/kernel/drivers/misc else - scp balister@192.168.1.10:src/git/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc + scp balister@192.168.1.10:src/git/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33/kernel/drivers/misc fi sync -- cgit v1.2.3 From 5583cb575e45441c98480f7beecb48437842fc5c Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Mon, 3 May 2010 22:36:56 +0000 Subject: Spi data returned in struct now. --- host/apps/omap_debug/usrp-e-spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index 47ee9369c..2fcc39b9b 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) if (*argv[1] == 'r') { spi_dat.readback = 1; ret = ioctl(fp, USRP_E_SPI, &spi_dat); - printf("Data returned = %d\n", ret); + printf("Ioctl returns: %d, Data returned = %d\n", ret, spi_dat.data); } else { spi_dat.readback = 0; ioctl(fp, USRP_E_SPI, &spi_dat); -- cgit v1.2.3 From 6929d0cba40a2bf4f4b3b81819bb915bdbb16488 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 5 May 2010 21:12:43 +0000 Subject: Remove workaround for driver hang. --- host/apps/omap_debug/usrp-e-i2c.c | 2 -- host/apps/omap_debug/usrp-e-spi.c | 2 -- host/apps/omap_debug/usrp_e.h | 4 ++-- 3 files changed, 2 insertions(+), 6 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c index 57a3f4739..615dc557b 100644 --- a/host/apps/omap_debug/usrp-e-i2c.c +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -38,8 +38,6 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); - sleep(1); - if (direction) { count = argc - 3; } else { diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index 2fcc39b9b..d2c38e524 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -29,8 +29,6 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); - sleep(1); // HACK HACK - spi_dat.slave = slave; spi_dat.data = data; spi_dat.length = length; diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h index d4132021f..0b582f59b 100644 --- a/host/apps/omap_debug/usrp_e.h +++ b/host/apps/omap_debug/usrp_e.h @@ -66,8 +66,8 @@ struct usrp_e_i2c { #define USRP_E_READ_CTL16 _IOWR(USRP_E_IOC_MAGIC, 0x21, struct usrp_e_ctl16) #define USRP_E_WRITE_CTL32 _IOW(USRP_E_IOC_MAGIC, 0x22, struct usrp_e_ctl32) #define USRP_E_READ_CTL32 _IOWR(USRP_E_IOC_MAGIC, 0x23, struct usrp_e_ctl32) -#define USRP_E_SPI _IOW(USRP_E_IOC_MAGIC, 0x24, struct usrp_e_spi) -#define USRP_E_I2C_READ _IOR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) +#define USRP_E_SPI _IOWR(USRP_E_IOC_MAGIC, 0x24, struct usrp_e_spi) +#define USRP_E_I2C_READ _IOWR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) #define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) // Data transfer frame definition -- cgit v1.2.3 From b47920906bd1b0480bbcd8427b2d703889cb78e3 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 7 May 2010 19:23:58 +0000 Subject: Print an error and exit if open fails for some programs. --- host/apps/omap_debug/usrp-e-debug-pins.c | 4 ++++ host/apps/omap_debug/usrp-e-i2c.c | 6 ++++++ host/apps/omap_debug/usrp-e-spi.c | 7 +++++++ 3 files changed, 17 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-debug-pins.c b/host/apps/omap_debug/usrp-e-debug-pins.c index d4e3f5223..d18bbf990 100644 --- a/host/apps/omap_debug/usrp-e-debug-pins.c +++ b/host/apps/omap_debug/usrp-e-debug-pins.c @@ -46,6 +46,10 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); + if (fp < 0) { + perror("Open failed"); + return -1; + } if (strcmp(argv[1], "0") == 0) { printf("Selected 0 based on %s\n", argv[1]); diff --git a/host/apps/omap_debug/usrp-e-i2c.c b/host/apps/omap_debug/usrp-e-i2c.c index 615dc557b..da8709ae1 100644 --- a/host/apps/omap_debug/usrp-e-i2c.c +++ b/host/apps/omap_debug/usrp-e-i2c.c @@ -37,6 +37,12 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); + if (fp < 0) { + perror("Open failed"); + return -1; + } + +// sleep(1); if (direction) { count = argc - 3; diff --git a/host/apps/omap_debug/usrp-e-spi.c b/host/apps/omap_debug/usrp-e-spi.c index d2c38e524..c353c409b 100644 --- a/host/apps/omap_debug/usrp-e-spi.c +++ b/host/apps/omap_debug/usrp-e-spi.c @@ -28,6 +28,13 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); + if (fp < 0) { + perror("Open failed"); + return -1; + } + +// sleep(1); + spi_dat.slave = slave; spi_dat.data = data; -- 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') 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 6c306995a733622a0b0c3fb8c13c23dc8301d926 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 7 May 2010 16:14:28 -0400 Subject: Update usrp_e.h file from kernel header. --- host/apps/omap_debug/usrp_e.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h index 0b582f59b..fd74e6e9e 100644 --- a/host/apps/omap_debug/usrp_e.h +++ b/host/apps/omap_debug/usrp_e.h @@ -34,13 +34,8 @@ struct usrp_e_ctl32 { #define UE_SPI_TXRX 1 // Defines for spi ctrl register -#define UE_SPI_CTRL_ASS (1<<13) -#define UE_SPI_CTRL_IE (1<<12) -#define UE_SPI_CTRL_LSB (1<<11) #define UE_SPI_CTRL_TXNEG (1<<10) #define UE_SPI_CTRL_RXNEG (1<<9) -#define UE_SPI_CTRL_GO_BSY (1<<8) -#define UE_SPI_CTRL_CHAR_LEN_MASK 0x7f #define UE_SPI_PUSH_RISE 0 #define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG -- 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') 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 9251c115b302b7b5773e2e16bbd7a7dfd6c18b74 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 12 May 2010 14:11:10 -0400 Subject: Add calculation for data trasnfer rates. --- host/apps/omap_debug/usrp-e-crc-rw.c | 46 +++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index 1f23c8d54..f99654781 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -44,6 +44,8 @@ static void *read_thread(void *threadid) int i; unsigned long crc; unsigned int rx_crc; + unsigned long bytes_transfered, elapsed_seconds; + struct timeval start_time, finish_time; printf("Greetings from the reading thread!\n"); @@ -51,7 +53,10 @@ static void *read_thread(void *threadid) rx_data = malloc(2048); rx_pkt_cnt = 0; - + + bytes_transfered = 0; + gettimeofday(&start_time, NULL); + while (1) { cnt = read(fp, rx_data, 2048); @@ -81,7 +86,20 @@ static void *read_thread(void *threadid) printf("CRC Error, sent: %d, rx: %d\n", rx_crc, (crc & 0xFFFFFFFF)); } - + + bytes_transfered += rx_data->len; + + if (bytes_transfered > (100 * 1000000)) { + gettimeofday(&finish_time, NULL); + elapsed_seconds = start_time.tv_sec - finish_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; + } } } @@ -91,12 +109,16 @@ static void *write_thread(void *threadid) int tx_len; unsigned long crc; 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(2048); + bytes_transfered = 0; + gettimeofday(&start_time, NULL); + while (1) { tx_pkt_cnt++; @@ -115,6 +137,8 @@ static void *write_thread(void *threadid) } tx_len = 2048 - sizeof(struct usrp_transfer_frame) - sizeof(int); + tx_data->len = tx_len + sizeof(int); + crc = 0xFFFFFFFF; for (i = 0; i < tx_len; i++) { tx_data->buf[i] = rand() & 0xFF; @@ -128,6 +152,22 @@ static void *write_thread(void *threadid) 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 = start_time.tv_sec - finish_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); } } -- cgit v1.2.3 From 89d6cb12a03153934b68d51e69bfdb3b9af43872 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 13 May 2010 18:25:36 +0000 Subject: Print a . for every packet received. --- host/apps/omap_debug/usrp-e-rw-random.c | 2 ++ host/apps/omap_debug/usrp-e-rw.c | 3 +++ 2 files changed, 5 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-rw-random.c b/host/apps/omap_debug/usrp-e-rw-random.c index c6a838067..43f1571cb 100644 --- a/host/apps/omap_debug/usrp-e-rw-random.c +++ b/host/apps/omap_debug/usrp-e-rw-random.c @@ -76,6 +76,8 @@ static void *read_thread(void *threadid) if (calc_checksum(p) != p->checksum) printf("Checksum fail packet = %d, expected = %d\n", calc_checksum(p), p->checksum); + printf("."); + fflush(stdout); // printf("\n"); } diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c index edfcea92a..7fba8cd2a 100644 --- a/host/apps/omap_debug/usrp-e-rw.c +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -68,6 +68,9 @@ 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("."); + fflush(stdout); // printf("\n"); } -- cgit v1.2.3 From 41928cd9ff513f1e6d753e02a74db15bda4b1ba8 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 13 May 2010 15:51:28 -0400 Subject: Change to 24 bit transfers. --- host/apps/omap_debug/clkgen-config.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/clkgen-config.cc b/host/apps/omap_debug/clkgen-config.cc index c21f54a60..70c63c6e8 100644 --- a/host/apps/omap_debug/clkgen-config.cc +++ b/host/apps/omap_debug/clkgen-config.cc @@ -239,7 +239,7 @@ spidev::spidev(std::string fname) int ret; int mode = 0; int speed = 12000000; - int bits = 32; + int bits = 24; fd = open(fname.c_str(), O_RDWR); @@ -264,7 +264,7 @@ void spidev::send(char *buf, char *rbuf, unsigned int nbytes) tr.len = nbytes; tr.delay_usecs = 0; tr.speed_hz = 12000000; - tr.bits_per_word = 32; + tr.bits_per_word = 24; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); -- cgit v1.2.3 From d4a75cef3ed64a305b8c4ef3001ed34c9d47d287 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 13 May 2010 17:46:53 -0400 Subject: Connect enable to the correct gpio. --- host/apps/omap_debug/clkgen-config.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/clkgen-config.cc b/host/apps/omap_debug/clkgen-config.cc index 70c63c6e8..85371c5d1 100644 --- a/host/apps/omap_debug/clkgen-config.cc +++ b/host/apps/omap_debug/clkgen-config.cc @@ -117,7 +117,7 @@ static const unsigned int config_data[] = { }; -const unsigned int CLKGEN_SELECT = 145; +const unsigned int CLKGEN_SELECT = 127; enum gpio_direction {IN, OUT}; -- cgit v1.2.3 From bb3c5d65561bbd720085d8c0bac2ac5cb978773e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 13 May 2010 22:49:42 +0000 Subject: got clock gen config working and tested --- host/apps/omap_debug/clkgen-config.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/clkgen-config.cc b/host/apps/omap_debug/clkgen-config.cc index 85371c5d1..e8279b4ae 100644 --- a/host/apps/omap_debug/clkgen-config.cc +++ b/host/apps/omap_debug/clkgen-config.cc @@ -50,6 +50,7 @@ static const unsigned int config_data[] = { 0x001704, 0x001807, 0x001900, + //0x001a00,//for debug 0x001a32, 0x001b12, 0x001c44, @@ -117,7 +118,7 @@ static const unsigned int config_data[] = { }; -const unsigned int CLKGEN_SELECT = 127; +const unsigned int CLKGEN_SELECT = 145; enum gpio_direction {IN, OUT}; @@ -238,7 +239,7 @@ spidev::spidev(std::string fname) { int ret; int mode = 0; - int speed = 12000000; + int speed = 12000; int bits = 24; fd = open(fname.c_str(), O_RDWR); @@ -277,9 +278,10 @@ static void send_config_to_clkgen(gpio &chip_select, const unsigned int data[], for (unsigned int i = 0; i < data_size; i++) { - chip_select.set_value(1); - spi.send((char *)&data[i], (char *)&rbuf, 4); + std::cout << "sending " << std::hex << data[i] << std::endl; chip_select.set_value(0); + spi.send((char *)&data[i], (char *)&rbuf, 4); + chip_select.set_value(1); }; } -- cgit v1.2.3 From 4d82cabe938b398bc42cab3d316983d2bbe40d06 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 14 May 2010 10:05:54 -0400 Subject: Update test program to reflect what is in the FPGA image. --- host/apps/omap_debug/usrp-e-crc-rw.c | 41 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index f99654781..e32cf2c59 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -177,43 +177,42 @@ 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 }; + int read, write; - if (argc < 4) { - printf("%s t|w|rw decimation data_size\n", argv[0]); + if (argc < 2) { + printf("%s r|w|rw tx_data_size\n", argv[0]); return -1; } - decimation = atoi(argv[2]); - packet_data_length = atoi(argv[3]); + packet_data_length = atoi(argv[2]); - fp = open("/dev/usrp_e0", O_RDWR); - printf("fp = %d\n", fp); + if (strcmp(argv[1], "r") == 0) { + read = 1; + write = 0; + } - 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)); + if (strcmp(argv[1], "w") == 0) { + read = 0; + write = 1; + } - fpga_config_flag |= decimation; + if (strcmp(argv[1], "rw") == 0) { + read = 1; + write = 1; + } - d.offset = 14; - d.count = 1; - d.buf[0] = fpga_config_flag; - ioctl(fp, USRP_E_WRITE_CTL16, &d); + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); 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 (read) { if (pthread_create(&rx, NULL, read_thread, (void *) t)) { printf("Failed to create rx thread\n"); exit(-1); @@ -222,7 +221,7 @@ int main(int argc, char *argv[]) sleep(1); - if (fpga_config_flag & (1 << 15)) { + if (write) { if (pthread_create(&tx, NULL, write_thread, (void *) t)) { printf("Failed to create tx thread\n"); exit(-1); -- cgit v1.2.3 From 7d0a98fc33c17457c9f4cd8e03eddb0d559457f0 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 18 May 2010 10:26:21 -0400 Subject: Revert "Update test program to reflect what is in the FPGA image." This reverts commit 4d82cabe938b398bc42cab3d316983d2bbe40d06. Now sure where I got the idea this image did not contain the rate setting code. --- host/apps/omap_debug/usrp-e-crc-rw.c | 41 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index e32cf2c59..f99654781 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -177,42 +177,43 @@ 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 }; - int read, write; - if (argc < 2) { - printf("%s r|w|rw tx_data_size\n", argv[0]); + if (argc < 4) { + printf("%s t|w|rw decimation data_size\n", argv[0]); return -1; } - packet_data_length = atoi(argv[2]); + decimation = atoi(argv[2]); + packet_data_length = atoi(argv[3]); - if (strcmp(argv[1], "r") == 0) { - read = 1; - write = 0; - } + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); - if (strcmp(argv[1], "w") == 0) { - read = 0; - write = 1; - } + 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)); - if (strcmp(argv[1], "rw") == 0) { - read = 1; - write = 1; - } + fpga_config_flag |= decimation; - fp = open("/dev/usrp_e0", O_RDWR); - printf("fp = %d\n", fp); + 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 (read) { + if (fpga_config_flag & (1 << 14)) { if (pthread_create(&rx, NULL, read_thread, (void *) t)) { printf("Failed to create rx thread\n"); exit(-1); @@ -221,7 +222,7 @@ int main(int argc, char *argv[]) sleep(1); - if (write) { + if (fpga_config_flag & (1 << 15)) { if (pthread_create(&tx, NULL, write_thread, (void *) t)) { printf("Failed to create tx thread\n"); exit(-1); -- cgit v1.2.3 From 3689cdd36c43656edc93cfee25d3bee1837f8bbd Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 18 May 2010 14:27:57 +0000 Subject: Remove rand for now. Fix bug in data rate calculation. --- host/apps/omap_debug/usrp-e-crc-rw.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index f99654781..b3f8ccc90 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -114,6 +114,7 @@ static void *write_thread(void *threadid) printf("Greetings from the write thread!\n"); + tx_pkt_cnt = 0; tx_data = malloc(2048); bytes_transfered = 0; @@ -141,7 +142,7 @@ static void *write_thread(void *threadid) crc = 0xFFFFFFFF; for (i = 0; i < tx_len; i++) { - tx_data->buf[i] = rand() & 0xFF; + tx_data->buf[i] = i & 0xFF; crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ tx_data->buf[i]) & 0xFF]; @@ -158,8 +159,9 @@ static void *write_thread(void *threadid) if (bytes_transfered > (100 * 1000000)) { gettimeofday(&finish_time, NULL); - elapsed_seconds = start_time.tv_sec - finish_time.tv_sec; + elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; + printf("%d bytes transfered in %d seconds.\n", bytes_transfered, elapsed_seconds); printf("TX data transfer rate = %f K Bps\n", (float) bytes_transfered / (float) elapsed_seconds / 1000); -- cgit v1.2.3 From b5dfe74e991d240f0e666dfd521726ec61128eb8 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 18 May 2010 13:56:57 -0400 Subject: Revert "Revert "Update test program to reflect what is in the FPGA image."" This reverts commit 7d0a98fc33c17457c9f4cd8e03eddb0d559457f0. Must make filenames more different. --- host/apps/omap_debug/usrp-e-crc-rw.c | 41 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index b3f8ccc90..d47dfef5e 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -179,43 +179,42 @@ 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 }; + int read, write; - if (argc < 4) { - printf("%s t|w|rw decimation data_size\n", argv[0]); + if (argc < 2) { + printf("%s r|w|rw tx_data_size\n", argv[0]); return -1; } - decimation = atoi(argv[2]); - packet_data_length = atoi(argv[3]); + packet_data_length = atoi(argv[2]); - fp = open("/dev/usrp_e0", O_RDWR); - printf("fp = %d\n", fp); + if (strcmp(argv[1], "r") == 0) { + read = 1; + write = 0; + } - 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)); + if (strcmp(argv[1], "w") == 0) { + read = 0; + write = 1; + } - fpga_config_flag |= decimation; + if (strcmp(argv[1], "rw") == 0) { + read = 1; + write = 1; + } - d.offset = 14; - d.count = 1; - d.buf[0] = fpga_config_flag; - ioctl(fp, USRP_E_WRITE_CTL16, &d); + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); 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 (read) { if (pthread_create(&rx, NULL, read_thread, (void *) t)) { printf("Failed to create rx thread\n"); exit(-1); @@ -224,7 +223,7 @@ int main(int argc, char *argv[]) sleep(1); - if (fpga_config_flag & (1 << 15)) { + if (write) { if (pthread_create(&tx, NULL, write_thread, (void *) t)) { printf("Failed to create tx thread\n"); exit(-1); -- cgit v1.2.3 From e62fd331f37f532e63bdc302236a53dc2e2021e9 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 18 May 2010 17:58:39 +0000 Subject: Comment out progress indicators. --- host/apps/omap_debug/usrp-e-crc-rw.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index d47dfef5e..cd95761a2 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -64,13 +64,15 @@ static void *read_thread(void *threadid) 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"); @@ -91,7 +93,7 @@ static void *read_thread(void *threadid) if (bytes_transfered > (100 * 1000000)) { gettimeofday(&finish_time, NULL); - elapsed_seconds = start_time.tv_sec - finish_time.tv_sec; + 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); @@ -123,6 +125,8 @@ static void *write_thread(void *threadid) while (1) { tx_pkt_cnt++; + +#if 0 if (tx_pkt_cnt == 512) { printf("."); fflush(stdout); @@ -136,6 +140,7 @@ static void *write_thread(void *threadid) fflush(stdout); tx_pkt_cnt = 0; } +#endif tx_len = 2048 - sizeof(struct usrp_transfer_frame) - sizeof(int); tx_data->len = tx_len + sizeof(int); @@ -161,7 +166,6 @@ static void *write_thread(void *threadid) gettimeofday(&finish_time, NULL); elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; - printf("%d bytes transfered in %d seconds.\n", bytes_transfered, elapsed_seconds); printf("TX data transfer rate = %f K Bps\n", (float) bytes_transfered / (float) elapsed_seconds / 1000); -- cgit v1.2.3 From ad01832ca5a52d70a5f26de9c45868626b850785 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 19 May 2010 15:01:23 +0000 Subject: Keep repo in sync with my churn ... --- host/apps/omap_debug/usrp-e-crc-rw.c | 3 ++- host/apps/omap_debug/usrp-e-rw.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index cd95761a2..e1d9bf0db 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -211,12 +211,13 @@ int main(int argc, char *argv[]) write = 1; } + printf("About to open /dev/usrp_e0"); fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); sleep(1); // in case the kernel threads need time to start. FIXME if so - sched_setscheduler(0, SCHED_RR, &s); +// sched_setscheduler(0, SCHED_RR, &s); if (read) { if (pthread_create(&rx, NULL, read_thread, (void *) t)) { diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c index 7fba8cd2a..1b12fa889 100644 --- a/host/apps/omap_debug/usrp-e-rw.c +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -35,7 +35,7 @@ static int calc_checksum(struct pkt *p) static void *read_thread(void *threadid) { - int cnt, prev_seq_num; + int cnt, prev_seq_num, pkt_count; struct usrp_transfer_frame *rx_data; struct pkt *p; @@ -50,6 +50,7 @@ static void *read_thread(void *threadid) printf("sizeof rx data = %d\n", sizeof(struct usrp_transfer_frame) + sizeof(struct pkt)); prev_seq_num = 0; + pkt_count = 0; while (1) { @@ -60,14 +61,17 @@ static void *read_thread(void *threadid) // 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\n", - p->seq_num, prev_seq_num); + 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\n", - calc_checksum(p), p->checksum); + printf("Checksum fail packet = %X, expected = %X, pkt_count = %d\n", + calc_checksum(p), p->checksum, pkt_count); printf("."); fflush(stdout); @@ -108,7 +112,7 @@ static void *write_thread(void *threadid) cnt = write(fp, tx_data, 2048); if (cnt < 0) printf("Error returned from write: %d\n", cnt); - // sleep(1); + sleep(1); } } -- 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') 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 d6fc36cb7aa39cbe3f6dde1b6bc4606a2e686279 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 19 May 2010 17:41:11 +0000 Subject: Fix initialization bug. --- host/apps/omap_debug/usrp-e-timed.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-timed.c b/host/apps/omap_debug/usrp-e-timed.c index 69e6c07ca..cfc70f724 100644 --- a/host/apps/omap_debug/usrp-e-timed.c +++ b/host/apps/omap_debug/usrp-e-timed.c @@ -45,6 +45,9 @@ static void *read_thread(void *threadid) 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)); @@ -102,6 +105,9 @@ static void *write_thread(void *threadid) printf("Greetings from the write thread!\n"); + bytes_transfered = 0; + gettimeofday(&start_time, NULL); + 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); -- 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') 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 090d066570993f068f2e3b3a6c6bd25986fc92b7 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 19 May 2010 22:26:14 +0000 Subject: Calculate received sample rate for loopback test. --- host/apps/omap_debug/usrp-e-rw.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c index 1b12fa889..f96e4e25b 100644 --- a/host/apps/omap_debug/usrp-e-rw.c +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -38,9 +38,14 @@ 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)); @@ -73,8 +78,24 @@ static void *read_thread(void *threadid) printf("Checksum fail packet = %X, expected = %X, pkt_count = %d\n", calc_checksum(p), p->checksum, pkt_count); - printf("."); - fflush(stdout); + + 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"); } @@ -112,7 +133,7 @@ static void *write_thread(void *threadid) cnt = write(fp, tx_data, 2048); if (cnt < 0) printf("Error returned from write: %d\n", cnt); - sleep(1); +// sleep(1); } } -- cgit v1.2.3 From 3bb874f8061f203d8adf6f07e61fd50a154e9906 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 19 May 2010 22:27:06 +0000 Subject: Display data rate in samples/second and fix typo. --- host/apps/omap_debug/usrp-e-timed.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-timed.c b/host/apps/omap_debug/usrp-e-timed.c index cfc70f724..c71651741 100644 --- a/host/apps/omap_debug/usrp-e-timed.c +++ b/host/apps/omap_debug/usrp-e-timed.c @@ -84,8 +84,8 @@ static void *read_thread(void *threadid) 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); + printf("RX data transfer rate = %f K Samples/second\n", + (float) bytes_transfered / (float) elapsed_seconds / 4000); start_time = finish_time; @@ -159,8 +159,8 @@ static void *write_thread(void *threadid) 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); + printf("TX data transfer rate = %f K Samples/second\n", + (float) bytes_transfered / (float) elapsed_seconds / 4000); start_time = finish_time; @@ -182,7 +182,7 @@ int main(int argc, char *argv[]) }; if (argc < 4) { - printf("%s t|w|rw decimation data_size\n", argv[0]); + printf("%s r|w|rw decimation data_size\n", argv[0]); return -1; } -- cgit v1.2.3 From a9fefde874503c0c4e0c542846c1dd1c74156d07 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 20 May 2010 15:05:04 +0000 Subject: Enable realtime scheduling in loopback test to prevent overruns. --- host/apps/omap_debug/usrp-e-rw.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-rw.c b/host/apps/omap_debug/usrp-e-rw.c index f96e4e25b..798bc4b45 100644 --- a/host/apps/omap_debug/usrp-e-rw.c +++ b/host/apps/omap_debug/usrp-e-rw.c @@ -142,6 +142,9 @@ 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]); @@ -153,6 +156,8 @@ int main(int argc, char *argv[]) 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); -- 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') 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 96ef5b171b44956f44e02672af8a734f3c0e38c4 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 21 May 2010 10:14:03 -0400 Subject: OK, now crc uses the timed interface to set the data rate. Revert "Revert "Revert "Update test program to reflect what is in the FPGA image.""" This reverts commit b5dfe74e991d240f0e666dfd521726ec61128eb8. Conflicts: host/apps/omap_debug/usrp-e-crc-rw.c --- host/apps/omap_debug/usrp-e-crc-rw.c | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index e1d9bf0db..b0982de86 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -183,43 +183,43 @@ 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 }; - int read, write; - if (argc < 2) { - printf("%s r|w|rw tx_data_size\n", argv[0]); + if (argc < 4) { + printf("%s t|w|rw decimation data_size\n", argv[0]); return -1; } - packet_data_length = atoi(argv[2]); + decimation = atoi(argv[2]); + packet_data_length = atoi(argv[3]); - if (strcmp(argv[1], "r") == 0) { - read = 1; - write = 0; - } + fp = open("/dev/usrp_e0", O_RDWR); + printf("fp = %d\n", fp); - if (strcmp(argv[1], "w") == 0) { - read = 0; - write = 1; - } + 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)); - if (strcmp(argv[1], "rw") == 0) { - read = 1; - write = 1; - } + fpga_config_flag |= decimation; - printf("About to open /dev/usrp_e0"); - fp = open("/dev/usrp_e0", O_RDWR); - printf("fp = %d\n", fp); + 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 (read) { + if (fpga_config_flag & (1 << 14)) { if (pthread_create(&rx, NULL, read_thread, (void *) t)) { printf("Failed to create rx thread\n"); exit(-1); @@ -228,7 +228,7 @@ int main(int argc, char *argv[]) sleep(1); - if (write) { + if (fpga_config_flag & (1 << 15)) { if (pthread_create(&tx, NULL, write_thread, (void *) t)) { printf("Failed to create tx thread\n"); exit(-1); -- cgit v1.2.3 From 85e32e298217a16102d25a455d605c55a05e369c Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 21 May 2010 21:13:25 +0000 Subject: Work on crc testing program. Currently dumps first received packet to the screen. Started to reduce teh number of warnings. --- host/apps/omap_debug/usrp-e-crc-rw.c | 46 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index b0982de86..8883366ae 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -1,5 +1,8 @@ #include #include +#include +#include +#include #include #include #include @@ -34,6 +37,8 @@ static u_int32_t chksum_crc32_gentab(void) } crc_tab[i] = crc; } + + return 0; } static void *read_thread(void *threadid) @@ -47,6 +52,9 @@ static void *read_thread(void *threadid) unsigned long bytes_transfered, elapsed_seconds; struct timeval start_time, finish_time; + __u8 *p; + __u32 *pi; + printf("Greetings from the reading thread!\n"); // IMPORTANT: must assume max length packet from fpga @@ -81,12 +89,24 @@ static void *read_thread(void *threadid) crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ rx_data->buf[i]) & 0xFF]; } - - rx_crc = *((int *) &rx_data[rx_data->len - 4]); - + + p = &rx_data->buf[rx_data->len - 4]; + pi = (__u32 *) p; + rx_crc = *pi; + +#if 1 + printf("rx_data->len = %d\n", rx_data->len); + printf("rx_data->flags = %d\n", rx_data->flags); + for (i = 0; i < rx_data->len; i++) + printf("idx = %d, data = %X\n", i, rx_data->buf[i]); + printf("calc crc = %lX, rx crc = %X\n", crc, rx_crc); + fflush(stdout); + break; +#endif + if (rx_crc != (crc & 0xFFFFFFFF)) { - printf("CRC Error, sent: %d, rx: %d\n", - rx_crc, (crc & 0xFFFFFFFF)); + printf("CRC Error, calc crc: %X, rx_crc: %X\n", + (crc & 0xFFFFFFFF), rx_crc); } bytes_transfered += rx_data->len; @@ -95,8 +115,9 @@ static void *read_thread(void *threadid) 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); + printf("Bytes transfered = %ld, elapsed seconds = %ld\n", bytes_transfered, elapsed_seconds); + printf("RX data transfer rate = %f K Samples/second\n", + (float) bytes_transfered / (float) elapsed_seconds / 250); start_time = finish_time; @@ -166,8 +187,9 @@ static void *write_thread(void *threadid) 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); + printf("Bytes transfered = %d, elapsed seconds = %d\n", bytes_transfered, elapsed_seconds); + printf("TX data transfer rate = %f K Samples/second\n", + (float) bytes_transfered / (float) elapsed_seconds / 250); start_time = finish_time; @@ -194,6 +216,8 @@ int main(int argc, char *argv[]) return -1; } + chksum_crc32_gentab(); + decimation = atoi(argv[2]); packet_data_length = atoi(argv[3]); @@ -217,7 +241,7 @@ int main(int argc, char *argv[]) sleep(1); // in case the kernel threads need time to start. FIXME if so -// sched_setscheduler(0, SCHED_RR, &s); + sched_setscheduler(0, SCHED_RR, &s); if (fpga_config_flag & (1 << 14)) { if (pthread_create(&rx, NULL, read_thread, (void *) t)) { @@ -238,4 +262,6 @@ int main(int argc, char *argv[]) sleep(10000); printf("Done sleeping\n"); + + return 0; } -- cgit v1.2.3 From f113ae17863729f05b6ada815b9817cd16001211 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Sun, 23 May 2010 12:58:58 +0000 Subject: Divide by 4 to convert byts/sec to samples/sec. Multiply by 4 is right out. --- host/apps/omap_debug/usrp-e-loopback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-loopback.c b/host/apps/omap_debug/usrp-e-loopback.c index 798bc4b45..177394947 100644 --- a/host/apps/omap_debug/usrp-e-loopback.c +++ b/host/apps/omap_debug/usrp-e-loopback.c @@ -86,7 +86,7 @@ static void *read_thread(void *threadid) 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); + (float) bytes_transfered / (float) elapsed_seconds / 4000); start_time = finish_time; -- cgit v1.2.3 From ac62d187cc7a4adde65c1e6fb1807ec5a967f966 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 28 May 2010 17:41:01 +0000 Subject: reverted usrp-e-led sorry --- host/apps/omap_debug/usrp-e-led.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-led.c b/host/apps/omap_debug/usrp-e-led.c index 30fbb66e0..d1b6c8996 100644 --- a/host/apps/omap_debug/usrp-e-led.c +++ b/host/apps/omap_debug/usrp-e-led.c @@ -20,16 +20,16 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); - d.offset = UE_REG_MISC_BASE+14; + d.offset = UE_REG_MISC_BASE; d.count = 1; - d.buf[0] = 0x4020; - ret = ioctl(fp, USRP_E_WRITE_CTL16, &d); - - sleep(10); - - d.buf[0] = 0x0; - ret = ioctl(fp, USRP_E_WRITE_CTL16, &d); + while (1) { + for (i=0; i<8; i++) { + d.buf[0] = i; + ret = ioctl(fp, USRP_E_WRITE_CTL16, &d); + sleep(1); + } + } return 0; } -- cgit v1.2.3 From 8869208ea8d8dfdd5fe86adc1637b93c4b390c0c Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Fri, 28 May 2010 11:26:40 +0000 Subject: Update usrp_e.h file. Change programs to use struct element status instead of flags. --- host/apps/omap_debug/usrp-e-crc-rw.c | 15 +++++++++++---- host/apps/omap_debug/usrp-e-lb-test.c | 2 +- host/apps/omap_debug/usrp-e-loopback.c | 6 +++--- host/apps/omap_debug/usrp-e-rw-random.c | 4 ++-- host/apps/omap_debug/usrp-e-timed.c | 6 +++--- host/apps/omap_debug/usrp_e.h | 16 +++++++++------- 6 files changed, 29 insertions(+), 20 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index 8883366ae..c3ae45cc1 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -81,13 +81,20 @@ static void *read_thread(void *threadid) } #endif - if (rx_data->flags & RB_OVERRUN) + if (rx_data->status & RB_OVERRUN) printf("O"); - + + printf("rx_data->len = %d\n", rx_data->len); + + crc = 0xFFFFFFFF; - for (i = 0; i < rx_data->len - 4; i++) { + for (i = 0; i < rx_data->len - 4; i+=2) { + crc = ((crc >> 8) & 0x00FFFFFF) ^ + crc_tab[(crc ^ rx_data->buf[i+1]) & 0xFF]; +printf("idx = %d, data = %X, crc = %X\n", i, rx_data->buf[i+1],crc); crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ rx_data->buf[i]) & 0xFF]; +printf("idx = %d, data = %X, crc = %X\n", i, rx_data->buf[i],crc); } p = &rx_data->buf[rx_data->len - 4]; @@ -96,7 +103,7 @@ static void *read_thread(void *threadid) #if 1 printf("rx_data->len = %d\n", rx_data->len); - printf("rx_data->flags = %d\n", rx_data->flags); + printf("rx_data->status = %d\n", rx_data->status); for (i = 0; i < rx_data->len; i++) printf("idx = %d, data = %X\n", i, rx_data->buf[i]); printf("calc crc = %lX, rx crc = %X\n", crc, rx_crc); diff --git a/host/apps/omap_debug/usrp-e-lb-test.c b/host/apps/omap_debug/usrp-e-lb-test.c index 675de8622..68848064e 100644 --- a/host/apps/omap_debug/usrp-e-lb-test.c +++ b/host/apps/omap_debug/usrp-e-lb-test.c @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) tx_data = malloc(2048); rx_data = malloc(2048); - tx_data->flags = 0; + tx_data->status = 0; tx_data->len = sizeof(struct usrp_transfer_frame) + packet_data_length; while (1) { diff --git a/host/apps/omap_debug/usrp-e-loopback.c b/host/apps/omap_debug/usrp-e-loopback.c index 177394947..535ce1025 100644 --- a/host/apps/omap_debug/usrp-e-loopback.c +++ b/host/apps/omap_debug/usrp-e-loopback.c @@ -63,7 +63,7 @@ static void *read_thread(void *threadid) 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("Packet received, status = %X, len = %d\n", rx_data->status, rx_data->len); // printf("p->seq_num = %d\n", p->seq_num); @@ -119,7 +119,7 @@ static void *write_thread(void *threadid) // p->data[i] = random() >> 16; p->data[i] = i; - tx_data->flags = 0xdeadbeef; + tx_data->status = 0xdeadbeef; tx_data->len = 8 + packet_data_length * 2; printf("tx_data->len = %d\n", tx_data->len); @@ -127,7 +127,7 @@ static void *write_thread(void *threadid) seq_number = 1; while (1) { -// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); +// printf("tx status = %X, len = %d\n", tx_data->status, tx_data->len); p->seq_num = seq_number++; p->checksum = calc_checksum(p); cnt = write(fp, tx_data, 2048); diff --git a/host/apps/omap_debug/usrp-e-rw-random.c b/host/apps/omap_debug/usrp-e-rw-random.c index 43f1571cb..5960b8fbd 100644 --- a/host/apps/omap_debug/usrp-e-rw-random.c +++ b/host/apps/omap_debug/usrp-e-rw-random.c @@ -65,7 +65,7 @@ static void *read_thread(void *threadid) while (1) { cnt = read(fp, rx_data, 2048); -// printf("Packet received, flags = %X, len = %d\n", rx_data->flags, rx_data->len); +// 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) @@ -102,7 +102,7 @@ static void *write_thread(void *threadid) // p->data[i] = random() >> 16; p->data[i] = i; - tx_data->flags = 0xdeadbeef; + tx_data->status = 0xdeadbeef; tx_data->len = 8 + packet_data_length * 2; printf("tx_data->len = %d\n", tx_data->len); diff --git a/host/apps/omap_debug/usrp-e-timed.c b/host/apps/omap_debug/usrp-e-timed.c index c71651741..3cb33ce2d 100644 --- a/host/apps/omap_debug/usrp-e-timed.c +++ b/host/apps/omap_debug/usrp-e-timed.c @@ -75,7 +75,7 @@ static void *read_thread(void *threadid) } #endif - if (rx_data->flags & RB_OVERRUN) + if (rx_data->status & RB_OVERRUN) printf("O"); bytes_transfered += rx_data->len; @@ -118,7 +118,7 @@ static void *write_thread(void *threadid) // p->data[i] = random() >> 16; p->data[i] = i; - tx_data->flags = 0; + tx_data->status = 0; tx_data->len = 8 + packet_data_length * 2; printf("tx_data->len = %d\n", tx_data->len); @@ -146,7 +146,7 @@ static void *write_thread(void *threadid) } #endif -// printf("tx flags = %X, len = %d\n", tx_data->flags, tx_data->len); +// printf("tx status = %X, len = %d\n", tx_data->status, tx_data->len); p->seq_num = seq_number++; p->checksum = calc_checksum(p); cnt = write(fp, tx_data, 2048); diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h index fd74e6e9e..b098ad114 100644 --- a/host/apps/omap_debug/usrp_e.h +++ b/host/apps/omap_debug/usrp_e.h @@ -28,14 +28,14 @@ struct usrp_e_ctl32 { __u32 buf[10]; }; -// SPI interface +/* SPI interface */ #define UE_SPI_TXONLY 0 #define UE_SPI_TXRX 1 -// Defines for spi ctrl register -#define UE_SPI_CTRL_TXNEG (1<<10) -#define UE_SPI_CTRL_RXNEG (1<<9) +/* Defines for spi ctrl register */ +#define UE_SPI_CTRL_TXNEG (1 << 10) +#define UE_SPI_CTRL_RXNEG (1 << 9) #define UE_SPI_PUSH_RISE 0 #define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG @@ -65,20 +65,22 @@ struct usrp_e_i2c { #define USRP_E_I2C_READ _IOWR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) #define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) -// Data transfer frame definition +/* Data transfer frame definition */ struct usrp_transfer_frame { - __u32 flags; + __u32 status; __u32 len; __u8 buf[]; }; -// Flag defines +/* Flag defines */ #define RB_USER (1 << 0) #define RB_KERNEL (1 << 1) #define RB_OVERRUN (1 << 2) +#define RB_DMA_ACTIVE (1 << 3) struct ring_buffer_entry { + unsigned int flags; unsigned long dma_addr; struct usrp_transfer_frame *frame_addr; }; -- cgit v1.2.3 From 7edefe21d6476e0570313a0bbdeada38ea835b9a Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Sat, 5 Jun 2010 11:43:15 +0000 Subject: Exit on errors. Run until an error occurs. Alloq for up to 2 sequence number errors so program can start with "dirty" fpga contents. --- host/apps/omap_debug/usrp-e-loopback.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-loopback.c b/host/apps/omap_debug/usrp-e-loopback.c index 535ce1025..929d65604 100644 --- a/host/apps/omap_debug/usrp-e-loopback.c +++ b/host/apps/omap_debug/usrp-e-loopback.c @@ -9,6 +9,7 @@ // max length #define PKT_DATA_LENGTH 1016 static int packet_data_length; +static int error; struct pkt { int checksum; @@ -35,7 +36,7 @@ static int calc_checksum(struct pkt *p) static void *read_thread(void *threadid) { - int cnt, prev_seq_num, pkt_count; + int cnt, prev_seq_num, pkt_count, seq_num_failure; struct usrp_transfer_frame *rx_data; struct pkt *p; unsigned long bytes_transfered, elapsed_seconds; @@ -56,12 +57,13 @@ static void *read_thread(void *threadid) 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\n", cnt); + 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); @@ -69,15 +71,22 @@ static void *read_thread(void *threadid) pkt_count++; - if (p->seq_num != prev_seq_num + 1) + 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); + + seq_num_failure ++; + if (seq_num_failure > 2) + error = 1; + } + prev_seq_num = p->seq_num; - if (calc_checksum(p) != p->checksum) + 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 += rx_data->len; @@ -157,6 +166,7 @@ int main(int argc, char *argv[]) printf("fp = %d\n", fp); sched_setscheduler(0, SCHED_RR, &s); + error = 0; if (pthread_create(&rx, NULL, read_thread, (void *) t)) { printf("Failed to create rx thread\n"); @@ -170,7 +180,8 @@ int main(int argc, char *argv[]) exit(-1); } - sleep(10000); + while (!error) + sleep(1); 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') 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 cd537e846af8547b83c4b8f8ca30de4860c7fefb Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 15 Jun 2010 20:53:28 +0000 Subject: Add gitignore file. --- host/apps/omap_debug/.gitignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 host/apps/omap_debug/.gitignore (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/.gitignore b/host/apps/omap_debug/.gitignore new file mode 100644 index 000000000..5d6b1c6f5 --- /dev/null +++ b/host/apps/omap_debug/.gitignore @@ -0,0 +1,19 @@ +.gitignore +clkgen-config +fpga-downloader +usrp-e-button +usrp-e-crc-rw +usrp-e-ctl +usrp-e-debug-pins +usrp-e-fpga-rw +usrp-e-gpio +usrp-e-i2c +usrp-e-lb-test +usrp-e-led +usrp-e-loopback +usrp-e-random-loopback +usrp-e-rw +usrp-e-spi +usrp-e-timed +usrp-e-uart +usrp-e-uart-rx -- 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') 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 From 6ce879c36aedc7d69ceadbecd8878fa3856547f0 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 11 Aug 2010 17:23:42 +0000 Subject: Add usrp-e-mm-loopback to .gitignore. --- host/apps/omap_debug/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/.gitignore b/host/apps/omap_debug/.gitignore index 5d6b1c6f5..008a23138 100644 --- a/host/apps/omap_debug/.gitignore +++ b/host/apps/omap_debug/.gitignore @@ -17,3 +17,4 @@ usrp-e-spi usrp-e-timed usrp-e-uart usrp-e-uart-rx +usrp-e-mm-loopback -- cgit v1.2.3 From 74e5238d08c780e96f617c86bea848a05f76988c Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 11 Aug 2010 17:53:53 +0000 Subject: Convert non-mmaped loopback test program to use new simple read/write api. Done by copying from the -mm version, which will be used to test mmaped ring buffer. --- host/apps/omap_debug/usrp-e-loopback.c | 76 +++++++++++++++------------------- 1 file changed, 33 insertions(+), 43 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-loopback.c b/host/apps/omap_debug/usrp-e-loopback.c index c463e774d..d11cf7d09 100644 --- a/host/apps/omap_debug/usrp-e-loopback.c +++ b/host/apps/omap_debug/usrp-e-loopback.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "usrp_e.h" // max length #define PKT_DATA_LENGTH 1016 @@ -12,9 +13,9 @@ static int packet_data_length; static int error; struct pkt { + int len; int checksum; int seq_num; - int len; short data[]; }; @@ -38,8 +39,8 @@ static int calc_checksum(struct pkt *p) static void *read_thread(void *threadid) { + char *rx_data; int cnt, prev_seq_num, pkt_count, seq_num_failure; - struct usrp_transfer_frame *rx_data; struct pkt *p; unsigned long bytes_transfered, elapsed_seconds; struct timeval start_time, finish_time; @@ -51,32 +52,25 @@ static void *read_thread(void *threadid) // IMPORTANT: must assume max length packet from fpga 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)); + 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("Packet received, status = %X, len = %d\n", rx_data->status, rx_data->len); -// printf("p->seq_num = %d, p->len = %d\n", p->seq_num, p->len); - +// printf("p->seq_num = %d\n", p->seq_num); - 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++; if (p->seq_num != prev_seq_num + 1) { - printf("Sequence number fail, current = %X, previous = %X, pkt_count = %d\n", + printf("Sequence number fail, current = %d, previous = %d, pkt_count = %d\n", p->seq_num, prev_seq_num, pkt_count); seq_num_failure ++; @@ -87,12 +81,12 @@ static void *read_thread(void *threadid) prev_seq_num = p->seq_num; if (calc_checksum(p) != p->checksum) { - 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); + printf("Checksum fail packet = %X, expected = %X, pkt_count = %d\n", + calc_checksum(p), p->checksum, pkt_count); error = 1; } - bytes_transfered += rx_data->len; + bytes_transfered += cnt; if (bytes_transfered > (100 * 1000000)) { gettimeofday(&finish_time, NULL); @@ -116,47 +110,32 @@ static void *read_thread(void *threadid) static void *write_thread(void *threadid) { - int seq_number, i, cnt, data_length; - struct usrp_transfer_frame *tx_data; + 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 + offsetof(struct usrp_transfer_frame, buf)); - printf("Address of tx_data = %p, p = %p\n", tx_data, p); + p = (struct pkt *) ((void *)tx_data); - printf("sizeof rp_transfer_frame = %d, sizeof pkt = %d\n", sizeof(struct usrp_transfer_frame), sizeof(struct pkt)); - - for (i=0; i < 2048; i++) + for (i=0; i < packet_data_length; i++) // p->data[i] = random() >> 16; p->data[i] = i; - tx_data->status = 0xdeadbeef; - - printf("tx_data->len = %d\n", tx_data->len); - seq_number = 1; 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); - 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); + if (packet_data_length > 0) + p->len = packet_data_length; + else + p->len = (random() & 0x1ff) + (1004 - 512); - cnt = write(fp, tx_data, sizeof(struct usrp_transfer_frame) + sizeof(struct pkt) + 2 * p->len); -// cnt = write(fp, tx_data, 2048); + 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); @@ -171,6 +150,8 @@ int main(int argc, char *argv[]) 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]); @@ -182,23 +163,32 @@ int main(int argc, char *argv[]) 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(1); +// while (!error) + sleep(1000000000); printf("Done sleeping\n"); } -- cgit v1.2.3 From a58b90ef219746e927a777efba919db15d139e84 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Wed, 11 Aug 2010 22:23:40 +0000 Subject: Convert to use mmaped rx ring buffer. --- host/apps/omap_debug/usrp-e-mm-loopback.c | 63 ++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 13 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c index d11cf7d09..722d09825 100644 --- a/host/apps/omap_debug/usrp-e-mm-loopback.c +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "usrp_e.h" // max length #define PKT_DATA_LENGTH 1016 @@ -16,9 +17,20 @@ struct pkt { int len; int checksum; int seq_num; - short data[]; + short data[1024-6]; }; +/* delete after usrp_e.h updated */ +struct ring_buffer_info { + int flags; + int len; +}; + +struct ring_buffer_info (*rxi)[]; +struct ring_buffer_info (*txi)[]; +struct pkt (*rx_buf)[200]; +struct pkt (*tx_buf)[200]; + static int fp; static int calc_checksum(struct pkt *p) @@ -39,32 +51,44 @@ static int calc_checksum(struct pkt *p) 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; + int rb_read; printf("Greetings from the reading thread!\n"); + printf("sizeof pkt = %d\n", sizeof(struct pkt)); + + rb_read = 0; 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); + if (!((*rxi)[rb_read].flags & RB_USER)) { + printf("Waiting for data\n"); + struct pollfd pfd; + pfd.fd = fp; + pfd.events = POLLIN; + ssize_t ret = poll(&pfd, 1, -1); + } -// printf("p->seq_num = %d\n", p->seq_num); + printf("pkt received, rb_read = %d\n", rb_read); + + cnt = (*rxi)[rb_read].len; + p = &(*rx_buf)[rb_read]; + +// 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 = %X, p->seq_num = %d p->len = %d\n", p, p->seq_num, p->len); pkt_count++; @@ -86,6 +110,12 @@ static void *read_thread(void *threadid) error = 1; } + (*rxi)[rb_read].flags = RB_KERNEL; + + rb_read++; + if (rb_read == 200) + rb_read = 0; + bytes_transfered += cnt; if (bytes_transfered > (100 * 1000000)) { @@ -151,7 +181,6 @@ int main(int argc, char *argv[]) .sched_priority = 1 }; void *rb; - struct usrp_transfer_frame *tx_rb, *rx_rb; if (argc < 2) { printf("%s data_size\n", argv[0]); @@ -164,11 +193,19 @@ int main(int argc, char *argv[]) printf("fp = %d\n", fp); rb = mmap(0, 202 * 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fp, 0); - if (!rb) { - printf("mmap failed\n"); + if (rb == MAP_FAILED) { + perror("mmap failed"); exit; } + printf("rb = %X\n", rb); + + rxi = rb; + rx_buf = rb + 4096; + txi = rb + 4096 + 4096 * 200; + tx_buf = rb + 4096 * 2 + 4096 * 200; + + printf("rxi = %X, rx_buf = %X, txi = %X, tx_buf = %X\n", rxi, rx_buf, txi, tx_buf); sched_setscheduler(0, SCHED_RR, &s); error = 0; -- cgit v1.2.3 From 7888b861d51fc612abe4c28a2f05c83df7ec1cb1 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 20 Sep 2010 20:31:52 +0000 Subject: Fix really dumb mistake in rad ring buffer code. Add/comment debug lines. --- host/apps/omap_debug/usrp-e-mm-loopback.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c index 722d09825..7a1747f9b 100644 --- a/host/apps/omap_debug/usrp-e-mm-loopback.c +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -72,14 +72,14 @@ static void *read_thread(void *threadid) while (1) { if (!((*rxi)[rb_read].flags & RB_USER)) { - printf("Waiting for data\n"); +// printf("Waiting for data\n"); struct pollfd pfd; pfd.fd = fp; pfd.events = POLLIN; ssize_t ret = poll(&pfd, 1, -1); } - printf("pkt received, rb_read = %d\n", rb_read); +// printf("pkt received, rb_read = %d\n", rb_read); cnt = (*rxi)[rb_read].len; p = &(*rx_buf)[rb_read]; @@ -88,7 +88,7 @@ static void *read_thread(void *threadid) // if (cnt < 0) // printf("Error returned from read: %d, sequence number = %d\n", cnt, p->seq_num); - printf("p = %X, p->seq_num = %d p->len = %d\n", p, p->seq_num, p->len); +// printf("p = %X, p->seq_num = %d p->len = %d\n", p, p->seq_num, p->len); pkt_count++; @@ -96,6 +96,8 @@ static void *read_thread(void *threadid) 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); + printf("pkt received, rb_read = %d\n", rb_read); + printf("p = %X, p->seq_num = %d p->len = %d\n", p, p->seq_num, p->len); seq_num_failure ++; if (seq_num_failure > 2) @@ -113,7 +115,7 @@ static void *read_thread(void *threadid) (*rxi)[rb_read].flags = RB_KERNEL; rb_read++; - if (rb_read == 200) + if (rb_read == 100) rb_read = 0; bytes_transfered += cnt; -- cgit v1.2.3 From d4a80a2b93a13dc371ef100df962ba99c53a9bb9 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 21 Sep 2010 13:33:51 +0000 Subject: Fix ring buffer size calculation. --- host/apps/omap_debug/usrp-e-mm-loopback.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c index 7a1747f9b..71519d535 100644 --- a/host/apps/omap_debug/usrp-e-mm-loopback.c +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -194,18 +194,18 @@ int main(int argc, char *argv[]) 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); + rb = mmap(0, 102 * 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fp, 0); if (rb == MAP_FAILED) { perror("mmap failed"); - exit; + return -1; } printf("rb = %X\n", rb); rxi = rb; rx_buf = rb + 4096; - txi = rb + 4096 + 4096 * 200; - tx_buf = rb + 4096 * 2 + 4096 * 200; + txi = rb + 4096 + 4096 * 100; + tx_buf = rb + 4096 * 2 + 4096 * 100; printf("rxi = %X, rx_buf = %X, txi = %X, tx_buf = %X\n", rxi, rx_buf, txi, tx_buf); -- cgit v1.2.3 From d6c4fbb29e818aec79864d25a0d308decb0db92d Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 21 Sep 2010 18:07:25 +0000 Subject: Read the ring buffer size from the kernel and use that to set up the structures that read and write the ring buffer. --- host/apps/omap_debug/usrp-e-mm-loopback.c | 27 +++++++++++++++--------- host/apps/omap_debug/usrp_e.h | 35 +++++++++++++++---------------- host/include/linux/usrp_e.h | 35 +++++++++++++++---------------- 3 files changed, 51 insertions(+), 46 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c index 71519d535..a1da926a2 100644 --- a/host/apps/omap_debug/usrp-e-mm-loopback.c +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -20,12 +21,6 @@ struct pkt { short data[1024-6]; }; -/* delete after usrp_e.h updated */ -struct ring_buffer_info { - int flags; - int len; -}; - struct ring_buffer_info (*rxi)[]; struct ring_buffer_info (*txi)[]; struct pkt (*rx_buf)[200]; @@ -182,6 +177,8 @@ int main(int argc, char *argv[]) struct sched_param s = { .sched_priority = 1 }; + struct usrp_e_ring_buffer_size_t rb_size; + int ret, map_size, page_size; void *rb; if (argc < 2) { @@ -194,7 +191,14 @@ int main(int argc, char *argv[]) fp = open("/dev/usrp_e0", O_RDWR); printf("fp = %d\n", fp); - rb = mmap(0, 102 * 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fp, 0); + page_size = getpagesize(); + + ret = ioctl(fp, USRP_E_GET_RB_INFO, &rb_size); + + map_size = (rb_size.num_pages_rx_flags + rb_size.num_pages_tx_flags) * page_size + + (rb_size.num_rx_frames + rb_size.num_tx_frames) * (page_size >> 1); + + rb = mmap(0, map_size, PROT_READ|PROT_WRITE, MAP_SHARED, fp, 0); if (rb == MAP_FAILED) { perror("mmap failed"); return -1; @@ -203,9 +207,12 @@ int main(int argc, char *argv[]) printf("rb = %X\n", rb); rxi = rb; - rx_buf = rb + 4096; - txi = rb + 4096 + 4096 * 100; - tx_buf = rb + 4096 * 2 + 4096 * 100; + rx_buf = rb + (rb_size.num_pages_rx_flags * page_size); + txi = rb + (rb_size.num_pages_rx_flags * page_size) + + (rb_size.num_rx_frames * page_size >> 1); + tx_buf = rb + (rb_size.num_pages_rx_flags * page_size) + + (rb_size.num_rx_frames * page_size >> 1) + + (rb_size.num_pages_tx_flags * page_size); printf("rxi = %X, rx_buf = %X, txi = %X, tx_buf = %X\n", rxi, rx_buf, txi, tx_buf); diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h index b098ad114..fd38027d4 100644 --- a/host/apps/omap_debug/usrp_e.h +++ b/host/apps/omap_debug/usrp_e.h @@ -34,8 +34,8 @@ struct usrp_e_ctl32 { #define UE_SPI_TXRX 1 /* Defines for spi ctrl register */ -#define UE_SPI_CTRL_TXNEG (1 << 10) -#define UE_SPI_CTRL_RXNEG (1 << 9) +#define UE_SPI_CTRL_TXNEG (BIT(10)) +#define UE_SPI_CTRL_RXNEG (BIT(9)) #define UE_SPI_PUSH_RISE 0 #define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG @@ -64,25 +64,24 @@ struct usrp_e_i2c { #define USRP_E_SPI _IOWR(USRP_E_IOC_MAGIC, 0x24, struct usrp_e_spi) #define USRP_E_I2C_READ _IOWR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) #define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) +#define USRP_E_GET_RB_INFO _IOR(USRP_E_IOC_MAGIC, 0x27, struct usrp_e_ring_buffer_size_t) -/* Data transfer frame definition */ - -struct usrp_transfer_frame { - __u32 status; - __u32 len; - __u8 buf[]; +/* Flag defines */ +#define RB_USER (1<<0) +#define RB_KERNEL (1<<1) +#define RB_OVERRUN (1<<2) +#define RB_DMA_ACTIVE (1<<3) + +struct ring_buffer_info { + int flags; + int len; }; -/* Flag defines */ -#define RB_USER (1 << 0) -#define RB_KERNEL (1 << 1) -#define RB_OVERRUN (1 << 2) -#define RB_DMA_ACTIVE (1 << 3) - -struct ring_buffer_entry { - unsigned int flags; - unsigned long dma_addr; - struct usrp_transfer_frame *frame_addr; +struct usrp_e_ring_buffer_size_t { + int num_pages_rx_flags; + int num_rx_frames; + int num_pages_tx_flags; + int num_tx_frames; }; #endif diff --git a/host/include/linux/usrp_e.h b/host/include/linux/usrp_e.h index b098ad114..fd38027d4 100644 --- a/host/include/linux/usrp_e.h +++ b/host/include/linux/usrp_e.h @@ -34,8 +34,8 @@ struct usrp_e_ctl32 { #define UE_SPI_TXRX 1 /* Defines for spi ctrl register */ -#define UE_SPI_CTRL_TXNEG (1 << 10) -#define UE_SPI_CTRL_RXNEG (1 << 9) +#define UE_SPI_CTRL_TXNEG (BIT(10)) +#define UE_SPI_CTRL_RXNEG (BIT(9)) #define UE_SPI_PUSH_RISE 0 #define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG @@ -64,25 +64,24 @@ struct usrp_e_i2c { #define USRP_E_SPI _IOWR(USRP_E_IOC_MAGIC, 0x24, struct usrp_e_spi) #define USRP_E_I2C_READ _IOWR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) #define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) +#define USRP_E_GET_RB_INFO _IOR(USRP_E_IOC_MAGIC, 0x27, struct usrp_e_ring_buffer_size_t) -/* Data transfer frame definition */ - -struct usrp_transfer_frame { - __u32 status; - __u32 len; - __u8 buf[]; +/* Flag defines */ +#define RB_USER (1<<0) +#define RB_KERNEL (1<<1) +#define RB_OVERRUN (1<<2) +#define RB_DMA_ACTIVE (1<<3) + +struct ring_buffer_info { + int flags; + int len; }; -/* Flag defines */ -#define RB_USER (1 << 0) -#define RB_KERNEL (1 << 1) -#define RB_OVERRUN (1 << 2) -#define RB_DMA_ACTIVE (1 << 3) - -struct ring_buffer_entry { - unsigned int flags; - unsigned long dma_addr; - struct usrp_transfer_frame *frame_addr; +struct usrp_e_ring_buffer_size_t { + int num_pages_rx_flags; + int num_rx_frames; + int num_pages_tx_flags; + int num_tx_frames; }; #endif -- cgit v1.2.3 From 380889798a9a9b5319e708743c5bb216405f77f4 Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 21 Sep 2010 19:47:32 +0000 Subject: Convert write to use the mmap interface. --- host/apps/omap_debug/usrp-e-mm-loopback.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c index a1da926a2..81bdb410a 100644 --- a/host/apps/omap_debug/usrp-e-mm-loopback.c +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -137,7 +137,7 @@ static void *read_thread(void *threadid) static void *write_thread(void *threadid) { - int seq_number, i, cnt; + int seq_number, i, cnt, rb_write; void *tx_data; struct pkt *p; @@ -151,6 +151,7 @@ static void *write_thread(void *threadid) p->data[i] = i; seq_number = 1; + rb_write = 0; while (1) { p->seq_num = seq_number++; @@ -162,9 +163,26 @@ static void *write_thread(void *threadid) 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); + if (!((*txi)[rb_write].flags & RB_KERNEL)) { +// printf("Waiting for space\n"); + struct pollfd pfd; + pfd.fd = fp; + pfd.events = POLLOUT; + ssize_t ret = poll(&pfd, 1, -1); + } + + memcpy(&(*tx_buf)[rb_write], tx_data, p->len * 2 + 12); + + (*txi)[rb_write].len = p->len * 2 + 12; + (*txi)[rb_write].flags = RB_USER; + + rb_write++; + if (rb_write == 100) + rb_write = 0; + +// cnt = write(fp, tx_data, p->len * 2 + 12); +// if (cnt < 0) +// printf("Error returned from write: %d\n", cnt); // sleep(1); } } -- cgit v1.2.3 From 943bfa271c97b36dcba74f1d65220e6f66f50c7f Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 21 Sep 2010 19:59:02 +0000 Subject: Use the ring buffer sizes read from the kernel. --- host/apps/omap_debug/usrp-e-mm-loopback.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c index 81bdb410a..053f60b60 100644 --- a/host/apps/omap_debug/usrp-e-mm-loopback.c +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -27,6 +27,7 @@ struct pkt (*rx_buf)[200]; struct pkt (*tx_buf)[200]; static int fp; +static struct usrp_e_ring_buffer_size_t rb_size; static int calc_checksum(struct pkt *p) { @@ -110,7 +111,7 @@ static void *read_thread(void *threadid) (*rxi)[rb_read].flags = RB_KERNEL; rb_read++; - if (rb_read == 100) + if (rb_read == rb_size.num_rx_frames) rb_read = 0; bytes_transfered += cnt; @@ -177,7 +178,7 @@ static void *write_thread(void *threadid) (*txi)[rb_write].flags = RB_USER; rb_write++; - if (rb_write == 100) + if (rb_write == rb_size.num_tx_frames) rb_write = 0; // cnt = write(fp, tx_data, p->len * 2 + 12); @@ -195,7 +196,6 @@ int main(int argc, char *argv[]) struct sched_param s = { .sched_priority = 1 }; - struct usrp_e_ring_buffer_size_t rb_size; int ret, map_size, page_size; void *rb; -- cgit v1.2.3 From 77cdb4a9695e71e64e1d87cfad2cb4d8717f971e Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Tue, 21 Sep 2010 20:06:43 +0000 Subject: Use a dummy write to start DMA transfers when sending data to the FPGA. Poll will also start data transfers. --- host/apps/omap_debug/usrp-e-mm-loopback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp-e-mm-loopback.c b/host/apps/omap_debug/usrp-e-mm-loopback.c index 053f60b60..f5fc83c87 100644 --- a/host/apps/omap_debug/usrp-e-mm-loopback.c +++ b/host/apps/omap_debug/usrp-e-mm-loopback.c @@ -181,7 +181,7 @@ static void *write_thread(void *threadid) if (rb_write == rb_size.num_tx_frames) rb_write = 0; -// cnt = write(fp, tx_data, p->len * 2 + 12); + cnt = write(fp, NULL, 0); // if (cnt < 0) // printf("Error returned from write: %d\n", cnt); // sleep(1); -- cgit v1.2.3 From dd9f9c340a8def560235d737df446454ea75dadc Mon Sep 17 00:00:00 2001 From: root Date: Thu, 30 Sep 2010 18:25:24 +0000 Subject: Ignore direction for GPIO 114 since it is always an input. --- host/apps/omap_debug/fpga-downloader.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/fpga-downloader.cc b/host/apps/omap_debug/fpga-downloader.cc index fb96b64a3..4e475b5c1 100644 --- a/host/apps/omap_debug/fpga-downloader.cc +++ b/host/apps/omap_debug/fpga-downloader.cc @@ -97,15 +97,17 @@ gpio::gpio(unsigned int gpio_num, gpio_direction pin_direction) std::fstream direction_file; 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; + if (gpio_num != 114) { + 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; -- cgit v1.2.3 From db0e3e574e9058ad51cacea91ccc42f0baed95fa Mon Sep 17 00:00:00 2001 From: Philip Balister Date: Thu, 21 Oct 2010 22:26:53 -0400 Subject: usrp_e: Add driver compatibility ioctl to header file. --- host/apps/omap_debug/usrp_e.h | 3 +++ host/include/linux/usrp_e.h | 3 +++ 2 files changed, 6 insertions(+) (limited to 'host/apps/omap_debug') diff --git a/host/apps/omap_debug/usrp_e.h b/host/apps/omap_debug/usrp_e.h index fd38027d4..f96706c4a 100644 --- a/host/apps/omap_debug/usrp_e.h +++ b/host/apps/omap_debug/usrp_e.h @@ -41,6 +41,9 @@ struct usrp_e_ctl32 { #define UE_SPI_PUSH_FALL UE_SPI_CTRL_TXNEG #define UE_SPI_LATCH_RISE 0 #define UE_SPI_LATCH_FALL UE_SPI_CTRL_RXNEG +#define USRP_E_GET_COMPAT_NUMBER _IO(USRP_E_IOC_MAGIC, 0x28) + +#define USRP_E_COMPAT_NUMBER 1 struct usrp_e_spi { __u8 readback; diff --git a/host/include/linux/usrp_e.h b/host/include/linux/usrp_e.h index cb62d940d..4c6a5dd89 100644 --- a/host/include/linux/usrp_e.h +++ b/host/include/linux/usrp_e.h @@ -65,6 +65,9 @@ struct usrp_e_i2c { #define USRP_E_I2C_READ _IOWR(USRP_E_IOC_MAGIC, 0x25, struct usrp_e_i2c) #define USRP_E_I2C_WRITE _IOW(USRP_E_IOC_MAGIC, 0x26, struct usrp_e_i2c) #define USRP_E_GET_RB_INFO _IOR(USRP_E_IOC_MAGIC, 0x27, struct usrp_e_ring_buffer_size_t) +#define USRP_E_GET_COMPAT_NUMBER _IO(USRP_E_IOC_MAGIC, 0x28) + +#define USRP_E_COMPAT_NUMBER 1 /* Flag defines */ #define RB_USER (1<<0) -- cgit v1.2.3