/*********************************  timers.c  *********************************
 * $Source: /home/cvs/ESP/gen2/software/msp430/lib/common/timers.c,v $
 *  Copyright (C) 2003 MBARI
 *
 *  MBARI Proprietary Information. All rights reserved.
 * $Id: timers.c,v 1.2 2004/03/25 01:12:55 brent Exp $
 *
 * Simple interval timers for the MSP430
 *
 * Each timer consists of a countdown, a repeatRate and an action
 * function to call when the countdown decriments from one to zero.
 * The repeatRate is a divisor on the fundamental timer frequency.
 * Each time the countdown reaches zero, it is reloaded with the
 * repeatRate.  If the repeatRate is zero, the timer functions as
 * a one shot -- i.e. when its countdown reaches zero, it is reloaded
 * with zero and remains inactive.
 *
 * The action function assocated with each timer must always be
 * a valid timerAction.  It must never be NULL!  Use one of the
 * stock timerAction functions when no action is desired.
 *
 * To prevent reentry to a hypothetical "nonReentrantTimerAction" function:
 *   void nonReentrantTimerAction (array, index, timer) {
 *    timer->action = dummyTimerAction;  //ignore any attempts to reenter
 *      .... non-reentrant stuff ....
 *    timer->action = nonReentrantTimerAction;
 *   }
 *
 * A skeleton for using timers in an application:
 *
 *  Declare:
 *    struct timer myTimers[TIMERS];
 *
 *  At reset:
 *    initTimers (myTimers, TIMERS);
 *    (configure MSP430 clocks, timers & interrupts)
 *  
 *  In timer Interrupt Service Routine:
 *    processTimers (myTimers, TIMERS);
 * 
 *****************************************************************************/

#include "timers.h"

void initTimers (struct timer *array, unsigned timers)
/*
  (re-)initialize a timer array of timers elements
*/
{
  while (timers--) {
    array->countdown = array->period = 0;
    array->action = dummyTimerAction;
  }
}


/* some stock timerAction functions */

void 
 dummyTimerAction (struct timer *array, unsigned index, struct timer *timer)
/*
  do nothing -- ignore countdown
*/
{
}
