/******************************************************************************/
/*                       Copyright 2001 Broadcom Corporation                  */
/*                                                                            */
/* This material is the confidential trade secret and proprietary information */
/* of Broadcom Corp.  It may not be reproduced, used, sold or transferred to  */
/* any third party without the prior written consent of Broadcom Corp.        */
/* All rights reserved.                                                       */
/******************************************************************************/
/*   FileName        : bcm_timer.h                                            */
/*   Purpose         : Usefull timer variables used for time out features     */
/*   Limitations     : None                                                   */
/*   Author          : Emmanuel Hanssens                                      */
/*   Creation Date   : 20-Sep-2001                                            */
/*   History         : Compiled by CVS                                        */
/******************************************************************************/
/*   $Id: bcm_timer.h,v 1.12 2004/06/22 13:51:00 hanssens Exp $  */
/******************************************************************************/
#ifndef TIMER_H
# define TIMER_H

# include "bcm_userdef.h"

/* own timer structure definition (same as system timeval) */
typedef struct MyTime MyTime;
struct MyTime
{
  long int sec;
  long int usec;
};

/* global timer variables */

/* internal definition (only included in bcm_timer.c, thanks to TIMER_C) */
# ifdef TIMER_C

#  ifndef EXTERN
#   define EXTERN
#  endif

/* wait BCM_QA_TIMEOUT_MS for free position in queue before time out failure */
EXTERN const MyTime requestTimeOut = {BCM_QA_TIMEOUT_MS/1000,
                                      (BCM_QA_TIMEOUT_MS%1000)*1000};

/* wait BCM_QA_TIMEOUT_MS for message in reply queue before time out failure */
EXTERN const MyTime replyTimeOut = {BCM_QA_TIMEOUT_MS/1000,
                                    (BCM_QA_TIMEOUT_MS%1000)*1000};

/* wait BOOTER_TIMEOUT_MS for booter image ready */
EXTERN const MyTime booterReadyTimeOut = {BOOTER_TIMEOUT_MS/1000,
                                          (BOOTER_TIMEOUT_MS%1000)*1000};

/* wait FIRMWARE_TIMEOUT_MS for target image ready */
EXTERN const MyTime fwReadyTimeOut = {FIRMWARE_TIMEOUT_MS/1000,
                                      (FIRMWARE_TIMEOUT_MS%1000)*1000};

/* sleep time of 1ms between polling */
EXTERN const MyTime sleepTime = {0, 1000};
# else

/* extern declaration */
extern const MyTime requestTimeOut;
extern const MyTime replyTimeOut;
extern const MyTime booterReadyTimeOut;
extern const MyTime fwReadyTimeOut;
extern const MyTime sleepTime;


# endif

void startTimer(void);
int  compareTimer(MyTime timeOut);
void getTimer(MyTime *myTime);
void stopTimer(void);
void goSleep(MyTime timeToSleep);

#endif
