TrueRNGpro Raw Binary Format

TrueRNGpro comes with various modes which can be set by the user. This document explains the format of the data when TrueRNGpro is in RAW Binary mode. The stream contains a 4 byte packet (2 Bytes for RNG1 and 2 Bytes for RNG2). Each byte in the packet contains a sequence (SEQ) code to indicate which generator it belongs to and if it’s the low or high order bits in the sequence.

TEN BIT ADC SAMPLE
HIGH ORDER BITS:SAMPLE(4) LOW ORDER BITS:SAMPLE(6)
9 8 7 6 5 4 3 2 1 0
ORIGINAL 10 BIT ADC SAMPLE
HIGH ORDER BITS (4)
MASK (0xC0)11000000 MASK 0x0F00001111
SEQ SAMPLE <9:6>
7 6 X X 3 2 1 0
bit 7:6 bit 3:0
LOW ORDER BITS (6)
MASK (0xC0)11000000 MASK 0x3F00111111
SEQ SAMPLE <5:0>
7 6 5 4 3 2 1 0
bit 7:6 bit 5:0
SEQUENCE (SEQ)
MASK <7:6> HEX DESCRIPTION
00XXXXXX 0x00 Generator 1 High order
01XXXXXX 0x40 Generator 1 Low order
10XXXXXX 0x80 Generator 2 High order
11XXXXXX 0xC0 Generator 2 Low order

Pseudocode

// Init
i = 0
sequence_array = { 0x00, 0x40, 0x80, 0xC0 }
expected_sequence = sequence_array [ i ]
first_byte_has_happened = 0
// loop
while ( data_to_parse_or_fetch_count )
{
GEN1 = 0
GEN2 = 0
temp = get_next_byte()
next_sequence = temp & 0xC0
if (next_sequence != expected_sequence)
{
    if ( ! first_byte_has_happened )
    {
     // Since we can not guarantee where in the byte stream we will enter
     // we allow the first misalignment to happen
     first_byte_has_happened = 1
    }
    else
    {
     // We are out of sequence, we can either stop here and report the error
     // or throw this sample  away and keep going
      report_error()
    }
}
else
{
  // This is the expected sequence
  switch ( next_sequence )
  {
case 0x00:
GEN1 = ( temp & 0x0F ) << 6
break
case 0x40:
GEN1 |= ( temp & 0x3F )
break
case 0x80:
GEN2 = ( temp & 0x0F ) << 6
break
case 0xC0:
GEN2 |= ( temp & 0x3F )
break  
  }
 // Update next sequence
 i = ( ++i ) % 4
 next_sequence = sequence_array [ i ] 
if ( next_sequence == 0x00 )
{
	// We just looped over an entire sample, so lets do something with the data
	write_data(GEN1, GEN2)
}
}
}