Statistics
| Branch: | Tag: | Revision:

root / host / apps / omap_debug / usrp-e-rw.c @ 4e5429b2

History | View | Annotate | Download (1.63 KB)

1
#include <stdio.h>
2
#include <sys/types.h>
3
#include <fcntl.h>
4
#include <pthread.h>
5
#include <stdlib.h>
6

    
7
struct pkt {
8
        int checksum;
9
        int seq_num;
10
        short data[1020];
11
};
12

    
13
static int fp;
14

    
15
static int calc_checksum(struct pkt *p)
16
{
17
        int i, sum;
18

    
19
        i = 0;
20
        sum = 0;
21

    
22
        for (i=0; i<1020; i++)
23
                sum += p->data[i];
24

    
25
        sum += p->seq_num;
26

    
27
        return sum;
28
}
29

    
30
static void *read_thread(void *threadid)
31
{
32
        int cnt, prev_seq_num;
33
        struct pkt rx_data;
34

    
35
        printf("Greetings from the reading thread!\n");
36

    
37
        prev_seq_num = 0;
38

    
39
        while (1) {
40
                cnt = read(fp, &rx_data, 2048);
41

    
42
                if (rx_data.seq_num != prev_seq_num + 1)
43
                        printf("Sequence number fail, current = %d, previous = %d\n",
44
                                rx_data.seq_num, prev_seq_num);
45
                prev_seq_num = rx_data.seq_num;
46

    
47
                if (calc_checksum(&rx_data) != rx_data.checksum)
48
                        printf("Checksum fail packet = %d, expected = %d\n",
49
                                calc_checksum(&rx_data), rx_data.checksum);
50
        }
51

    
52
}
53

    
54
static void *write_thread(void *threadid)
55
{
56
        int seq_number, i, cnt;
57
        struct pkt tx_data;
58

    
59
        printf("Greetings from the write thread!\n");
60

    
61
        for (i=0; i<1020; i++)
62
                tx_data.data[i] = random() >> 16;
63

    
64

    
65
        seq_number = 1;
66

    
67
        while (1) {
68
                tx_data.seq_num = seq_number++;
69
                tx_data.checksum = calc_checksum(&tx_data);
70
                cnt = write(fp, &tx_data, 2048);
71
        }
72
}
73

    
74

    
75
int main(int argc, char *argv[])
76
{
77
        int ret;
78
        pthread_t tx, rx;
79
        long int t;
80

    
81
        fp = open("/dev/usrp1_e0", O_RDWR);
82
        printf("fp = %d\n", fp);
83

    
84
        if (pthread_create(&rx, NULL, read_thread, (void *) t)) {
85
                printf("Failed to create rx thread\n");
86
                exit(-1);
87
        }
88

    
89
        if (pthread_create(&tx, NULL, write_thread, (void *) t)) {
90
                printf("Failed to create tx thread\n");
91
                exit(-1);
92
        }
93

    
94
        sleep(10000);
95

    
96
        printf("Done sleeping\n");
97
}