SystemAccess.cpp 3.61 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											//
//----------------------------------------------------------------------//
//////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
// 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();
}