/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss of reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#include "kernel.h"

/****************************************************************************/
/*					Public API functions									*/
/****************************************************************************/

/** @addtogroup bx_time */
/** @{ */

/**
*	Returns the system uptime.
*
*	This function returns the uptime. It returns an <tt>unsigned long long</tt>
*	value. The upper 32 bits contain the number of seconds and the lower 32
*	bits is the microseconds. This method was chosen over returning a
*	structure because structures are always returned on the stack while
*	a long long is returned in 2 32-bit registers. The compiler is smart
*	enough to know that if you shift a long long to the right by 32 bits and
*	assign it to a 32-bit variable it does not have to actually shift, but use
*	the register representing the upper half of the long long.
*
*	@retval		((uptime_microsecs/1E6)<<32)+(uptime_microsecs%1E6)
*/

unsigned long long BX_TimerUptime( void )
{
int	cpsr;
unsigned long long retv;

	cpsr = _bx_IrqDis();
	retv = ( (unsigned long long) _bx_state.secs << 32 ) + _bx_state.usec;
	_bx_IrqRes( cpsr );
	return( retv );
}

/** @} */

