Skip to content

Commit

Permalink
Just an insignificant indentation change.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfukar committed Jun 29, 2011
1 parent 53aef61 commit 2ae56b6
Showing 1 changed file with 75 additions and 74 deletions.
149 changes: 75 additions & 74 deletions prng.c
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;
}

0 comments on commit 2ae56b6

Please sign in to comment.