Page MenuHomec4science

timer.h
No OneTemporary

File Metadata

Created
Wed, Feb 19, 23:05
/*
timer.h
Copyright (C) 2013 Alexandre Tuleu
EPFL Biorobotics Laboratory (http://biorob.epfl.ch)
EPFL Ecole Polytechnique Federale de Lausanne (http://www.epfl.ch)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \addtogroup timer */
/*@{*/
/** \file timer.h
\brief Timer handling
This file contains the public definitions and function declarations for
timer handling.
\author Rico Moeckel
\version 1.2
\date 2011-04-28
*/
#ifndef __TIMER_H__
#define __TIMER_H__
#include "config.h"
/// Value corresponds to the maximum frequency of 40MIPS.
#define FCY 39613750
//warning : if you change this, you will have to recompute constants !!!!!
// rougly this gave us a ticks of 6.5 us
#define SYSCLK_PRESCALE (256)
/**
* Defines a clock ticks. ticks are incremented every SYSCLK_PRESCALE
* / FCY seconds. It makes this clock suitable for relative time
* measurement between t1 and t2 using t2 - t1.
*/
typedef unsigned int ticks;
extern volatile unsigned int rtc_overflow_;
/**
* Converts a time in clock ticks to us
*/
#define ticks_to_us(t) (t * 645 / 100 ) //roughly config is 1 ticks == 6.5 us
/**
* Converts a time in us to clock ticks
*/
#define us_to_ticks(t) ( t * 10 / 645 )
/**
* returns current clock time.
*/
#define current_time() (TMR1)
#define rtc_overflow() ( (const volatile unsigned int)rtc_overflow_)
/**
* returns time since event
*/
#define ticks_since(t) (current_time() - t )
/*************************************************************************
*
* PUBLIC FUNCTIONS
*
*************************************************************************/
void timer_init();
#endif /* __TIMER_H__*/
/*@}*/

Event Timeline