LoTimer.h

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/irccm/LoTimer.h
00003    \brief Generalized timer API for Robolocust's iRobot Create Command
00004    Module control program.
00005 
00006    This file defines an API for "generalized" one and ten millisecond
00007    timers for the iRobot Create Command Module control program used by
00008    Robolocust. The API provides a means for other parts of the control
00009    program to setup "stop clocks" and perform whatever operations they
00010    need while this stop clock ticks away. Additionally, these timers are
00011    "generalized" in the sense that client modules may register arbitrary
00012    callback functions that will be triggered each time the timer ISR
00013    kicks in.
00014 */
00015 
00016 /*
00017  ************************************************************************
00018  * The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   *
00019  * by the University of Southern California (USC) and the iLab at USC.  *
00020  * See http:  iLab.usc.edu for information about this project.          *
00021  *                                                                      *
00022  * Major portions of the iLab Neuromorphic Vision Toolkit are protected *
00023  * under the U.S. patent ``Computation of Intrinsic Perceptual Saliency *
00024  * in Visual Environments, and Applications'' by Christof Koch and      *
00025  * Laurent Itti, California Institute of Technology, 2001 (patent       *
00026  * pending; application number 09/912,225 filed July 23, 2001; see      *
00027  * http:  pair.uspto.gov/cgi-bin/final/home.pl for current status).     *
00028  ************************************************************************
00029  * This file is part of the iLab Neuromorphic Vision C++ Toolkit.       *
00030  *                                                                      *
00031  * The iLab Neuromorphic Vision C++ Toolkit is free software; you can   *
00032  * redistribute it and/or modify it under the terms of the GNU General  *
00033  * Public License as published by the Free Software Foundation; either  *
00034  * version 2 of the License, or (at your option) any later version.     *
00035  *                                                                      *
00036  * The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  *
00037  * that it will be useful, but WITHOUT ANY WARRANTY; without even the   *
00038  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      *
00039  * PURPOSE.  See the GNU General Public License for more details.       *
00040  *                                                                      *
00041  * You should have received a copy of the GNU General Public License    *
00042  * along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   *
00043  * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   *
00044  * Boston, MA 02111-1307 USA.                                           *
00045  ************************************************************************
00046 */
00047 
00048 /*
00049    Primary maintainer for this file: mviswana usc edu
00050    $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/irccm/LoTimer.h $
00051    $Id: LoTimer.h 13689 2010-07-23 03:38:35Z mviswana $
00052 */
00053 
00054 #ifndef LOBOT_IRCCM_TIMER_DOT_H
00055 #define LOBOT_IRCCM_TIMER_DOT_H
00056 
00057 /*------------------------------- TYPES -------------------------------*/
00058 
00059 /// The ATmega128 provides three timers that tick away in parallel with
00060 /// the main clock. These three timers provide a means for asynchronous
00061 /// operations w.r.t. the main "thread" of execution. However, as there
00062 /// are only three such timers, if each module that required some form of
00063 /// asynchrony were to "capture" a timer for itself, only three modules
00064 /// could possibly take advantage of this feature.
00065 ///
00066 /// To work around this limitation, the Robolocust low-level controller
00067 /// uses the ATmega128's two 8-bit timers to implement a 1ms timer and a
00068 /// 10ms timer. This timer module then associates a list of arbitrary
00069 /// callbacks with each of these timers and allows client modules to
00070 /// register their timer callbacks here, thus, enabling all modules to
00071 /// take advantage of asynchrony if required. Hence the term "generalized
00072 /// timer."
00073 ///
00074 /// The following type defines the signature for timer callback
00075 /// functions.
00076 ///
00077 /// NOTE: Timer callbacks should not be computationally involved. Rather
00078 /// they should perform a quick couple of assignments, if statements and
00079 /// other simple operations. Otherwise, the timer callbacks run the risk
00080 /// of not being triggered every one and ten milliseconds.
00081 ///
00082 /// NOTE 2: This timer module supports a maximum of ten callbacks per
00083 /// generalized timer.
00084 typedef void (*TimerCallback)(void) ;
00085 
00086 /*-------------------------- INITIALIZATION ---------------------------*/
00087 
00088 /// This function sets up the ATmega's two 8-bit timers, one to fire
00089 /// every millisecond and the other to fire every ten milliseconds.
00090 /// Client modules can then register their timer callbacks to take
00091 /// advantage of the asynchrony supported by the ATmega128.
00092 void lo_init_timer(void) ;
00093 
00094 /// This function adds a timer callback to the 1ms timer's callback list.
00095 ///
00096 /// NOTE: A maximum of 10 such callbacks are supported.
00097 void lo_add_timer1_cb(TimerCallback) ;
00098 
00099 /// This function adds a timer callback to the 10ms timer's callback
00100 /// list.
00101 ///
00102 /// NOTE: A maximum of 10 such callbacks are supported.
00103 void lo_add_timer10_cb(TimerCallback) ;
00104 
00105 /*----------------------------- TIMER API -----------------------------*/
00106 
00107 /// Return the current total number of milliseconds that have elapsed
00108 /// since the low-level controller's 1ms timer was setup.
00109 unsigned long lo_ticks(void) ;
00110 
00111 /// Setup a stop watch for the specified number of milliseconds.
00112 void lo_setup_timer(unsigned int ms) ;
00113 
00114 /// Check if a stop watch is running.
00115 char lo_timer_is_running(void) ;
00116 
00117 /// Busy wait for the specified number of milliseconds.
00118 void lo_wait(unsigned int ms) ;
00119 
00120 /// This function can be used to temporarily disable the 10ms timer's
00121 /// (i.e., the ATmega Timer2) interrupts.
00122 #define lo_suspend_timer10() TIMSK2 &= ~0x02
00123 
00124 /// This function can be used to reenable temporarily disabled 10ms timer
00125 /// (i.e., the ATmega Timer2) interrupts.
00126 #define lo_resume_timer10() TIMSK2 |= 0x02
00127 
00128 /*---------------------------------------------------------------------*/
00129 
00130 #endif
Generated on Sun May 8 08:41:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3