bool MemoryManagerV3::flushAll()
{
	for (unsigned int i = 0; i < this->count(); ++i) 
	{
		MemoryArea* area = this->getMemoryArea(i);
		MemoryCacheCtrl* ctrl = area->getCacheCtrl();
		if (ctrl) 
		{
			if (!ctrl->flush(0, area->getSize()))
				return false;

			ctrl->clear(0, area->getSize());
		}
	}
	return true;
}
bool MemoryAreaBase::verify(uint32_t address, uint32_t* buffer, size_t count)
{
	MemoryCacheCtrl* cc = this->getCacheCtrl(); 
	if (cc && !cc->flush(address,count))
		return false;

	if (address & 0x1) 
	{
		uint32_t tmp = 0;	
		if (!this->read(address++, &tmp, 1) || !this->sync())
			return false;

		if (buffer? tmp != *(buffer++): tmp != 0xFF)
			return false;

		--count;
	}

	if (count > 1) 
	{
		HalExecCommand cmd;
		cmd.setTimeout( max((size_t)20000, count/15) ); //Set timeout according to data size
		
		HalExecElement*el = new HalExecElement(this->devHandle->checkHalId(ID_Psa));
		el->appendInputData32(static_cast<uint32_t>((address+this->getStart()) & 0xFFFFFFFF));
		el->appendInputData32(static_cast<uint32_t>((count / 2) & 0xFFFFFFFF));
		el->appendInputData8(this->psaType);
		el->setOutputSize(2);
		cmd.elements.push_back(el);
		if (!this->devHandle->send(cmd))
			return false;
		
		if (MemoryAreaBase::psa(address+this->getStart(), buffer, (size_t)((uint32_t)count&0xfffffffe)) != el->getOutputAt16(0))
			return false;				
	}

	if (count & 1) 
	{
		uint32_t tmp = 0;
		if (!this->read(address + count - 1, &tmp, 1) || !this->sync())
			return false;

		if (buffer? tmp != buffer[count - 1]: tmp != 0xFF)
			return false;
	}
	return true;
}