/****************************************************************************/
/*	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 "coop.h"

/** @addtogroup coop_time */
/** @{ */

/**
*	Return the uptime of the system.
*
*	The function returns the uptime of the system in microseconds. It
*	relies on the calls to BZ_TimerTick(), basically summing the arguments
*	of those calls.
*
*	@return		The uptime. It is returned as an <tt>unsigned long long</tt>
*				but it is actually two <tt>unsigned int</tt>s, one being the
*				number of seconds and the other the microseconds. It is
*				guaranteed that the microsecond count is never larger than
*				999999. The upper 32-bits of the word represent the seconds
*				and the lower 32 are the microseconds. That is:
*				@code
*				unsigned long long	temp;
*				unsigned int		sec, usec;
*
*					temp = BZ_TimerUptime();
*					usec = temp;
*					sec  = temp >> 32;
*				@endcode
*/

unsigned long long 	BZ_TimerUptime( void )
{
BZ_STAT				*base = &_bz_stat;
unsigned int		stat;
unsigned long long	retv;

	stat = BZ_IrqDisable( 1 );
	retv = ( (unsigned long long) base->upts << 32 ) | base->upts;
	BZ_IrqDisable( stat );
	return( retv );
}

/** @} */

