/*********************************************************************
 *
 *                  Tick Manager for PIC18
 *
 *********************************************************************
 * FileName:        Tick.h
 * Dependencies:    
 * Processor:       PIC18F67J50
 * Compiler:       	MPLAB C18 (mcc18.exe) v3.35
 * Linker:          MPLAB MPLINK Object Linker (mplink.exe) v4.35
 * Company:         TechToys Company (www.TechToys.com.hk)
 *
 * John Leung		18/08/10
********************************************************************/

#ifndef TICK_H
#define TICK_H

#include <p18cxxx.h>
#include "GenericTypeDefs.h"
#include "HardwareProfile.h"

#ifndef CLOCK_FREQ
#define CLOCK_FREQ                     48000000		//Fosc freq.
#endif

#if !defined(TICKS_PER_SECOND)
#define TICKS_PER_SECOND               100			//10ms interval
#endif

#if !defined(TICK_PRESCALE_VALUE)
#define TICK_PRESCALE_VALUE            2			//1:2 prescale
#endif

typedef unsigned long TICK;									//it is 32-bit unsigned

#define TICK_SECOND             ((TICK)TICKS_PER_SECOND)

#define TickGetDiff(a, b)       (a-b)
//#define TickGetDiff(a, b)       (TICK)(a < b) ? (((TICK)0xffff - b) + a) : (a - b)

/*
* API functions here
*/
void TickInit(void);		//Tick manager is initialized.
TICK TickGet(void);			//Return current TICK value
void TickUpdate(void);		//Internal Tick and Seconds count are updated, isr() routine
#endif
