SystemAccess.h
4.86 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
//=========================================================
// 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
//==========================================================
//
// Class Name:
// Author:
// Company: VAutomation An Arc Cores Company
// Date created: 2/01/2001 at 9:46
//
//
//==========================================================
//
// Notes: This file should not modified. It is designed to
// compile under a wide range of compilers and any addtional
// dependencies may defeat the purpose of its structure.
//
//
//
//==========================================================
// SystemAccess.h - Wrappers for system calls
//==========================================================
#ifndef _SystemAccess_
#define _SystemAccess_
#include "DataTypes.h"
//==========================================================
//Time functions - These time functions should be used with care if simulation code will be
//re-hosted onto an embedded processor. (See Notes Below)
//
// Note1 ) If a SystemWait call is used during simulation with a unit of time like MS_UNITS and the embedded
// processor does not have any way calculate time, the code will not port.
//
// Note2 )If a designer wishes to write code that will wait for ever in the main loop, while interrupts are used to do all
// processing, the loop should use a SystemWait(1) in the tight loop to pass time.
//
// Example Code:
//
// bool done
// IRQ_function()
// {
// //Do some processing here.
// DoSomeThing();
//
// if( cnt = 100 )
// done = true;
// cnt++;
// }
//
// void MainThread()
// {
// while( done == false )
// {
// SystemWait(TICK_UNITS); //This will allow time to pass in a simulation.
// }
// }
//
//==========================================================
typedef double ClockType;
enum TimeType{ TICK_UNITS, NS_UNITS, US_UNITS, MS_UNITS, SEC_UNITS };
bool SystemWait( const UnSignedLong& units, const TimeType time_type = TICK_UNITS );
bool GetSystemTicks( ClockType& units, const TimeType time_type = TICK_UNITS );
//==========================================================
// Thread Functions - These function calls are used to start threads
// of code. The SystemCreateThread function is used to hide the implementation
// of the calling thread code.
//
// Note 1) If simulation code is going to be re-hosted to a processor the number of
// Threads spawned should not exceed the system capability of the re-hosted system.
//
// For example: If code is written for a embedded processor with no OS ( no thread libs )
// The code should only create one thread( one main function ). Prototype for a
// SystemThread Function
//==========================================================
typedef bool SystemThread();
bool SystemCreateThread( SystemThread *thread_function );
//==========================================================
//Memory Functions - These functions calls are heap access calls.
//
// Note 1) When writing BFM code, we always allocate the memory accessed
// by peripherals. This will first removed the need to create special memory segments
// in the memory map for the peripheral access. This will second allow detection of improper
// memory accesses from the peripherals during simulation.
//
// Note 2) When writing embedded processor code this function will used malloc with free or
// new with delete depending on the code requirements.
//
//==========================================================
AddressType AllocMemory( const UnSignedLong & size );
bool DeleteMemory( AddressType allocated_data );
//==========================================================
//SystemAbort Functions - This function aborts the execution.
//
// This call will abort the code execution.
//
// Note 1) When this function is called in BFM simulation the string with the message and error number is
// printed to the console followed by a call to the simulator break function.
//
// Note 2) The implementation of this function for an embedded processor will typically set an error register and then
// call the abort function from the C-library.
//
//
//==========================================================
void SystemAbort( char* message = 0, UnSignedLong error_code = 0);
//==========================================================
//SystemAbort Functions - Generates a random number from zero to max rand.
//
//==========================================================
UnSignedLong RandomNumber(); //rand()
//==========================================================
//SystemAbort Functions - Resets the random number generator
//
//==========================================================
void InitRandomNumber( unsigned int seed ); //srand
#endif