Design Pattern Examples
Overview of object-oriented design patterns
Adapter_Functions.h File Reference

Declaration of the Adapter functions used in the Adapter Pattern. More...

#include <stdbool.h>
#include <stdint.h>
Include dependency graph for Adapter_Functions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __ADAPTER_FUNCTIONS_H__
 

Enumerations

enum  MemoryBlockNumber { Memory_Block_0 = 0 , Memory_Block_1 = 1 , Memory_Block_2 = 2 }
 Represents the memory blocks that can be accessed. Hides how memory blocks are actually identified. More...
 

Functions

bool Adapter_OpenMemory (MemoryBlockNumber blockNumber, int *dataHandle)
 Open a memory block for access.
 
bool Adapter_CloseMemory (int dataHandle)
 Closes a memory block from access.
 
bool Adapter_GetMemorySize (int dataHandle, int *sizeInBytes)
 Retrieve the number of bytes in the memory block associated with the specified data handle.
 
bool Adapter_ReadMemory (int dataHandle, int byteOffset, uint8_t *buffer, int maxBytes, int *bytesRead)
 Read a requested number of bytes from the memory block associated with the given handle.
 
bool Adapter_WriteMemory (int dataHandle, int byteOffset, const uint8_t *buffer, int maxBytes, int *bytesWritten)
 Write a requested number of bytes to the memory block associated with the given handle.
 
const char * Adapter_GetLastErrorMessage (void)
 Retrieve a string describing the last error that occurred in the Adapter.
 
const char * Adapter_BufferToString (const uint8_t *data, uint32_t maxBytes, int indent)
 Convert the specified data up to the specified number of bytes into a string by performing a "hex dump" on the data.
 

Detailed Description

Declaration of the Adapter functions used in the Adapter Pattern.

Definition in file Adapter_Functions.h.

Macro Definition Documentation

◆ __ADAPTER_FUNCTIONS_H__

#define __ADAPTER_FUNCTIONS_H__

Definition at line 8 of file Adapter_Functions.h.

Enumeration Type Documentation

◆ MemoryBlockNumber

Represents the memory blocks that can be accessed. Hides how memory blocks are actually identified.

Enumerator
Memory_Block_0 

First block.

Memory_Block_1 

Second block.

Memory_Block_2 

Third block.

Definition at line 17 of file Adapter_Functions.h.

Function Documentation

◆ Adapter_BufferToString()

const char * Adapter_BufferToString ( const uint8_t *  data,
uint32_t  maxBytes,
int  indent 
)

Convert the specified data up to the specified number of bytes into a string by performing a "hex dump" on the data.

Parameters
dataThe data to process.
maxBytesThe number of bytes from the data to process.
indentNumber of spaces to indent each line.
Returns
A string containing the data in the form of a hex dump, possibly multiple lines.

Definition at line 400 of file Adapter_Functions.c.

References _countof, _hexdump, and _ReportErrorMessage().

Referenced by Adapter_Exercise().

◆ Adapter_CloseMemory()

bool Adapter_CloseMemory ( int  dataHandle)

Closes a memory block from access.

Parameters
dataHandleThe handle returned from Adapter_OpenMemory() to be closed.
Returns
Returns true if all went well; otherwise, returns false, use AdapterGetLastErrorMessage() to get the reason for the failure.

Definition at line 173 of file Adapter_Functions.c.

References _ReportDDRError(), _ResetLastError(), DDR_CloseMemoryBlock(), and DDR_ErrorCode_Success.

Referenced by Adapter_Exercise().

◆ Adapter_GetLastErrorMessage()

const char * Adapter_GetLastErrorMessage ( void  )

Retrieve a string describing the last error that occurred in the Adapter.

Returns
A string containing an error message. Remains valid until the next Adapter operation that is called.

Definition at line 391 of file Adapter_Functions.c.

References _lastError.

Referenced by Adapter_Exercise().

◆ Adapter_GetMemorySize()

bool Adapter_GetMemorySize ( int  dataHandle,
int *  sizeInBytes 
)

Retrieve the number of bytes in the memory block associated with the specified data handle.

Parameters
dataHandleThe handle returned from Adapter_OpenMemory() to access.
sizeInBytesReturns the number of bytes available to access.
Returns
Returns true if all went well; otherwise, returns false, use AdapterGetLastErrorMessage() to get the reason for the failure.

Definition at line 191 of file Adapter_Functions.c.

References _ReportDDRError(), _ReportErrorMessage(), _ResetLastError(), DDR_ErrorCode_Success, and DDR_GetMemorySize().

Referenced by Adapter_Exercise().

◆ Adapter_OpenMemory()

bool Adapter_OpenMemory ( MemoryBlockNumber  blockNumber,
int *  dataHandle 
)

Open a memory block for access.

Parameters
blockNumberA value from the MemoryBlockNumber enumeration indicating which memory block to access.
dataHandleReturns the handle to the memory block to access.
Returns
Returns true if all went well; otherwise, returns false, use AdapterGetLastErrorMessage() to get the reason for the failure.

Definition at line 142 of file Adapter_Functions.c.

References _GetBlockNameForBlockNumber(), _ReportDDRError(), _ReportErrorMessage(), _ResetLastError(), DDR_ErrorCode_Success, and DDR_OpenMemoryBlock().

Referenced by Adapter_Exercise().

◆ Adapter_ReadMemory()

bool Adapter_ReadMemory ( int  dataHandle,
int  byteOffset,
uint8_t *  buffer,
int  maxBytes,
int *  bytesRead 
)

Read a requested number of bytes from the memory block associated with the given handle.

Parameters
dataHandleThe handle returned from Adapter_OpenMemory() to access.
byteOffsetByte offset into the memory block from which to start reading.
bufferBuffer to fill with bytes from the memory block.
maxBytesThe number of bytes to read.
bytesReadif not NULL, returns the number of bytes actually read.
Returns
Returns true if all went well; otherwise, returns false, use AdapterGetLastErrorMessage() to get the reason for the failure.

Definition at line 223 of file Adapter_Functions.c.

References _ReportDDRError(), _ReportErrorMessage(), _ResetLastError(), DDR_ErrorCode_Success, DDR_GetDataChunk(), and DDR_MAX_OFFSET.

Referenced by Adapter_Exercise().

◆ Adapter_WriteMemory()

bool Adapter_WriteMemory ( int  dataHandle,
int  byteOffset,
const uint8_t *  buffer,
int  maxBytes,
int *  bytesWritten 
)

Write a requested number of bytes to the memory block associated with the given handle.

Parameters
dataHandleThe handle returned from Adapter_OpenMemory() to access.
byteOffsetByte offset into the memory block to which to start writing.
bufferBuffer of bytes to write to the memory block.
maxBytesThe number of bytes to write.
bytesWrittenIf not NULL, returns the number of bytes actually written.
Returns
Returns true if all went well; otherwise, returns false, use AdapterGetLastErrorMessage() to get the reason for the failure.

Definition at line 294 of file Adapter_Functions.c.

References _ReportDDRError(), _ReportErrorMessage(), _ResetLastError(), DDR_ErrorCode_Success, DDR_GetDataChunk(), DDR_MAX_OFFSET, and DDR_SetDataChunk().

Referenced by Adapter_Exercise().