SimulatorMemory.h
/*
* Copyright (c) 2013-14, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _Memory_h_
#define _Memory_h_
#include "blfwk/host_types.h"
namespace blfwk
{
class MemoryStore
{
public:
enum
{
kMapIndexFlash = 0,
kMapIndexSRAM = 1
};
public:
MemoryStore(int mapIndex, uint32_t fillByte = 0)
: m_mapIndex(mapIndex)
, m_fillByte(fillByte)
, m_size(0)
, m_startAddress(0)
, m_memoryFile(NULL)
{
}
bool open(const std::string &pathToDir, bool forceCreate);
void close()
{
if (m_memoryFile)
{
fclose(m_memoryFile);
m_memoryFile = NULL;
}
}
size_t read(long int offset, size_t size, unsigned char *buffer);
size_t write(long int offset, size_t size, const unsigned char *buffer);
void erase(long int offset, size_t size);
void erase() { erase(0, m_size); }
protected:
int m_mapIndex;
uint8_t m_fillByte;
size_t m_size;
uint32_t m_startAddress;
FILE *m_memoryFile;
};
class FlashMemoryStore : public MemoryStore
{
public:
FlashMemoryStore()
: MemoryStore(MemoryStore::kMapIndexFlash, ~0)
{
}
};
class SramMemoryStore : public MemoryStore
{
public:
SramMemoryStore()
: MemoryStore(MemoryStore::kMapIndexSRAM)
{
}
};
class OptionsStore
{
public:
OptionsStore()
: m_optionsFile()
{
}
bool init(const std::string &pathToDir, bool forceCreate);
void persist();
protected:
std::string m_optionsFile;
};
} // namespace blfwk
// Prototypes
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
status_t sim_flash_read(uint32_t address, uint32_t length, uint8_t *buffer);
status_t sim_flash_write(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t sim_flash_fill(uint32_t address, uint32_t length, uint32_t pattern);
status_t sim_flash_erase(uint32_t address, uint32_t length);
status_t sim_flash_erase_all(void);
status_t sim_sram_mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
status_t sim_sram_mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t sim_sram_mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
status_t sim_device_mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
status_t sim_device_mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t sim_device_mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
#if defined(__cplusplus)
}
#endif // __cplusplus
#endif // _Memory_h_
// EOF
blfwk::MemoryStore::close
void close()
Close the store.
Definition: SimulatorMemory.h:72
blfwk::MemoryStore::write
size_t write(long int offset, size_t size, const unsigned char *buffer)
Write to memory.
Definition: SimulatorMemory.cpp:188
blfwk::MemoryStore::m_fillByte
uint8_t m_fillByte
Erase value.
Definition: SimulatorMemory.h:116
blfwk
Definition: BlfwkErrors.h:16
blfwk::FlashMemoryStore::FlashMemoryStore
FlashMemoryStore()
Default Constructor.
Definition: SimulatorMemory.h:129
blfwk::MemoryStore::m_mapIndex
int m_mapIndex
Index of memory map entry.
Definition: SimulatorMemory.h:115
blfwk::MemoryStore::kMapIndexFlash
Flash memory.
Definition: SimulatorMemory.h:47
blfwk::OptionsStore::m_optionsFile
std::string m_optionsFile
Options file name.
Definition: SimulatorMemory.h:177
blfwk::MemoryStore::m_startAddress
uint32_t m_startAddress
Address address from map.
Definition: SimulatorMemory.h:118
blfwk::MemoryStore::MemoryStore
MemoryStore(int mapIndex, uint32_t fillByte=0)
Constructor that takes a map index.
Definition: SimulatorMemory.h:56
blfwk::MemoryStore::read
size_t read(long int offset, size_t size, unsigned char *buffer)
Read from memory.
Definition: SimulatorMemory.cpp:177
blfwk::MemoryStore::m_size
size_t m_size
Size of memory file.
Definition: SimulatorMemory.h:117
blfwk::MemoryStore::m_memoryFile
FILE * m_memoryFile
Handle to memory file.
Definition: SimulatorMemory.h:119
blfwk::OptionsStore
Holds persistent options.
Definition: SimulatorMemory.h:151
blfwk::MemoryStore
Represents target device memory as a disk file.
Definition: SimulatorMemory.h:41
blfwk::SramMemoryStore
Represents target SRAM memory.
Definition: SimulatorMemory.h:138
blfwk::FlashMemoryStore
Represents target Flash memory.
Definition: SimulatorMemory.h:125
blfwk::OptionsStore::OptionsStore
OptionsStore()
Constructor.
Definition: SimulatorMemory.h:155
blfwk::MemoryStore::erase
void erase()
Erase all memory.
Definition: SimulatorMemory.h:113
blfwk::SramMemoryStore::SramMemoryStore
SramMemoryStore()
Default Constructor.
Definition: SimulatorMemory.h:142
blfwk::MemoryStore::open
bool open(const std::string &pathToDir, bool forceCreate)
Open the store.
Definition: SimulatorMemory.cpp:128
blfwk::MemoryStore::kMapIndexSRAM
SRAM.
Definition: SimulatorMemory.h:48