WPILib 2012
WPILibRoboticsLibraryforFRC
Notifier.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2008. All Rights Reserved.                                                         */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef NOTIFIER_H
00008 #define NOTIFIER_H
00009 
00010 #include "ChipObject.h"
00011 #include "ErrorBase.h"
00012 
00013 typedef void (*TimerEventHandler)(void *param);
00014 
00015 class Notifier : public ErrorBase
00016 {
00017 public:
00018         Notifier(TimerEventHandler handler, void *param = NULL);
00019         virtual ~Notifier();
00020         void StartSingle(double delay);
00021         void StartPeriodic(double period);
00022         void Stop();
00023 private:
00024         static Notifier *timerQueueHead;
00025         static SEM_ID queueSemaphore;
00026         static tAlarm *talarm;
00027         static tInterruptManager *manager;
00028         static int refcount;
00029 
00030         static const UINT32 kTimerInterruptNumber = 28;
00031         static void ProcessQueue(uint32_t mask, void *params); // process the timer queue on a timer event
00032         static void UpdateAlarm();                      // update the FPGA alarm since the queue has changed
00033         void InsertInQueue(bool reschedule);    // insert this Notifier in the timer queue
00034         void DeleteFromQueue();                         // delete this Notifier from the timer queue
00035         TimerEventHandler m_handler;                    // address of the handler
00036         void *m_param;                                                  // a parameter to pass to the handler
00037         double m_period;                                                // the relative time (either periodic or single)
00038         double m_expirationTime;                                // absolute expiration time for the current event
00039         Notifier *m_nextEvent;                                  // next Nofifier event
00040         bool m_periodic;                                                // true if this is a periodic event
00041         bool m_queued;                                                  // indicates if this entry is queued
00042         SEM_ID m_handlerSemaphore;                              // held by interrupt manager task while handler call is in progress 
00043         DISALLOW_COPY_AND_ASSIGN(Notifier);
00044 };
00045 
00046 #endif
 All Classes Functions Variables