Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
SimulatorMemory.h
1 /*
2  * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _Memory_h_
32 #define _Memory_h_
33 
34 #include "blfwk/host_types.h"
35 
36 namespace blfwk
37 {
42 {
43 public:
45  enum
46  {
49  };
50 
51 public:
56  MemoryStore(int mapIndex, uint32_t fillByte = 0)
57  : m_mapIndex(mapIndex)
58  , m_fillByte(fillByte)
59  , m_size(0)
60  , m_startAddress(0)
61  , m_memoryFile(NULL)
62  {
63  }
64 
69  bool open(const std::string &pathToDir, bool forceCreate);
70 
72  void close()
73  {
74  if (m_memoryFile)
75  {
76  fclose(m_memoryFile);
77  m_memoryFile = NULL;
78  }
79  }
80 
90  size_t read(long int offset, size_t size, unsigned char *buffer);
91 
101  size_t write(long int offset, size_t size, const unsigned char *buffer);
102 
110  void erase(long int offset, size_t size);
111 
113  void erase() { erase(0, m_size); }
114 protected:
116  uint8_t m_fillByte;
117  size_t m_size;
118  uint32_t m_startAddress;
119  FILE *m_memoryFile;
120 };
121 
126 {
127 public:
131  {
132  }
133 };
134 
139 {
140 public:
144  {
145  }
146 };
147 
152 {
153 public:
156  : m_optionsFile()
157  {
158  }
159 
164  bool init(const std::string &pathToDir, bool forceCreate);
165 
167  void persist();
168 
170 
171 
173 
175 
176 protected:
177  std::string m_optionsFile;
178 };
179 
180 } // namespace blfwk
181 
183 // Prototypes
185 
186 #if defined(__cplusplus)
187 extern "C" {
188 #endif // __cplusplus
189 
198 status_t sim_flash_read(uint32_t address, uint32_t length, uint8_t *buffer);
199 
208 status_t sim_flash_write(uint32_t address, uint32_t length, const uint8_t *buffer);
209 
218 status_t sim_flash_fill(uint32_t address, uint32_t length, uint32_t pattern);
219 
227 status_t sim_flash_erase(uint32_t address, uint32_t length);
228 
233 status_t sim_flash_erase_all(void);
234 
243 status_t sim_sram_mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
244 
253 status_t sim_sram_mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
254 
263 status_t sim_sram_mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
264 
270 status_t sim_device_mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
271 
277 status_t sim_device_mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
278 
284 status_t sim_device_mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
285 
286 #if defined(__cplusplus)
287 }
288 #endif // __cplusplus
289 
290 #endif // _Memory_h_
291 
293 // EOF
void close()
Close the store.
Definition: SimulatorMemory.h:72
size_t write(long int offset, size_t size, const unsigned char *buffer)
Write to memory.
Definition: SimulatorMemory.cpp:188
uint8_t m_fillByte
Erase value.
Definition: SimulatorMemory.h:116
Definition: BlfwkErrors.h:16
FlashMemoryStore()
Default Constructor.
Definition: SimulatorMemory.h:129
int m_mapIndex
Index of memory map entry.
Definition: SimulatorMemory.h:115
Flash memory.
Definition: SimulatorMemory.h:47
std::string m_optionsFile
Options file name.
Definition: SimulatorMemory.h:177
uint32_t m_startAddress
Address address from map.
Definition: SimulatorMemory.h:118
MemoryStore(int mapIndex, uint32_t fillByte=0)
Constructor that takes a map index.
Definition: SimulatorMemory.h:56
size_t read(long int offset, size_t size, unsigned char *buffer)
Read from memory.
Definition: SimulatorMemory.cpp:177
size_t m_size
Size of memory file.
Definition: SimulatorMemory.h:117
FILE * m_memoryFile
Handle to memory file.
Definition: SimulatorMemory.h:119
Holds persistent options.
Definition: SimulatorMemory.h:151
Represents target device memory as a disk file.
Definition: SimulatorMemory.h:41
Represents target SRAM memory.
Definition: SimulatorMemory.h:138
Represents target Flash memory.
Definition: SimulatorMemory.h:125
OptionsStore()
Constructor.
Definition: SimulatorMemory.h:155
void erase()
Erase all memory.
Definition: SimulatorMemory.h:113
SramMemoryStore()
Default Constructor.
Definition: SimulatorMemory.h:142
bool open(const std::string &pathToDir, bool forceCreate)
Open the store.
Definition: SimulatorMemory.cpp:128
SRAM.
Definition: SimulatorMemory.h:48