Blame include/complib/cl_timer.h

Packit Service 54dbc3
/*
Packit Service 54dbc3
 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
Packit Service 54dbc3
 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
Packit Service 54dbc3
 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 * This software is available to you under a choice of one of two
Packit Service 54dbc3
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit Service 54dbc3
 * General Public License (GPL) Version 2, available from the file
Packit Service 54dbc3
 * COPYING in the main directory of this source tree, or the
Packit Service 54dbc3
 * OpenIB.org BSD license below:
Packit Service 54dbc3
 *
Packit Service 54dbc3
 *     Redistribution and use in source and binary forms, with or
Packit Service 54dbc3
 *     without modification, are permitted provided that the following
Packit Service 54dbc3
 *     conditions are met:
Packit Service 54dbc3
 *
Packit Service 54dbc3
 *      - Redistributions of source code must retain the above
Packit Service 54dbc3
 *        copyright notice, this list of conditions and the following
Packit Service 54dbc3
 *        disclaimer.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 *      - Redistributions in binary form must reproduce the above
Packit Service 54dbc3
 *        copyright notice, this list of conditions and the following
Packit Service 54dbc3
 *        disclaimer in the documentation and/or other materials
Packit Service 54dbc3
 *        provided with the distribution.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service 54dbc3
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service 54dbc3
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit Service 54dbc3
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit Service 54dbc3
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit Service 54dbc3
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service 54dbc3
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service 54dbc3
 * SOFTWARE.
Packit Service 54dbc3
 *
Packit Service 54dbc3
 */
Packit Service 54dbc3
Packit Service 54dbc3
/*
Packit Service 54dbc3
 * Abstract:
Packit Service 54dbc3
 *	Declaration of timer abstraction.
Packit Service 54dbc3
 */
Packit Service 54dbc3
Packit Service 54dbc3
#ifndef _CL_TIMER_H_
Packit Service 54dbc3
#define _CL_TIMER_H_
Packit Service 54dbc3
Packit Service 54dbc3
#include <complib/cl_types.h>
Packit Service 54dbc3
Packit Service 54dbc3
#ifdef __cplusplus
Packit Service 54dbc3
#  define BEGIN_C_DECLS extern "C" {
Packit Service 54dbc3
#  define END_C_DECLS   }
Packit Service 54dbc3
#else				/* !__cplusplus */
Packit Service 54dbc3
#  define BEGIN_C_DECLS
Packit Service 54dbc3
#  define END_C_DECLS
Packit Service 54dbc3
#endif				/* __cplusplus */
Packit Service 54dbc3
Packit Service 54dbc3
BEGIN_C_DECLS
Packit Service 54dbc3
/****h* Component Library/Timer
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	Timer
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The Timer provides the ability to schedule a function to be invoked at
Packit Service 54dbc3
*	a given time in the future.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	The timer callback function must not perform any blocking operations.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	The timer functions operate on a cl_timer_t structure which should be
Packit Service 54dbc3
*	treated as opaque and should be manipulated only through the provided
Packit Service 54dbc3
*	functions.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Structures:
Packit Service 54dbc3
*		cl_timer_t
Packit Service 54dbc3
*
Packit Service 54dbc3
*	Callbacks:
Packit Service 54dbc3
*		cl_pfn_timer_callback_t
Packit Service 54dbc3
*
Packit Service 54dbc3
*	Initialization:
Packit Service 54dbc3
*		cl_timer_construct, cl_timer_init, cl_timer_destroy
Packit Service 54dbc3
*
Packit Service 54dbc3
*	Manipulation:
Packit Service 54dbc3
*		cl_timer_start, cl_timer_stop
Packit Service 54dbc3
*********/
Packit Service 54dbc3
/****d* Component Library: Timer/cl_pfn_timer_callback_t
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_pfn_timer_callback_t
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_pfn_timer_callback_t function type defines the prototype for
Packit Service 54dbc3
*	functions used to notify users of a timer expiration.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
typedef void (*cl_pfn_timer_callback_t) (IN void *context);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* PARAMETERS
Packit Service 54dbc3
*	context
Packit Service 54dbc3
*		[in] Value specified in a previous call to cl_timer_init.
Packit Service 54dbc3
*
Packit Service 54dbc3
* RETURN VALUE
Packit Service 54dbc3
*	This function does not return a value.
Packit Service 54dbc3
*
Packit Service 54dbc3
* NOTES
Packit Service 54dbc3
*	This function type is provided as function prototype reference for the
Packit Service 54dbc3
*	function provided by users as a parameter to the cl_timer_init function.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_timer_init
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/*
Packit Service 54dbc3
 * This include file defines the timer structure, and depends on the timer
Packit Service 54dbc3
 * callback definition.
Packit Service 54dbc3
 */
Packit Service 54dbc3
#include <complib/cl_timer_osd.h>
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Timer/cl_timer_construct
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_timer_construct
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_timer_construct function initializes the state of a timer.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
void cl_timer_construct(IN cl_timer_t * const p_timer);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* PARAMETERS
Packit Service 54dbc3
*	p_timer
Packit Service 54dbc3
*		[in] Pointer to a cl_timer_t structure whose state to initialize.
Packit Service 54dbc3
*
Packit Service 54dbc3
* RETURN VALUE
Packit Service 54dbc3
*	This function does not return a value.
Packit Service 54dbc3
*
Packit Service 54dbc3
* NOTES
Packit Service 54dbc3
*	Allows calling cl_timer_destroy without first calling cl_timer_init.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	Calling cl_timer_construct is a prerequisite to calling any other
Packit Service 54dbc3
*	timer function except cl_timer_init.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_timer_init, cl_timer_destroy
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Timer/cl_timer_init
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_timer_init
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_timer_init function initializes a timer for use.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
cl_status_t
Packit Service 54dbc3
cl_timer_init(IN cl_timer_t * const p_timer,
Packit Service 54dbc3
	      IN cl_pfn_timer_callback_t pfn_callback,
Packit Service 54dbc3
	      IN const void *const context);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* PARAMETERS
Packit Service 54dbc3
*	p_timer
Packit Service 54dbc3
*		[in] Pointer to a cl_timer_t structure to initialize.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	pfn_callback
Packit Service 54dbc3
*		[in] Address of a callback function to be invoked when a timer expires.
Packit Service 54dbc3
*		See the cl_pfn_timer_callback_t function type definition for details
Packit Service 54dbc3
*		about the callback function.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	context
Packit Service 54dbc3
*		[in] Value to pass to the callback function.
Packit Service 54dbc3
*
Packit Service 54dbc3
* RETURN VALUES
Packit Service 54dbc3
*	CL_SUCCESS if the timer was successfully initialized.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	CL_ERROR otherwise.
Packit Service 54dbc3
*
Packit Service 54dbc3
* NOTES
Packit Service 54dbc3
*	Allows calling cl_timer_start and cl_timer_stop.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_timer_construct, cl_timer_destroy, cl_timer_start,
Packit Service 54dbc3
*	cl_timer_stop, cl_pfn_timer_callback_t
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Timer/cl_timer_destroy
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_timer_destroy
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_timer_destroy function performs any necessary cleanup of a timer.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
void cl_timer_destroy(IN cl_timer_t * const p_timer);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* PARAMETERS
Packit Service 54dbc3
*	p_timer
Packit Service 54dbc3
*		[in] Pointer to a cl_timer_t structure to destroy.
Packit Service 54dbc3
*
Packit Service 54dbc3
* RETURN VALUE
Packit Service 54dbc3
*	This function does not return a value.
Packit Service 54dbc3
*
Packit Service 54dbc3
* NOTES
Packit Service 54dbc3
*	cl_timer_destroy cancels any pending callbacks.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	This function should only be called after a call to cl_timer_construct
Packit Service 54dbc3
*	or cl_timer_init.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_timer_construct, cl_timer_init
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Timer/cl_timer_start
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_timer_start
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_timer_start function sets a timer to expire after a given interval.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
cl_status_t
Packit Service 54dbc3
cl_timer_start(IN cl_timer_t * const p_timer, IN const uint32_t time_ms);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* PARAMETERS
Packit Service 54dbc3
*	p_timer
Packit Service 54dbc3
*		[in] Pointer to a cl_timer_t structure to schedule.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	time_ms
Packit Service 54dbc3
*		[in] Time, in milliseconds, before the timer should expire.
Packit Service 54dbc3
*
Packit Service 54dbc3
* RETURN VALUES
Packit Service 54dbc3
*	CL_SUCCESS if the timer was successfully scheduled.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	CL_ERROR otherwise.
Packit Service 54dbc3
*
Packit Service 54dbc3
* NOTES
Packit Service 54dbc3
*	cl_timer_start implicitly stops the timer before being scheduled.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	The interval specified by the time_ms parameter is a minimum interval.
Packit Service 54dbc3
*	The timer is guaranteed to expire no sooner than the desired interval, but
Packit Service 54dbc3
*	may take longer to expire.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_timer_stop, cl_timer_trim
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Timer/cl_timer_stop
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_timer_stop
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_timer_stop function stops a pending timer from expiring.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
void cl_timer_stop(IN cl_timer_t * const p_timer);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* PARAMETERS
Packit Service 54dbc3
*	p_timer
Packit Service 54dbc3
*		[in] Pointer to a cl_timer_t structure.
Packit Service 54dbc3
*
Packit Service 54dbc3
* RETURN VALUE
Packit Service 54dbc3
*	This function does not return a value.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_timer_start, cl_timer_trim
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Timer/cl_timer_trim
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_timer_trim
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_timer_trim function pulls in the absolute expiration
Packit Service 54dbc3
*	time of a timer if the current expiration time exceeds the specified
Packit Service 54dbc3
*	interval.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	sets a timer to expire after a given
Packit Service 54dbc3
*	interval if that interval is less than the current timer expiration.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
cl_status_t
Packit Service 54dbc3
cl_timer_trim(IN cl_timer_t * const p_timer, IN const uint32_t time_ms);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* PARAMETERS
Packit Service 54dbc3
*	p_timer
Packit Service 54dbc3
*		[in] Pointer to a cl_timer_t structure to schedule.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	time_ms
Packit Service 54dbc3
*		[in] Maximum time, in milliseconds, before the timer should expire.
Packit Service 54dbc3
*
Packit Service 54dbc3
* RETURN VALUES
Packit Service 54dbc3
*	CL_SUCCESS if the timer was successfully scheduled.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	CL_ERROR otherwise.
Packit Service 54dbc3
*
Packit Service 54dbc3
* NOTES
Packit Service 54dbc3
*	cl_timer_trim has no effect if the time interval is greater than the
Packit Service 54dbc3
*	remaining time when the timer is set.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	If the new interval time is less than the remaining time, cl_timer_trim
Packit Service 54dbc3
*	implicitly stops the timer before resetting it.
Packit Service 54dbc3
*
Packit Service 54dbc3
*	If the timer is reset, it is guaranteed to expire no sooner than the
Packit Service 54dbc3
*	new interval, but may take longer to expire.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_timer_start, cl_timer_stop
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Time Stamp/cl_get_time_stamp
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_get_time_stamp
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_get_time_stamp function returns the current time stamp in
Packit Service 54dbc3
*	microseconds since the system was booted.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
uint64_t cl_get_time_stamp(void);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* RETURN VALUE
Packit Service 54dbc3
*	Time elapsed, in microseconds, since the system was booted.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_get_time_stamp_sec
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
/****f* Component Library: Time Stamp/cl_get_time_stamp_sec
Packit Service 54dbc3
* NAME
Packit Service 54dbc3
*	cl_get_time_stamp_sec
Packit Service 54dbc3
*
Packit Service 54dbc3
* DESCRIPTION
Packit Service 54dbc3
*	The cl_get_time_stamp_sec function returns the current time stamp in
Packit Service 54dbc3
*	seconds since the system was booted.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SYNOPSIS
Packit Service 54dbc3
*/
Packit Service 54dbc3
uint32_t cl_get_time_stamp_sec(void);
Packit Service 54dbc3
/*
Packit Service 54dbc3
* RETURN VALUE
Packit Service 54dbc3
*	Time elapsed, in seconds, since the system was booted.
Packit Service 54dbc3
*
Packit Service 54dbc3
* SEE ALSO
Packit Service 54dbc3
*	Timer, cl_get_time_stamp
Packit Service 54dbc3
*********/
Packit Service 54dbc3
Packit Service 54dbc3
END_C_DECLS
Packit Service 54dbc3
#endif				/* _CL_TIMER_H_ */