/*
 * Copyright (c) 2010-2012 Digi International Inc.,
 * All rights not expressly granted are reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 * =======================================================================
 */
/**
	@addtogroup hal_posix
	@{
	@file xbee_platform_msp430.c
	Platform-specific functions for use by the XBee Driver on POSIX platform.

	@todo Create a platform unit test, one that can verify that the millisecond
			timer doesn't run backwards and that it matches up accurately with
			the seconds timer (base it on the HCS08 regression).
*/

/**************************************************************************************************
*                                           INCLUDES
**************************************************************************************************/

#include "cavalier_board_cfg_rev2.h"
#include "platform.h"
#include "sys_tick.h"

/**************************************************************************************************
*                                           PUBLIC API
**************************************************************************************************/

/**
	@brief
	Platform-specific function to return the number of elapsed seconds

	On some platforms, this is the equivalent of an "uptime".

	On other platforms, it may reflect the value of the RTC, which might
	not be synchronized with a time server and might include leap seconds.

	Regardless, it should consistently report elapsed time and not jump on
	clock synchronization.

	In addition to determining timeouts, the \ref zcl_time "ZCL Time Cluster"
	makes use of it to report current time.

	(Function name wrapped in parentheses so platforms can use a macro function
	of the same name.)

	@return Number of elapsed seconds.
*/
uint32_t xbee_seconds_timer()
{
	return tick_GetUptime();
}

/**
	@brief
	Platform-specific function to return the number of elapsed milliseconds.

	OK for this counter to rollover.  Used for timing and should have a
	resolution of at least 60ms.

	- Rabbit has 1ms resolution.
	- HCS08 has 4ms resolution.
	- DOS has 18 ticks/second (55.55ms resolution)

	(Function name wrapped in parentheses so platforms can use a macro function
	of the same name.)

	@return Number of elapsed milliseconds.

	@sa XBEE_MS_TIMER_RESOLUTION
*/
uint32_t xbee_millisecond_timer()
{
	return( tick_GetTickcount() * TICK_TIMER_FAST_MS_PER_TICK );
}



