void testErase() { int i; uint16_t addr = 0x1F; getReady(); // Enable write shiftOutBits(EWEN_OPCODE, EWEN_OPCODE_BITS); shiftOutBits(0, EWEN_ADDR_BITS); standby(); if (writeTo(addr, addr)) { stop(); getReady(); // Write successful -- continue CPPUNIT_ASSERT_EQUAL(addr, readAt(addr)); stop(); getReady(); shiftOutBits(ERASE_OPCODE, ERASE_OPCODE_BITS); shiftOutBits(addr, ERASE_ADDR_BITS); standby(); for (i = 0; i < 200; i++) { if (eeprom->read() & DO) break; //usec_delay(50); } if (i == 200) { CPPUNIT_FAIL("EEPROM erase was not completed"); stop(); return; } standby(); shiftOutBits(EWDS_OPCODE, EWDS_OPCODE_BITS); shiftOutBits(0, EWDS_ADDR_BITS); stop(); getReady(); CPPUNIT_ASSERT_EQUAL((uint16_t)0xFFFF, readAt(addr)); } else { CPPUNIT_FAIL("EEPROM write was not completed"); } stop(); }
status_t BnDataSource::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { switch (code) { case GET_IMEMORY: { CHECK_INTERFACE(IDataSource, data, reply); reply->writeStrongBinder(IInterface::asBinder(getIMemory())); return NO_ERROR; } break; case READ_AT: { CHECK_INTERFACE(IDataSource, data, reply); off64_t offset = (off64_t) data.readInt64(); size_t size = (size_t) data.readInt64(); reply->writeInt64(readAt(offset, size)); return NO_ERROR; } break; case GET_SIZE: { CHECK_INTERFACE(IDataSource, data, reply); off64_t size; status_t err = getSize(&size); reply->writeInt32(err); reply->writeInt64(size); return NO_ERROR; } break; case CLOSE: { CHECK_INTERFACE(IDataSource, data, reply); close(); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } }
void testWriteAll() { uint16_t addr; getReady(); // Enable write writeOpAddr(EWEN_OPCODE, EWEN_OPCODE_BITS, 0, EWEN_ADDR_BITS); standby(); // Fill all memory writeOpAddr(WRAL_OPCODE, WRAL_OPCODE_BITS, 0, WRAL_ADDR_BITS); writeData(0xABBA); standby(); if (waitForCompletion()) { stop(); getReady(); // Write successful -- verify all memory for ( addr=0; addr < EEPROM93C46::SIZE; addr++ ) { CPPUNIT_ASSERT_EQUAL((uint16_t)0xABBA, readAt(addr)); } } else { CPPUNIT_FAIL("EEPROM write was not completed"); } stop(); }
void testEraseAll() { //unused: int i; uint16_t addr = 0x1F; getReady(); // Enable write writeOpAddr(EWEN_OPCODE, EWEN_OPCODE_BITS, 0, EWEN_ADDR_BITS); standby(); // Fill all memory writeOpAddr(WRITE_OPCODE, WRITE_OPCODE_BITS, addr, WRITE_ADDR_BITS); writeData(0); standby(); if (waitForCompletion()) { stop(); getReady(); // Write successful -- verify random location CPPUNIT_ASSERT_EQUAL((uint16_t)0, readAt(addr)); stop(); getReady(); writeOpAddr(ERAL_OPCODE, ERAL_OPCODE_BITS, addr, ERAL_ADDR_BITS); standby(); if (!waitForCompletion()) { CPPUNIT_FAIL("EEPROM erase was not completed"); stop(); return; } standby(); writeOpAddr(EWDS_OPCODE, EWDS_OPCODE_BITS, 0, EWDS_ADDR_BITS); stop(); getReady(); for ( addr=0; addr < EEPROM93C46::SIZE; addr++ ) { CPPUNIT_ASSERT_EQUAL((uint16_t)0xFFFF, readAt(addr)); } } else { CPPUNIT_FAIL("EEPROM write was not completed"); } stop(); }
void testWriteDisabled() { getReady(); uint16_t addr = 0; uint16_t oldValue = readAt(addr); stop(); getReady(); if (writeTo(addr, ~oldValue)) { // Write appears to be successful -- continue CPPUNIT_ASSERT_EQUAL(oldValue, readAt(addr)); } else { CPPUNIT_FAIL("EEPROM write was not completed"); } stop(); }
// @mfunc Attempt to read the number of bytes given by <p byteCount> // from the current position in this <c OMCachedRawStorage> // into the buffer at address <p bytes>. // The actual number of bytes read is returned in <p bytesRead>. // Reading from positions greater than // <mf OMCachedRawStorage::size> causes <p bytesRead> to be less // than <p byteCount>. Reading bytes that have never been written // returns undefined data in <p bytes>. // @parm The buffer into which the bytes are to be read. // @parm The number of bytes to read. // @parm The number of bytes actually read. // @this const void OMCachedRawStorage::read(OMByte* bytes, OMUInt32 byteCount, OMUInt32& bytesRead) const { TRACE("OMCachedRawStorage::read"); readAt(_position, bytes, byteCount, bytesRead); }
bool DataSource::getUInt16(off64_t offset, uint16_t *x) { *x = 0; uint8_t byte[2]; if (readAt(offset, byte, 2) != 2) { return false; } *x = (byte[0] << 8) | byte[1]; return true; }
bool DataSource::getUInt64(off64_t offset, uint64_t *x) { *x = 0; uint64_t tmp; if (readAt(offset, &tmp, 8) != 8) { return false; } *x = ntoh64(tmp); return true; }
bool DataSource::getUInt32(off64_t offset, uint32_t *x) { *x = 0; uint32_t tmp; if (readAt(offset, &tmp, 4) != 4) { return false; } *x = ntohl(tmp); return true; }
bool DataSource::getUInt24(off64_t offset, uint32_t *x) { *x = 0; uint8_t byte[3]; if (readAt(offset, byte, 3) != 3) { return false; } *x = (byte[0] << 16) | (byte[1] << 8) | byte[2]; return true; }
ssize_t TinyCacheSource::readAt(off64_t offset, void* data, size_t size) { if (size >= kCacheSize) { return mSource->readAt(offset, data, size); } // Check if the cache satisfies the read. if (mCachedOffset <= offset && offset < (off64_t) (mCachedOffset + mCachedSize)) { if (offset + size <= mCachedOffset + mCachedSize) { memcpy(data, &mCache[offset - mCachedOffset], size); return size; } else { // If the cache hits only partially, flush the cache and read the // remainder. // This value is guaranteed to be greater than 0 because of the // enclosing if statement. const ssize_t remaining = mCachedOffset + mCachedSize - offset; memcpy(data, &mCache[offset - mCachedOffset], remaining); const ssize_t readMore = readAt(offset + remaining, (uint8_t*)data + remaining, size - remaining); if (readMore < 0) { return readMore; } return remaining + readMore; } } // Fill the cache and copy to the caller. const ssize_t numRead = mSource->readAt(offset, mCache, kCacheSize); if (numRead <= 0) { // Flush cache on error mCachedSize = 0; mCachedOffset = 0; return numRead; } if ((size_t)numRead > kCacheSize) { // Flush cache on error mCachedSize = 0; mCachedOffset = 0; return ERROR_OUT_OF_RANGE; } mCachedSize = numRead; mCachedOffset = offset; CHECK(mCachedSize <= kCacheSize && mCachedOffset >= 0); const size_t numToReturn = std::min(size, (size_t)numRead); memcpy(data, mCache, numToReturn); return numToReturn; }
unsigned int IdHash::getTabId(const unsigned & id) const { return readAt(hashFunction(id),id); }
virtual ssize_t readAt(off_t offset, void *data, size_t size) { return readAt(static_cast<off64_t>(offset), data, size); }