diff options
Diffstat (limited to 'host/apps')
-rw-r--r-- | host/apps/omap_debug/usrp-e-crc-rw.c | 93 |
1 files changed, 76 insertions, 17 deletions
diff --git a/host/apps/omap_debug/usrp-e-crc-rw.c b/host/apps/omap_debug/usrp-e-crc-rw.c index c6f3427f0..f91c4fa85 100644 --- a/host/apps/omap_debug/usrp-e-crc-rw.c +++ b/host/apps/omap_debug/usrp-e-crc-rw.c @@ -32,7 +32,7 @@ static u_int32_t chksum_crc32_gentab(void) unsigned long crc, poly; unsigned long i, j; - poly = 0xEDB88320L; + poly = 0x04C11DB7L; for (i = 0; i < 256; i++) { crc = i; @@ -44,23 +44,43 @@ static u_int32_t chksum_crc32_gentab(void) } } crc_tab[i] = crc; +// printf("crc_tab[%d] = %X\n", i , crc); } return 0; } +struct timeval delta_time(struct timeval f, struct timeval s) +{ + struct timeval d; + + if (f.tv_usec > s.tv_usec) { + d.tv_usec = f.tv_usec - s.tv_usec; + d.tv_sec = f.tv_sec - s.tv_sec; + } else { + d.tv_usec = f.tv_usec - s.tv_usec + 1e6; + d.tv_sec = f.tv_sec - s.tv_sec - 1; + } + + return d; +} + + static void *read_thread(void *threadid) { int cnt; int rx_pkt_cnt, rb_read; int i; - unsigned long crc; - unsigned int rx_crc; - unsigned long bytes_transfered, elapsed_seconds; - struct timeval start_time, finish_time; + unsigned long crc, ck_sum; + unsigned int rx_crc, pkt_len, pkt_seq; + unsigned long bytes_transfered; + struct timeval start_time; + unsigned int prev_seq = 0; + int first = 1; __u8 *p; + printf("Greetings from the reading thread!\n"); // IMPORTANT: must assume max length packet from fpga @@ -87,17 +107,41 @@ static void *read_thread(void *threadid) rx_crc = *(int *) &p[cnt-4]; crc = 0xFFFFFFFF; - for (i = 0; i < cnt - 4; i+=2) { - crc = ((crc >> 8) & 0x00FFFFFF) ^ - crc_tab[(crc ^ p[i+1]) & 0xFF]; -//printf("idx = %d, data = %X, crc = %X\n", i, p[i+1],crc); + ck_sum = 0; + + pkt_len = *(unsigned int *) &p[0]; + pkt_seq = *(unsigned int *) &p[4]; + +// printf("Pkt len = %X, pkt seq = %X, driver len = %X\n", pkt_len, pkt_seq, cnt); + + if (pkt_len != (cnt - 4)) + printf("Packet length check fail, driver len = %ud, content = %ud\n", + cnt, pkt_len); + + if (!first && (pkt_seq != (prev_seq + 1))) + printf("Sequence number check fail, pkt_seq = %ud, prev_seq = %ud\n", + pkt_seq, prev_seq); + first = 0; + prev_seq = pkt_seq; + + for (i = 0; i < cnt-4; i++) { + ck_sum += p[i]; + crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ p[i]) & 0xFF]; -//printf("idx = %d, data = %X, crc = %X\n", i, p[i],crc); +//printf("idx = %d, data = %X, crc = %X, ck_sum = %X\n", i, p[i], crc, ck_sum); +// crc = ((crc >> 8) & 0x00FFFFFF) ^ +// crc_tab[(crc ^ p[i+1]) & 0xFF]; +//printf("idx = %d, data = %X, crc = %X\n", i, p[i+1],crc); } (*rxi)[rb_read].flags = RB_KERNEL; + + if (rx_crc != ck_sum) + printf("Ck_sum eror, calc ck_sum = %lX, rx ck_sum = %X\n", + ck_sum, rx_crc); + #if 0 if (rx_crc != (crc & 0xFFFFFFFF)) { printf("CRC Error, calc crc: %X, rx_crc: %X\n", @@ -112,10 +156,18 @@ static void *read_thread(void *threadid) bytes_transfered += cnt; if (bytes_transfered > (100 * 1000000)) { + struct timeval finish_time, d_time; + float elapsed_seconds; + gettimeofday(&finish_time, NULL); - elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; - printf("Bytes transfered = %ld, elapsed seconds = %ld\n", bytes_transfered, elapsed_seconds); + printf("sec = %ld, usec = %ld\n", finish_time.tv_sec, finish_time.tv_usec); + + d_time = delta_time(finish_time, start_time); + + elapsed_seconds = (float)d_time.tv_sec + ((float)d_time.tv_usec * 1e-6f); + + printf("Bytes transfered = %ld, elapsed seconds = %f\n", bytes_transfered, elapsed_seconds); printf("RX data transfer rate = %f K Samples/second\n", (float) bytes_transfered / (float) elapsed_seconds / 4000); @@ -131,8 +183,8 @@ static void *write_thread(void *threadid) int i, tx_pkt_cnt, rb_write; int tx_len; unsigned long crc; - unsigned long bytes_transfered, elapsed_seconds; - struct timeval start_time, finish_time; + unsigned long bytes_transfered; + struct timeval start_time; __u8 *p; printf("Greetings from the write thread!\n"); @@ -183,12 +235,13 @@ static void *write_thread(void *threadid) crc = 0xFFFFFFFF; for (i = 0; i < tx_len-4; i++) { p[i] = i & 0xFF; - +// printf("%X ", p[i]); crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ p[i]) & 0xFF]; } *(int *) &p[tx_len-4] = crc; +// printf("\n crc = %lX\n", crc); (*txi)[rb_write].len = tx_len; (*txi)[rb_write].flags = RB_USER; @@ -200,10 +253,16 @@ static void *write_thread(void *threadid) bytes_transfered += tx_len; if (bytes_transfered > (100 * 1000000)) { + struct timeval finish_time, d_time; + float elapsed_seconds; + gettimeofday(&finish_time, NULL); - elapsed_seconds = finish_time.tv_sec - start_time.tv_sec; - printf("Bytes transfered = %d, elapsed seconds = %d\n", bytes_transfered, elapsed_seconds); + d_time = delta_time(finish_time, start_time); + + elapsed_seconds = (float)d_time.tv_sec - ((float)d_time.tv_usec * 1e-6f); + + printf("Bytes transfered = %ld, elapsed seconds = %f\n", bytes_transfered, elapsed_seconds); printf("TX data transfer rate = %f K Samples/second\n", (float) bytes_transfered / (float) elapsed_seconds / 4000); |