summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/apps/omap_debug/usrp-e-rw.c64
-rw-r--r--host/apps/omap_debug/usrp_e.h13
2 files changed, 60 insertions, 17 deletions
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 <pthread.h>
#include <stdlib.h>
#include <unistd.h>
+#include <stddef.h>
+#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; i<PKT_DATA_LENGTH; i++)
sum += p->data[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; i<PKT_DATA_LENGTH; i++)
+// p->data[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