Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
src/blfwk/DataTarget.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 #if !defined(_DataTarget_h_)
31 #define _DataTarget_h_
32 
33 #include "stdafx.h"
34 #include "DataSource.h"
35 
36 namespace blfwk
37 {
38 // Forward declaration
39 class DataSource;
40 
58 {
59 public:
62  struct AddressRange
63  {
64  uint32_t m_begin;
65  uint32_t m_end;
66  };
67 
68 public:
71  : m_source(0)
72  {
73  }
74 
76  virtual ~DataTarget() {}
78  virtual bool isBounded() { return false; }
79  virtual uint32_t getBeginAddress() { return 0; }
80  virtual uint32_t getEndAddress() { return 0; }
83 
84  inline void setSource(DataSource *source) { m_source = source; }
85  inline DataSource *getSource() const { return m_source; }
86 protected:
88 };
89 
98 {
99 public:
101  ConstantDataTarget(uint32_t start)
102  : DataTarget()
103  , m_begin(start)
104  , m_end(0)
105  , m_hasEnd(false)
106  {
107  }
108 
110  ConstantDataTarget(uint32_t start, uint32_t end)
111  : DataTarget()
112  , m_begin(start)
113  , m_end(end)
114  , m_hasEnd(true)
115  {
116  }
117 
119  virtual bool isBounded() { return m_hasEnd; }
120  virtual uint32_t getBeginAddress() { return m_begin; }
121  virtual uint32_t getEndAddress() { return m_end; }
124 
125 protected:
126  uint32_t m_begin;
127  uint32_t m_end;
128  bool m_hasEnd;
129 };
130 
139 {
140 public:
143  : DataTarget()
144  {
145  }
146 
148  virtual bool isBounded() { return true; }
151 };
152 
153 }; // namespace blfwk
154 
155 #endif // _DataTarget_h_
uint32_t m_end
End address.
Definition: src/blfwk/DataTarget.h:127
Definition: BlfwkErrors.h:16
virtual bool isBounded()
The target is bounded if an end address was specified.
Definition: src/blfwk/DataTarget.h:119
Target address that is the "natural" location of whatever the source data is.
Definition: src/blfwk/DataTarget.h:138
Simple structure that describes an addressed region of memory.
Definition: src/blfwk/DataTarget.h:62
DataSource * m_source
Corresponding data source for this target.
Definition: src/blfwk/DataTarget.h:87
NaturalDataTarget()
Default constructor.
Definition: src/blfwk/DataTarget.h:142
Abstract base class for the target address or range of data.
Definition: src/blfwk/DataTarget.h:57
uint32_t m_begin
Start address.
Definition: src/blfwk/DataTarget.h:126
ConstantDataTarget(uint32_t start, uint32_t end)
Constructor taking both begin and end addresses.
Definition: src/blfwk/DataTarget.h:110
Target with a constant values for the addresses.
Definition: src/blfwk/DataTarget.h:97
Discrete, contiguous part of the source's data.
Definition: src/blfwk/DataSource.h:65
ConstantDataTarget(uint32_t start)
Constructor taking only a begin address.
Definition: src/blfwk/DataTarget.h:101
Abstract base class for data sources.
Definition: src/blfwk/DataSource.h:56
bool m_hasEnd
Was an end address specified?
Definition: src/blfwk/DataTarget.h:128
DataTarget()
Default constructor.
Definition: src/blfwk/DataTarget.h:70
virtual bool isBounded()
Natural data targets are bounded by their source's segment lengths.
Definition: src/blfwk/DataTarget.h:148
virtual ~DataTarget()
Destructor.
Definition: src/blfwk/DataTarget.h:76
virtual bool isBounded()
Whether the target is just a single address or has an end to it.
Definition: src/blfwk/DataTarget.h:78
virtual DataTarget::AddressRange getRangeForSegment(DataSource &source, DataSource::Segment &segment)=0
Return the address range for a segment of a data source.