CMemorySegment.cpp
6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//===========================================================
//
// Class Name: CMemorySegment
//
//===========================================================
// SOURCE CODE NOTES:
//==========================================================
//
// No notes.
//
//
//
//===========================================================
//===========================================================
// SOURCE INCLUDE FILE SECTION
//===========================================================
#include "CMemorySegment.h"
#include <memory.h>
#include <stdio.h>
//===========================================================
// TYPES
//===========================================================
//===========================================================
// Public Functions
//===========================================================
bool CMemorySegment::PrintWorkingDataBytes( CMessageIO& message_interface )
{
message_interface.PrintStringStdioLF( "----------- Start of Working Bytes Hex Dump -----------");
message_interface.PrintStringStdioLF("");
const UnSignedLong row_size = 16;
for( UnSignedLong i=0; i<m_working_byte_size; i++ )
{
if( i % row_size == 0 )
{
char buffer[50];
sprintf(&(buffer[0]),"[%10lX - %10lX] :", (unsigned long)(m_working_start_address+i), (unsigned long)(m_working_start_address+i+row_size) );
message_interface.PrintStringStdioLF(&(buffer[0]));
}
else
if( i % 4 == 0 )
{
message_interface.PrintStringStdio(", ");
}
volatile unsigned char *char_ptr = ( volatile unsigned char *)(m_working_start_address+i);
unsigned char tmp = *char_ptr;
char buffer[20];
sprintf(&(buffer[0])," %2X", (unsigned int)tmp);
message_interface.PrintStringStdio( &(buffer[0]) );
}
message_interface.PrintStringStdioLF("");
message_interface.PrintStringStdioLF( "----------- End of Working Bytes Hex Dump -----------");
return( true );
}
//===========================================================
bool CMemorySegment::SetWorkingAddressForAccessOnly( volatile AddressType access_only_address )
{
if( m_working_start_address != 0 )
{
return( false ); //This segment has already been created.
}
m_working_start_address = ( volatile unsigned char *) access_only_address;
return( true );
}
bool CMemorySegment::Create( const UnSignedLong working_data_bytes, const UnSignedLong alignment_boundary, const unsigned char init_value )
{
m_working_byte_size = working_data_bytes;
m_alignment_boundary = alignment_boundary;
m_true_byte_size = working_data_bytes + (alignment_boundary*2);
m_true_heap_start_address = (volatile unsigned char*) AllocMemory( m_true_byte_size );
if( m_true_heap_start_address == 0 )
{
return( false );
}
m_working_start_address = ( volatile unsigned char *) ((m_true_heap_start_address + ( m_alignment_boundary - ((UnSignedLong)m_true_heap_start_address%m_alignment_boundary))));
for( UnSignedLong i=0; i<m_true_byte_size; i++ )
{
((volatile unsigned char*)m_true_heap_start_address)[i] = init_value;
}
return( true );
}
//===========================================================
volatile AddressType CMemorySegment::GetWorkingAddress() const
{
return( (AddressType) m_working_start_address );
}
//===========================================================
//===========================================================
// Member functions default overrides
//===========================================================
CMemorySegment::CMemorySegment( ) // Default constructor
{
//Set the default values
m_true_heap_start_address = 0;
m_working_start_address = 0;
m_working_byte_size = 0;
m_true_byte_size = 0;
m_alignment_boundary = 0;
}
//===========================================================
CMemorySegment::~CMemorySegment( ) // Destructor
{
if( m_true_heap_start_address != 0 )
{
DeleteMemory( (AddressType)m_true_heap_start_address );
}
}
//===========================================================
CMemorySegment::CMemorySegment( const CMemorySegment &cmemorysegment_item ) // Copy constructor
{
CopyDataToThis( cmemorysegment_item );
}
//===========================================================
//===========================================================
// Operator Members
//===========================================================
CMemorySegment& CMemorySegment::operator = ( const CMemorySegment &cmemorysegment_item )
{
CopyDataToThis( cmemorysegment_item );
return( *this );
}
//===========================================================
bool CMemorySegment::operator == ( const CMemorySegment &cmemorysegment_item ) const
{
bool return_value = false;
if( m_true_heap_start_address == cmemorysegment_item.m_true_heap_start_address &&
m_working_start_address == cmemorysegment_item.m_working_start_address &&
m_working_byte_size == cmemorysegment_item.m_working_byte_size &&
m_true_byte_size == cmemorysegment_item.m_true_byte_size &&
m_alignment_boundary == cmemorysegment_item.m_alignment_boundary )
return_value = true;
return( return_value );
}
//===========================================================
//===========================================================
// Private Functions
//===========================================================
//===========================================================
// GetCopy Member Functions
//===========================================================
UnSignedLong CMemorySegment::GetCopyWorkingByteSize( void ) const
{
return( m_working_byte_size );
}
//===========================================================
UnSignedLong CMemorySegment::GetCopyTrueByteSize( void ) const
{
return( m_true_byte_size );
}
//===========================================================
//===========================================================
// Set Member Functions
//===========================================================
//===========================================================
// Protected Functions
//===========================================================
void CMemorySegment::CopyDataToThis( const CMemorySegment &cmemorysegment_item ) //Class copy internal data.
{
//Copy all the data into this.
m_true_heap_start_address = cmemorysegment_item.m_true_heap_start_address;
m_working_start_address = cmemorysegment_item.m_working_start_address;
m_working_byte_size = cmemorysegment_item.m_working_byte_size;
m_true_byte_size = cmemorysegment_item.m_true_byte_size;
m_alignment_boundary = cmemorysegment_item.m_alignment_boundary;
}
//===========================================================
// Friend functions
//===========================================================
//===========================================================
// END OF FILE
//===========================================================