uint8_t one_wire_read_bit (void) { uint8_t a; PIN_OUTPUT (ONE_WIRE_DATA_PORT, ONE_WIRE_DATA_BIT) ; CLEARBIT (ONE_WIRE_DATA_PORT, ONE_WIRE_DATA_BIT) ; _delay_us (1) ; SETBIT (ONE_WIRE_DATA_PORT, ONE_WIRE_DATA_BIT) ; PIN_INPUT (ONE_WIRE_DATA_PORT, ONE_WIRE_DATA_BIT) ; _delay_us (9) ; a = BITVAL (ONE_WIRE_DATA_PIN, ONE_WIRE_DATA_BIT) ; _delay_us (50) ; return a; }
/* * Determine the next random block number to which to write. * If an already-written block is selected, choose the next * unused higher-numbered block. Returns the block number, * or -1 if we exhaust available blocks looking for an unused * one. */ static int findblock(void) { int block, numblocks; numblocks = filesize / blocksize; block = random() % numblocks; while (BITVAL(valid, block)) { if (++block == numblocks) { printf("returning block -1\n"); return -1; } } return block; }
static int readblks(int fd, size_t alignment) { __uint64_t offset; char *buffer, *tmp; unsigned int xfer, block, i; int err=0; if (alloconly) return 0; xfer = READ_XFER*blocksize; if (posix_memalign((void **) &buffer, alignment, xfer)) { perror("malloc"); exit(1); } memset(buffer, 0, xfer); if (verbose) printf("\n"); if (lseek64(fd, fileoffset, SEEK_SET) < 0) { perror("lseek"); exit(1); } block = 0; offset = 0; while (offset < filesize) { if ((i = read(fd, buffer, xfer) < xfer)) { if (i < 2) break; perror("read"); exit(1); } tmp = buffer; for (i = 0; i < READ_XFER; i++) { __uint64_t want; __uint64_t first; __uint64_t second; if (verbose && ((block % 100) == 0)) { printf("+"); fflush(stdout); } want = BITVAL(valid, block) ? offset : 0; first = *(__uint64_t *) tmp; second = *(__uint64_t *) (tmp + 256); if (first != want || second != want) { printf("mismatched data at offset=0x%" PRIx64 ", expected 0x%" PRIx64 ", got 0x%" PRIx64 " and 0x%" PRIx64 "\n", fileoffset + offset, want, first, second); err++; } if (verbose > 2) { printf("block %d blocksize %d\n", block, blocksize); dumpblock((int *)tmp, fileoffset + offset, blocksize); } block++; offset += blocksize; tmp += blocksize; } } if (verbose) printf("\n"); free(buffer); return err; }
#else const unsigned int PortADuet12KOutputBit = 2; const unsigned int AdcThermistor1Chan = 3; const unsigned int PortASeriesResistorSenseBit = 4; #endif const unsigned int PortAFanControlBit = 5; const unsigned int PortANearLedBit = 6; #if DUAL_NOZZLE const unsigned int PortADuet12KOutputBit = 7; #else const unsigned int PortADuet10KOutputBit = 7; #endif const uint8_t PortAUnusedBitMask = 0; const uint8_t PortBFarLedMask = BITVAL(0) | BITVAL(1); #if DUAL_NOZZLE const unsigned int PortBDuet10KOutputBit = 2; const uint8_t PortBUnusedBitMask = 0; #elif ISR_DEBUG const unsigned int PortBDebugPin = 2; const uint8_t PortBUnusedBitMask = 0; #else const uint8_t PortBUnusedBitMask = BITVAL(2); #endif // Approximate MPU frequency (8MHz internal oscillator) const uint32_t F_CPU = 8000000uL; // IR parameters. These also allow us to receive a signal through the command input. const uint16_t interruptFreq = 8000; // interrupt frequency. We run the IR sensor at one quarter of this, i.e. 2kHz