SystemAccess.h 4.86 KB
//=========================================================
// 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