Implementation of the memory read/write functions as used in the Adapter Pattern. More...
Go to the source code of this file.
Classes | |
struct | MemoryBlock |
Represents a single memory block. More... | |
Macros | |
#define | BLOCK_0_NAME "gorp" |
#define | BLOCK_1_NAME "baba" |
#define | BLOCK_2_NAME "yaga" |
#define | MAX_DATA_SIZE 32 |
Maximum number of 32-bit chunks in a single memory block. | |
Functions | |
static int | _FindBlock (const char *blockName) |
Retrieve the index of the requested memory block. | |
static bool | _ConvertHandleToBlockIndex (int dataHandle, int *memoryIndex) |
Convert the given data handle to an index into the memory blocks. | |
static bool | _IsValidOffset (int chunkOffset) |
Determine if the given offset is valid. | |
DDR_ErrorCode | DDR_OpenMemoryBlock (const char *blockName, int *dataHandle) |
Open access to a memory block for exclusive use, given the name of the memory block. | |
DDR_ErrorCode | DDR_CloseMemoryBlock (int dataHandle) |
Close access to a previously opened memory block, thus releasing it for others to open. | |
DDR_ErrorCode | DDR_GetMemorySize (int dataHandle, int *memorySizeInChunks) |
Retrieve the number of chunks in the memory block indicated by the handle to the successfully opened memory block. | |
DDR_ErrorCode | DDR_GetDataChunk (int dataHandle, int chunkOffset, uint32_t *value) |
Read a single 32-bit value at the given offset in the memory block indicated by the specified handle. | |
DDR_ErrorCode | DDR_SetDataChunk (int dataHandle, int chunkOffset, uint32_t value) |
Writes a single 32-bit value to the given offset in the memory block indicated by the specified handle. | |
Variables | |
const char * | BLOCK_NAME_0 = BLOCK_0_NAME |
Name of the first block. | |
const char * | BLOCK_NAME_1 = BLOCK_1_NAME |
Name of the second block. | |
const char * | BLOCK_NAME_2 = BLOCK_2_NAME |
Name of the third block. | |
static MemoryBlock | memory_blocks [] |
Predefined set of memory blocks that can be accessed by name. Data for each memory block is stored as a set of 32-bit values and can only be accessed as a 32-bit quantity. | |
static size_t | memory_block_count = _countof(memory_blocks) |
Implementation of the memory read/write functions as used in the Adapter Pattern.
Definition in file Adapter_BackEnd.c.
#define BLOCK_0_NAME "gorp" |
Definition at line 9 of file Adapter_BackEnd.c.
#define BLOCK_1_NAME "baba" |
Definition at line 10 of file Adapter_BackEnd.c.
#define BLOCK_2_NAME "yaga" |
Definition at line 11 of file Adapter_BackEnd.c.
#define MAX_DATA_SIZE 32 |
Maximum number of 32-bit chunks in a single memory block.
Definition at line 20 of file Adapter_BackEnd.c.
|
static |
Convert the given data handle to an index into the memory blocks.
dataHandle | Data handle as returned from the DDR_OpenMemoryBlock() function. |
memoryIndex | Returns the index into the memory blocks if the data handle is valid. |
Definition at line 89 of file Adapter_BackEnd.c.
References memory_block_count.
Referenced by DDR_CloseMemoryBlock(), DDR_GetDataChunk(), DDR_GetMemorySize(), and DDR_SetDataChunk().
|
static |
Retrieve the index of the requested memory block.
blockName | Name of the block to find |
Definition at line 65 of file Adapter_BackEnd.c.
References memory_block_count, and memory_blocks.
Referenced by DDR_OpenMemoryBlock().
|
static |
Determine if the given offset is valid.
chunkOffset | Offset into a memory block to verify. |
Definition at line 113 of file Adapter_BackEnd.c.
References DDR_MAX_OFFSET.
Referenced by DDR_GetDataChunk(), and DDR_SetDataChunk().
DDR_ErrorCode DDR_CloseMemoryBlock | ( | int | dataHandle | ) |
Close access to a previously opened memory block, thus releasing it for others to open.
dataHandle | Handle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function. |
Definition at line 150 of file Adapter_BackEnd.c.
References _ConvertHandleToBlockIndex(), DDR_ErrorCode_Block_Not_Opened, DDR_ErrorCode_Invalid_Handle, DDR_ErrorCode_Success, MemoryBlock::locked, and memory_blocks.
Referenced by Adapter_CloseMemory(), and DataReaderWriter::~DataReaderWriter().
DDR_ErrorCode DDR_GetDataChunk | ( | int | dataHandle, |
int | chunkOffset, | ||
uint32_t * | value | ||
) |
Read a single 32-bit value at the given offset in the memory block indicated by the specified handle.
dataHandle | Handle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function. |
chunkOffset | Offset into the memory block from which to get the value (range is 0 to DDR_MAX_OFFSET-1). |
value | Returns the requested value. |
Definition at line 191 of file Adapter_BackEnd.c.
References _ConvertHandleToBlockIndex(), _IsValidOffset(), MemoryBlock::data, DDR_ErrorCode_Block_Not_Opened, DDR_ErrorCode_Invalid_Offset, DDR_ErrorCode_Null_Argument, DDR_ErrorCode_Success, and memory_blocks.
Referenced by Adapter_ReadMemory(), Adapter_WriteMemory(), DataReaderWriter::Read(), and DataReaderWriter::Write().
DDR_ErrorCode DDR_GetMemorySize | ( | int | dataHandle, |
int * | memorySizeInChunks | ||
) |
Retrieve the number of chunks in the memory block indicated by the handle to the successfully opened memory block.
dataHandle | Handle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function. |
memorySizeInChunks | Returns the number of 32-bit chunks in the memory block. |
Definition at line 171 of file Adapter_BackEnd.c.
References _ConvertHandleToBlockIndex(), DDR_ErrorCode_Invalid_Handle, DDR_ErrorCode_Null_Argument, DDR_ErrorCode_Success, and MAX_DATA_SIZE.
Referenced by Adapter_GetMemorySize(), and DataReaderWriter::DataReaderWriter().
DDR_ErrorCode DDR_OpenMemoryBlock | ( | const char * | blockName, |
int * | dataHandle | ||
) |
Open access to a memory block for exclusive use, given the name of the memory block.
blockName | Name of the block to access (one of the predefined names, BLOCK_NAME_0 , BLOCK_NAME_1 , or BLOCK_NAME_2 ) |
dataHandle | Returns a handle to be used for accessing the specific memory block. |
Definition at line 121 of file Adapter_BackEnd.c.
References _FindBlock(), DDR_ErrorCode_Block_Already_Opened, DDR_ErrorCode_Invalid_Block_Name, DDR_ErrorCode_Null_Argument, DDR_ErrorCode_Success, DDR_INVALID_HANDLE, MemoryBlock::locked, and memory_blocks.
Referenced by Adapter_OpenMemory(), and DataReaderWriter::DataReaderWriter().
DDR_ErrorCode DDR_SetDataChunk | ( | int | dataHandle, |
int | chunkOffset, | ||
uint32_t | value | ||
) |
Writes a single 32-bit value to the given offset in the memory block indicated by the specified handle.
dataHandle | Handle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function. |
chunkOffset | Offset into the memory block to which to set the value (range is 0 to DDR_MAX_OFFSET-1). |
value | The value to write to the memory block |
Definition at line 219 of file Adapter_BackEnd.c.
References _ConvertHandleToBlockIndex(), _IsValidOffset(), MemoryBlock::data, DDR_ErrorCode_Block_Not_Opened, DDR_ErrorCode_Invalid_Handle, DDR_ErrorCode_Invalid_Offset, DDR_ErrorCode_Success, and memory_blocks.
Referenced by Adapter_WriteMemory(), and DataReaderWriter::Write().
const char* BLOCK_NAME_0 = BLOCK_0_NAME |
Name of the first block.
Definition at line 13 of file Adapter_BackEnd.c.
Referenced by DataReaderWriter::_GetBlockNameForBlockNumber(), and _GetBlockNameForBlockNumber().
const char* BLOCK_NAME_1 = BLOCK_1_NAME |
Name of the second block.
Definition at line 14 of file Adapter_BackEnd.c.
Referenced by DataReaderWriter::_GetBlockNameForBlockNumber(), and _GetBlockNameForBlockNumber().
const char* BLOCK_NAME_2 = BLOCK_2_NAME |
Name of the third block.
Definition at line 15 of file Adapter_BackEnd.c.
Referenced by DataReaderWriter::_GetBlockNameForBlockNumber(), and _GetBlockNameForBlockNumber().
|
static |
Definition at line 57 of file Adapter_BackEnd.c.
Referenced by _ConvertHandleToBlockIndex(), and _FindBlock().
|
static |
Predefined set of memory blocks that can be accessed by name. Data for each memory block is stored as a set of 32-bit values and can only be accessed as a 32-bit quantity.
Definition at line 50 of file Adapter_BackEnd.c.
Referenced by _FindBlock(), DDR_CloseMemoryBlock(), DDR_GetDataChunk(), DDR_OpenMemoryBlock(), and DDR_SetDataChunk().