N
Niv (KP)
I have the following code, which generates the sequence I require, but
I have several questions:
(code at end, note, this snippet only puts out a few of the values):
1. Is there a better/faster way to do the LFSR calc.
2. I need to modify the code so it is executed as part of a tcl "exec"
and the current value is passed in with the new value returned.
NOTE: This is a maximal length lfsr, starting with all '0's, and
forcing the all '1's condition, so I get 2^n values, not 2^n - 1.
main( )
{
unsigned short lfsr = 32768; // A start value to check all ones
case is forced OK.
unsigned short mask = 0x80D0u;
unsigned short temp;
unsigned short xorbit = 0x0u;
unsigned short all_ones = 0;
unsigned short i;
for ( i=0; i<20; i++) // just do a few values to test for now.
{
printf("%10d %10x %10d\n", lfsr, temp, xorbit); // debug aid
if (lfsr == 32768)
{
lfsr = 65535;
all_ones = 1;
}
else
if (all_ones == 1)
{
all_ones = 0;
lfsr = 32768;
}
// now do the usual lfsr calc, (a bit different as it starts all
'0's, but XOR's a '1' with the feedback taps.
temp = mask & lfsr;
xorbit = ( (temp>>15) ^ (temp>>7) ^ (temp>>6) ^ (temp>>4) ^
0x01u ) & 0x01u;
lfsr = (lfsr << 1) | xorbit;
}
return 0;
}
I have several questions:
(code at end, note, this snippet only puts out a few of the values):
1. Is there a better/faster way to do the LFSR calc.
2. I need to modify the code so it is executed as part of a tcl "exec"
and the current value is passed in with the new value returned.
NOTE: This is a maximal length lfsr, starting with all '0's, and
forcing the all '1's condition, so I get 2^n values, not 2^n - 1.
main( )
{
unsigned short lfsr = 32768; // A start value to check all ones
case is forced OK.
unsigned short mask = 0x80D0u;
unsigned short temp;
unsigned short xorbit = 0x0u;
unsigned short all_ones = 0;
unsigned short i;
for ( i=0; i<20; i++) // just do a few values to test for now.
{
printf("%10d %10x %10d\n", lfsr, temp, xorbit); // debug aid
if (lfsr == 32768)
{
lfsr = 65535;
all_ones = 1;
}
else
if (all_ones == 1)
{
all_ones = 0;
lfsr = 32768;
}
// now do the usual lfsr calc, (a bit different as it starts all
'0's, but XOR's a '1' with the feedback taps.
temp = mask & lfsr;
xorbit = ( (temp>>15) ^ (temp>>7) ^ (temp>>6) ^ (temp>>4) ^
0x01u ) & 0x01u;
lfsr = (lfsr << 1) | xorbit;
}
return 0;
}