OpenCores
URL https://opencores.org/ocsvn/logicprobe/logicprobe/trunk

Subversion Repositories logicprobe

[/] [logicprobe/] [trunk/] [tst/] [sim-c/] [lfsr128.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 hellwig
/*
2
 * lfsr128.c -- a linear feedback shift register with 128 bits
3
 *              (actually constructed from 4 instances of a 32-bit lfsr)
4
 */
5
 
6
 
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <string.h>
10
 
11
 
12
int main(void) {
13
  unsigned int startState[4] = {
14
    0xC70337DB,
15
    0x7F4D514F,
16
    0x75377599,
17
    0x7D5937A3
18
  };
19
  /* taps at 32 31 29 1 */
20
  unsigned int taps = 0xD0000001;
21
  unsigned int lfsr[4];
22
  int i, n;
23
 
24
  for (i = 0; i < 4; i++) {
25
    lfsr[i] = startState[i];
26
  }
27
  for (n = 0; n < 530; n++) {
28
    /*
29
     * The trigger condition in the actual hardware test will be set
30
     * to lfsr[0]==0x7119C0CD, which is reached at n==10. Therefore
31
     * we print out n-10 instead of n to get identical index numbers.
32
     */
33
    printf("%03d:  ", n - 10);
34
    for (i = 0; i < 4; i++) {
35
      printf("%02X  ", (lfsr[i] >> 24) & 0xFF);
36
      printf("%02X  ", (lfsr[i] >> 16) & 0xFF);
37
      printf("%02X  ", (lfsr[i] >>  8) & 0xFF);
38
      printf("%02X  ", (lfsr[i] >>  0) & 0xFF);
39
    }
40
    printf("\n");
41
    for (i = 0; i < 4; i++) {
42
      if ((lfsr[i] & 1) == 0) {
43
        lfsr[i] = lfsr[i] >> 1;
44
      } else {
45
        lfsr[i] = (lfsr[i] >> 1) ^ taps;
46
      }
47
    }
48
  }
49
  return 0;
50
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.