Did some testing on the FT240X sync mode bit-bang... all working fine.
This commit is contained in:
@@ -143,17 +143,19 @@ static void scaleZeroOneCounts(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This should be called for each bit generated.
|
// This should be called for each bit generated.
|
||||||
bool inmHealthCheckAddBit(bool evenBit, bool oddBit, bool even) {
|
bool inmHealthCheckAddBit(bool evenBit, bool oddBit, bool even, uint8_t addr) {
|
||||||
bool bit;
|
bool bit;
|
||||||
if(even) {
|
if(even) {
|
||||||
bit = evenBit;
|
bit = evenBit;
|
||||||
if(evenBit != inmPrevEven) {
|
if(evenBit != inmPrevEven) {
|
||||||
inmEvenMisfires++;
|
inmEvenMisfires++;
|
||||||
|
//printf("even misfire\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bit = oddBit;
|
bit = oddBit;
|
||||||
if(oddBit != inmPrevOdd) {
|
if(oddBit != inmPrevOdd) {
|
||||||
inmOddMisfires++;
|
inmOddMisfires++;
|
||||||
|
//printf("odd misfire\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inmPrevEven = evenBit;
|
inmPrevEven = evenBit;
|
||||||
@@ -376,7 +378,7 @@ int main() {
|
|||||||
} else {
|
} else {
|
||||||
oddBit = bit;
|
oddBit = bit;
|
||||||
}
|
}
|
||||||
if(!inmHealthCheckAddBit(evenBit, oddBit, even)) {
|
if(!inmHealthCheckAddBit(evenBit, oddBit, even, 0)) {
|
||||||
printf("Failed health check!\n");
|
printf("Failed health check!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,15 +37,59 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// The remaining 8 bits are driven with 0 .. 15 to help track the cause of misfires
|
||||||
|
#define ADDR0 3
|
||||||
|
#define ADDR1 5
|
||||||
|
#define ADDR2 6
|
||||||
|
#define ADDR3 7
|
||||||
|
|
||||||
// All data bus bits of the FT240X are outputs, except COMP1 and COMP2
|
// All data bus bits of the FT240X are outputs, except COMP1 and COMP2
|
||||||
#define MASK (0xff & ~(1 << COMP1) & ~(1 << COMP2))
|
#define MASK (0xff & ~(1 << COMP1) & ~(1 << COMP2))
|
||||||
|
|
||||||
|
// Convert an address value 0 to 15 to an 8-bit value using ADDR0 .. ADDR3.
|
||||||
|
static uint8_t makeAddress(uint8_t addr) {
|
||||||
|
uint8_t value = 0;
|
||||||
|
if(addr & 1) {
|
||||||
|
value |= 1 << ADDR0;
|
||||||
|
}
|
||||||
|
if(addr & 2) {
|
||||||
|
value |= 1 << ADDR1;
|
||||||
|
}
|
||||||
|
if(addr & 4) {
|
||||||
|
value |= 1 << ADDR2;
|
||||||
|
}
|
||||||
|
if(addr & 8) {
|
||||||
|
value |= 1 << ADDR3;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract a value form 0 to 15 from the ADDR0 .. ADDR3 bits.
|
||||||
|
static uint8_t extractAddress(uint8_t value) {
|
||||||
|
uint8_t addr = 0;
|
||||||
|
if(value & (1 << ADDR0)) {
|
||||||
|
addr |= 1;
|
||||||
|
}
|
||||||
|
if(value & (1 << ADDR1)) {
|
||||||
|
addr |= 2;
|
||||||
|
}
|
||||||
|
if(value & (1 << ADDR2)) {
|
||||||
|
addr |= 4;
|
||||||
|
}
|
||||||
|
if(value & (1 << ADDR3)) {
|
||||||
|
addr |= 8;
|
||||||
|
}
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Extract the INM output from the data received. Basically, either COMP1 or COMP2
|
// Extract the INM output from the data received. Basically, either COMP1 or COMP2
|
||||||
// changes, not both, so alternate reading bits from them. We get 1 INM bit of output
|
// changes, not both, so alternate reading bits from them. We get 1 INM bit of output
|
||||||
// per byte read. Feed bits from the INM to the health checker. Return the expected
|
// per byte read. Feed bits from the INM to the health checker. Return the expected
|
||||||
// bits of entropy.
|
// bits of entropy.
|
||||||
static uint32_t extractBytes(uint8_t *bytes, uint8_t *inBuf, bool raw) {
|
static uint32_t extractBytes(uint8_t *bytes, uint8_t *inBuf, bool raw) {
|
||||||
inmClearEntropyLevel();
|
inmClearEntropyLevel();
|
||||||
|
//printf("New batch\n");
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for(i = 0; i < BUFLEN/8; i++) {
|
for(i = 0; i < BUFLEN/8; i++) {
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
@@ -59,8 +103,9 @@ static uint32_t extractBytes(uint8_t *bytes, uint8_t *inBuf, bool raw) {
|
|||||||
uint8_t bit = even? oddBit : evenBit;
|
uint8_t bit = even? oddBit : evenBit;
|
||||||
byte = (byte << 1) | bit;
|
byte = (byte << 1) | bit;
|
||||||
// This is a good place to feed the bit from the INM to the health checker.
|
// This is a good place to feed the bit from the INM to the health checker.
|
||||||
//printf("Adding evenBit:%u oddBit:%u even:%u\n", evenBit, oddBit, even);
|
uint8_t addr = extractAddress(val);
|
||||||
if(!inmHealthCheckAddBit(evenBit, oddBit, even)) {
|
//printf("Address: %u, adding evenBit:%u oddBit:%u even:%u\n", addr, evenBit, oddBit, even);
|
||||||
|
if(!inmHealthCheckAddBit(evenBit, oddBit, even, addr)) {
|
||||||
fputs("Health check of Infinite Noise Multiplier failed!\n", stderr);
|
fputs("Health check of Infinite Noise Multiplier failed!\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -229,6 +274,7 @@ int main(int argc, char **argv)
|
|||||||
for(i = 0; i < BUFLEN; i++) {
|
for(i = 0; i < BUFLEN; i++) {
|
||||||
// Alternate Ph1 and Ph2 - maybe should have both off in between
|
// Alternate Ph1 and Ph2 - maybe should have both off in between
|
||||||
outBuf[i] = i & 1? (1 << SWEN2) : (1 << SWEN1);
|
outBuf[i] = i & 1? (1 << SWEN2) : (1 << SWEN1);
|
||||||
|
outBuf[i] |= makeAddress(i & 0xf);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
bool inmHealthCheckStart(uint8_t N, double K, bool debug);
|
bool inmHealthCheckStart(uint8_t N, double K, bool debug);
|
||||||
void inmHealthCheckStop(void);
|
void inmHealthCheckStop(void);
|
||||||
bool inmHealthCheckAddBit(bool evenBit, bool oddBit, bool even);
|
bool inmHealthCheckAddBit(bool evenBit, bool oddBit, bool even, uint8_t addr);
|
||||||
bool inmHealthCheckOkToUseData(void);
|
bool inmHealthCheckOkToUseData(void);
|
||||||
double inmHealthCheckEstimateK(void);
|
double inmHealthCheckEstimateK(void);
|
||||||
double inmHealthCheckEstimateEntropyPerBit(void);
|
double inmHealthCheckEstimateEntropyPerBit(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user