MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/MemoryAccessSplitter.cpp
2024-06-07 11:12:56 +03:00

85 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* MemoryAccessSplitter.cpp
*
* Created on: 28 июл. 2020 г.
* Author: LeonidTitov
*/
#include "MemoryAccessSplitter.hh"
peripheral::IMemoryAccess & driver::MemoryAccessSplitter::piece() {
return first_part;
}
peripheral::IMemoryAccess & driver::MemoryAccessSplitter::remainder() {
return second_part;
}
driver::MemoryAccessSplitter::MemoryAccessSplitter(
peripheral::IMemoryAccess & memory, std::size_t piece_size ) :
first_part( memory, piece_size, 0 ),
second_part( memory, memory.getCapacity() - piece_size, piece_size ) {}
bool driver::MemoryAccessSplitter::MemoryPiece::read(char * data,
std::size_t r_begin,
std::size_t r_size ) {
if( r_begin + r_size > size )
read_query = false;
else
read_query = memory.read( data, r_begin + offset, r_size );
if( read_query )
read_complite = false;
return read_query;
}
bool driver::MemoryAccessSplitter::MemoryPiece::write(const char * data,
std::size_t w_begin,
std::size_t w_size ) {
if( w_begin + w_size > size )
write_query = false;
else
write_query = memory.write( data, w_begin + offset, w_size );
if( write_query )
write_complite = false;
return write_query;
}
bool driver::MemoryAccessSplitter::MemoryPiece::isReadComplete() const {
if( read_query and memory.isReadComplete() )
read_complite = true;
return read_query and read_complite;
}
bool driver::MemoryAccessSplitter::MemoryPiece::isWriteComplete() const {
if( write_query and memory.isWriteComplete() )
write_complite = true;
return write_query and write_complite;
}
std::size_t driver::MemoryAccessSplitter::MemoryPiece::getCapacity() const {
return size;
}
driver::MemoryAccessSplitter::MemoryPiece::MemoryPiece(
peripheral::IMemoryAccess & memory, std::size_t size, std::size_t offset ) : memory(memory), size(size), offset(offset) {}