SystemAccess.cpp
3.61 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
//////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------//
//-- Copyright 2001 VAutomation Inc. Nashua NH USA. All rights reserved.//
//-- This software is provided under license and contains proprietary //
//-- and confidential material which is the property of VAutomation Inc.//
//-- HTTP://www.vautomation.com //
//----------------------------------------------------------------------//
//////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// SystemAccess.cpp: implementation of the CVirtualComponentInterface class.
//
///////////////////////////////////////////////////////////////////
#include "SystemAccess.h"
#include "MainEntry.h"
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
bool DeleteMemory( AddressType allocated_data )
{
if( (void*)allocated_data == NULL )
{
printf("Error: Attempt to delete a NULL pointer.");
return( false );
}
else
{
delete( (void*)allocated_data );
return( true );
}
}
AddressType AllocMemory( const UnSignedLong & size )
{
AddressType new_address;
new_address = (AddressType) new unsigned char[size];
return( new_address );
}
bool GetSystemTicks( ClockType& units, const TimeType time_type )
{
return( true );
}
bool SystemWait( const UnSignedLong& units, const TimeType time_type )
{
bool status = true;
//This function will be set to burn cpu time for a default of 30MHZ
//Some considerations when dealing with code optimizations.
// 1-Use a branch to keep the compiler from removing the code.
// 2-Make sure we do not create bus accesses.
// 3-Expect this function to be used with 1 TICK in most cases.
UnSignedLong ns_units; //Not set
switch( time_type )
{
case TICK_UNITS:
ns_units = 33; //one clock at 30MHZ
break;
case NS_UNITS:
ns_units = 1;
break;
case US_UNITS: //about 0.03333 per tick
ns_units = 1000;
break;
case MS_UNITS:
ns_units = 1000000;
break;
case SEC_UNITS:
ns_units = 1000000000;
break;
default:
status = false;
ns_units = 1;
break;
};
//This loop will attempt to burn 33 ns per loop iter
//on the ARC processor.
const UnSignedLong NS_PER_LOOP = 231; //2 clocks for the loop cmp, 2 for the if cmp, 3 for the -= , Total 7 , 7*33 = 231, WAG
UnSignedLong iters_33_ns = units * ns_units;
while( iters_33_ns > NS_PER_LOOP )
{
iters_33_ns -= NS_PER_LOOP;
if( iters_33_ns < NS_PER_LOOP ) //This branch is to keep the compiler from removing the loop code.
{
return( status );
}
}
return(status);
}
#ifndef WIN32
_Asm int SetErrorRegister(UnSignedLong error_code)
{
%reg error_code
mov %r11, error_code
// department/test system/dut
or %r11, %r11, BASE_TEST_CODE
// set
mov %r25, %r11
}
#else
int SetErrorRegister(UnSignedLong error_code)
{
return(0);
}
#endif
void SystemAbort( char* message, UnSignedLong error_code )
{
error_code = error_code << 16;
#define __CRITICAL 0x4
error_code = __CRITICAL | error_code;
SetErrorRegister(error_code);
printf("Abort: message = %s, Code = %lu", message, error_code );
abort();
}
bool SystemCreateThread( SystemThread *thread_function )
{
//Just excute it for single thread
bool return_value = thread_function();
return( return_value );
}
UnSignedLong RandomNumber()
{
return( rand() );
}
void InitRandomNumber( unsigned int seed )
{
srand( seed );
}
void main()
{
if( HardwareCreate() == true )
{
#define __PASSED 0x1
SetErrorRegister(__PASSED);
}
else
{
#define __FAILED 0x0
SetErrorRegister(__FAILED);
}
HardwareDestroy();
}