int main( void ) { cli(); setup_clock(); InitBuffer(&ab); //Don't touch any PORTB below 4, those are for printf // SetupPrintf(); USB_ZeroPrescaler(); USB_Init(); DDRC = 0x0; SPI_MasterInit(); // _delay_ms(10); //wait for tiny 44 to be ready for data // setup_timers(); setup_channel_interrupt(); DDRD |= _BV(PD6); sei(); // testAsm(); // if (testPtr == 'w') PORTD |= _BV(PD6); while(1) { UENUM = 4; //interrupts can change this //these if statements can take a bit of time so run them and save the //result for future use if ( USB_READY(UEINTX) && (BytesFree(&ab) >= 8) ) dataState=1; else if ( BytesUsed(&ab) >= 2) dataState=2; else dataState=0; while (needAudioFlag==0); cli(); needAudioFlag=0; DoAudioState(); sei(); } return 0; }
/*! Finds a good split index for an insertion of \a bytesNeeded bytes at index \a index. */ int32 DirEntryBlock::FindSplitIndex(int32 index, size_t bytesNeeded) const { size_t splitSize = (BytesUsed() + bytesNeeded) / 2; int32 entryCount = EntryCount(); for (int32 i = 0; i < entryCount; i++) { size_t bytesUsed = BytesUsedFor(i + 1); if (i == index) bytesUsed += bytesNeeded; if (bytesUsed > splitSize) return i; } // This should never happen. return entryCount; }
size_t DirEntryBlock::FreeSpace() const { return fBlockSize - BytesUsed(); }