forked from mfukar/lfsr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just an insignificant indentation change.
- Loading branch information
Showing
1 changed file
with
75 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,75 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "lfsr.h" | ||
|
||
lfsr_t glfsr_d0; | ||
lfsr_t glfsr_c0; | ||
|
||
int main(int argc, char **argv) { | ||
unsigned char bit0; | ||
unsigned char bitc0; | ||
unsigned char bitr = 0; | ||
char byte = 0, bitpos = 7; | ||
unsigned long long bitcounter = 0, ones = 0, zeros = 0, dropped = 0; | ||
lfsr_data polynom_d, init_value_d, | ||
polynom_c, init_value_c; | ||
|
||
if (argc < 5) { | ||
fprintf(stderr, "Usage: %s <data_polynomial> <data_seed> <clock_polynomial> <clock_seed>\n", argv[0]); | ||
exit(1); | ||
} | ||
|
||
FILE *fp = fopen("bitstream.bin", "w"); | ||
if(!fp) { | ||
fprintf(stderr, "Error opening output file.\n"); | ||
exit(-1); | ||
} | ||
|
||
sscanf(argv[1], "%lx", &polynom_d); | ||
sscanf(argv[2], "%lx", &init_value_d); | ||
GLFSR_init(&glfsr_d0, polynom_d, init_value_d); | ||
|
||
sscanf(argv[3], "%lx", &polynom_c); | ||
sscanf(argv[4], "%lx", &init_value_c); | ||
GLFSR_init(&glfsr_c0, polynom_c, init_value_c); | ||
|
||
do { | ||
bit0 = GLFSR_next(&glfsr_d0); | ||
bitc0 = GLFSR_next(&glfsr_c0); | ||
|
||
if (glfsr_d0.data == init_value_d) | ||
printf("GLFSR D0 overflow at %llu.\n", bitcounter); | ||
|
||
if (glfsr_c0.data == init_value_c) | ||
printf("GLFSR C0 overflow at %llu.\n", bitcounter); | ||
|
||
printf("Next bits: %d, %d\t= ", bit0, bitc0); | ||
|
||
if (bitc0) { | ||
bitr = bit0; | ||
printf("%d\n", bitr); | ||
|
||
if (bitpos < 0) { | ||
fprintf(fp, "%c", byte); | ||
bitpos = 7; | ||
byte = 0; | ||
} | ||
|
||
byte |= bitr << bitpos; | ||
bitpos--; | ||
|
||
bitr ? ones++ : zeros++; | ||
} else { | ||
printf("dropped\n"); | ||
dropped++; | ||
} | ||
|
||
bitcounter++; | ||
} while (!((glfsr_d0.data == init_value_d) && (glfsr_c0.data == init_value_c))); | ||
|
||
fclose(fp); | ||
printf("\nNumber of steps: %llu (%llu bytes)\nOnes: %llu, zeros: %llu, dropped: %llu\n", bitcounter, (zeros + ones) / 8, ones, zeros, dropped); | ||
|
||
return 0; | ||
} | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "lfsr.h" | ||
|
||
lfsr_t glfsr_d0; | ||
lfsr_t glfsr_c0; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
unsigned char bit0; | ||
unsigned char bitc0; | ||
unsigned char bitr = 0; | ||
char byte = 0, bitpos = 7; | ||
unsigned long long bitcounter = 0, ones = 0, zeros = 0, dropped = 0; | ||
lfsr_data polynom_d, init_value_d, | ||
polynom_c, init_value_c; | ||
|
||
if (argc < 5) { | ||
fprintf(stderr, "Usage: %s <data_polynomial> <data_seed> <clock_polynomial> <clock_seed>\n", argv[0]); | ||
exit(1); | ||
} | ||
|
||
FILE *fp = fopen("bitstream.bin", "w"); | ||
if(!fp) { | ||
fprintf(stderr, "Error opening output file.\n"); | ||
exit(-1); | ||
} | ||
|
||
sscanf(argv[1], "%lx", &polynom_d); | ||
sscanf(argv[2], "%lx", &init_value_d); | ||
GLFSR_init(&glfsr_d0, polynom_d, init_value_d); | ||
|
||
sscanf(argv[3], "%lx", &polynom_c); | ||
sscanf(argv[4], "%lx", &init_value_c); | ||
GLFSR_init(&glfsr_c0, polynom_c, init_value_c); | ||
|
||
do { | ||
bit0 = GLFSR_next(&glfsr_d0); | ||
bitc0 = GLFSR_next(&glfsr_c0); | ||
|
||
if (glfsr_d0.data == init_value_d) | ||
printf("GLFSR D0 overflow at %llu.\n", bitcounter); | ||
|
||
if (glfsr_c0.data == init_value_c) | ||
printf("GLFSR C0 overflow at %llu.\n", bitcounter); | ||
|
||
printf("Next bits: %d, %d\t= ", bit0, bitc0); | ||
|
||
if (bitc0) { | ||
bitr = bit0; | ||
printf("%d\n", bitr); | ||
|
||
if (bitpos < 0) { | ||
fprintf(fp, "%c", byte); | ||
bitpos = 7; | ||
byte = 0; | ||
} | ||
|
||
byte |= bitr << bitpos; | ||
bitpos--; | ||
|
||
bitr ? ones++ : zeros++; | ||
} else { | ||
printf("dropped\n"); | ||
dropped++; | ||
} | ||
|
||
bitcounter++; | ||
} while (!((glfsr_d0.data == init_value_d) && (glfsr_c0.data == init_value_c))); | ||
|
||
fclose(fp); | ||
printf("\nNumber of steps: %llu (%llu bytes)\nOnes: %llu, zeros: %llu, dropped: %llu\n", bitcounter, (zeros + ones) / 8, ones, zeros, dropped); | ||
|
||
return 0; | ||
} |