aboutsummaryrefslogtreecommitdiffstats
path: root/host/apps/omap_debug/usrp-e-rw.c
diff options
context:
space:
mode:
authorroot <root@usrp1-e.(none)>2010-03-24 16:59:01 +0000
committerroot <root@usrp1-e.(none)>2010-03-24 16:59:01 +0000
commit46c0c6ca62296ad86e9e302e85577dc4b800c6cb (patch)
treedda705431f700a18ceebc34f3ecbc52c07a27f40 /host/apps/omap_debug/usrp-e-rw.c
parent550bf3230aa1a5e7236d5bdb64a77c4ae1acea66 (diff)
parent4e5429b2839115235c7be778fe334479b833f128 (diff)
downloaduhd-46c0c6ca62296ad86e9e302e85577dc4b800c6cb.tar.gz
uhd-46c0c6ca62296ad86e9e302e85577dc4b800c6cb.tar.bz2
uhd-46c0c6ca62296ad86e9e302e85577dc4b800c6cb.zip
Merge branch 'u1e_uhd' of git@ettus.sourcerepo.com:ettus/uhd into u1e_uhd
Diffstat (limited to 'host/apps/omap_debug/usrp-e-rw.c')
-rw-r--r--host/apps/omap_debug/usrp-e-rw.c97
1 files changed, 97 insertions, 0 deletions
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 <stdio.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+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");
+}