/****************************************************************************/
/* Copyright 2009 - 2015 MBARI                                              */
/****************************************************************************/
/* Summary  : Definitions for system timer/ticker for OASIS5                */
/* Filename : sys_timer.h                                                   */
/* Author   : Mike Risi (mrisi), Robert Herlien (rah)                       */
/* Project  : OASIS Mooring Replacement (OASIS5)                            */
/* Revision: 1.0                                                            */
/* Created  : 2009 by Mike Risi, Adapted for Oasis5 10/29/2015 by Bob Herlien*/
/*                                                                          */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*                                                                          */
/****************************************************************************/
/* Modification History:                                                    */
/* 29oct2015 rah - adapted from Respirometer chamber controller             */
/****************************************************************************/

#ifndef SYS_TIMER_H
#define SYS_TIMER_H

#define SYSCLK      24000000L           /* System clock                 */

#define PBCLK       SYSCLK              /* Peripheral Bus Clock         */
#define TICKS_PER_SEC 1000              /* System tick rate             */

#define TMR2PRD         (PBCLK/(8*TICKS_PER_SEC))-1
#define MS_PER_TICK     (1000/TICKS_PER_SEC)

#define DEBUG_TICKER
#ifdef  DEBUG_TICKER
#define tickPinOn()     digTest0On()
#define tickPinOff()    digTest0Off()
#else
#define tickPinOn()
#define tickPinOff()
#endif

void tmrInit();                         /* intialize the timer                  */
void tmrDelayTicks(unsigned int ticks); /* delay for a specified number of timer ticks */
void tmrDelayMs(unsigned int ms);       /* delay for a specified number of milliseconds */
void tmrDelayUs(unsigned int us);       /* delay for a specified number of microseconds */
unsigned long tmrGetTicks();            /* get internal tick counts             */

#endif
