PN9 Generator.
Uses PN9 to generate a pseudo-random number sequence. The LFSR uses x^9 + x^5 as the primitive polynom. pn9_get_byte() returns the sequence one byte at the time. The following code shows how to generate 40 bits (5 bytes) of the PN9 sequence
uint8_t idx; uint8_t sequence[5]; pn9_init(); for (idx = 0; idx < 5; idx++) { sequence[idx] = pn9_get_byte(); }
Functions | |
| void | pn9_init (void) |
| uint8_t | pn9_get_byte (void) |
| void pn9_init | ( | void | ) |
| uint8_t pn9_get_byte | ( | void | ) |
Get the next 8 bits of PN9 sequence. Each time this function is called the next 8 bit of the PN9 sequence is calculated and returned.
Definition at line 38 of file pn9.c.
{
bit feedback;
uint8_t i, out_value;
out_value = bits_9_to_2;
for (i = 0; i < 8; i++)
{
// Tap the register
feedback =
((((bits_9_to_2 & pn9_bit9)>>4) ^ (bits_9_to_2 & pn9_bit5)) == 0) ? 0 : 1;
// Shift
bits_9_to_2<<=1;
bits_9_to_2 |= (uint8_t) bit_1;
// Enter feedback
bit_1 = feedback;
}
return out_value;
}
1.7.2